@@ -4,12 +4,14 @@ import styled, { css } from 'styled-components';
4
4
import { focusVisibleAlt } from '@/styles/mixins' ;
5
5
import { getStyles , getTypographyStyles } from '@/utils/getStyles/getStyles' ;
6
6
7
- import { TextPropsStylesType } from '../text/types' ;
7
+ import { applyVariantStyles as applyTextVariantStyles } from '../text/text.styled' ;
8
+ import { TextPropsStylesType , TextVariantStylesType } from '../text/types' ;
8
9
import { LinkPositionType , LinkPropsStylesType , LinkPropsType , LinkStateType } from './types' ;
9
10
10
11
type LinkPropsExtended = {
11
12
linkStyles : LinkPropsStylesType ;
12
13
alignCenter : boolean ;
14
+ textStyles ?: TextVariantStylesType ;
13
15
} ;
14
16
const applyDevicePropsTextStyles = ( props : TextPropsStylesType ) => {
15
17
return css `
@@ -44,45 +46,52 @@ const applyPropsTextStyles = (props: TextPropsStylesType) => css`
44
46
` }
45
47
` ;
46
48
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
+
47
66
export const TextStyledExtended = styled . p . withConfig ( {
48
67
shouldForwardProp : ( ) => true ,
49
68
} ) < 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 ] } ) }
54
71
${ ( { alignCenter } ) =>
55
72
alignCenter &&
56
73
css `
57
74
margin : auto;
58
75
` } ;
59
76
60
77
&[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 ] } ) }
65
80
}
66
81
67
82
&: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 ] } ) }
72
85
}
73
86
74
87
&: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 ] } ) }
79
90
}
80
91
81
92
&: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 ] } ) }
86
95
}
87
96
88
97
// Apply props tokens
0 commit comments