123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- import {action} from '@storybook/addon-actions';
- import CompactSelect from 'sentry/components/compactSelect';
- import CompositeSelect from 'sentry/components/compositeSelect';
- import RadioGroup from 'sentry/components/forms/controls/radioGroup';
- import RangeSlider from 'sentry/components/forms/controls/rangeSlider';
- import NewBooleanField from 'sentry/components/forms/fields/booleanField';
- import CheckboxField from 'sentry/components/forms/fields/checkboxField';
- import DatePickerField from 'sentry/components/forms/fields/datePickerField';
- import FileField from 'sentry/components/forms/fields/fileField';
- import RadioField from 'sentry/components/forms/fields/radioField';
- import SelectField from 'sentry/components/forms/fields/selectField';
- import TextareaField from 'sentry/components/forms/fields/textareaField';
- import TextField from 'sentry/components/forms/fields/textField';
- import Form from 'sentry/components/forms/form';
- import FormField from 'sentry/components/forms/formField';
- import {Panel} from 'sentry/components/panels';
- import {RadioGroupRating} from 'sentry/components/radioGroupRating';
- import Switch from 'sentry/components/switchButton';
- import TextCopyInput from 'sentry/components/textCopyInput';
- export default {
- title: 'Components/Forms/Fields',
- };
- export const _TextField = () => (
- <Panel>
- <Form initialData={{context: {location: 'cat'}}}>
- <TextField
- name="simpletextfieldvalue"
- label="Simple Text Field with Value"
- placeholder="Simple Text Field"
- defaultValue="With a value present"
- />
- <TextField
- name="simpletextfieldplaceholder"
- label="Simple Text Field with Placeholder"
- placeholder="This is placeholder text"
- />
- <TextField
- name="simpletextfieldvaluedisabled"
- label="Disabled - Simple Text Field with Value"
- placeholder="Simple Text Field"
- defaultValue="With a value present"
- disabled
- />
- <TextField
- name="simpletextfieldplaceholderdisabled"
- label="Disabled - Simple Text Field with Placeholder"
- placeholder="This is placeholder text in a disabled field"
- disabled
- />
- <TextField
- name="textfieldflexiblecontrol"
- label="Text Field With Flexible Control State Size"
- placeholder="Type text and then delete it"
- required
- flexibleControlStateSize
- />
- <TextField
- name="textfielddisabled"
- label="Text field with disabled reason"
- placeholder="I am disabled"
- disabled
- disabledReason="This is the reason this field is disabled"
- />
- </Form>
- </Panel>
- );
- _TextField.storyName = 'Text';
- _TextField.parameters = {
- docs: {
- description: {
- story: 'Simple text field',
- },
- },
- };
- export const _TextareaField = ({autosize, rows}) => (
- <Panel>
- <Form initialData={{context: {location: 'cat'}}}>
- <TextareaField
- name="simpletextfieldvalue"
- label="Simple Textarea Field with Value"
- help="Additional help text"
- placeholder="Simple Textarea Field"
- defaultValue="With a value present"
- />
- <TextareaField
- name="simpletextfieldautosize"
- autosize={autosize}
- label="Textarea field with autosize"
- rows={rows}
- placeholder="Use knobs to control rows and autosize setting"
- />
- <TextareaField
- name="simpletextfieldvaluedisabled"
- label="Disabled - Simple Textarea Field with Value"
- placeholder="Simple Textarea Field"
- defaultValue="With a value present"
- disabled
- />
- <TextareaField
- name="simpletextfieldplaceholderdisabled"
- label="Disabled - Simple Textarea Field with Placeholder"
- placeholder="This is placeholder text in a disabled field"
- disabled
- />
- <TextareaField
- name="textfieldflexiblecontrol"
- label="Textarea Field With Flexible Control State Size"
- placeholder="Type text and then delete it"
- required
- flexibleControlStateSize
- />
- <TextareaField
- name="textfielddisabled"
- label="Textarea Field with disabled reason"
- placeholder="I am disabled"
- disabled
- disabledReason="This is the reason this field is disabled"
- />
- <TextareaField
- name="textareafielderror"
- label="Textarea Field with error"
- placeholder="I have an error"
- error="An error has occurred"
- />
- </Form>
- </Panel>
- );
- _TextareaField.storyName = 'Textarea';
- _TextareaField.args = {
- autosize: true,
- rows: 1,
- };
- export const __BooleanField = () => (
- <Form>
- <NewBooleanField name="field" label="New Boolean Field" />
- </Form>
- );
- __BooleanField.storyName = 'Boolean';
- export const _CheckboxField = () => (
- <Form>
- <CheckboxField name="agree" label="Do you agree?" />
- <CheckboxField
- name="compelled"
- label="You are compelled to agree"
- help="More content to help you decide."
- required
- />
- </Form>
- );
- _CheckboxField.storyName = 'Checkbox';
- export const _DatePickerField = () => (
- <Form>
- <DatePickerField name="field" label="Date Picker Field" />
- </Form>
- );
- _DatePickerField.storyName = 'Datepicker';
- export const _RadioField = () => (
- <Form>
- <RadioField
- name="radio"
- label="Radio Field"
- choices={[
- ['choice_one', 'Choice One'],
- ['choice_two', 'Choice Two'],
- ['choice_three', 'Choice Three'],
- ]}
- />
- <RadioField
- orientInline
- name="inline-radio"
- label="Inline Radios"
- choices={[
- ['choice_one', 'Choice One'],
- ['choice_two', 'Choice Two'],
- ]}
- />
- </Form>
- );
- export const __FileField = () => (
- <Form>
- <FileField name="field" label="File Field" />
- </Form>
- );
- __FileField.storyName = 'File';
- _RadioField.storyName = 'Radio';
- export const _SelectField = () => (
- <Form>
- <SelectField
- name="select"
- label="Select Field"
- options={[
- {value: 'choice_one', label: 'Choice One'},
- {value: 'choice_two', label: 'Choice Two'},
- {value: 'choice_three', label: 'Choice Three'},
- ]}
- />
- </Form>
- );
- _SelectField.storyName = 'Select';
- export const SelectFieldMultiple = () => (
- <Form>
- <SelectField
- name="select"
- label="Multi Select"
- multiple
- options={[
- {value: 'choice_one', label: 'Choice One'},
- {value: 'choice_two', label: 'Choice Two'},
- {value: 'choice_three', label: 'Choice Three'},
- ]}
- />
- </Form>
- );
- SelectFieldMultiple.storyName = 'Select - Multiple';
- export const SelectFieldGrouped = () => (
- <Form>
- <SelectField
- name="select"
- label="Grouped Select"
- options={[
- {
- label: 'Group 1',
- options: [
- {value: 'choice_one', label: 'Choice One'},
- {value: 'choice_two', label: 'Choice Two'},
- ],
- },
- {
- label: 'Group 2',
- options: [
- {value: 'choice_three', label: 'Choice Three'},
- {value: 'choice_four', label: 'Choice Four'},
- ],
- },
- ]}
- />
- </Form>
- );
- SelectFieldGrouped.storyName = 'Select - Grouped';
- export const SelectFieldInFieldLabel = () => (
- <Form>
- <SelectField
- name="select"
- label="Select With Label In Field"
- inFieldLabel="Label: "
- options={[
- {value: 'choice_one', label: 'Choice One'},
- {value: 'choice_two', label: 'Choice Two'},
- {value: 'choice_three', label: 'Choice Three'},
- ]}
- />
- </Form>
- );
- SelectFieldInFieldLabel.storyName = 'Select - Label in Field';
- SelectFieldInFieldLabel.parameters = {
- docs: {
- description: {
- story: 'Select Control w/ Label In Field',
- },
- },
- };
- export const CompactSelectField = props => (
- <CompactSelect
- defaultValue="opt_one"
- options={[
- {value: 'opt_one', label: 'Option One'},
- {value: 'opt_two', label: 'Option Two'},
- ]}
- {...props}
- />
- );
- CompactSelectField.storyName = 'Select - Compact';
- CompactSelectField.parameters = {
- docs: {
- description: {
- story: 'Compact',
- },
- },
- };
- CompactSelectField.args = {
- size: 'md',
- menuTitle: '',
- isSearchable: false,
- isDisabled: false,
- isClearable: false,
- isLoading: false,
- multiple: false,
- placeholder: 'Search…',
- closeOnSelect: true,
- shouldCloseOnBlur: true,
- isDismissable: true,
- offset: 8,
- crossOffset: 0,
- containerPadding: 8,
- placement: 'bottom left',
- triggerProps: {
- prefix: 'Prefix',
- },
- };
- CompactSelectField.argTypes = {
- placement: {
- options: [
- 'top',
- 'bottom',
- 'left',
- 'right',
- 'top left',
- 'top right',
- 'bottom left',
- 'bottom right',
- 'left top',
- 'left bottom',
- 'right top',
- 'right bottom',
- ],
- control: {type: 'radio'},
- },
- size: {
- options: ['md', 'sm', 'xs'],
- control: {type: 'radio'},
- },
- };
- export const CompositeSelectField = props => (
- <CompositeSelect
- sections={[
- {
- label: 'Group 1',
- value: 'group_1',
- defaultValue: 'choice_one',
- options: [
- {value: 'choice_one', label: 'Choice One'},
- {value: 'choice_two', label: 'Choice Two'},
- ],
- },
- {
- label: 'Group 2',
- value: 'group_2',
- defaultValue: ['choice_three'],
- multiple: true,
- options: [
- {value: 'choice_three', label: 'Choice Three'},
- {value: 'choice_four', label: 'Choice Four'},
- ],
- },
- ]}
- {...props}
- />
- );
- CompositeSelectField.storyName = 'Select - Composite';
- CompositeSelectField.args = {...CompactSelectField.args};
- delete CompositeSelectField.args.multiple;
- CompositeSelectField.argTypes = CompactSelectField.argTypes;
- export const NonInlineField = () => (
- <Form>
- <FormField name="radio" label="Radio Field" inline={false}>
- {({value, label, onChange}) => (
- <RadioGroup
- onChange={onChange}
- label={label}
- value={value}
- choices={[
- ['choice_one', 'Choice One', 'Description for Choice One'],
- ['choice_two', 'Choice Two', 'Description for Choice Two'],
- ['choice_three', 'Choice Three'],
- ]}
- />
- )}
- </FormField>
- </Form>
- );
- NonInlineField.storyName = 'Non-inline';
- NonInlineField.parameters = {
- docs: {
- description: {
- story: 'Radio Group used w/ FormField',
- },
- },
- };
- export const _RadioGroupRating = () => (
- <RadioGroupRating
- name="feelingIfFeatureNotAvailableRating"
- options={{
- 0: {
- label: 'Very Dissatisfied',
- description: "Not disappointed (It isn't really useful)",
- },
- 1: {
- label: 'Dissatisfied',
- },
- 2: {
- label: 'Neutral',
- },
- 3: {
- label: 'Satisfied',
- },
- 4: {
- description: "Very disappointed (It's a deal breaker)",
- label: 'Very Satisfied',
- },
- }}
- label="How satisfied are you with this feature?"
- inline={false}
- stacked
- />
- );
- _RadioGroupRating.storyName = 'Radio Group Rating';
- _RadioGroupRating.parameters = {
- docs: {
- description: {
- story: 'Used to provide insights regarding opinions and experiences',
- },
- },
- };
- export const _RangeSlider = () => (
- <div style={{backgroundColor: '#fff', padding: 20}}>
- <RangeSlider
- name="rangeField"
- min={1}
- max={10}
- step={1}
- value={1}
- formatLabel={value => {
- return `${value} Toaster Strudle${value > 1 ? 's' : ''}`;
- }}
- />
- </div>
- );
- _RangeSlider.storyName = 'Range Slider';
- export const WithoutAParentForm = ({onChange}) => {
- return (
- <div>
- <TextField
- name="simpletextfield"
- label="Simple Text Field"
- placeholder="Simple Text Field"
- onChange={onChange}
- />
- <NewBooleanField name="field" label="New Boolean Field" onChange={onChange} />
- <RadioField
- name="radio"
- label="Radio Field"
- onChange={onChange}
- choices={[
- ['choice_one', 'Choice One'],
- ['choice_two', 'Choice Two'],
- ['choice_three', 'Choice Three'],
- ]}
- />
- <Switch id="test" />
- </div>
- );
- };
- WithoutAParentForm.storyName = 'Without a Parent Form';
- WithoutAParentForm.argTypes = {
- onChange: {action: 'onChange'},
- };
- WithoutAParentForm.parameters = {
- docs: {
- description: {
- story: 'New form fields used without having a parent Form',
- },
- },
- };
- export const __TextCopyInput = () => (
- <TextCopyInput onCopy={action('Copied!')}>Value to be copied </TextCopyInput>
- );
- __TextCopyInput.storyName = 'Text Copy';
|