UNPKG

@react-vant-next/campaign

Version:

React Mobile UI Components based on Vant UI - Next Generation

86 lines (81 loc) 2.84 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var jsxRuntime = require('react/jsx-runtime'); var ui = require('@react-vant-next/ui'); var utils = require('@react-vant-next/utils'); var cls = require('clsx'); var React = require('react'); const INHERIT_PROPS = [ "title", "visible", "popup", "value", "defaultValue", "loading", "readOnly", "itemHeight", "swipeDuration", "visibleItemCount", "cancelButtonText", "confirmButtonText", "toolbar", "columnsTop", "columnsBottom", "optionRender", "placeholder", "onChange", "onCancel", "onConfirm", "children", ]; function parseVanAreaList(data, columnsNum) { const { province_list = {}, city_list = {}, county_list = {} } = data; const provinces = Object.entries(province_list).map(([value, text]) => ({ value, text, })); const citys = Object.entries(city_list).map(([value, text]) => ({ value, text, })); const countrys = Object.entries(county_list).map(([value, text]) => ({ value, text, })); if (columnsNum > 2) { citys.forEach((city) => { var _a; const value = (_a = city.value) === null || _a === void 0 ? void 0 : _a.slice(0, 4); const children = countrys.filter(country => { var _a; return ((_a = country.value) === null || _a === void 0 ? void 0 : _a.slice(0, 4)) === value; }); city.children = children; }); } if (columnsNum > 1) { provinces.forEach((province) => { var _a; const provinceCode = (_a = province.value) === null || _a === void 0 ? void 0 : _a.slice(0, 2); const children = citys.filter(city => { var _a; return ((_a = city.value) === null || _a === void 0 ? void 0 : _a.slice(0, 2)) === provinceCode; }); province.children = children; }); } return provinces; } const [bem] = utils.createNamespace("area"); function Area(_a) { var { ref } = _a, p = tslib.__rest(_a, ["ref"]); const props = utils.mergeProps(p, { areaList: {}, columnsNum: 3, itemHeight: 44, visibleItemCount: 5, swipeDuration: 300, showToolbar: true, placeholder: true, toolbarPosition: "top", }); const columns = React.useMemo(() => { var _a; return (_a = props.columns) !== null && _a !== void 0 ? _a : parseVanAreaList(props.areaList, +props.columnsNum); }, [props.columnsNum, props.areaList, props.columns]); return (jsxRuntime.jsx(ui.Picker, Object.assign({ ref: ref, style: props.style, className: cls(bem(), props.className), columns: columns }, utils.pick(props, INHERIT_PROPS)))); } exports.default = Area; //# sourceMappingURL=Area.js.map