form.stories.js 9.6 KB

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