-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathuseLinkStyles.styles.ts
More file actions
152 lines (139 loc) · 4.08 KB
/
useLinkStyles.styles.ts
File metadata and controls
152 lines (139 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'use client';
import { shorthands, makeStyles, mergeClasses } from '@griffel/react';
import { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';
import { tokens } from '@fluentui/react-theme';
import type { LinkSlots, LinkState } from './Link.types';
import type { SlotClassNames } from '@fluentui/react-utilities';
export const linkClassNames: SlotClassNames<LinkSlots> = {
root: 'fui-Link',
};
const useStyles = makeStyles({
focusIndicator: createCustomFocusIndicatorStyle({
textDecorationColor: tokens.colorStrokeFocus2,
textDecorationLine: 'underline',
textDecorationStyle: 'double',
outlineStyle: 'none',
}),
// Common styles.
root: {
':focus-visible': {
outlineStyle: 'none',
},
backgroundColor: 'transparent',
boxSizing: 'border-box',
color: tokens.colorBrandForegroundLink,
cursor: 'pointer',
display: 'inline',
fontFamily: tokens.fontFamilyBase,
fontSize: tokens.fontSizeBase300,
fontWeight: tokens.fontWeightRegular,
margin: '0',
padding: '0',
overflow: 'inherit',
textAlign: 'left',
textDecorationLine: 'none',
textDecorationThickness: tokens.strokeWidthThin,
textOverflow: 'inherit',
userSelect: 'text',
':hover': {
textDecorationLine: 'underline',
color: tokens.colorBrandForegroundLinkHover,
},
':active': {
textDecorationLine: 'underline',
color: tokens.colorBrandForegroundLinkPressed,
},
},
// Overrides when the Link renders as a button.
button: {
...shorthands.borderStyle('none'),
},
// Overrides when an href is present so the Link renders as an anchor.
href: {
fontSize: 'inherit',
},
// Overrides when the Link appears subtle.
subtle: {
color: tokens.colorNeutralForeground2Link,
':hover': {
textDecorationLine: 'underline',
color: tokens.colorNeutralForeground2LinkHover,
},
':active': {
textDecorationLine: 'underline',
color: tokens.colorNeutralForeground2LinkPressed,
},
},
// Overrides when the Link is rendered inline within text.
inline: {
textDecorationLine: 'underline',
},
// Overrides when the Link is disabled.
disabled: {
textDecorationLine: 'none',
color: tokens.colorNeutralForegroundDisabled,
cursor: 'not-allowed',
':hover': {
textDecorationLine: 'none',
color: tokens.colorNeutralForegroundDisabled,
},
':active': {
textDecorationLine: 'none',
color: tokens.colorNeutralForegroundDisabled,
},
},
inverted: {
color: tokens.colorBrandForegroundInverted,
':hover': {
color: tokens.colorBrandForegroundInverted,
},
':active': {
color: tokens.colorBrandForegroundInverted,
},
},
brand: {
color: tokens.colorNeutralForegroundInvertedLink,
':hover': {
color: tokens.colorNeutralForegroundInvertedLinkHover,
},
':active': {
color: tokens.colorNeutralForegroundInvertedLinkPressed,
},
},
bold: {
fontWeight: tokens.fontWeightSemibold,
},
appearanceInverted: {
color: tokens.colorNeutralForegroundInvertedLink,
':hover': {
color: tokens.colorNeutralForegroundInvertedLinkHover,
},
':hover:active': {
color: tokens.colorNeutralForegroundInvertedLinkPressed,
},
':focus': {
textDecorationColor: tokens.colorNeutralForegroundInvertedLink,
},
},
});
export const useLinkStyles_unstable = (state: LinkState): LinkState => {
'use no memo';
const styles = useStyles();
const { appearance, bold, disabled, inline, root, backgroundAppearance } = state;
state.root.className = mergeClasses(
linkClassNames.root,
styles.root,
styles.focusIndicator,
root.as === 'a' && root.href && styles.href,
root.as === 'button' && styles.button,
appearance === 'subtle' && styles.subtle,
appearance === 'inverted' && styles.appearanceInverted,
backgroundAppearance === 'inverted' && styles.inverted,
backgroundAppearance === 'brand' && styles.brand,
inline && styles.inline,
bold && styles.bold,
disabled && styles.disabled,
state.root.className,
);
return state;
};