UNPKG

@amaui/ui-react

Version:
65 lines (64 loc) 4.85 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const utils_1 = require("@amaui/utils"); const style_react_1 = require("@amaui/style-react"); const AutoComplete_1 = __importDefault(require("../AutoComplete")); const ListItem_1 = __importDefault(require("../ListItem")); const Type_1 = __importDefault(require("../Type")); const utils_2 = require("../utils"); const useStyle = (0, style_react_1.style)(theme => ({ root: {} }), { name: 'amaui-AutoCompleteCountry' }); const AutoCompleteCountry = react_1.default.forwardRef((props_, ref) => { const theme = (0, style_react_1.useAmauiTheme)(); const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.amauiAutoCompleteCountry) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]); const AutoComplete = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.AutoComplete) || AutoComplete_1.default; }, [theme]); const ListItem = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.ListItem) || ListItem_1.default; }, [theme]); const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]); const { value, valueDefault, valueInputDefault: valueInputDefault_, size = 'regular', className, children } = props, other = __rest(props, ["value", "valueDefault", "valueInputDefault", "size", "className", "children"]); 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_1.default.useMemo(() => { return utils_1.countries.map(item => (Object.assign(Object.assign({}, item), { value: item['alpha-2'] }))); }, [utils_1.countries]); const valueInputDefault = react_1.default.useMemo(() => { var _a; return valueInputDefault_ !== undefined ? valueInputDefault_ : (_a = options.find(item => item.value === (value !== undefined ? value : valueDefault))) === null || _a === void 0 ? void 0 : _a.name; }, []); return ((0, jsx_runtime_1.jsx)(AutoComplete, Object.assign({ ref: ref, valueInputDefault: valueInputDefault, valueDefault: valueDefault, value: value, options: options, size: size, renderOption: (item, index_, propsItem) => ((0, jsx_runtime_1.jsx)(ListItem, Object.assign({ start: item.flag, startAlign: 'center', primary: ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3' }, { children: item.name }))), value: item.value, selected: item.value === ((value === null || value === void 0 ? void 0 : value.value) !== undefined ? value === null || value === void 0 ? void 0 : value.value : value), size: 'small', button: true }, propsItem), index_)), className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('AutoCompleteCountry', theme) && [ 'amaui-AutoCompleteCountry-root', `amaui-AutoCompleteCountry-size-${size}` ], className, classes.root ]) }, other))); }); AutoCompleteCountry.displayName = 'amaui-AutoCompleteCountry'; exports.default = AutoCompleteCountry;