import React, { FunctionComponent } from 'react'; import { storiesOf } from '@storybook/react'; import { Form, useFormState, useFormApi, withField, Input, Button, Upload } from '../../index'; import { values } from 'lodash'; const stories = storiesOf('Form', module); import { FormApi, FormFCChild } from '../interface'; const treeData = [ { label: '浙江省', value: 'zhejiang', key: '0', children: [ { label: '杭州市', value: 'hangzhou', key: '0-0', children: [ { label: '西湖区', value: 'xihu', key: '0-0-0', }, { label: '萧山区', value: 'xiaoshan', key: '0-0-1', }, { label: '临安区', value: 'linan', key: '0-0-2', }, ], }, { label: '宁波市', value: 'ningbo', key: '0-1', children: [ { label: '海曙区', value: 'haishu', key: '0-1-0', }, { label: '江北区', value: 'jiangbei', key: '0-1-1', }, ], }, ], }, ]; const htmlInput = (props: any) => { let value = props.value || ''; delete props.validateStatus; // prevent props being transparently transmitted to DOM return ; }; const FieldB = withField(Input); const FieldA = withField(htmlInput, { valueKey: 'value', onKeyChangeFnName: 'onChange', valuePath: 'target.value' }); const Fields: FunctionComponent = ({ formState, values, formApi }) => { const ref = React.useRef(); return ( <> console.log(v)} ref={ref} /> admin user guest root 我已阅读并清楚相关规定(Checkbox) {JSON.stringify(formState)} ) }; stories.add('Form', () =>
{Fields}
); interface IProps { [x:string]: any; } interface IState { visible: boolean; } interface FData { test: boolean; test2: boolean; test3: string; // [x: string]: unknown; } class Demo extends React.Component { constructor(props:any) { super(props); this.state = { visible: false}; } getFormApi(formApi: FormApi) { formApi.getValue() } render() { const { visible } = this.state; return ( <>
); } } stories.add('Form render', () =>
}>
); stories.add('Form children', () =>
{({ formState, formApi, values }) => ( <> ) } );