diff --git a/src/form/_example/horizontal.tsx b/src/form/_example/horizontal.tsx index 2f9754ee5..b7584ffd4 100644 --- a/src/form/_example/horizontal.tsx +++ b/src/form/_example/horizontal.tsx @@ -1,10 +1,153 @@ -import React, { useMemo, useRef } from 'react'; -import { Button, Form, Input, Radio, RadioGroup, Rate, Stepper, Textarea } from 'tdesign-mobile-react'; +import React, { useEffect, useMemo, useRef, useState } from 'react'; +import { + Button, + Cascader, + DateTimePicker, + Form, + Input, + Popup, + Radio, + RadioGroup, + Rate, + Stepper, + Textarea, + Upload, + type UploadFile, +} from 'tdesign-mobile-react'; import { BrowseOffIcon } from 'tdesign-icons-react'; const RATE_GAP = 8; -export default function HorizontalForm({ disabled }) { - const formRef = useRef(null); + +const action = 'https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com/api/upload-demo'; + +const initialPhoto: UploadFile[] = [ + { + url: 'https://tdesign.gtimg.com/mobile/demos/example4.png', + name: 'uploaded1.png', + type: 'image', + }, + { + url: 'https://tdesign.gtimg.com/mobile/demos/example6.png', + name: 'uploaded2.png', + type: 'image', + }, +]; + +const initialData = { + name: '', + password: '', + gender: '', + birth: '', + place: '', + age: 3, + description: 2, + resume: '', + photo: initialPhoto, +}; + +const addressOptions = [ + { + label: '北京市', + value: '110000', + children: [ + { + value: '110100', + label: '北京市', + children: [ + { value: '110101', label: '东城区' }, + { value: '110102', label: '西城区' }, + { value: '110105', label: '朝阳区' }, + { value: '110106', label: '丰台区' }, + { value: '110107', label: '石景山区' }, + { value: '110108', label: '海淀区' }, + { value: '110109', label: '门头沟区' }, + { value: '110111', label: '房山区' }, + { value: '110112', label: '通州区' }, + { value: '110113', label: '顺义区' }, + { value: '110114', label: '昌平区' }, + { value: '110115', label: '大兴区' }, + { value: '110116', label: '怀柔区' }, + { value: '110117', label: '平谷区' }, + { value: '110118', label: '密云区' }, + { value: '110119', label: '延庆区' }, + ], + }, + ], + }, + { + label: '天津市', + value: '120000', + children: [ + { + value: '120100', + label: '天津市', + children: [ + { value: '120101', label: '和平区' }, + { value: '120102', label: '河东区' }, + { value: '120103', label: '河西区' }, + { value: '120104', label: '南开区' }, + { value: '120105', label: '河北区' }, + { value: '120106', label: '红桥区' }, + { value: '120110', label: '东丽区' }, + { value: '120111', label: '西青区' }, + { value: '120112', label: '津南区' }, + { value: '120113', label: '北辰区' }, + { value: '120114', label: '武清区' }, + { value: '120115', label: '宝坻区' }, + { value: '120116', label: '滨海新区' }, + { value: '120117', label: '宁河区' }, + { value: '120118', label: '静海区' }, + { value: '120119', label: '蓟州区' }, + ], + }, + ], + }, +]; + +const onFail = ({ file, e }: any) => { + console.log('[onFail]', { file, e }); +}; + +const onProgress = ({ file, percent, type, e }: any) => { + console.log('[onProgress]', { file, percent, type, e }); +}; + +const onPreview = ({ file, e }: any) => { + console.log('[onPreview]', { file, e }); +}; + +const onSuccess = ({ file, fileList, response, e }: any) => { + console.log('[onSuccess]', { file, fileList, e, response }); +}; + +const onRemove = ({ index, file, e }: any) => { + console.log('[onRemove]', { index, file, e }); +}; + +const onSelectChange = (files: UploadFile[]) => { + console.log('[onSelectChange]', files); +}; + +export default function HorizontalForm({ disabled }: { disabled?: boolean }) { + const [form] = Form.useForm(); + const [birthVisible, setBirthVisible] = useState(false); + const [placeVisible, setPlaceVisible] = useState(false); + const [placeValue, setPlaceValue] = useState('120119'); + const birthInputRef = useRef(null); + const placeInputRef = useRef(null); + + useEffect(() => { + if (!birthVisible) { + birthInputRef.current?.blur?.(); + } + }, [birthVisible]); + + useEffect(() => { + if (!placeVisible) { + placeInputRef.current?.blur?.(); + } + }, [placeVisible]); + const rules = useMemo( () => ({ name: [{ validator: (val: any) => val?.length === 8, message: '只能输入8个字符英文' }], @@ -18,55 +161,152 @@ export default function HorizontalForm({ disabled }) { [], ); + const groupChangeFn = (value: any, context: any) => { + console.log(value, context); + }; + + const onBirthChange = (value: any) => { + console.log('[change]', value); + }; + + const onBirthPick = (value: any) => { + console.log('[pick]', value); + }; + + const onBirthCancel = () => { + console.log('[cancel]'); + setBirthVisible(false); + }; + + const onBirthConfirm = (value: any) => { + console.log('[confirm]', value); + form.setFieldsValue({ birth: String(value) }); + setBirthVisible(false); + }; + + const onPlaceChange = (value: string | number, selectedOptions: any) => { + setPlaceValue(value); + setPlaceVisible(false); + form.setFieldsValue({ place: selectedOptions?.map((item: any) => item.label).join('/') }); + }; + const onReset = () => { - console.log('===onReset'); + console.log('[onReset]'); }; + const onSubmit = (e: any) => { - console.log('===onSubmit', e); + console.log('[onSubmit]', e); }; + return ( -
- - - - - } /> - - - - - - - - - - - - - - - -
0/50
"`; +exports[`ssr snapshot test > ssr test src/form/_example/horizontal.tsx 1`] = `"
输入用户名
男
女
保密
0/50
"`; -exports[`ssr snapshot test > ssr test src/form/_example/index.tsx 1`] = `"

Form 表单

用以收集、校验和提交数据,一般由输入框、单选框、复选框、选择器等控件组成。

01 组件类型

基础表单

禁用态
请输入用户名
男
女
保密
0/50
"`; +exports[`ssr snapshot test > ssr test src/form/_example/index.tsx 1`] = `"

Form 表单

用以收集、校验和提交数据,一般由输入框、单选框、复选框、选择器等控件组成。

01 组件类型

基础表单

禁用态
输入用户名
男
女
保密
0/50
"`; -exports[`ssr snapshot test > ssr test src/form/_example/vertical.tsx 1`] = `"
请输入用户名
男
女
保密
0/50
"`; +exports[`ssr snapshot test > ssr test src/form/_example/vertical.tsx 1`] = `"
输入用户名
男
女
保密
0/50
"`; exports[`ssr snapshot test > ssr test src/grid/_example/badge.tsx 1`] = `"
标题文字
8
标题文字
13
标题五字内
NEW
标题五字内
"`; diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap index 62b3bde13..62416ccdb 100644 --- a/test/snap/__snapshots__/ssr.test.jsx.snap +++ b/test/snap/__snapshots__/ssr.test.jsx.snap @@ -256,11 +256,11 @@ exports[`ssr snapshot test > ssr test src/footer/_example/links.tsx 1`] = `"
ssr test src/footer/_example/logo.tsx 1`] = `""`; -exports[`ssr snapshot test > ssr test src/form/_example/horizontal.tsx 1`] = `"
请输入用户名
男
女
保密
0/50
"`; +exports[`ssr snapshot test > ssr test src/form/_example/horizontal.tsx 1`] = `"
输入用户名
男
女
保密
0/50
"`; -exports[`ssr snapshot test > ssr test src/form/_example/index.tsx 1`] = `"

Form 表单

用以收集、校验和提交数据,一般由输入框、单选框、复选框、选择器等控件组成。

01 组件类型

基础表单

禁用态
请输入用户名
男
女
保密
0/50
"`; +exports[`ssr snapshot test > ssr test src/form/_example/index.tsx 1`] = `"

Form 表单

用以收集、校验和提交数据,一般由输入框、单选框、复选框、选择器等控件组成。

01 组件类型

基础表单

禁用态
输入用户名
男
女
保密
0/50
"`; -exports[`ssr snapshot test > ssr test src/form/_example/vertical.tsx 1`] = `"
请输入用户名
男
女
保密
0/50
"`; +exports[`ssr snapshot test > ssr test src/form/_example/vertical.tsx 1`] = `"
输入用户名
男
女
保密
0/50
"`; exports[`ssr snapshot test > ssr test src/grid/_example/badge.tsx 1`] = `"
标题文字
8
标题文字
13
标题五字内
NEW
标题五字内
"`;