UNPKG

@onesy/ui-react

Version:
81 lines (80 loc) 3.72 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["value", "valueDefault", "valueInputDefault", "size", "className", "children"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import { countries } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import AutoCompleteElement from '../AutoComplete'; import ListItemElement from '../ListItem'; import TypeElement from '../Type'; import { staticClassName } from '../utils'; import { jsx as _jsx } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: {} }), { name: 'onesy-AutoCompleteCountry' }); const AutoCompleteCountry = props_ => { const theme = useOnesyTheme(); const l = theme.l; const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyAutoCompleteCountry?.props?.default), props_); const AutoComplete = theme?.elements?.AutoComplete || AutoCompleteElement; const ListItem = theme?.elements?.ListItem || ListItemElement; const Type = theme?.elements?.Type || TypeElement; const { value, valueDefault, valueInputDefault: valueInputDefault_, size = 'regular', className, children } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); // { // flag: string; // name: string; // full_name: string; // sovereignty: string; // 'alpha-2': string; // 'alpha-3': string; // numeric: string; // subdivision: string; // tlds: string[]; // } const options = React.useMemo(() => { return countries.map(item => _objectSpread(_objectSpread({}, item), {}, { name: l(item.name), value: item['alpha-2'] })); }, [countries]); const valueInputDefault = React.useMemo(() => { return valueInputDefault_ !== undefined ? valueInputDefault_ : options.find(item_0 => item_0.value === (value !== undefined ? value : valueDefault))?.name; }, []); return /*#__PURE__*/_jsx(AutoComplete, _objectSpread({ valueInputDefault: valueInputDefault, valueDefault: valueDefault, value: value, options: options, size: size, renderOption: (item_1, index_, propsItem) => /*#__PURE__*/_jsx(ListItem, _objectSpread({ start: item_1.flag, startAlign: "center", primary: /*#__PURE__*/_jsx(Type, { version: "b3", children: item_1.name }), value: item_1.value, selected: item_1.value === (value?.value !== undefined ? value?.value : value), size: "small", button: true }, propsItem), index_), className: classNames([staticClassName('AutoCompleteCountry', theme) && ['onesy-AutoCompleteCountry-root', `onesy-AutoCompleteCountry-size-${size}`], className, classes.root]) }, other)); }; AutoCompleteCountry.displayName = 'onesy-AutoCompleteCountry'; export default AutoCompleteCountry;