@react-vant-next/campaign
Version:
React Mobile UI Components based on Vant UI - Next Generation
82 lines (79 loc) • 2.75 kB
JavaScript
import { __rest } from 'tslib';
import { jsx } from 'react/jsx-runtime';
import { Picker } from '@react-vant-next/ui';
import { createNamespace, mergeProps, pick } from '@react-vant-next/utils';
import cls from 'clsx';
import { useMemo } from '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] = createNamespace("area");
function Area(_a) {
var { ref } = _a, p = __rest(_a, ["ref"]);
const props = mergeProps(p, {
areaList: {},
columnsNum: 3,
itemHeight: 44,
visibleItemCount: 5,
swipeDuration: 300,
showToolbar: true,
placeholder: true,
toolbarPosition: "top",
});
const columns = useMemo(() => { var _a; return (_a = props.columns) !== null && _a !== void 0 ? _a : parseVanAreaList(props.areaList, +props.columnsNum); }, [props.columnsNum, props.areaList, props.columns]);
return (jsx(Picker, Object.assign({ ref: ref, style: props.style, className: cls(bem(), props.className), columns: columns }, pick(props, INHERIT_PROPS))));
}
export { Area as default };
//# sourceMappingURL=Area.js.map