Skip to content

Commit 017bb88

Browse files
refactor: [M3-9656] - [Akamai Design System] Label Component (#12224)
* refactor: [M3-9652] - [Akamai Design System] Label Component * Add changeset * PR feedback to use icon tokens for various states
1 parent 4b87f39 commit 017bb88

File tree

7 files changed

+123
-24
lines changed

7 files changed

+123
-24
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/ui": Changed
3+
---
4+
5+
Akamai Design System - Label component ([#12224](https://github.com/linode/manager/pull/12224))

packages/ui/src/components/TextField/TextField.stories.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ export const WithTooltip: Story = {
9898
},
9999
};
100100

101+
export const WithTooltipIconLeft: Story = {
102+
args: {
103+
label: 'Label',
104+
labelTooltipText: 'Tooltip Text',
105+
noMarginTop: true,
106+
placeholder: 'Placeholder',
107+
labelTooltipIconPosition: 'left',
108+
},
109+
};
110+
111+
export const WithTooltipSmall: Story = {
112+
args: {
113+
label: 'Label',
114+
labelTooltipText: 'Tooltip Text',
115+
noMarginTop: true,
116+
placeholder: 'Placeholder',
117+
labelTooltipIconSize: 'small',
118+
},
119+
};
120+
121+
export const WithTooltipLarge: Story = {
122+
args: {
123+
label: 'Label',
124+
labelTooltipText: 'Tooltip Text',
125+
noMarginTop: true,
126+
placeholder: 'Placeholder',
127+
labelTooltipIconSize: 'large',
128+
},
129+
};
130+
101131
export const WithAdornment: Story = {
102132
args: {
103133
InputProps: {

packages/ui/src/components/TextField/TextField.tsx

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ interface BaseProps {
103103
type Value = null | number | string | undefined;
104104

105105
interface LabelToolTipProps {
106+
/**
107+
* Position of the tooltip icon
108+
* @default right
109+
*/
110+
labelTooltipIconPosition?: 'left' | 'right';
111+
/**
112+
* Size of the tooltip icon
113+
* @default small
114+
*/
115+
labelTooltipIconSize?: 'large' | 'small';
106116
labelTooltipText?: JSX.Element | string;
107117
}
108118

@@ -147,6 +157,8 @@ export const TextField = (props: TextFieldProps) => {
147157
inputProps,
148158
label,
149159
labelTooltipText,
160+
labelTooltipIconPosition = 'right',
161+
labelTooltipIconSize = 'small',
150162
loading,
151163
max,
152164
min,
@@ -170,6 +182,26 @@ export const TextField = (props: TextFieldProps) => {
170182
const [_value, setValue] = React.useState<Value>(value ?? '');
171183
const theme = useTheme();
172184

185+
const sxTooltipIconLeft = {
186+
marginRight: `${theme.spacingFunction(4)}`,
187+
padding: `${theme.spacingFunction(4)} ${theme.spacingFunction(4)} ${theme.spacingFunction(4)} ${theme.spacingFunction(2)}`,
188+
'&& svg': {
189+
fill: theme.tokens.component.Label.Icon,
190+
stroke: theme.tokens.component.Label.Icon,
191+
strokeWidth: 0,
192+
':hover': {
193+
color: theme.tokens.alias.Content.Icon.Primary.Hover,
194+
fill: theme.tokens.alias.Content.Icon.Primary.Hover,
195+
stroke: theme.tokens.alias.Content.Icon.Primary.Hover,
196+
},
197+
},
198+
};
199+
200+
const sxTooltipIconRight = {
201+
marginLeft: `${theme.spacingFunction(4)}`,
202+
padding: `${theme.spacingFunction(4)}`,
203+
};
204+
173205
const { errorScrollClassName, errorTextId, helperTextId, validInputId } =
174206
useFieldIds({ errorGroup, hasError: Boolean(errorText), inputId, label });
175207

@@ -254,9 +286,7 @@ export const TextField = (props: TextFieldProps) => {
254286
return (
255287
<Box
256288
{...containerProps}
257-
className={`${errorText ? errorScrollClassName : ''} ${
258-
containerProps?.className || ''
259-
}`}
289+
className={`${errorText ? errorScrollClassName : ''} ${containerProps?.className || ''}`}
260290
sx={{
261291
...(Boolean(tooltipText) && {
262292
alignItems: 'flex-end',
@@ -276,12 +306,25 @@ export const TextField = (props: TextFieldProps) => {
276306
...(!noMarginTop && { marginTop: theme.spacing(2) }),
277307
}}
278308
>
309+
{labelTooltipText && labelTooltipIconPosition === 'left' && (
310+
<TooltipIcon
311+
labelTooltipIconSize={labelTooltipIconSize}
312+
status="help"
313+
sxTooltipIcon={sxTooltipIconLeft}
314+
text={labelTooltipText}
315+
width={tooltipWidth}
316+
/>
317+
)}
279318
<InputLabel
280319
data-qa-textfield-label={label}
281320
htmlFor={validInputId}
282321
sx={{
283322
marginBottom: 0,
284323
transform: 'none',
324+
fontSize:
325+
labelTooltipIconSize === 'large'
326+
? theme.tokens.font.FontSize.S
327+
: theme.tokens.font.FontSize.Xs,
285328
}}
286329
{...InputLabelProps} // We should change this name so that it's not conflicting with the deprecated prop
287330
>
@@ -293,13 +336,11 @@ export const TextField = (props: TextFieldProps) => {
293336
</Box>
294337
)}
295338
</InputLabel>
296-
{labelTooltipText && (
339+
{labelTooltipText && labelTooltipIconPosition === 'right' && (
297340
<TooltipIcon
341+
labelTooltipIconSize={labelTooltipIconSize}
298342
status="help"
299-
sxTooltipIcon={{
300-
marginLeft: `${theme.spacing(0.5)}`,
301-
padding: `${theme.spacing(0.5)}`,
302-
}}
343+
sxTooltipIcon={sxTooltipIconRight}
303344
text={labelTooltipText}
304345
width={tooltipWidth}
305346
/>

packages/ui/src/components/TooltipIcon/TooltipIcon.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,22 @@ export const VariableWidth: Story = {
2828
render: (args) => <TooltipIcon {...args} />,
2929
};
3030

31+
export const SmallTooltipIcon: Story = {
32+
args: {
33+
status: 'help',
34+
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
35+
labelTooltipIconSize: 'small',
36+
},
37+
render: (args) => <TooltipIcon {...args} />,
38+
};
39+
40+
export const LargeTooltipIcon: Story = {
41+
args: {
42+
status: 'help',
43+
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
44+
labelTooltipIconSize: 'large',
45+
},
46+
render: (args) => <TooltipIcon {...args} />,
47+
};
48+
3149
export default meta;

packages/ui/src/components/TooltipIcon/TooltipIcon.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export interface TooltipIconProps
4040
* @todo this seems like a flaw... passing an icon should not require `status` to be `other`
4141
*/
4242
icon?: JSX.Element;
43+
/**
44+
* Size of the tooltip icon
45+
* @default small
46+
*/
47+
labelTooltipIconSize?: 'large' | 'small';
4348
/**
4449
* Enables a leaveDelay of 3000ms
4550
* @default false
@@ -100,6 +105,7 @@ export const TooltipIcon = (props: TooltipIconProps) => {
100105
tooltipAnalyticsEvent,
101106
tooltipPosition,
102107
width,
108+
labelTooltipIconSize,
103109
} = props;
104110

105111
const handleOpenTooltip = () => {
@@ -112,18 +118,17 @@ export const TooltipIcon = (props: TooltipIconProps) => {
112118

113119
const sxRootStyle = {
114120
'&&': {
115-
fill: theme.tokens.color.Neutrals[50],
116-
stroke: theme.tokens.color.Neutrals[50],
121+
fill: theme.tokens.component.Label.InfoIcon,
122+
stroke: theme.tokens.component.Label.InfoIcon,
117123
strokeWidth: 0,
118124
},
119125
'&:hover': {
120-
color: theme.palette.primary.main,
121-
fill: theme.palette.primary.main,
122-
stroke: theme.palette.primary.main,
126+
color: theme.tokens.alias.Content.Icon.Primary.Hover,
127+
fill: theme.tokens.alias.Content.Icon.Primary.Hover,
128+
stroke: theme.tokens.alias.Content.Icon.Primary.Hover,
123129
},
124-
color: theme.tokens.color.Neutrals[50],
125-
height: 20,
126-
width: 20,
130+
height: labelTooltipIconSize === 'small' ? 16 : 20,
131+
width: labelTooltipIconSize === 'small' ? 16 : 20,
127132
};
128133

129134
switch (status) {

packages/ui/src/foundations/themes/dark.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,15 @@ export const darkTheme: ThemeOptions = {
553553
styleOverrides: {
554554
root: {
555555
'&$disabled': {
556-
color: Color.Neutrals[40],
556+
color: Component.Label.Text,
557557
},
558558
'&$error': {
559-
color: Color.Neutrals[40],
559+
color: Component.Label.Text,
560560
},
561561
'&.Mui-focused': {
562-
color: Color.Neutrals[40],
562+
color: Component.Label.Text,
563563
},
564-
color: Color.Neutrals[40],
564+
color: Component.Label.Text,
565565
},
566566
},
567567
},

packages/ui/src/foundations/themes/light.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,16 +877,16 @@ export const lightTheme: ThemeOptions = {
877877
styleOverrides: {
878878
root: {
879879
'&$disabled': {
880-
color: Color.Neutrals[70],
880+
color: Component.Label.Text,
881881
opacity: 0.5,
882882
},
883883
'&$error': {
884-
color: Color.Neutrals[70],
884+
color: Component.Label.Text,
885885
},
886886
'&.Mui-focused': {
887-
color: Color.Neutrals[70],
887+
color: Component.Label.Text,
888888
},
889-
color: Color.Neutrals[70],
889+
color: Component.Label.Text,
890890
font: Typography.Body.Bold,
891891
marginBottom: 8,
892892
},

0 commit comments

Comments
 (0)