form.stories.js 9.4 KB

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