UNPKG

baseui

Version:

A React Component library implementing the Base design language

85 lines (83 loc) 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _constants = require("./constants"); var _defaultProps = _interopRequireDefault(require("./default-props")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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. */ // needs to be removed from here // @ts-expect-error todo(flow->ts): possible bug const defaultStateReducer = (type, nextState) => nextState; class StatefulPhoneInputContainer extends _react.default.Component { constructor(...args) { super(...args); // @ts-ignore _defineProperty(this, "state", { text: '', country: _constants.COUNTRIES.US, ...this.props.initialState }); _defineProperty(this, "internalSetState", (type, nextState) => { this.setState(this.props.stateReducer(type, nextState, this.state)); }); _defineProperty(this, "onTextChange", event => { this.props.onTextChange(event); this.internalSetState(_constants.STATE_CHANGE_TYPE.textChange, { text: event.target.value }); }); _defineProperty(this, "onCountryChange", event => { this.props.onCountryChange(event); if (event.option && event.option.id) { this.internalSetState(_constants.STATE_CHANGE_TYPE.countryChange, { // @ts-ignore country: _constants.COUNTRIES[event.option.id] }); } }); } render() { return this.props.children({ ..._defaultProps.default, 'aria-label': this.props['aria-label'], 'aria-labelledby': this.props['aria-labelledby'], 'aria-describedby': this.props['aria-describedby'], disabled: this.props.disabled, error: this.props.error, id: this.props.id, maxDropdownHeight: this.props.maxDropdownHeight, maxDropdownWidth: this.props.maxDropdownWidth, mapIsoToLabel: this.props.mapIsoToLabel, name: this.props.name, overrides: this.props.overrides, placeholder: this.props.placeholder, positive: this.props.positive, required: this.props.required, size: this.props.size, clearable: this.props.clearable, country: this.state.country, text: this.state.text, onTextChange: this.onTextChange, onCountryChange: this.onCountryChange }); } } exports.default = StatefulPhoneInputContainer; _defineProperty(StatefulPhoneInputContainer, "defaultProps", { initialState: { text: _defaultProps.default.text, country: _defaultProps.default.country }, onTextChange: _defaultProps.default.onTextChange, onCountryChange: _defaultProps.default.onTextChange, stateReducer: defaultStateReducer, overrides: {} });