diff --git a/packages/fuselage/src/components/Field/Field.stories.tsx b/packages/fuselage/src/components/Field/Field.stories.tsx index bb408898eb..7f966654ba 100644 --- a/packages/fuselage/src/components/Field/Field.stories.tsx +++ b/packages/fuselage/src/components/Field/Field.stories.tsx @@ -3,16 +3,18 @@ import type { ComponentStory, ComponentMeta } from '@storybook/react'; import React from 'react'; import { - CheckBox, Field, FieldDescription, FieldError, FieldHint, FieldRow, FieldLabel, - InputBox, ToggleSwitch, FieldLink, + TextInput, + TextAreaInput, + RadioButton, + CheckBox, } from '../..'; import { FieldLabelInfo } from './FieldLabelInfo'; @@ -30,150 +32,107 @@ export default { <Description /> <Primary /> - <Stories title={'Field Patterns'} /> + <Stories /> </> ), }, }, } as ComponentMeta<typeof Field>; -export const Default: ComponentStory<typeof Field> = () => ( +export const WithTextInput: ComponentStory<typeof Field> = () => ( <Field> - <FieldLabel>Label</FieldLabel> - <FieldDescription>Description</FieldDescription> - <FieldRow> - <InputBox.Skeleton /> - </FieldRow> - <FieldError>Error</FieldError> - <FieldHint>Hint</FieldHint> - </Field> -); -export const WithLabelInfo: ComponentStory<typeof Field> = () => ( - <Field> - <FieldLabel htmlFor='label-info-id'> + <FieldLabel required htmlFor='fieldWithText'> Label - <FieldLabelInfo id='info-id' title='this is a info label' /> + <FieldLabelInfo id='fieldWithTextInfo' title='this is a info label' /> </FieldLabel> <FieldDescription>Description</FieldDescription> <FieldRow> - <InputBox id='label-info-id' type='text' aria-describedby='info-id' /> + <TextInput id='fieldWithText' aria-describedby='fieldWithTextInfo' /> + </FieldRow> + <FieldError>Error feedback</FieldError> + <FieldRow> + <FieldHint>Hint</FieldHint> + <FieldLink href='#'>Link</FieldLink> </FieldRow> - <FieldError>Error</FieldError> - <FieldHint>Hint</FieldHint> </Field> ); -export const RequiredWithLabelInfo: ComponentStory<typeof Field> = () => ( +export const WithTextArea: ComponentStory<typeof Field> = () => ( <Field> - <FieldLabel required htmlFor='label-required-id'> + <FieldLabel required htmlFor='fieldWithTextArea'> Label - <FieldLabelInfo id='required-info-id' title='this is a info label' /> + <FieldLabelInfo id='fieldWithTextAreaInfo' title='this is a info label' /> </FieldLabel> <FieldDescription>Description</FieldDescription> <FieldRow> - <InputBox - id='label-required-id' - type='text' - aria-describedby='required-info-id' + <TextAreaInput + id='fieldWithTextArea' + aria-describedby='fieldWithTextAreaInfo' /> </FieldRow> - <FieldError>Error</FieldError> - <FieldHint>Hint</FieldHint> - </Field> -); - -export const WithCheckBox: ComponentStory<typeof Field> = () => ( - <Field> - <FieldRow> - <CheckBox id='check-box' /> - <FieldLabel htmlFor='check-box'>Label</FieldLabel> - </FieldRow> - </Field> -); - -export const WithToggleSwitch: ComponentStory<typeof Field> = () => ( - <Field> + <FieldError>Error feedback</FieldError> <FieldRow> - <ToggleSwitch id='toggle-switch' /> - <FieldLabel htmlFor='toggle-switch'>Label</FieldLabel> + <FieldHint>Hint</FieldHint> + <FieldLink href='#'>Link</FieldLink> </FieldRow> </Field> ); - -export const WithDescription: ComponentStory<typeof Field> = () => ( +export const WithRadioButton: ComponentStory<typeof Field> = () => ( <Field> - <FieldLabel>Label</FieldLabel> - <FieldDescription> - Descriptions should add useful and relevant additional information about - what is required of the user for the related input. Its content is - strictly composed by plain text. - </FieldDescription> <FieldRow> - <InputBox.Skeleton /> + <FieldLabel required htmlFor='fieldWithRadio'> + Label + <FieldLabelInfo id='fieldWithRadioInfo' title='this is a info label' /> + </FieldLabel> + <RadioButton id='fieldWithRadio' aria-describedby='fieldWithRadioInfo' /> </FieldRow> - </Field> -); - -export const WithError: ComponentStory<typeof Field> = () => ( - <Field> - <FieldLabel>Label</FieldLabel> + <FieldDescription>Description</FieldDescription> + <FieldError>Error feedback</FieldError> <FieldRow> - <InputBox.Skeleton /> + <FieldHint>Hint</FieldHint> + <FieldLink href='#'>Link</FieldLink> </FieldRow> - <FieldError> - Error text appears when the user has inputted an invalid response to a - field and let's the user know exactly what the issue is, so as to let them - remedy the error as easily as possible. - </FieldError> </Field> ); - -export const WithHint: ComponentStory<typeof Field> = () => ( +export const WithToggleSwitch: ComponentStory<typeof Field> = () => ( <Field> - <FieldLabel>Label</FieldLabel> <FieldRow> - <InputBox.Skeleton /> + <FieldLabel required htmlFor='fieldWithToggle'> + Label + <FieldLabelInfo id='fieldWithToggleInfo' title='this is a info label' /> + </FieldLabel> + <ToggleSwitch + id='fieldWithToggle' + aria-describedby='fieldWithToggleInfo' + /> </FieldRow> - <FieldHint> - Hint fields help by explaining technical terms or concepts related to - third-party apps and integrations. - </FieldHint> - </Field> -); - -export const WithHintAndError: ComponentStory<typeof Field> = () => ( - <Field> - <FieldLabel>Label</FieldLabel> + <FieldDescription>Description</FieldDescription> + <FieldError>Error feedback</FieldError> <FieldRow> - <InputBox.Skeleton /> + <FieldHint>Hint</FieldHint> + <FieldLink href='#'>Link</FieldLink> </FieldRow> - <FieldError>Error must be above.</FieldError> - <FieldHint>Hint must be below.</FieldHint> </Field> ); - -export const WithLink: ComponentStory<typeof Field> = () => ( +export const WithCheckbox: ComponentStory<typeof Field> = () => ( <Field> - <FieldLabel>Label</FieldLabel> <FieldRow> - <InputBox.Skeleton /> - </FieldRow> - <FieldRow justifyContent='end'> - <FieldLink href='#'> - Link is used for external resources or documentation. - </FieldLink> + <FieldLabel required htmlFor='fieldWithCheckbox'> + Label + <FieldLabelInfo + id='fieldWithCheckboxInfo' + title='this is a info label' + /> + </FieldLabel> + <CheckBox + id='fieldWithCheckbox' + aria-describedby='fieldWithCheckboxInfo' + /> </FieldRow> - </Field> -); - -export const WithHintAndLink: ComponentStory<typeof Field> = () => ( - <Field> - <FieldLabel>Label</FieldLabel> + <FieldDescription>Description</FieldDescription> + <FieldError>Error feedback</FieldError> <FieldRow> - <InputBox.Skeleton /> - </FieldRow> - <FieldRow justifyContent='space-between'> - <FieldHint>Same line as Link in the left</FieldHint> - <FieldLink href='#'>Same line as Hint in the right</FieldLink> + <FieldHint>Hint</FieldHint> + <FieldLink href='#'>Link</FieldLink> </FieldRow> </Field> ); diff --git a/packages/fuselage/src/components/Field/Field.styles.scss b/packages/fuselage/src/components/Field/Field.styles.scss index c7ce7c8b95..75ebb93aca 100644 --- a/packages/fuselage/src/components/Field/Field.styles.scss +++ b/packages/fuselage/src/components/Field/Field.styles.scss @@ -38,10 +38,6 @@ margin-block-end: lengths.margin(2); color: colors.font(secondary-info); - - & .rcx-field__label { - padding-inline-start: lengths.padding(8); - } } &__hint { diff --git a/packages/fuselage/src/components/Field/__snapshots__/Field.spec.tsx.snap b/packages/fuselage/src/components/Field/__snapshots__/Field.spec.tsx.snap index 706b04c819..b9f331a746 100644 --- a/packages/fuselage/src/components/Field/__snapshots__/Field.spec.tsx.snap +++ b/packages/fuselage/src/components/Field/__snapshots__/Field.spec.tsx.snap @@ -1,114 +1,90 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`[Field Component] renders Default without crashing 1`] = ` +exports[`[Field Component] renders WithCheckbox without crashing 1`] = ` <body> <div> <div class="rcx-box rcx-box--full rcx-field" > - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - > - Label - </label> - <span - class="rcx-box rcx-box--full rcx-field__description" - > - Description - </span> <span class="rcx-box rcx-box--full rcx-field__row" > - <div - class="rcx-box rcx-box--full rcx-skeleton__input" - > - <span - class="rcx-box rcx-box--full rcx-skeleton--text rcx-skeleton rcx-css-1qcz93u" - /> - </div> - </span> - <span - class="rcx-box rcx-box--full rcx-field__error" - > - Error - </span> - <span - class="rcx-box rcx-box--full rcx-field__hint" - > - Hint - </span> - </div> - </div> -</body> -`; - -exports[`[Field Component] renders RequiredWithLabelInfo without crashing 1`] = ` -<body> - <div> - <div - class="rcx-box rcx-box--full rcx-field" - > - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - for="label-required-id" - > - Label - <span - class="rcx-box rcx-box--full rcx-label__info rcx-css-wcp0mp" + <label + class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" + for="fieldWithCheckbox" > + Label <span - hidden="" - id="required-info-id" + class="rcx-box rcx-box--full rcx-label__info rcx-css-wcp0mp" > - this is a info label + <span + hidden="" + id="fieldWithCheckboxInfo" + > + this is a info label + </span> + <i + aria-hidden="true" + class="rcx-box rcx-box--full rcx-icon--name-info-circled rcx-icon" + title="this is a info label" + > +  + </i> </span> - <i + <span aria-hidden="true" - class="rcx-box rcx-box--full rcx-icon--name-info-circled rcx-icon" - title="this is a info label" + class="rcx-box rcx-box--full rcx-label__required rcx-css-b7g1a9" > -  - </i> - </span> - <span - aria-hidden="true" - class="rcx-box rcx-box--full rcx-label__required rcx-css-b7g1a9" + * + </span> + </label> + <label + class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-check-box" > - * - </span> - </label> + <input + aria-describedby="fieldWithCheckboxInfo" + class="rcx-box rcx-box--full rcx-check-box__input" + id="fieldWithCheckbox" + type="checkbox" + /> + <i + aria-hidden="true" + class="rcx-box rcx-box--full rcx-check-box__fake" + /> + </label> + </span> <span class="rcx-box rcx-box--full rcx-field__description" > Description </span> - <span - class="rcx-box rcx-box--full rcx-field__row" - > - <input - aria-describedby="required-info-id" - class="rcx-box rcx-box--full rcx-box--animated rcx-input-box--type-text rcx-input-box" - id="label-required-id" - size="1" - type="text" - /> - </span> <span class="rcx-box rcx-box--full rcx-field__error" > - Error + Error feedback </span> <span - class="rcx-box rcx-box--full rcx-field__hint" + class="rcx-box rcx-box--full rcx-field__row" > - Hint + <span + class="rcx-box rcx-box--full rcx-field__hint" + > + Hint + </span> + <a + class="rcx-box rcx-box--full rcx-field__link" + href="#" + target="_blank" + > + Link + </a> </span> </div> </div> </body> `; -exports[`[Field Component] renders WithCheckBox without crashing 1`] = ` +exports[`[Field Component] renders WithRadioButton without crashing 1`] = ` <body> <div> <div @@ -118,95 +94,81 @@ exports[`[Field Component] renders WithCheckBox without crashing 1`] = ` class="rcx-box rcx-box--full rcx-field__row" > <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-check-box" + class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" + for="fieldWithRadio" + > + Label + <span + class="rcx-box rcx-box--full rcx-label__info rcx-css-wcp0mp" + > + <span + hidden="" + id="fieldWithRadioInfo" + > + this is a info label + </span> + <i + aria-hidden="true" + class="rcx-box rcx-box--full rcx-icon--name-info-circled rcx-icon" + title="this is a info label" + > +  + </i> + </span> + <span + aria-hidden="true" + class="rcx-box rcx-box--full rcx-label__required rcx-css-b7g1a9" + > + * + </span> + </label> + <label + class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-radio-button" > <input - class="rcx-box rcx-box--full rcx-check-box__input" - id="check-box" - type="checkbox" + aria-describedby="fieldWithRadioInfo" + class="rcx-box rcx-box--full rcx-radio-button__input" + id="fieldWithRadio" + type="radio" /> <i aria-hidden="true" - class="rcx-box rcx-box--full rcx-check-box__fake" + class="rcx-box rcx-box--full rcx-radio-button__fake" /> </label> - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - for="check-box" - > - Label - </label> </span> - </div> - </div> -</body> -`; - -exports[`[Field Component] renders WithDescription without crashing 1`] = ` -<body> - <div> - <div - class="rcx-box rcx-box--full rcx-field" - > - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - > - Label - </label> <span class="rcx-box rcx-box--full rcx-field__description" > - Descriptions should add useful and relevant additional information about what is required of the user for the related input. Its content is strictly composed by plain text. + Description </span> <span - class="rcx-box rcx-box--full rcx-field__row" + class="rcx-box rcx-box--full rcx-field__error" > - <div - class="rcx-box rcx-box--full rcx-skeleton__input" - > - <span - class="rcx-box rcx-box--full rcx-skeleton--text rcx-skeleton rcx-css-1qcz93u" - /> - </div> + Error feedback </span> - </div> - </div> -</body> -`; - -exports[`[Field Component] renders WithError without crashing 1`] = ` -<body> - <div> - <div - class="rcx-box rcx-box--full rcx-field" - > - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - > - Label - </label> <span class="rcx-box rcx-box--full rcx-field__row" > - <div - class="rcx-box rcx-box--full rcx-skeleton__input" + <span + class="rcx-box rcx-box--full rcx-field__hint" > - <span - class="rcx-box rcx-box--full rcx-skeleton--text rcx-skeleton rcx-css-1qcz93u" - /> - </div> - </span> - <span - class="rcx-box rcx-box--full rcx-field__error" - > - Error text appears when the user has inputted an invalid response to a field and let's the user know exactly what the issue is, so as to let them remedy the error as easily as possible. + Hint + </span> + <a + class="rcx-box rcx-box--full rcx-field__link" + href="#" + target="_blank" + > + Link + </a> </span> </div> </div> </body> `; -exports[`[Field Component] renders WithHint without crashing 1`] = ` +exports[`[Field Component] renders WithTextArea without crashing 1`] = ` <body> <div> <div @@ -214,103 +176,68 @@ exports[`[Field Component] renders WithHint without crashing 1`] = ` > <label class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" + for="fieldWithTextArea" > Label - </label> - <span - class="rcx-box rcx-box--full rcx-field__row" - > - <div - class="rcx-box rcx-box--full rcx-skeleton__input" + <span + class="rcx-box rcx-box--full rcx-label__info rcx-css-wcp0mp" > <span - class="rcx-box rcx-box--full rcx-skeleton--text rcx-skeleton rcx-css-1qcz93u" - /> - </div> - </span> + hidden="" + id="fieldWithTextAreaInfo" + > + this is a info label + </span> + <i + aria-hidden="true" + class="rcx-box rcx-box--full rcx-icon--name-info-circled rcx-icon" + title="this is a info label" + > +  + </i> + </span> + <span + aria-hidden="true" + class="rcx-box rcx-box--full rcx-label__required rcx-css-b7g1a9" + > + * + </span> + </label> <span - class="rcx-box rcx-box--full rcx-field__hint" + class="rcx-box rcx-box--full rcx-field__description" > - Hint fields help by explaining technical terms or concepts related to third-party apps and integrations. + Description </span> - </div> - </div> -</body> -`; - -exports[`[Field Component] renders WithHintAndError without crashing 1`] = ` -<body> - <div> - <div - class="rcx-box rcx-box--full rcx-field" - > - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - > - Label - </label> <span class="rcx-box rcx-box--full rcx-field__row" > - <div - class="rcx-box rcx-box--full rcx-skeleton__input" - > - <span - class="rcx-box rcx-box--full rcx-skeleton--text rcx-skeleton rcx-css-1qcz93u" - /> - </div> + <textarea + aria-describedby="fieldWithTextAreaInfo" + class="rcx-box rcx-box--full rcx-box--animated rcx-input-box--type-textarea rcx-input-box" + cols="1" + id="fieldWithTextArea" + size="1" + /> </span> <span class="rcx-box rcx-box--full rcx-field__error" > - Error must be above. + Error feedback </span> - <span - class="rcx-box rcx-box--full rcx-field__hint" - > - Hint must be below. - </span> - </div> - </div> -</body> -`; - -exports[`[Field Component] renders WithHintAndLink without crashing 1`] = ` -<body> - <div> - <div - class="rcx-box rcx-box--full rcx-field" - > - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - > - Label - </label> <span class="rcx-box rcx-box--full rcx-field__row" - > - <div - class="rcx-box rcx-box--full rcx-skeleton__input" - > - <span - class="rcx-box rcx-box--full rcx-skeleton--text rcx-skeleton rcx-css-1qcz93u" - /> - </div> - </span> - <span - class="rcx-box rcx-box--full rcx-field__row rcx-css-rzpqmp" > <span class="rcx-box rcx-box--full rcx-field__hint" > - Same line as Link in the left + Hint </span> <a class="rcx-box rcx-box--full rcx-field__link" href="#" target="_blank" > - Same line as Hint in the right + Link </a> </span> </div> @@ -318,7 +245,7 @@ exports[`[Field Component] renders WithHintAndLink without crashing 1`] = ` </body> `; -exports[`[Field Component] renders WithLabelInfo without crashing 1`] = ` +exports[`[Field Component] renders WithTextInput without crashing 1`] = ` <body> <div> <div @@ -326,7 +253,7 @@ exports[`[Field Component] renders WithLabelInfo without crashing 1`] = ` > <label class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - for="label-info-id" + for="fieldWithText" > Label <span @@ -334,7 +261,7 @@ exports[`[Field Component] renders WithLabelInfo without crashing 1`] = ` > <span hidden="" - id="info-id" + id="fieldWithTextInfo" > this is a info label </span> @@ -346,6 +273,12 @@ exports[`[Field Component] renders WithLabelInfo without crashing 1`] = `  </i> </span> + <span + aria-hidden="true" + class="rcx-box rcx-box--full rcx-label__required rcx-css-b7g1a9" + > + * + </span> </label> <span class="rcx-box rcx-box--full rcx-field__description" @@ -356,9 +289,9 @@ exports[`[Field Component] renders WithLabelInfo without crashing 1`] = ` class="rcx-box rcx-box--full rcx-field__row" > <input - aria-describedby="info-id" + aria-describedby="fieldWithTextInfo" class="rcx-box rcx-box--full rcx-box--animated rcx-input-box--type-text rcx-input-box" - id="label-info-id" + id="fieldWithText" size="1" type="text" /> @@ -366,49 +299,22 @@ exports[`[Field Component] renders WithLabelInfo without crashing 1`] = ` <span class="rcx-box rcx-box--full rcx-field__error" > - Error - </span> - <span - class="rcx-box rcx-box--full rcx-field__hint" - > - Hint + Error feedback </span> - </div> - </div> -</body> -`; - -exports[`[Field Component] renders WithLink without crashing 1`] = ` -<body> - <div> - <div - class="rcx-box rcx-box--full rcx-field" - > - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - > - Label - </label> <span class="rcx-box rcx-box--full rcx-field__row" > - <div - class="rcx-box rcx-box--full rcx-skeleton__input" + <span + class="rcx-box rcx-box--full rcx-field__hint" > - <span - class="rcx-box rcx-box--full rcx-skeleton--text rcx-skeleton rcx-css-1qcz93u" - /> - </div> - </span> - <span - class="rcx-box rcx-box--full rcx-field__row rcx-css-17mu816" - > + Hint + </span> <a class="rcx-box rcx-box--full rcx-field__link" href="#" target="_blank" > - Link is used for external resources or documentation. + Link </a> </span> </div> @@ -425,12 +331,42 @@ exports[`[Field Component] renders WithToggleSwitch without crashing 1`] = ` <span class="rcx-box rcx-box--full rcx-field__row" > + <label + class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" + for="fieldWithToggle" + > + Label + <span + class="rcx-box rcx-box--full rcx-label__info rcx-css-wcp0mp" + > + <span + hidden="" + id="fieldWithToggleInfo" + > + this is a info label + </span> + <i + aria-hidden="true" + class="rcx-box rcx-box--full rcx-icon--name-info-circled rcx-icon" + title="this is a info label" + > +  + </i> + </span> + <span + aria-hidden="true" + class="rcx-box rcx-box--full rcx-label__required rcx-css-b7g1a9" + > + * + </span> + </label> <label class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-toggle-switch" > <input + aria-describedby="fieldWithToggleInfo" class="rcx-box rcx-box--full rcx-toggle-switch__input" - id="toggle-switch" + id="fieldWithToggle" type="checkbox" /> <i @@ -438,12 +374,32 @@ exports[`[Field Component] renders WithToggleSwitch without crashing 1`] = ` class="rcx-box rcx-box--full rcx-toggle-switch__fake" /> </label> - <label - class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-field__label" - for="toggle-switch" + </span> + <span + class="rcx-box rcx-box--full rcx-field__description" + > + Description + </span> + <span + class="rcx-box rcx-box--full rcx-field__error" + > + Error feedback + </span> + <span + class="rcx-box rcx-box--full rcx-field__row" + > + <span + class="rcx-box rcx-box--full rcx-field__hint" > - Label - </label> + Hint + </span> + <a + class="rcx-box rcx-box--full rcx-field__link" + href="#" + target="_blank" + > + Link + </a> </span> </div> </div>