Skip to content

Commit 63be35b

Browse files
author
Hector Arce De Las Heras
committed
Fix Font-Weight and Color Props of Link Component
This commit addresses two issues with the Link component: the 'font-weight' and 'color' props were not functioning correctly. When a user set a different value from the default in Storybook, the changes were not reflected visually in the component. Key changes include: link.tsx: Added receipt of 'weight' value via props. Previously, the 'styles.container' object wasn't storing the 'weight' value, so it was always undefined. link.styled.ts: Included 'applyDevicePropsTextStyles' function to link's style. The 'color' is a text property and needs to be applied by 'TextStylesExtended' styles const. These changes ensure that the 'font-weight' and 'color' props of the Link component function as expected, improving the component's flexibility and usability.
1 parent d4e9978 commit 63be35b

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

src/components/link/link.styled.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import styled, { css } from 'styled-components';
44
import { focusVisibleAlt } from '@/styles/mixins';
55
import { getStyles, getTypographyStyles } from '@/utils/getStyles/getStyles';
66

7-
import { TextPropsStylesType } from '../text/types';
7+
import { applyVariantStyles as applyTextVariantStyles } from '../text/text.styled';
8+
import { TextPropsStylesType, TextVariantStylesType } from '../text/types';
89
import { LinkPositionType, LinkPropsStylesType, LinkPropsType, LinkStateType } from './types';
910

