1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | require('./slicedToArray-ef426d0f.js');
|
8 | require('./unsupportedIterableToArray-8a00e599.js');
|
9 | var React = require('react');
|
10 | var React__default = _interopDefault(React);
|
11 | require('./_commonjsHelpers-72d386ba.js');
|
12 | var index = require('./index-b0606964.js');
|
13 | var defineProperty$1 = require('./defineProperty-0921a47c.js');
|
14 | var toConsumableArray = require('./toConsumableArray-7f36359f.js');
|
15 | var getPrototypeOf = require('./getPrototypeOf-e2d1e599.js');
|
16 | require('./color.js');
|
17 | var components = require('./components.js');
|
18 | require('./contains-component.js');
|
19 | require('./css.js');
|
20 | require('./dayjs.min-aa59a48e.js');
|
21 | require('./date.js');
|
22 | var miscellaneous = require('./miscellaneous.js');
|
23 | require('./environment.js');
|
24 | require('./font.js');
|
25 | require('./math-ecfd5d91.js');
|
26 | require('./characters.js');
|
27 | require('./format.js');
|
28 | require('./keycodes.js');
|
29 | require('./url.js');
|
30 | require('./web3.js');
|
31 | var _extends$1 = require('./extends-40571110.js');
|
32 |
|
33 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = getPrototypeOf._getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = getPrototypeOf._getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return getPrototypeOf._possibleConstructorReturn(this, result); }; }
|
34 |
|
35 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
36 |
|
37 | var _React$createContext = React__default.createContext({}),
|
38 | Provider = _React$createContext.Provider,
|
39 | Consumer = _React$createContext.Consumer;
|
40 |
|
41 | var RadioGroup = function (_React$PureComponent) {
|
42 | getPrototypeOf._inherits(RadioGroup, _React$PureComponent);
|
43 |
|
44 | var _super = _createSuper(RadioGroup);
|
45 |
|
46 | function RadioGroup() {
|
47 | var _this;
|
48 |
|
49 | getPrototypeOf._classCallCheck(this, RadioGroup);
|
50 |
|
51 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
52 | args[_key] = arguments[_key];
|
53 | }
|
54 |
|
55 | _this = _super.call.apply(_super, [this].concat(args));
|
56 |
|
57 | defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "state", {
|
58 |
|
59 | radios: new Set()
|
60 | });
|
61 |
|
62 | defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "handleChange", function (id) {
|
63 | _this.props.onChange(id);
|
64 | });
|
65 |
|
66 | defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "addRadio", function (id) {
|
67 | _this.setState(function (state) {
|
68 | var radios = new Set(state.radios);
|
69 | radios.add(id);
|
70 | return {
|
71 | radios: radios
|
72 | };
|
73 | });
|
74 | });
|
75 |
|
76 | defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "removeRadio", function (id) {
|
77 | _this.setState(function (state) {
|
78 | var radios = new Set(state.radios);
|
79 | radios.delete(id);
|
80 | return {
|
81 | radios: radios
|
82 | };
|
83 | });
|
84 | });
|
85 |
|
86 | defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "selectPrev", function () {
|
87 | var id = _this.getSiblingId(-1);
|
88 |
|
89 | if (id !== null) {
|
90 | _this.props.onChange(id);
|
91 | }
|
92 | });
|
93 |
|
94 | defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "selectNext", function () {
|
95 | var id = _this.getSiblingId(1);
|
96 |
|
97 | if (id !== null) {
|
98 | _this.props.onChange(id);
|
99 | }
|
100 | });
|
101 |
|
102 | return _this;
|
103 | }
|
104 |
|
105 | getPrototypeOf._createClass(RadioGroup, [{
|
106 | key: "getSiblingId",
|
107 | value: function getSiblingId(position) {
|
108 | var selected = this.props.selected;
|
109 |
|
110 | var radios = toConsumableArray._toConsumableArray(this.state.radios);
|
111 |
|
112 | var selectedIndex = selected === undefined ? 0 : radios.indexOf(selected);
|
113 | var newSelectedIndex = selectedIndex + position;
|
114 |
|
115 | if (radios.length === 0) {
|
116 | return null;
|
117 | }
|
118 |
|
119 |
|
120 | if (newSelectedIndex === -1) {
|
121 | return radios[radios.length - 1];
|
122 | }
|
123 |
|
124 |
|
125 | if (newSelectedIndex === radios.length) {
|
126 | return radios[0];
|
127 | }
|
128 |
|
129 |
|
130 | if (selectedIndex > -1 && radios[newSelectedIndex]) {
|
131 | return radios[newSelectedIndex];
|
132 | }
|
133 |
|
134 |
|
135 | return radios[0] === undefined ? null : radios[0];
|
136 | }
|
137 | }, {
|
138 | key: "render",
|
139 | value: function render() {
|
140 | var radios = this.state.radios;
|
141 | var _this$props = this.props,
|
142 | children = _this$props.children,
|
143 | selected = _this$props.selected;
|
144 | var focusableId = radios.has(selected) ? selected : toConsumableArray._toConsumableArray(radios)[0];
|
145 | return React__default.createElement(Provider, {
|
146 | value: {
|
147 | selected: selected,
|
148 | focusableId: focusableId,
|
149 | onChange: this.handleChange,
|
150 | addRadio: this.addRadio,
|
151 | removeRadio: this.removeRadio,
|
152 | selectPrev: this.selectPrev,
|
153 | selectNext: this.selectNext
|
154 | }
|
155 | }, React__default.createElement("div", _extends$1._extends({
|
156 | role: "radiogroup"
|
157 | }, components.stylingProps(this)), children));
|
158 | }
|
159 | }]);
|
160 |
|
161 | return RadioGroup;
|
162 | }(React__default.PureComponent);
|
163 |
|
164 | defineProperty$1._defineProperty(RadioGroup, "propTypes", {
|
165 | children: index.PropTypes.node,
|
166 | selected: index.PropTypes.oneOfType([index.PropTypes.string, index.PropTypes.number]),
|
167 | onChange: index.PropTypes.func
|
168 | });
|
169 |
|
170 | defineProperty$1._defineProperty(RadioGroup, "defaultProps", {
|
171 | onChange: miscellaneous.noop
|
172 | });
|
173 |
|
174 | exports.RadioGroupConsumer = Consumer;
|
175 | exports.default = RadioGroup;
|
176 |
|