Skip to content

Commit 907cc39

Browse files
authored
feat(Label)!: remove deprecated props (#1868)
- remove `requiredLabel` from component - remove `optionalLabel` from component neither of these are used, and removing them adds clarity and simplicity to the component. Also added an additional story to the component documentation for clarity.
1 parent f9d73dd commit 907cc39

File tree

5 files changed

+60
-56
lines changed

5 files changed

+60
-56
lines changed

src/components/Label/Label.module.css

-10
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
display: inline-block;
1515
}
1616

17-
/**
18-
* Label flag
19-
*
20-
* A flag to mark whether or not a field is required or optional. Currently a flag
21-
* is only present for optional fields.
22-
*/
23-
.label__flag {
24-
font: var(--eds-theme-typography-body-sm);
25-
}
26-
2717
/**
2818
* Label after
2919
*

src/components/Label/Label.stories.ts

-21
This file was deleted.
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { StoryObj, Meta } from '@storybook/react';
2+
import React from 'react';
3+
4+
import { Label } from './Label';
5+
import Tooltip from '../Tooltip';
6+
7+
export default {
8+
title: 'Components/Label',
9+
component: Label,
10+
parameters: {
11+
badges: ['1.0'],
12+
},
13+
} as Meta<Args>;
14+
15+
type Args = React.ComponentProps<typeof Label>;
16+
17+
/**
18+
* Labels can denote some text to label the content, and whether that content is marked as required.
19+
*/
20+
export const Default: StoryObj<Args> = {
21+
args: {
22+
text: 'Label',
23+
required: true,
24+
},
25+
};
26+
27+
/**
28+
* You can use `labelAfter` to affix additional functionality to the label, like an optional `<Tooltip>`.
29+
*/
30+
export const LabelAfter: StoryObj<Args> = {
31+
args: {
32+
text: 'Label',
33+
labelAfter: (
34+
<Tooltip text="Test">
35+
<span>*</span>
36+
</Tooltip>
37+
),
38+
},
39+
};

src/components/Label/Label.tsx

+5-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import clsx from 'clsx';
22
import type { ReactNode } from 'react';
33
import React from 'react';
4+
5+
import Text from '../Text';
46
import styles from './Label.module.css';
57

68
export interface Props {
@@ -24,26 +26,10 @@ export interface Props {
2426
* Slot for node to appear directly after field label. Typically used to include a Toolip
2527
*/
2628
labelAfter?: ReactNode;
27-
/**
28-
* String for the optional label.
29-
*
30-
* **Default is `"(optional)"`**
31-
*
32-
* **Deprecated**. This will be removed in the next major version.
33-
* @deprecated
34-
*/
35-
optionalLabel?: string;
3629
/**
3730
* Indicates that field is required for form to be successfully submitted.
3831
*/
3932
required?: boolean;
40-
/**
41-
* String for the required label to add additional information if needed.
42-
*
43-
* **Deprecated**. This will be removed in the next major version.
44-
* @deprecated
45-
*/
46-
requiredLabel?: string;
4733
/**
4834
* The label text string
4935
*/
@@ -61,9 +47,7 @@ export const Label = ({
6147
htmlFor,
6248
id,
6349
labelAfter,
64-
optionalLabel = '(optional)',
6550
required = true,
66-
requiredLabel,
6751
text,
6852
...other
6953
}: Props) => {
@@ -76,14 +60,10 @@ export const Label = ({
7660
return (
7761
<label className={componentClassName} htmlFor={htmlFor} id={id} {...other}>
7862
{text}{' '}
79-
{!required && (
80-
<span className={styles['label__flag']}>{optionalLabel}</span>
81-
)}
82-
{requiredLabel && (
83-
<span className={styles['label__flag']}>{requiredLabel}</span>
84-
)}
8563
{labelAfter && (
86-
<span className={styles['label__after']}>{labelAfter}</span>
64+
<Text as="span" preset="body-sm">
65+
{labelAfter}
66+
</Text>
8767
)}
8868
</label>
8969
);

src/components/Label/__snapshots__/Label.test.ts.snap

+16
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ exports[`<Label /> Default story renders snapshot 1`] = `
88
99
</label>
1010
`;
11+
12+
exports[`<Label /> LabelAfter story renders snapshot 1`] = `
13+
<label
14+
class="label"
15+
>
16+
Label
17+
18+
<span
19+
class="text text--body-sm"
20+
>
21+
<span>
22+
*
23+
</span>
24+
</span>
25+
</label>
26+
`;

0 commit comments

Comments
 (0)