form-fields.stories.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. import React from 'react';
  2. import {action} from '@storybook/addon-actions';
  3. import {Panel} from 'app/components/panels';
  4. import Switch from 'app/components/switchButton';
  5. import NewBooleanField from 'app/views/settings/components/forms/booleanField';
  6. import RadioGroup from 'app/views/settings/components/forms/controls/radioGroup';
  7. import RangeSlider from 'app/views/settings/components/forms/controls/rangeSlider';
  8. import DatePickerField from 'app/views/settings/components/forms/datePickerField';
  9. import Form from 'app/views/settings/components/forms/form';
  10. import FormField from 'app/views/settings/components/forms/formField';
  11. import RadioBooleanField from 'app/views/settings/components/forms/radioBooleanField';
  12. import RadioField from 'app/views/settings/components/forms/radioField';
  13. import SelectField from 'app/views/settings/components/forms/selectField';
  14. import TextareaField from 'app/views/settings/components/forms/textareaField';
  15. import TextCopyInput from 'app/views/settings/components/forms/textCopyInput';
  16. import TextField from 'app/views/settings/components/forms/textField';
  17. export default {
  18. title: 'Forms/Fields',
  19. };
  20. export const _TextField = () => (
  21. <Panel>
  22. <Form initialData={{context: {location: 'cat'}}}>
  23. <TextField
  24. name="simpletextfieldvalue"
  25. label="Simple Text Field with Value"
  26. placeholder="Simple Text Field"
  27. defaultValue="With a value present"
  28. />
  29. <TextField
  30. name="simpletextfieldplaceholder"
  31. label="Simple Text Field with Placeholder"
  32. placeholder="This is placeholder text"
  33. />
  34. <TextField
  35. name="simpletextfieldvaluedisabled"
  36. label="Disabled - Simple Text Field with Value"
  37. placeholder="Simple Text Field"
  38. defaultValue="With a value present"
  39. disabled
  40. />
  41. <TextField
  42. name="simpletextfieldplaceholderdisabled"
  43. label="Disabled - Simple Text Field with Placeholder"
  44. placeholder="This is placeholder text in a disabled field"
  45. disabled
  46. />
  47. <TextField
  48. name="textfieldwithreturnsubmit"
  49. label="Text Field With Return Submit"
  50. placeholder="Type here to show the return button"
  51. showReturnButton
  52. />
  53. <TextField
  54. name="textfieldflexiblecontrol"
  55. label="Text Field With Flexible Control State Size"
  56. placeholder="Type text and then delete it"
  57. required
  58. flexibleControlStateSize
  59. />
  60. <TextField
  61. name="textfielddisabled"
  62. label="Text field with disabled reason"
  63. placeholder="I am disabled"
  64. disabled
  65. disabledReason="This is the reason this field is disabled"
  66. />
  67. </Form>
  68. </Panel>
  69. );
  70. _TextField.storyName = 'TextField';
  71. _TextField.parameters = {
  72. docs: {
  73. description: {
  74. story: 'Simple text field',
  75. },
  76. },
  77. };
  78. export const _TextareaField = ({autosize, rows}) => (
  79. <Panel>
  80. <Form initialData={{context: {location: 'cat'}}}>
  81. <TextareaField
  82. name="simpletextfieldvalue"
  83. label="Simple Textarea Field with Value"
  84. help="Additional help text"
  85. placeholder="Simple Textarea Field"
  86. defaultValue="With a value present"
  87. />
  88. <TextareaField
  89. name="simpletextfieldautosize"
  90. autosize={autosize}
  91. label="Textarea field with autosize"
  92. rows={rows}
  93. placeholder="Use knobs to control rows and autosize setting"
  94. />
  95. <TextareaField
  96. name="simpletextfieldvaluedisabled"
  97. label="Disabled - Simple Textarea Field with Value"
  98. placeholder="Simple Textarea Field"
  99. defaultValue="With a value present"
  100. disabled
  101. />
  102. <TextareaField
  103. name="simpletextfieldplaceholderdisabled"
  104. label="Disabled - Simple Textarea Field with Placeholder"
  105. placeholder="This is placeholder text in a disabled field"
  106. disabled
  107. />
  108. <TextareaField
  109. name="textfieldwithreturnsubmit"
  110. label="Textarea Field With Return Submit"
  111. placeholder="Type here to show the return button"
  112. showReturnButton
  113. />
  114. <TextareaField
  115. name="textfieldflexiblecontrol"
  116. label="Textarea Field With Flexible Control State Size"
  117. placeholder="Type text and then delete it"
  118. required
  119. flexibleControlStateSize
  120. />
  121. <TextareaField
  122. name="textfielddisabled"
  123. label="Textarea Field with disabled reason"
  124. placeholder="I am disabled"
  125. disabled
  126. disabledReason="This is the reason this field is disabled"
  127. />
  128. <TextareaField
  129. name="textareafielderror"
  130. label="Textarea Field with error"
  131. placeholder="I have an error"
  132. error="An error has occurred"
  133. />
  134. </Form>
  135. </Panel>
  136. );
  137. _TextareaField.storyName = 'TextareaField';
  138. _TextareaField.args = {
  139. autosize: true,
  140. rows: 1,
  141. };
  142. export const __BooleanField = () => (
  143. <Form>
  144. <NewBooleanField name="field" label="New Boolean Field" />
  145. </Form>
  146. );
  147. __BooleanField.storyName = 'BooleanField';
  148. export const _DatePickerField = () => (
  149. <Form>
  150. <DatePickerField name="field" label="Date Picker Field" />
  151. </Form>
  152. );
  153. _DatePickerField.storyName = 'DatePickerField';
  154. export const _RadioField = () => (
  155. <Form>
  156. <RadioField
  157. name="radio"
  158. label="Radio Field"
  159. choices={[
  160. ['choice_one', 'Choice One'],
  161. ['choice_two', 'Choice Two'],
  162. ['choice_three', 'Choice Three'],
  163. ]}
  164. />
  165. <RadioField
  166. orientInline
  167. name="inline-radio"
  168. label="Inline Radios"
  169. choices={[
  170. ['choice_one', 'Choice One'],
  171. ['choice_two', 'Choice Two'],
  172. ]}
  173. />
  174. </Form>
  175. );
  176. _RadioField.storyName = 'RadioField';
  177. export const _RadioBooleanField = ({disabled}) => (
  178. <Form>
  179. <RadioBooleanField
  180. name="subscribe"
  181. yesLabel="Yes, I would like to receive updates via email"
  182. noLabel="No, I'd prefer not to receive these updates"
  183. help="Help text for making an informed decision"
  184. disabled={disabled}
  185. />
  186. </Form>
  187. );
  188. _RadioBooleanField.storyName = 'RadioBooleanField';
  189. _RadioBooleanField.args = {
  190. disabled: false,
  191. };
  192. export const _SelectField = () => (
  193. <Form>
  194. <SelectField
  195. name="select"
  196. label="Select Field"
  197. choices={[
  198. ['choice_one', 'Choice One'],
  199. ['choice_two', 'Choice Two'],
  200. ['choice_three', 'Choice Three'],
  201. ]}
  202. />
  203. </Form>
  204. );
  205. _SelectField.storyName = 'SelectField';
  206. export const SelectFieldMultiple = () => (
  207. <Form>
  208. <SelectField
  209. name="select"
  210. label="Multi Select"
  211. multiple
  212. choices={[
  213. ['choice_one', 'Choice One'],
  214. ['choice_two', 'Choice Two'],
  215. ['choice_three', 'Choice Three'],
  216. ]}
  217. />
  218. </Form>
  219. );
  220. SelectFieldMultiple.storyName = 'SelectField multiple';
  221. export const SelectFieldGrouped = () => (
  222. <Form>
  223. <SelectField
  224. name="select"
  225. label="Grouped Select"
  226. options={[
  227. {
  228. label: 'Group 1',
  229. options: [
  230. {value: 'choice_one', label: 'Choice One'},
  231. {value: 'choice_two', label: 'Choice Two'},
  232. ],
  233. },
  234. {
  235. label: 'Group 2',
  236. options: [
  237. {value: 'choice_three', label: 'Choice Three'},
  238. {value: 'choice_four', label: 'Choice Four'},
  239. ],
  240. },
  241. ]}
  242. />
  243. </Form>
  244. );
  245. SelectFieldGrouped.storyName = 'SelectField grouped';
  246. export const SelectFieldInFieldLabel = () => (
  247. <Form>
  248. <SelectField
  249. name="select"
  250. label="Select With Label In Field"
  251. inFieldLabel="Label: "
  252. choices={[
  253. ['choice_one', 'Choice One'],
  254. ['choice_two', 'Choice Two'],
  255. ['choice_three', 'Choice Three'],
  256. ]}
  257. />
  258. </Form>
  259. );
  260. SelectFieldInFieldLabel.storyName = 'SelectField label in field';
  261. SelectFieldInFieldLabel.parameters = {
  262. docs: {
  263. description: {
  264. story: 'Select Control w/ Label In Field',
  265. },
  266. },
  267. };
  268. export const NonInlineField = () => (
  269. <Form>
  270. <FormField name="radio" label="Radio Field" inline={false}>
  271. {({value, label, onChange}) => (
  272. <RadioGroup
  273. onChange={onChange}
  274. label={label}
  275. value={value}
  276. choices={[
  277. ['choice_one', 'Choice One', 'Description for Choice One'],
  278. ['choice_two', 'Choice Two', 'Description for Choice Two'],
  279. ['choice_three', 'Choice Three'],
  280. ]}
  281. />
  282. )}
  283. </FormField>
  284. </Form>
  285. );
  286. NonInlineField.storyName = 'Non-inline field';
  287. NonInlineField.parameters = {
  288. docs: {
  289. description: {
  290. story: 'Radio Group used w/ FormField',
  291. },
  292. },
  293. };
  294. export const _RangeSlider = () => (
  295. <div style={{backgroundColor: '#fff', padding: 20}}>
  296. <RangeSlider
  297. name="rangeField"
  298. min={1}
  299. max={10}
  300. step={1}
  301. value={1}
  302. formatLabel={value => {
  303. return `${value} Toaster Strudle${value > 1 ? 's' : ''}`;
  304. }}
  305. />
  306. </div>
  307. );
  308. _RangeSlider.storyName = 'RangeSlider';
  309. export const WithoutAParentForm = ({onChange}) => {
  310. return (
  311. <div>
  312. <TextField
  313. name="simpletextfield"
  314. label="Simple Text Field"
  315. placeholder="Simple Text Field"
  316. onChange={onChange}
  317. />
  318. <NewBooleanField name="field" label="New Boolean Field" onChange={onChange} />
  319. <RadioField
  320. name="radio"
  321. label="Radio Field"
  322. onChange={onChange}
  323. choices={[
  324. ['choice_one', 'Choice One'],
  325. ['choice_two', 'Choice Two'],
  326. ['choice_three', 'Choice Three'],
  327. ]}
  328. />
  329. <Switch id="test" />
  330. </div>
  331. );
  332. };
  333. WithoutAParentForm.storyName = 'Without a parent Form';
  334. WithoutAParentForm.argTypes = {
  335. onChange: {action: 'onChange'},
  336. };
  337. WithoutAParentForm.parameters = {
  338. docs: {
  339. description: {
  340. story: 'New form fields used without having a parent Form',
  341. },
  342. },
  343. };
  344. export const __TextCopyInput = () => (
  345. <TextCopyInput onCopy={action('Copied!')}>Value to be copied </TextCopyInput>
  346. );
  347. __TextCopyInput.storyName = 'TextCopyInput';