form-fields.stories.js 10 KB

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