Skip to content

Commit 4dff78f

Browse files
author
Hector Arce De Las Heras
committed
Fix font-weight and color props of Link Component
This commit resolves two issues with the Link component where the font-weight and color props were not working as expected. Changes made include: In link.tsx, added receipt of weight value via props. This was necessary as the styles.container object was not storing the weight value, resulting in it always being undefined. In link.styled.ts, included the applyDevicePropsTextStyles function to the link's style. This was required as color is a text property and needs to be applied by the TextStylesExtended styles constant. These changes ensure that changes to the font-weight and color props in Storybook are accurately reflected in the Link component's visual representation
1 parent 34e437a commit 4dff78f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/components/link/link.styled.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,45 @@ 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';
78
import { LinkPositionType, LinkPropsStylesType, LinkPropsType, LinkStateType } from './types';
89

910
type LinkPropsExtended = {
1011
linkStyles: LinkPropsStylesType;
1112
alignCenter: boolean;
1213
};
14+
const applyDevicePropsTextStyles = (props: TextPropsStylesType) => {
15+
return css`
16+
color: ${props.color};
17+
display: ${props.display};
18+
text-decoration: ${props.decoration};
19+
text-align: ${props.align};
20+
font-weight: ${props.weight};
21+
${props.isDisabled &&
22+
css`
23+
pointer-events: none;
24+
`}
25+
`;
26+
};
27+
28+
const applyPropsTextStyles = (props: TextPropsStylesType) => css`
29+
${applyDevicePropsTextStyles(props)}
30+
${({
31+
theme: {
32+
MEDIA_QUERIES: { onlyDesktop, onlyTablet, onlyMobile },
33+
},
34+
}) => css`
35+
${onlyDesktop} {
36+
${applyDevicePropsTextStyles(props)}
37+
}
38+
${onlyTablet} {
39+
${applyDevicePropsTextStyles(props)}
40+
}
41+
${onlyMobile} {
42+
${applyDevicePropsTextStyles(props)}
43+
}
44+
`}
45+
`;
1346

1447
export const TextStyledExtended = styled.p.withConfig({
1548
shouldForwardProp: () => true,
@@ -51,6 +84,9 @@ export const TextStyledExtended = styled.p.withConfig({
5184
// In alternative variants, the focus colors must be change
5285
${({ linkStyles }) => linkStyles?.[LinkStateType.VISITED]?.altVariant && focusVisibleAlt()}
5386
}
87+
88+
// Apply props tokens
89+
${props => applyPropsTextStyles(props)}
5490
`;
5591

5692
export const LabelIconWrapper = styled.span<LinkPropsType>`

src/components/link/link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const LinkComponent = React.forwardRef(
4343
const isInline = action === LinkActionType.INLINE;
4444
const textDecoration = isInline ? TextDecorationType.UNDERLINE : decoration;
4545
const textVariant = textVariantProp ?? styles.container?.font_variant;
46-
const weight = styles.container?.font_weight;
46+
const weight = props.weight || styles.container?.font_weight;
4747
const color = colorLinkProp || styles.font_color || styles.container?.color;
4848

4949
const { state, setRef } = useManageState({

0 commit comments

Comments
 (0)