ModalPicker
ModalPicker Picker
代码示例
import { BfModalPicker } from '@bud-fe/react-taro-ui';import { Button, View } from '@tarojs/components';import React, { useState } from 'react';import styles from './index.module.less';const mockData = [{ label: '选项1', value: 1 },{ label: '选项2', value: 2 },{ label: '选项3', value: 3 },{ label: '选项4', value: 4 },{ label: '选项5', value: 5 },];const mockData1 = [{ name: '选项1', code: 1 },{ name: '选项2', code: 2 },{ name: '选项3', code: 3 },{ name: '选项4', code: 4 },];export default () => {const [isOpened, setIsOpened] = useState(false);const [isOpened2, setIsOpened2] = useState(false);return (<><Button className="group-title" onClick={() => setIsOpened(true)}>基础用法</Button><BfModalPickerisOpened={isOpened}data={mockData}onCancel={() => {console.log('onCancel');setIsOpened(false);}}onConfirm={(key, value) => {console.log('onConfirm', { key, value });setIsOpened(false);}}position="top"/><Button className="group-title" onClick={() => setIsOpened2(true)}>自定义渲染</Button><BfModalPickerisOpened={isOpened2}data={mockData1}fieldNames={{ label: 'name', value: 'code' }}indicatorClass={styles['indicatorClass']}onCancel={() => {console.log('onCancel');setIsOpened2(false);}}onConfirm={(key, value) => {console.log('onConfirm', { key, value });setIsOpened2(false);}}renderItem={(item, isCurrent) => {return (<View className={isCurrent ? styles['selected2'] : ''} key={item.value}>你好 {item.label}</View>);}}/></>);};
API
属性名 | 描述 | 类型 | 默认值 |
---|---|---|---|
id | id,多组数据共用一个Picker时,可通过该属性进行区分 | string | -- |
data | 数据源 | Record<string, any>[] | -- |
value | 当前值 | any | -- |
fieldNames | 自定义节点属性名称 | { label: string; value: string; } | { label: 'label', value: 'value' } |
onConfirm | 确认按钮回调 | (key: string, value: Record<string, any>) => void | -- |
indicatorClass | 设置选择器中间选中框的类名 @supported weapp, swan, alipay | string | -- |
renderItem | 每个Item项的渲染逻辑 isCurrent当前值是否选中 | (item: Record<string, any>, isCurrent: boolean) => any | -- |