UNPKG

baseui

Version:

A React Component library implementing the Base design language

80 lines (78 loc) 3.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var React = _interopRequireWildcard(require("react")); var _constants = require("./constants"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* Copyright (c) Uber Technologies, Inc. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ const defaultStateReducer = (type, nextState) => nextState; class StatefulRadioGroupContainer extends React.Component { constructor(props) { super(props); _defineProperty(this, "onChange", e => { this.stateReducer(_constants.STATE_TYPE.change, e); const { onChange } = this.props; onChange && onChange(e); }); _defineProperty(this, "stateReducer", (type, e) => { let nextState = {}; const { stateReducer } = this.props; if (type === _constants.STATE_TYPE.change) { nextState = { value: e.target.value }; } const newState = stateReducer(type, nextState, this.state, e); this.setState(newState); }); const { initialState } = this.props; this.state = { ...initialState }; } render() { const { // eslint-disable-next-line @typescript-eslint/no-unused-vars children = childProps => null, // eslint-disable-line no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars initialState, // eslint-disable-line no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars stateReducer, // eslint-disable-line no-unused-vars ...restProps } = this.props; const { onChange } = this; return children({ ...restProps, value: this.state.value, onChange }); } } _defineProperty(StatefulRadioGroupContainer, "defaultProps", { initialState: { value: '' }, stateReducer: defaultStateReducer, onChange: () => {} }); var _default = exports.default = StatefulRadioGroupContainer;