import React from 'react'; import { View, StyleSheet, Text } from 'react-native'; import Form from '../index'; import Button from '../../Button'; import { ScrollView } from 'react-native'; import BottomSafeArea from '../../BottomSafeArea'; import { Fill, Toast } from '@xrnjs/ui'; import Card from '_global/Card'; import OptionGroup from '../../OptionGroup'; type FormData = { tags: string[]; category: string; priority: number; status: string; department: string[]; level: string; skills: string[]; platform: string; }; const OptionGroupExamplesDemo: React.FC = () => { const form = Form.useForm({ defaultValues: { tags: [], category: '', priority: 1, status: '', department: [], level: '', skills: [], platform: '', }, }); const [categoryFixed, setCategoryFixed] = React.useState('web'); const onSubmit = (data: FormData) => { console.log('Form submitted:', data); Toast( `提交成功!\n标签: ${data.tags.join(', ')}\n类别: ${ data.category }\n优先级: ${data.priority}` ); }; const onError = (errors: Record) => { console.log('Form errors:', errors); }; return ( {/* 组合用法示例 */} { if (!value || value.length === 0) { return '请至少选择一个标签'; } return true; }, }} > {/* 快捷用法示例 */} {/* 高级配置示例 */} { if (!value || value.length === 0) { return '请至少选择一个部门'; } if (value.length > 3) { return '最多只能选择3个部门'; } return true; }, }} options={[ { label: '产品部', value: 'product' }, { label: '技术部', value: 'tech' }, { label: '设计部', value: 'design' }, { label: '市场部', value: 'marketing' }, { label: '运营部', value: 'operation' }, { label: '销售部', value: 'sales' }, ]} multiple numberOfSingleLines={2} scrollable operate /> {/* 滚动和操作面板示例 */} { if (!value || value.length === 0) { return '请至少选择一个技能'; } if ( value.includes('react') && !value.includes('javascript') ) { return 'React技能需要JavaScript基础'; } if ( value.includes('typescript') && !value.includes('javascript') ) { return 'TypeScript技能需要JavaScript基础'; } return true; }, }} options={[ { label: 'JavaScript', value: 'javascript' }, { label: 'TypeScript', value: 'typescript' }, { label: 'React', value: 'react' }, { label: 'Vue.js', value: 'vue' }, { label: 'Angular', value: 'angular' }, { label: 'Node.js', value: 'nodejs' }, { label: 'Python', value: 'python' }, { label: 'Java', value: 'java' }, { label: 'Go', value: 'go' }, { label: 'Rust', value: 'rust' }, { label: 'Swift', value: 'swift' }, { label: 'Kotlin', value: 'kotlin' }, { label: 'Flutter', value: 'flutter' }, { label: 'React Native', value: 'reactnative' }, { label: 'Docker', value: 'docker' }, { label: 'Kubernetes', value: 'k8s' }, { label: 'AWS', value: 'aws' }, { label: 'Azure', value: 'azure' }, ]} multiple numberOfSingleLines={4} scrollable scrollableWrap operate panelMaxHeight={200} /> {/* 禁用状态示例 */} { Toast(`${option.label} 功能即将上线,敬请期待!`); }} /> 当前值:{categoryFixed} setCategoryFixed(v as string)} /> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f5f5f5', }, scrollContainer: { flex: 1, padding: 20, paddingBottom: 0, }, cardStyle: { marginBottom: 16, }, fixedButtonContainer: { backgroundColor: '#fff', paddingHorizontal: 20, paddingTop: 16, paddingBottom: 30, borderTopWidth: 1, borderTopColor: '#e5e5e5', flexDirection: 'row', justifyContent: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: -2, }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 8, }, buttonSpacer: { width: 20, }, }); export default OptionGroupExamplesDemo;