import React, { useState, useMemo, useRef } from 'react'; import { Button, Fill, IndexBar, IndexBarGroupItem, IndexBarBaseData, Space, IndexBarValue, IndexBarRef, Toast, } from '@xrnjs/ui'; import { IconXChina1 } from '../../../icons'; import Card from '_global/Card'; import styles from './style'; import { cityJson } from './cityList'; type CityType = { name: string; code: string; }; // 格式化城市数据 const formatLocationData: IndexBarGroupItem[] = []; cityJson.forEach((i: { initial: string; cityNameList: CityType[] }) => { const { initial, cityNameList } = i; formatLocationData.push({ value: initial, label: initial, data: cityNameList.map((p: CityType) => ({ value: p.code, label: p.name, prefix: , description: p.name, })), }); }); const onDisabledPress = (v: IndexBarBaseData) => Toast({ position: 'middle', message: `${v.label} 不可操作提示`, forbidPress: true, }); const BasicUsage = () => { // 单选示例 const singleRef = useRef(null); const [singleVisible, setSingleVisible] = useState(false); const [singleValue, setSingleValue] = useState(); // 多选示例 const multipleRef = useRef(null); const [multipleVisible, setMultipleVisible] = useState(false); const [multipleValue, setMultipleValue] = useState([]); const SingleExample = useMemo(() => { return ( setSingleVisible(false), showConfirmButton: false, }} onPressOverlay={() => setSingleVisible(false)} onClosed={() => setSingleVisible(false)} groups={formatLocationData} value={singleValue} ref={singleRef} onChange={(item) => { setSingleValue(item); setSingleVisible(false); }} onDisabledPress={onDisabledPress} /> ); }, [singleVisible, singleValue]); const MultipleExample = useMemo(() => { return ( setMultipleVisible(false), showConfirmButton: true, onConfirm: () => setMultipleVisible(false), }} onPressOverlay={() => setMultipleVisible(false)} onClosed={() => setMultipleVisible(false)} groups={formatLocationData} mode="multiple" max={5} onChange={setMultipleValue} value={multipleValue} ref={multipleRef} footerStyle={styles.footerStyle} footer={ <> } onDisabledPress={onDisabledPress} /> ); }, [multipleVisible, multipleValue]); return ( {SingleExample} {singleValue && ( )} {MultipleExample} {Array.isArray(multipleValue) && multipleValue.length > 0 && ( )} ); }; export default BasicUsage;