1011
type LinkPropsExtended = {
1112
linkStyles: LinkPropsStylesType;
1213
alignCenter: boolean;
14+
textStyles?: TextVariantStylesType;
1315
};
1416
const applyDevicePropsTextStyles = (props: TextPropsStylesType) => {
1517
return css`
@@ -44,45 +46,52 @@ const applyPropsTextStyles = (props: TextPropsStylesType) => css`
4446
`}
4547
`;
4648

49+
const applyLinkStateStyles = ({
50+
textStyles,
51+
linkPropsStyles,
52+
}: {
53+
textStyles?: TextVariantStylesType;
54+
linkPropsStyles?: LinkPropsStylesType;
55+
}) => {
56+
return css`
57+
${getStyles(linkPropsStyles?.container)}
58+
${getTypographyStyles(linkPropsStyles?.container)}
59+
// If textVariant is defined it should be applied before the own variant styles
60+
${applyTextVariantStyles(textStyles)}
61+
// In alternative variants, the focus colors must be change
62+
${linkPropsStyles?.altVariant && focusVisibleAlt()}
63+
`;
64+
};
65+
4766
export const TextStyledExtended = styled.p.withConfig({
4867
shouldForwardProp: () => true,
4968
})<LinkPropsExtended>`
50-
${({ linkStyles }) => getStyles(linkStyles?.[LinkStateType.DEFAULT]?.container)}
51-
${({ linkStyles }) => getTypographyStyles(linkStyles?.[LinkStateType.DEFAULT]?.container)}
52-
// In alternative variants, the focus colors must be change
53-
${({ linkStyles }) => linkStyles?.[LinkStateType.DEFAULT]?.altVariant && focusVisibleAlt()}
69+
${({ linkStyles, textStyles }) =>
70+
applyLinkStateStyles({ textStyles, linkPropsStyles: linkStyles?.[LinkStateType.DEFAULT] })}
5471
${({ alignCenter }) =>
5572
alignCenter &&
5673
css`
5774
margin: auto;
5875
`};
5976
6077
&[aria-disabled='true'] {
61-
${({ linkStyles }) => getStyles(linkStyles?.[LinkStateType.DISABLED]?.container)}
62-
${({ linkStyles }) => getTypographyStyles(linkStyles?.[LinkStateType.DISABLED]?.container)}
63-
// In alternative variants, the focus colors must be change
64-
${({ linkStyles }) => linkStyles?.[LinkStateType.DEFAULT]?.altVariant && focusVisibleAlt()}
78+
${({ linkStyles, textStyles }) =>
79+
applyLinkStateStyles({ textStyles, linkPropsStyles: linkStyles?.[LinkStateType.DISABLED] })}
6580
}
6681
6782
&:hover:not([aria-disabled='true']) {
68-
${({ linkStyles }) => getStyles(linkStyles?.[LinkStateType.HOVER]?.container)}
69-
${({ linkStyles }) => getTypographyStyles(linkStyles?.[LinkStateType.HOVER]?.container)}
70-
// In alternative variants, the focus colors must be change
71-
${({ linkStyles }) => linkStyles?.[LinkStateType.HOVER]?.altVariant && focusVisibleAlt()}
83+
${({ linkStyles, textStyles }) =>
84+
applyLinkStateStyles({ textStyles, linkPropsStyles: linkStyles?.[LinkStateType.HOVER] })}
7285
}
7386
7487
&:active:not([aria-disabled='true']) {
75-
${({ linkStyles }) => getStyles(linkStyles?.[LinkStateType.PRESSED]?.container)}
76-
${({ linkStyles }) => getTypographyStyles(linkStyles?.[LinkStateType.PRESSED]?.container)}
77-
// In alternative variants, the focus colors must be change
78-
${({ linkStyles }) => linkStyles?.[LinkStateType.PRESSED]?.altVariant && focusVisibleAlt()}
88+
${({ linkStyles, textStyles }) =>
89+
applyLinkStateStyles({ textStyles, linkPropsStyles: linkStyles?.[LinkStateType.PRESSED] })}
7990
}
8091
8192
&:visited:not([aria-disabled='true']) {
82-
${({ linkStyles }) => getStyles(linkStyles?.[LinkStateType.VISITED]?.container)}
83-
${({ linkStyles }) => getTypographyStyles(linkStyles?.[LinkStateType.VISITED]?.container)}
84-
// In alternative variants, the focus colors must be change
85-
${({ linkStyles }) => linkStyles?.[LinkStateType.VISITED]?.altVariant && focusVisibleAlt()}
93+
${({ linkStyles, textStyles }) =>
94+
applyLinkStateStyles({ textStyles, linkPropsStyles: linkStyles?.[LinkStateType.VISITED] })}
8695
}
8796
8897
// Apply props tokens

src/components/link/link.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable complexity */
22
import * as React from 'react';
33

4-
import { TextDecorationType } from '@/components/text/types';
4+
import { TextDecorationType, TextVariantStylesType } from '@/components/text/types';
55
import { STYLES_NAME } from '@/constants';
6-
import { States, useManageState } from '@/hooks';
6+
import { States, useManageState, useStylesV2 } from '@/hooks';
77
import { useStyles } from '@/hooks/useStyles/useStyles';
88
import { ErrorBoundary, FallbackComponent } from '@/provider/errorBoundary';
99
import { useGenericComponents } from '@/provider/genericComponents/genericComponentsProvider';
@@ -26,7 +26,7 @@ const LinkComponent = React.forwardRef(
2626
alignCenter = false,
2727
disabled = false,
2828
color: colorLinkProp,
29-
textVariant: textVariantProp,
29+
textVariant,
3030
role: roleProp,
3131
variant,
3232
ctv,
@@ -38,11 +38,15 @@ const LinkComponent = React.forwardRef(
3838
const { role } = disabledLink(disabled, roleProp);
3939
const ariaDisabled = disabled || undefined;
4040
const actionStyles = useStyles<LinkPropsStylesType>(STYLES_NAME.LINK, action, ctv?.[action]);
41+
const textStyles = useStylesV2<TextVariantStylesType>({
42+
styleName: STYLES_NAME.TEXT,
43+
variantName: textVariant,
44+
isOptional: true,
45+
});
4146
const styles = (variant && actionStyles?.[variant]) || {};
4247

4348
const isInline = action === LinkActionType.INLINE;
4449
const textDecoration = isInline ? TextDecorationType.UNDERLINE : decoration;
45-
const textVariant = textVariantProp ?? styles.container?.font_variant;
4650
const weight = props.weight || styles.container?.font_weight;
4751
const color = colorLinkProp || styles.font_color || styles.container?.color;
4852

@@ -65,7 +69,7 @@ const LinkComponent = React.forwardRef(
6569
role={role}
6670
state={state as unknown as LinkStateType}
6771
styles={styles}
68-
textVariant={textVariant}
72+
textStyles={textStyles}
6973
weight={weight}
7074
/>
7175
);

src/components/link/linkStandAlone.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const LinkStandAloneComponent = (
2828
isDisabled={props.state === LinkStateType.DISABLED}
2929
linkStyles={props.styles}
3030
target={props.target}
31-
variant={props.textVariant}
31+
textStyles={props.textStyles}
3232
weight={props.weight}
3333
//We have to make this because even it was disabled, you could access to onClick by arrows
3434
onClick={props.state !== LinkStateType.DISABLED ? props.onClick : undefined}

src/components/link/types/link.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77
IButtonStandAlone,
88
} from '@/components/button';
99
import { IElementOrIcon } from '@/components/elementOrIcon';
10-
import { TextComponentType, TextDecorationType } from '@/components/text/types';
10+
import {
11+
TextComponentType,
12+
TextDecorationType,
13+
TextVariantStylesType,
14+
} from '@/components/text/types';
1115
import { GenericLinkType } from '@/provider/genericComponents';
1216
import { CustomTokenTypes } from '@/types';
1317

@@ -34,20 +38,24 @@ export interface ILinkStandAlone extends LinkAriaAttributes {
3438
role?: string;
3539
state: LinkStateType;
3640
styles: LinkPropsStylesType;
41+
textStyles?: TextVariantStylesType;
3742
target?: LinkTargetType;
38-
textVariant?: string;
3943
url: string;
4044
weight?: number;
4145
alignCenter: boolean;
4246
draggable?: boolean;
4347
}
4448

4549
export interface ILink
46-
extends Omit<ILinkStandAlone, 'styles' | 'component' | 'alignCenter' | 'state' | 'aria-disabled'>,
50+
extends Omit<
51+
ILinkStandAlone,
52+
'styles' | 'component' | 'alignCenter' | 'state' | 'aria-disabled' | 'textStyles'
53+
>,
4754
Omit<CustomTokenTypes<LinkStylesType<string>>, 'cts' | 'extraCt'> {
4855
alignCenter?: boolean;
4956
disabled?: boolean;
5057
variant: string;
58+
textVariant?: string;
5159
}
5260

5361
export interface ILinkAsButtonStandAlone extends Omit<IButtonStandAlone, 'showLoader'> {

0 commit comments

Comments
 (0)