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 SingleCheckOptions from '../../Options'; type FormData = { gender: string; paymentMethod: string; theme: string; language: string; priority: string; category: string; }; const SingleCheckOptionsExamplesDemo: React.FC = () => { const form = Form.useForm({ defaultValues: { gender: '', paymentMethod: 'alipay', theme: 'auto', language: '', priority: '', category: '', }, }); const [languageFixed, setLanguageFixed] = React.useState('en-US'); const onSubmit = (data: FormData) => { console.log('Form submitted:', data); Toast( `选择完成!\n性别: ${data.gender}\n支付方式: ${data.paymentMethod}\n主题: ${data.theme}` ); }; const onError = (errors: Record) => { console.log('Form errors:', errors); }; return ( {/* Form.SingleCheckOptions 快捷用法 */} {/* Form.Item + SingleCheckOptions 组合用法 */} {/* 主题选择示例 */} {/* 高级配置示例 */} {/* 优先级选择示例 */} { if (value === 'urgent') { return '紧急任务需要额外确认,请联系管理员'; } return true; }, }} options={[ { label: '低', value: 'low', description: '可延后', }, { label: '中', value: 'medium', description: '正常处理', }, { label: '高', value: 'high', description: '优先处理', }, { label: '紧急', value: 'urgent', description: '立即处理', }, ]} /> {/* 复杂验证示例 */} { const selectedPriority = form.getValues('priority'); // 企业级项目必须是高优先级或紧急 if ( value === 'enterprise' && !['high', 'urgent'].includes(selectedPriority) ) { return '企业级项目必须设置为高优先级或紧急'; } // 实验性项目不能是紧急优先级 if ( value === 'experimental' && selectedPriority === 'urgent' ) { return '实验性项目不能设置为紧急优先级'; } return true; }, }} options={[ { label: '个人项目', value: 'personal', description: '个人开发', }, { label: '团队项目', value: 'team', description: '团队协作', }, { label: '企业级', value: 'enterprise', description: '企业应用', }, { label: '开源项目', value: 'opensource', description: '开源贡献', }, { label: '实验性', value: 'experimental', description: '技术验证', }, { label: '商业项目', value: 'commercial', description: '商业应用', }, ]} /> {/* 禁用状态示例 */} 当前值:{languageFixed} setLanguageFixed(v as string)} /> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f5f5f5', }, scrollContainer: { flex: 1, padding: 20, paddingBottom: 0, }, cardStyle: { marginBottom: 16, }, optionsFullWidth: { width: '100%', }, 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 SingleCheckOptionsExamplesDemo;