Skip to content

refactor: [M3-9656] - [Akamai Design System] Label Component #12224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/ui/.changeset/pr-12224-changed-1747294477261.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/ui": Changed
---

Akamai Design System - Label component ([#12224](https://github.com/linode/manager/pull/12224))
30 changes: 30 additions & 0 deletions packages/ui/src/components/TextField/TextField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ export const WithTooltip: Story = {
},
};

export const WithTooltipIconLeft: Story = {
args: {
label: 'Label',
labelTooltipText: 'Tooltip Text',
noMarginTop: true,
placeholder: 'Placeholder',
labelTooltipIconPosition: 'left',
},
};

export const WithTooltipSmall: Story = {
args: {
label: 'Label',
labelTooltipText: 'Tooltip Text',
noMarginTop: true,
placeholder: 'Placeholder',
labelTooltipIconSize: 'small',
},
};

export const WithTooltipLarge: Story = {
args: {
label: 'Label',
labelTooltipText: 'Tooltip Text',
noMarginTop: true,
placeholder: 'Placeholder',
labelTooltipIconSize: 'large',
},
};

export const WithAdornment: Story = {
args: {
InputProps: {
Expand Down
57 changes: 49 additions & 8 deletions packages/ui/src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ interface BaseProps {
type Value = null | number | string | undefined;

interface LabelToolTipProps {
/**
* Position of the tooltip icon
* @default right
*/
labelTooltipIconPosition?: 'left' | 'right';
/**
* Size of the tooltip icon
* @default small
*/
labelTooltipIconSize?: 'large' | 'small';
labelTooltipText?: JSX.Element | string;
}

Expand Down Expand Up @@ -147,6 +157,8 @@ export const TextField = (props: TextFieldProps) => {
inputProps,
label,
labelTooltipText,
labelTooltipIconPosition = 'right',
labelTooltipIconSize = 'small',
loading,
max,
min,
Expand All @@ -170,6 +182,26 @@ export const TextField = (props: TextFieldProps) => {
const [_value, setValue] = React.useState<Value>(value ?? '');
const theme = useTheme();

const sxTooltipIconLeft = {
marginRight: `${theme.spacingFunction(4)}`,
padding: `${theme.spacingFunction(4)} ${theme.spacingFunction(4)} ${theme.spacingFunction(4)} ${theme.spacingFunction(2)}`,
'&& svg': {
fill: theme.tokens.component.Label.Icon,
stroke: theme.tokens.component.Label.Icon,
strokeWidth: 0,
':hover': {
color: theme.tokens.alias.Content.Icon.Primary.Hover,
fill: theme.tokens.alias.Content.Icon.Primary.Hover,
stroke: theme.tokens.alias.Content.Icon.Primary.Hover,
},
},
};

const sxTooltipIconRight = {
marginLeft: `${theme.spacingFunction(4)}`,
padding: `${theme.spacingFunction(4)}`,
};

const { errorScrollClassName, errorTextId, helperTextId, validInputId } =
useFieldIds({ errorGroup, hasError: Boolean(errorText), inputId, label });

Expand Down Expand Up @@ -254,9 +286,7 @@ export const TextField = (props: TextFieldProps) => {
return (
<Box
{...containerProps}
className={`${errorText ? errorScrollClassName : ''} ${
containerProps?.className || ''
}`}
className={`${errorText ? errorScrollClassName : ''} ${containerProps?.className || ''}`}
sx={{
...(Boolean(tooltipText) && {
alignItems: 'flex-end',
Expand All @@ -276,12 +306,25 @@ export const TextField = (props: TextFieldProps) => {
...(!noMarginTop && { marginTop: theme.spacing(2) }),
}}
>
{labelTooltipText && labelTooltipIconPosition === 'left' && (
<TooltipIcon
labelTooltipIconSize={labelTooltipIconSize}
status="help"
sxTooltipIcon={sxTooltipIconLeft}
text={labelTooltipText}
width={tooltipWidth}
/>
)}
<InputLabel
data-qa-textfield-label={label}
htmlFor={validInputId}
sx={{
marginBottom: 0,
transform: 'none',
fontSize:
labelTooltipIconSize === 'large'
? theme.tokens.font.FontSize.S
: theme.tokens.font.FontSize.Xs,
}}
{...InputLabelProps} // We should change this name so that it's not conflicting with the deprecated prop
>
Expand All @@ -293,13 +336,11 @@ export const TextField = (props: TextFieldProps) => {
</Box>
)}
</InputLabel>
{labelTooltipText && (
{labelTooltipText && labelTooltipIconPosition === 'right' && (
<TooltipIcon
labelTooltipIconSize={labelTooltipIconSize}
status="help"
sxTooltipIcon={{
marginLeft: `${theme.spacing(0.5)}`,
padding: `${theme.spacing(0.5)}`,
}}
sxTooltipIcon={sxTooltipIconRight}
text={labelTooltipText}
width={tooltipWidth}
/>
Expand Down
18 changes: 18 additions & 0 deletions packages/ui/src/components/TooltipIcon/TooltipIcon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,22 @@ export const VariableWidth: Story = {
render: (args) => <TooltipIcon {...args} />,
};

export const SmallTooltipIcon: Story = {
args: {
status: 'help',
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.',
labelTooltipIconSize: 'small',
},
render: (args) => <TooltipIcon {...args} />,
};

export const LargeTooltipIcon: Story = {
args: {
status: 'help',
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.',
labelTooltipIconSize: 'large',
},
render: (args) => <TooltipIcon {...args} />,
};

export default meta;
21 changes: 13 additions & 8 deletions packages/ui/src/components/TooltipIcon/TooltipIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export interface TooltipIconProps
* @todo this seems like a flaw... passing an icon should not require `status` to be `other`
*/
icon?: JSX.Element;
/**
* Size of the tooltip icon
* @default small
*/
labelTooltipIconSize?: 'large' | 'small';
/**
* Enables a leaveDelay of 3000ms
* @default false
Expand Down Expand Up @@ -100,6 +105,7 @@ export const TooltipIcon = (props: TooltipIconProps) => {
tooltipAnalyticsEvent,
tooltipPosition,
width,
labelTooltipIconSize,
} = props;

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

const sxRootStyle = {
'&&': {
fill: theme.tokens.color.Neutrals[50],
stroke: theme.tokens.color.Neutrals[50],
fill: theme.tokens.component.Label.InfoIcon,
stroke: theme.tokens.component.Label.InfoIcon,
strokeWidth: 0,
},
'&:hover': {
color: theme.palette.primary.main,
fill: theme.palette.primary.main,
stroke: theme.palette.primary.main,
color: theme.tokens.alias.Content.Icon.Primary.Hover,
fill: theme.tokens.alias.Content.Icon.Primary.Hover,
stroke: theme.tokens.alias.Content.Icon.Primary.Hover,
},
color: theme.tokens.color.Neutrals[50],
height: 20,
width: 20,
height: labelTooltipIconSize === 'small' ? 16 : 20,
width: labelTooltipIconSize === 'small' ? 16 : 20,
};

switch (status) {
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/foundations/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,15 @@ export const darkTheme: ThemeOptions = {
styleOverrides: {
root: {
'&$disabled': {
color: Color.Neutrals[40],
color: Component.Label.Text,
},
'&$error': {
color: Color.Neutrals[40],
color: Component.Label.Text,
},
'&.Mui-focused': {
color: Color.Neutrals[40],
color: Component.Label.Text,
},
color: Color.Neutrals[40],
color: Component.Label.Text,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/foundations/themes/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,16 +877,16 @@ export const lightTheme: ThemeOptions = {
styleOverrides: {
root: {
'&$disabled': {
color: Color.Neutrals[70],
color: Component.Label.Text,
opacity: 0.5,
},
'&$error': {
color: Color.Neutrals[70],
color: Component.Label.Text,
},
'&.Mui-focused': {
color: Color.Neutrals[70],
color: Component.Label.Text,
},
color: Color.Neutrals[70],
color: Component.Label.Text,
font: Typography.Body.Bold,
marginBottom: 8,
},
Expand Down