From 68674c502014e31b15cb81ab85d62677814a60fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Jaeger=20Foresti?= <60678893+juliajforesti@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:28:29 -0300 Subject: [PATCH] feat(fuselage): create `LabelInfo` component (#1214) --- .changeset/tame-bikes-reflect.md | 5 + .../src/components/Field/Field.stories.tsx | 33 +++++ .../src/components/Field/FieldLabel.tsx | 2 +- .../src/components/Field/FieldLabelInfo.tsx | 26 ++++ .../Field/__snapshots__/Field.spec.tsx.snap | 126 ++++++++++++++++++ .../fuselage/src/components/Field/index.tsx | 2 + .../src/components/Label/Label.stories.tsx | 15 +++ .../src/components/Label/Label.styles.scss | 9 ++ .../src/components/Label/LabelInfo.tsx | 19 +++ .../Label/__snapshots__/Label.spec.tsx.snap | 62 +++++++++ 10 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 .changeset/tame-bikes-reflect.md create mode 100644 packages/fuselage/src/components/Field/FieldLabelInfo.tsx create mode 100644 packages/fuselage/src/components/Label/LabelInfo.tsx diff --git a/.changeset/tame-bikes-reflect.md b/.changeset/tame-bikes-reflect.md new file mode 100644 index 0000000000..69a3afe9a2 --- /dev/null +++ b/.changeset/tame-bikes-reflect.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/fuselage": minor +--- + +feat(fuselage): create `LabelInfo` component diff --git a/packages/fuselage/src/components/Field/Field.stories.tsx b/packages/fuselage/src/components/Field/Field.stories.tsx index 0db4fa8f87..bb408898eb 100644 --- a/packages/fuselage/src/components/Field/Field.stories.tsx +++ b/packages/fuselage/src/components/Field/Field.stories.tsx @@ -14,6 +14,7 @@ import { ToggleSwitch, FieldLink, } from '../..'; +import { FieldLabelInfo } from './FieldLabelInfo'; export default { title: 'Inputs/Field', @@ -47,6 +48,38 @@ export const Default: ComponentStory = () => ( Hint ); +export const WithLabelInfo: ComponentStory = () => ( + + + Label + + + Description + + + + Error + Hint + +); +export const RequiredWithLabelInfo: ComponentStory = () => ( + + + Label + + + Description + + + + Error + Hint + +); export const WithCheckBox: ComponentStory = () => ( diff --git a/packages/fuselage/src/components/Field/FieldLabel.tsx b/packages/fuselage/src/components/Field/FieldLabel.tsx index c4059c943a..4cc20f48a4 100644 --- a/packages/fuselage/src/components/Field/FieldLabel.tsx +++ b/packages/fuselage/src/components/Field/FieldLabel.tsx @@ -6,7 +6,7 @@ import Box from '../Box'; import { Label } from '../Label'; import { FieldContext } from './Field'; -type FieldLabelProps = ComponentPropsWithoutRef; +type FieldLabelProps = ComponentPropsWithoutRef; export const FieldLabel = (props: FieldLabelProps) => { const component = ; diff --git a/packages/fuselage/src/components/Field/FieldLabelInfo.tsx b/packages/fuselage/src/components/Field/FieldLabelInfo.tsx new file mode 100644 index 0000000000..9cfd5c1f99 --- /dev/null +++ b/packages/fuselage/src/components/Field/FieldLabelInfo.tsx @@ -0,0 +1,26 @@ +import type { ComponentProps } from 'react'; +import React from 'react'; + +import WithErrorWrapper from '../../helpers/WithErrorWrapper'; +import { LabelInfo } from '../Label/LabelInfo'; +import { FieldContext } from './Field'; + +type FieldLabelInfoProps = ComponentProps; + +export const FieldLabelInfo = (props: FieldLabelInfoProps) => { + const component = ; + + if (process.env.NODE_ENV === 'development') { + return ( + + {component} + + ); + } + + return component; +}; 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 73a359f5cd..706b04c819 100644 --- a/packages/fuselage/src/components/Field/__snapshots__/Field.spec.tsx.snap +++ b/packages/fuselage/src/components/Field/__snapshots__/Field.spec.tsx.snap @@ -42,6 +42,72 @@ exports[`[Field Component] renders Default without crashing 1`] = ` `; +exports[`[Field Component] renders RequiredWithLabelInfo without crashing 1`] = ` + +
+
+ + + Description + + + + + + Error + + + Hint + +
+
+ +`; + exports[`[Field Component] renders WithCheckBox without crashing 1`] = `
@@ -252,6 +318,66 @@ exports[`[Field Component] renders WithHintAndLink without crashing 1`] = ` `; +exports[`[Field Component] renders WithLabelInfo without crashing 1`] = ` + +
+
+ + + Description + + + + + + Error + + + Hint + +
+
+ +`; + exports[`[Field Component] renders WithLink without crashing 1`] = `
diff --git a/packages/fuselage/src/components/Field/index.tsx b/packages/fuselage/src/components/Field/index.tsx index a3b69d1b34..9259ddaa91 100644 --- a/packages/fuselage/src/components/Field/index.tsx +++ b/packages/fuselage/src/components/Field/index.tsx @@ -3,6 +3,7 @@ import { FieldDescription } from './FieldDescription'; import { FieldError } from './FieldError'; import { FieldHint } from './FieldHint'; import { FieldLabel } from './FieldLabel'; +import { FieldLabelInfo } from './FieldLabelInfo'; import { FieldLink } from './FieldLink'; import { FieldRow } from './FieldRow'; @@ -12,6 +13,7 @@ export { FieldError, FieldHint, FieldLabel, + FieldLabelInfo, FieldLink, FieldRow, }; diff --git a/packages/fuselage/src/components/Label/Label.stories.tsx b/packages/fuselage/src/components/Label/Label.stories.tsx index e7ef03ddeb..cb679c441a 100644 --- a/packages/fuselage/src/components/Label/Label.stories.tsx +++ b/packages/fuselage/src/components/Label/Label.stories.tsx @@ -9,6 +9,7 @@ import type { ComponentStory, ComponentMeta } from '@storybook/react'; import React from 'react'; import { Label } from '../..'; +import { LabelInfo } from './LabelInfo'; export default { title: 'Inputs/Label', @@ -42,6 +43,20 @@ Required.args = { required: true, }; +export const Info: ComponentStory = (args) => ( + +); + +export const InfoRequired: ComponentStory = (args) => ( + +); + export const Disabled: ComponentStory = Template.bind({}); Disabled.args = { disabled: true, diff --git a/packages/fuselage/src/components/Label/Label.styles.scss b/packages/fuselage/src/components/Label/Label.styles.scss index b3c63466cf..cc579bd710 100644 --- a/packages/fuselage/src/components/Label/Label.styles.scss +++ b/packages/fuselage/src/components/Label/Label.styles.scss @@ -1,8 +1,11 @@ @use '../../styles/colors.scss'; @use '../../styles/typography.scss'; +@use '../../styles/lengths.scss'; .rcx-label { @include typography.use-font-scale(p2m); + display: flex; + color: colors.font(default); &--disabled { @@ -11,6 +14,12 @@ color: colors.font(secondary-info); } + &__info { + display: flex; + align-items: center; + order: 1; + } + &__required { color: colors.font(danger); } diff --git a/packages/fuselage/src/components/Label/LabelInfo.tsx b/packages/fuselage/src/components/Label/LabelInfo.tsx new file mode 100644 index 0000000000..23ff1fecea --- /dev/null +++ b/packages/fuselage/src/components/Label/LabelInfo.tsx @@ -0,0 +1,19 @@ +import type { ComponentProps } from 'react'; +import React from 'react'; + +import Box from '../Box/Box'; +import { Icon } from '../Icon'; + +type LabelInfoProps = { + title: string; + id?: string; +} & Omit, 'name'>; + +export const LabelInfo = ({ title, id, ...props }: LabelInfoProps) => ( + + + + +); diff --git a/packages/fuselage/src/components/Label/__snapshots__/Label.spec.tsx.snap b/packages/fuselage/src/components/Label/__snapshots__/Label.spec.tsx.snap index 73276213bc..047f398334 100644 --- a/packages/fuselage/src/components/Label/__snapshots__/Label.spec.tsx.snap +++ b/packages/fuselage/src/components/Label/__snapshots__/Label.spec.tsx.snap @@ -24,6 +24,68 @@ exports[`[Label Component] renders Disabled without crashing 1`] = ` `; +exports[`[Label Component] renders Info without crashing 1`] = ` + +
+ +
+ +`; + +exports[`[Label Component] renders InfoRequired without crashing 1`] = ` + +
+ +
+ +`; + exports[`[Label Component] renders Required without crashing 1`] = `