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 LayoutAndStyle = () => { // 描述在右边的示例 const rightDescRef = useRef(null); const [rightDescVisible, setRightDescVisible] = useState(false); const [rightDescValue, setRightDescValue] = useState(); // 无搜索无侧边栏示例 const noSearchSidebarRef = useRef(null); const [noSearchSidebarVisible, setNoSearchSidebarVisible] = useState(false); const [noSearchSidebarValue, setNoSearchSidebarValue] = useState([]); // 带分割线示例 const withLineRef = useRef(null); const [withLineVisible, setWithLineVisible] = useState(false); const [withLineValue, setWithLineValue] = useState(); // 不显示选中值示例 const noFooterValueRef = useRef(null); const [noFooterValueVisible, setNoFooterValueVisible] = useState(false); const [noFooterValueValue, setNoFooterValueValue] = useState( [] ); const RightDescExample = useMemo(() => { return ( setRightDescVisible(false), showConfirmButton: false, }} onPressOverlay={() => setRightDescVisible(false)} onClosed={() => setRightDescVisible(false)} groups={formatLocationData} value={rightDescValue} ref={rightDescRef} descPlacement="right" showSearch={false} onChange={(item) => { setRightDescValue(item); setRightDescVisible(false); }} onDisabledPress={onDisabledPress} /> ); }, [rightDescVisible, rightDescValue]); const NoSearchSidebarExample = useMemo(() => { return ( setNoSearchSidebarVisible(false), showConfirmButton: true, onConfirm: () => setNoSearchSidebarVisible(false), }} onPressOverlay={() => setNoSearchSidebarVisible(false)} onClosed={() => setNoSearchSidebarVisible(false)} groups={formatLocationData} mode="multiple" value={noSearchSidebarValue} ref={noSearchSidebarRef} showSearch={false} disableSidebar={true} descPlacement="right" onChange={setNoSearchSidebarValue} footerStyle={styles.footerStyle} footer={ <> } onDisabledPress={onDisabledPress} /> ); }, [noSearchSidebarVisible, noSearchSidebarValue]); const WithLineExample = useMemo(() => { return ( setWithLineVisible(false), showConfirmButton: false, }} onPressOverlay={() => setWithLineVisible(false)} onClosed={() => setWithLineVisible(false)} groups={formatLocationData} value={withLineValue} ref={withLineRef} showLine={true} lineStyle={styles.customLine} onChange={(item) => { setWithLineValue(item); setWithLineVisible(false); }} onDisabledPress={onDisabledPress} /> ); }, [withLineVisible, withLineValue]); const NoFooterValueExample = useMemo(() => { return ( setNoFooterValueVisible(false), showConfirmButton: true, onConfirm: () => setNoFooterValueVisible(false), }} onPressOverlay={() => setNoFooterValueVisible(false)} onClosed={() => setNoFooterValueVisible(false)} groups={formatLocationData} mode="multiple" value={noFooterValueValue} ref={noFooterValueRef} showFooterValue={false} descPlacement="right" onChange={setNoFooterValueValue} footerStyle={styles.footerStyle} footer={ <> } onDisabledPress={onDisabledPress} /> ); }, [noFooterValueVisible, noFooterValueValue]); return ( {RightDescExample} {rightDescValue && ( )} {NoSearchSidebarExample} {Array.isArray(noSearchSidebarValue) && noSearchSidebarValue.length > 0 && ( )} {WithLineExample} {withLineValue && ( )} {NoFooterValueExample} {Array.isArray(noFooterValueValue) && noFooterValueValue.length > 0 && ( )} ); }; export default LayoutAndStyle;