1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _overrides = require("../helpers/overrides.js");
|
11 |
|
12 | var _styledComponents = require("./styled-components.js");
|
13 |
|
14 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
15 |
|
16 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17 |
|
18 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
19 |
|
20 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
21 |
|
22 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
23 |
|
24 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
25 |
|
26 | function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
27 |
|
28 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
29 |
|
30 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
31 |
|
32 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
33 |
|
34 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
35 |
|
36 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
37 |
|
38 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
39 |
|
40 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
41 |
|
42 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
43 |
|
44 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
45 |
|
46 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
47 |
|
48 | function isLabelTopLeft(labelPlacement) {
|
49 | return labelPlacement === 'top' || labelPlacement === 'left';
|
50 | }
|
51 |
|
52 | function isLabelBottomRight(labelPlacement) {
|
53 | return labelPlacement === 'bottom' || labelPlacement === 'right';
|
54 | }
|
55 |
|
56 | var Radio =
|
57 |
|
58 | function (_React$Component) {
|
59 | _inherits(Radio, _React$Component);
|
60 |
|
61 | function Radio() {
|
62 | var _getPrototypeOf2;
|
63 |
|
64 | var _this;
|
65 |
|
66 | _classCallCheck(this, Radio);
|
67 |
|
68 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
69 | args[_key] = arguments[_key];
|
70 | }
|
71 |
|
72 | _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Radio)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
73 |
|
74 | _defineProperty(_assertThisInitialized(_this), "state", {
|
75 | isActive: false,
|
76 | isHovered: false
|
77 | });
|
78 |
|
79 | _defineProperty(_assertThisInitialized(_this), "onMouseEnter", function (e) {
|
80 | _this.setState({
|
81 | isHovered: true
|
82 | });
|
83 |
|
84 | _this.props.onMouseEnter && _this.props.onMouseEnter(e);
|
85 | });
|
86 |
|
87 | _defineProperty(_assertThisInitialized(_this), "onMouseLeave", function (e) {
|
88 | _this.setState({
|
89 | isHovered: false
|
90 | });
|
91 |
|
92 | _this.props.onMouseLeave && _this.props.onMouseLeave(e);
|
93 | });
|
94 |
|
95 | _defineProperty(_assertThisInitialized(_this), "onMouseDown", function (e) {
|
96 | _this.setState({
|
97 | isActive: true
|
98 | });
|
99 |
|
100 | _this.props.onMouseDown && _this.props.onMouseDown(e);
|
101 | });
|
102 |
|
103 | _defineProperty(_assertThisInitialized(_this), "onMouseUp", function (e) {
|
104 | _this.setState({
|
105 | isActive: false
|
106 | });
|
107 |
|
108 | _this.props.onMouseUp && _this.props.onMouseUp(e);
|
109 | });
|
110 |
|
111 | return _this;
|
112 | }
|
113 |
|
114 | _createClass(Radio, [{
|
115 | key: "componentDidMount",
|
116 | value: function componentDidMount() {
|
117 | if (this.props.autoFocus && this.props.inputRef.current) {
|
118 | this.props.inputRef.current.focus();
|
119 | }
|
120 |
|
121 | if (process.env.NODE_ENV !== "production" && this.props.isError) {
|
122 | console.warn('baseui:Radio Property "isError" will be removed in the next major version. Use "error" property instead.');
|
123 | }
|
124 | }
|
125 | }, {
|
126 | key: "render",
|
127 | value: function render() {
|
128 | var _this$props$overrides = this.props.overrides,
|
129 | overrides = _this$props$overrides === void 0 ? {} : _this$props$overrides;
|
130 |
|
131 | var _getOverrides = (0, _overrides.getOverrides)(overrides.Root, _styledComponents.Root),
|
132 | _getOverrides2 = _slicedToArray(_getOverrides, 2),
|
133 | Root = _getOverrides2[0],
|
134 | rootProps = _getOverrides2[1];
|
135 |
|
136 | var _getOverrides3 = (0, _overrides.getOverrides)(overrides.Label, _styledComponents.Label),
|
137 | _getOverrides4 = _slicedToArray(_getOverrides3, 2),
|
138 | Label = _getOverrides4[0],
|
139 | labelProps = _getOverrides4[1];
|
140 |
|
141 | var _getOverrides5 = (0, _overrides.getOverrides)(overrides.Input, _styledComponents.Input),
|
142 | _getOverrides6 = _slicedToArray(_getOverrides5, 2),
|
143 | Input = _getOverrides6[0],
|
144 | inputProps = _getOverrides6[1];
|
145 |
|
146 | var _getOverrides7 = (0, _overrides.getOverrides)(overrides.Description, _styledComponents.Description),
|
147 | _getOverrides8 = _slicedToArray(_getOverrides7, 2),
|
148 | Description = _getOverrides8[0],
|
149 | descriptionProps = _getOverrides8[1];
|
150 |
|
151 | var _getOverrides9 = (0, _overrides.getOverrides)(overrides.RadioMarkInner, _styledComponents.RadioMarkInner),
|
152 | _getOverrides10 = _slicedToArray(_getOverrides9, 2),
|
153 | RadioMarkInner = _getOverrides10[0],
|
154 | radioMarkInnerProps = _getOverrides10[1];
|
155 |
|
156 | var _getOverrides11 = (0, _overrides.getOverrides)(overrides.RadioMarkOuter, _styledComponents.RadioMarkOuter),
|
157 | _getOverrides12 = _slicedToArray(_getOverrides11, 2),
|
158 | RadioMarkOuter = _getOverrides12[0],
|
159 | radioMarkOuterProps = _getOverrides12[1];
|
160 |
|
161 | var sharedProps = {
|
162 | $align: this.props.align,
|
163 | $checked: this.props.checked,
|
164 | $disabled: this.props.disabled,
|
165 | $hasDescription: !!this.props.description,
|
166 | $isActive: this.state.isActive,
|
167 | $isError: this.props.isError,
|
168 | $error: this.props.error,
|
169 | $isFocused: this.props.isFocused,
|
170 | $isFocusVisible: this.props.isFocused && this.props.isFocusVisible,
|
171 | $isHovered: this.state.isHovered,
|
172 | $labelPlacement: this.props.labelPlacement,
|
173 | $required: this.props.required,
|
174 | $value: this.props.value
|
175 | };
|
176 | var label = React.createElement(Label, _extends({}, sharedProps, labelProps), this.props.children);
|
177 | return React.createElement(React.Fragment, null, React.createElement(Root, _extends({
|
178 | "data-baseweb": "radio",
|
179 | onMouseEnter: this.onMouseEnter,
|
180 | onMouseLeave: this.onMouseLeave,
|
181 | onMouseDown: this.onMouseDown,
|
182 | onMouseUp: this.onMouseUp
|
183 | }, sharedProps, rootProps), isLabelTopLeft(this.props.labelPlacement) && label, React.createElement(RadioMarkOuter, _extends({}, sharedProps, radioMarkOuterProps), React.createElement(RadioMarkInner, _extends({}, sharedProps, radioMarkInnerProps))), React.createElement(Input, _extends({
|
184 | "aria-invalid": this.props.error || this.props.isError || null,
|
185 | checked: this.props.checked,
|
186 | disabled: this.props.disabled,
|
187 | name: this.props.name,
|
188 | onBlur: this.props.onBlur,
|
189 | onFocus: this.props.onFocus,
|
190 | onChange: this.props.onChange,
|
191 | ref: this.props.inputRef,
|
192 | required: this.props.required,
|
193 | tabIndex: this.props.tabIndex,
|
194 | type: "radio",
|
195 | value: this.props.value
|
196 | }, sharedProps, inputProps)), isLabelBottomRight(this.props.labelPlacement) && label), !!this.props.description && React.createElement(Description, _extends({}, sharedProps, descriptionProps), this.props.description));
|
197 | }
|
198 | }]);
|
199 |
|
200 | return Radio;
|
201 | }(React.Component);
|
202 |
|
203 | _defineProperty(Radio, "defaultProps", {
|
204 | overrides: {},
|
205 | checked: false,
|
206 | disabled: false,
|
207 | autoFocus: false,
|
208 | inputRef: React.createRef(),
|
209 | align: 'vertical',
|
210 | isError: false,
|
211 | error: false,
|
212 | onChange: function onChange() {},
|
213 | onMouseEnter: function onMouseEnter() {},
|
214 | onMouseLeave: function onMouseLeave() {},
|
215 | onMouseDown: function onMouseDown() {},
|
216 | onMouseUp: function onMouseUp() {},
|
217 | onFocus: function onFocus() {},
|
218 | onBlur: function onBlur() {}
|
219 | });
|
220 |
|
221 | var _default = Radio;
|
222 | exports.default = _default; |
\ | No newline at end of file |