form.stories.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. import React, { useState, useLayoutEffect, useEffect, useRef } from 'react';
  2. import {
  3. Button,
  4. Form
  5. } from '../../index';
  6. import { BasicDemoWithInit, LinkFieldForm, DifferentDeclareUsage } from './demo';
  7. const {
  8. Input,
  9. Select,
  10. DatePicker,
  11. Switch,
  12. Slider,
  13. CheckboxGroup,
  14. Checkbox,
  15. RadioGroup,
  16. Radio,
  17. TimePicker,
  18. } = Form;
  19. import {
  20. UseFormApiDemo,
  21. UseFormStateDemo,
  22. UseFieldApiDemo,
  23. UseFieldStateDemo,
  24. WithFormStateDemo,
  25. WithFormApiDemo,
  26. ComponentUsingFormState,
  27. CustomStringify,
  28. } from './Hook/hookDemo';
  29. // layout
  30. import { LayoutDemo, InsetLabelDemo } from './Layout/layoutDemo';
  31. import { AssistComponent } from './Layout/slotDemo';
  32. import { ModalFormDemo } from './Layout/modalFormDemo';
  33. import { WithFieldDemo, CustomFieldDemo, NumberRange } from './HOC/withFieldDemo';
  34. import {
  35. CustomValidateDemo,
  36. ValidateFieldsDemo,
  37. PartValidAndResetDemo,
  38. RulesValidateDemo,
  39. SetBugDemo,
  40. UnmountedLeafDemo,
  41. RulesExample,
  42. RaceAsyncDemo,
  43. } from './Validate/validateDemo';
  44. // field props
  45. import { ConvertDemo } from './FieldProps/convert';
  46. import { NameDemo } from './FieldProps/name';
  47. import { HelpAndExtra, ExtraPositionDemo } from './FieldProps/helpAndExtra';
  48. import { BigNumberFieldDemo } from './FieldProps/bigNumberFieldPath';
  49. import { UpdateDemo, RuleupdateDemo } from './FieldProps/rulesUpdateDemo';
  50. import { FieldRefDemo } from './FieldProps/fieldRef';
  51. import { LableOptionalDemo } from './FieldProps/labelOptional';
  52. // form inputGroup
  53. import { InputGroupDemo } from './InputGroup/groupProps';
  54. // arrayField
  55. import {
  56. ArrayFieldCollapseDemo,
  57. ArrayFieldDemo,
  58. ArrayFieldWithFormInitValues,
  59. ArrayFieldWithInitValue,
  60. ArrayFieldSetValues,
  61. AsyncSetArrayField,
  62. } from './DynamicField/arrayFieldDemo';
  63. import { NestArrayField } from './DynamicField/nestArrayField';
  64. import { ArrayDemo } from './FormApi/arrayDemo';
  65. // performance
  66. import {
  67. ManyFieldDemo,
  68. EffectDemo,
  69. ModalFormSelectWithObject,
  70. } from './Performance/performanceDemo';
  71. import { SetValuesDemo, SetValuesWithArrayField } from './FormApi/setValuesDemo';
  72. import { SetValueUsingParentPath } from './FormApi/formApiDemo';
  73. import { FieldPathWithArrayDemo } from './Debug/bugDemo';
  74. import ChildDidMount from './Debug/childDidMount';
  75. export { default as FormSubmit } from './FormSubmit';
  76. export * from './ArrayField';
  77. export default {
  78. title: 'Form'
  79. }
  80. const Option = Select.Option;
  81. export const FormDeclareUsage = () => <DifferentDeclareUsage />;
  82. FormDeclareUsage.story = {
  83. name: 'Form declare usage',
  84. };
  85. export const BasicDemo = () => <BasicDemoWithInit />;
  86. BasicDemo.story = {
  87. name: 'BasicDemo',
  88. };
  89. export const LayoutFormWrapperColLabelCol = () => <LayoutDemo />;
  90. LayoutFormWrapperColLabelCol.story = {
  91. name: 'Layout-Form wrapperCol/labelCol',
  92. };
  93. export const LayoutInsetLabel = () => <InsetLabelDemo />;
  94. LayoutInsetLabel.story = {
  95. name: 'Layout-insetLabel',
  96. };
  97. export const LableOptional = () => <LableOptionalDemo></LableOptionalDemo>;
  98. LableOptional.story = {
  99. name: 'Layout-label show optional',
  100. };
  101. export const LayoutSlotErrorMessageLabel = () => <AssistComponent />;
  102. LayoutSlotErrorMessageLabel.story = {
  103. name: 'Layout-Slot/ErrorMessage/Label',
  104. };
  105. export const LayoutModalDemo = () => <ModalFormDemo />;
  106. LayoutModalDemo.story = {
  107. name: 'Layout-ModalDemo',
  108. };
  109. export const GroupProp = () => <InputGroupDemo />
  110. GroupProp.story = {
  111. name: 'Layout-InputGroup Prop - basic'
  112. };
  113. export const FormApiSetValuesOverride = () => <SetValuesDemo />;
  114. FormApiSetValuesOverride.story = {
  115. name: 'formApi-setValues(override)',
  116. };
  117. export const FormApiValidate = () => <PartValidAndResetDemo />;
  118. FormApiValidate.story = {
  119. name: 'formApi-validate',
  120. };
  121. export const FormApiSetValueUsingFieldParentPath = () => <SetValueUsingParentPath />;
  122. FormApiSetValueUsingFieldParentPath.story = {
  123. name: 'formApi-setValue using field parent path',
  124. };
  125. export const UseFormApiSetValueUpdateArray = () => <ArrayDemo />;
  126. UseFormApiSetValueUpdateArray.story = {
  127. name: 'formApi-setValue set array',
  128. };
  129. export const DynamicAddRemoveField = () => (
  130. <Form>
  131. {({ formState }) => (
  132. <React.Fragment>
  133. <Input field="name" label="First name:" />
  134. <RadioGroup field="married" label="Are you married?">
  135. <Radio value="yes">yes</Radio>
  136. <Radio value="no">no</Radio>
  137. </RadioGroup>
  138. {formState.values.married === 'yes' ? <Input field="spouse" label="Spouse name:" /> : null}
  139. <Button htmlType="submit">Submit</Button>
  140. <ComponentUsingFormState />
  141. </React.Fragment>
  142. )}
  143. </Form>
  144. );
  145. DynamicAddRemoveField.story = {
  146. name: 'Dynamic Add / Remove Field',
  147. };
  148. export const ArrayFieldBasicUsage = () => <ArrayFieldDemo />;
  149. ArrayFieldBasicUsage.story = {
  150. name: 'ArrayField-basic usage',
  151. };
  152. export const _ArrayFieldWithFormInitValues = () => <ArrayFieldWithFormInitValues />;
  153. _ArrayFieldWithFormInitValues.story = {
  154. name: 'ArrayField-with form initValues',
  155. };
  156. export const ArrayFieldWithArrayFieldInitValue = () => <ArrayFieldWithInitValue />;
  157. ArrayFieldWithArrayFieldInitValue.story = {
  158. name: 'ArrayField-with arrayField initValue',
  159. };
  160. export const ArrayFieldSetValuesDemo = () => <ArrayFieldSetValues />;
  161. ArrayFieldSetValuesDemo.story ={
  162. name: 'ArrayField-setValues didMount'
  163. }
  164. export const AsyncSetArrayFieldDemo = () => <AsyncSetArrayField></AsyncSetArrayField>;
  165. AsyncSetArrayFieldDemo.story = {
  166. name: 'ArrayField-update async'
  167. }
  168. export const ArrayFieldNestUsage = () => <NestArrayField />;
  169. ArrayFieldNestUsage.story = {
  170. name: 'ArrayField-Nest Usage',
  171. };
  172. export const _ArrayFieldCollapseDemo = () => <ArrayFieldCollapseDemo />;
  173. _ArrayFieldCollapseDemo.story = {
  174. name: 'ArrayField-CollapseDemo',
  175. };
  176. export const LinkField = () => <LinkFieldForm />;
  177. LinkField.story = {
  178. name: 'LinkField',
  179. };
  180. export const ValidateFormLevel = () => <ValidateFieldsDemo />;
  181. ValidateFormLevel.story = {
  182. name: 'Validate-FormLevel',
  183. };
  184. export const ValidateFieldValel = () => <CustomValidateDemo />;
  185. ValidateFieldValel.story = {
  186. name: 'Validate-FieldValel',
  187. };
  188. export const ValidateUseRules = () => <RulesValidateDemo />;
  189. ValidateUseRules.story = {
  190. name: 'Validate-use rules',
  191. };
  192. export const RaceAsync = () => <RaceAsyncDemo />;
  193. RaceAsync.story = {
  194. name: 'Validate-race async'
  195. }
  196. export const HooksUseFormApi = () => <UseFormApiDemo />;
  197. HooksUseFormApi.story = {
  198. name: 'Hooks-useFormApi',
  199. };
  200. export const HooksUseFormState = () => <UseFormStateDemo />;
  201. HooksUseFormState.story = {
  202. name: 'Hooks-useFormState',
  203. };
  204. export const HooksUseFieldApi = () => <UseFieldApiDemo />;
  205. HooksUseFieldApi.story = {
  206. name: 'Hooks-useFieldApi',
  207. };
  208. export const HooksUseFieldState = () => <UseFieldStateDemo />;
  209. HooksUseFieldState.story = {
  210. name: 'Hooks-useFieldState',
  211. };
  212. export const HocWithFormApi = () => <WithFormApiDemo />;
  213. HocWithFormApi.story = {
  214. name: 'Hoc-withFormApi',
  215. };
  216. export const HocWithFormState = () => <WithFormStateDemo />;
  217. HocWithFormState.story = {
  218. name: 'Hoc-withFormState',
  219. };
  220. export const WithField = () => <CustomFieldDemo />;
  221. WithField.story = {
  222. name: 'withField',
  223. };
  224. export const WithFieldWithStatefulComponent = () => <WithFieldDemo />;
  225. WithFieldWithStatefulComponent.story = {
  226. name: 'withField- with stateful component',
  227. };
  228. export const WithFieldNumberRange = () => (
  229. <Form onChange={v => console.log(v)}>
  230. <NumberRange field="number" initValue={[1, 2]} noLabel={true}></NumberRange>
  231. </Form>
  232. );
  233. WithFieldNumberRange.story = {
  234. name: 'withField - NumberRange',
  235. };
  236. export const PerformanceManyField = () => <ManyFieldDemo />;
  237. PerformanceManyField.story = {
  238. name: 'Performance-ManyField',
  239. };
  240. export const PerformanceModalFormSelectWithObject = () => <ModalFormSelectWithObject />;
  241. PerformanceModalFormSelectWithObject.story = {
  242. name: 'Performance-ModalFormSelectWithObject',
  243. };
  244. export const FiledPropConvert = () => <ConvertDemo />;
  245. FiledPropConvert.story = {
  246. name: 'Filed Prop-convert',
  247. };
  248. export const FieldPropsName = () => <NameDemo />;
  249. FieldPropsName.story = {
  250. name: 'Filed Prop-name',
  251. };
  252. export const FiledPropHelpTextExtraTextExtraTextPosition = () => (
  253. <>
  254. <HelpAndExtra />
  255. <ExtraPositionDemo />
  256. </>
  257. );
  258. FiledPropHelpTextExtraTextExtraTextPosition.story = {
  259. name: 'Filed Prop-helpText / extraText / extraTextPosition',
  260. };
  261. export const FieldPropsDynamicUpdateRulesRequired = () => <RuleupdateDemo />;
  262. FieldPropsDynamicUpdateRulesRequired.story = {
  263. name: 'Field Props-dynamic update rules.required',
  264. };
  265. export const FieldPropInitValue = () => <InitEmptyStringDemo />;
  266. FieldPropInitValue.story = {
  267. name: 'Field Prop-initValue=""',
  268. };
  269. export const FieldPropBigNumberFieldSubmit = () => <BigNumberFieldDemo />;
  270. FieldPropBigNumberFieldSubmit.story = {
  271. name: 'Field prop-big number field submit',
  272. };
  273. export const FieldPropPure = () => (
  274. <Form>
  275. <Form.Select
  276. field="name"
  277. pure
  278. className="fefefe"
  279. fieldClassName="feichang"
  280. style={{ width: 400 }}
  281. />
  282. </Form>
  283. );
  284. FieldPropPure.story = {
  285. name: 'Field Prop-pure',
  286. };
  287. export const FieldPropRef = () => <FieldRefDemo />;
  288. FieldPropRef.story = {
  289. name: 'Field Prop-ref',
  290. };
  291. const InitEmptyStringDemo = () => {
  292. return (
  293. <Form allowEmpty>
  294. <Form.Input field="name" initValue="" />
  295. <ComponentUsingFormState />
  296. </Form>
  297. );
  298. };
  299. export const DebugSetBugDemo = () => (
  300. <>
  301. <SetBugDemo />
  302. <UnmountedLeafDemo />
  303. </>
  304. );
  305. DebugSetBugDemo.story = {
  306. name: 'Debug-SetBugDemo',
  307. };
  308. export const DebugSetValuesWithArrayField = () => (
  309. <>
  310. <SetValuesWithArrayField />
  311. </>
  312. );
  313. DebugSetValuesWithArrayField.story = {
  314. name: 'Debug-SetValuesWithArrayField',
  315. };
  316. import { SetValuesArray, DoubleRerender } from './Debug/bugDemo';
  317. export const DebugArrayFieldPath = () => <FieldPathWithArrayDemo />;
  318. DebugArrayFieldPath.story = {
  319. name: 'Debug-数组类fieldPath',
  320. };
  321. export const DebugSetValuesDemo = () => (
  322. <>
  323. <SetValuesArray />
  324. </>
  325. );
  326. DebugSetValuesDemo.story = {
  327. name: 'Debug-SetValuesDemo',
  328. };
  329. export const DebugRerenderTwice = () => (
  330. <>
  331. <DoubleRerender />
  332. </>
  333. );
  334. DebugRerenderTwice.story = {
  335. name: 'Debug-RerenderTwice',
  336. };
  337. export const _ChildDidMount = () => <ChildDidMount />;
  338. _ChildDidMount.story = {
  339. name: 'child did mount',
  340. };