-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathButton.styling.ts
More file actions
112 lines (107 loc) · 3.51 KB
/
Button.styling.ts
File metadata and controls
112 lines (107 loc) · 3.51 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
import type { ColorValue } from 'react-native';
import type { Theme, UseStylingOptions } from '@fluentui-react-native/framework';
import { buildProps } from '@fluentui-react-native/framework';
import { getTextMarginAdjustment } from '@fluentui-react-native/styling-utils';
import { borderStyles, layoutStyles, fontStyles } from '@fluentui-react-native/tokens';
import type { FontTokens } from '@fluentui-react-native/tokens';
import { buttonName } from './Button.types';
import type { ButtonTokens, ButtonSlotProps, ButtonProps } from './Button.types';
import { defaultButtonColorTokens } from './ButtonColorTokens';
import { defaultButtonFontTokens } from './ButtonFontTokens';
import { buttonPlatformSlotProps } from './ButtonPlatform';
import { defaultButtonTokens } from './ButtonTokens';
export const buttonStates: (keyof ButtonTokens)[] = [
'block',
'small',
'medium',
'large',
'hasContent',
'hasIconAfter',
'hasIconBefore',
'primary',
'subtle',
'outline',
'rounded',
'circular',
'square',
'hovered',
'focused',
'pressed',
'disabled',
];
export const stylingSettings: UseStylingOptions<ButtonProps, ButtonSlotProps, ButtonTokens> = {
tokens: [defaultButtonTokens, defaultButtonFontTokens, defaultButtonColorTokens, buttonName],
states: buttonStates,
slotProps: {
...buttonPlatformSlotProps,
root: buildProps(
(tokens: ButtonTokens, theme: Theme) => ({
style: {
display: 'flex',
overflow: 'hidden',
alignItems: 'center',
flexDirection: 'row',
alignSelf: 'flex-start',
justifyContent: 'center',
width: tokens.width,
backgroundColor: tokens.backgroundColor,
...borderStyles.from(tokens, theme),
...layoutStyles.from(tokens, theme),
},
android_ripple: {
color: tokens.rippleColor,
},
}),
['backgroundColor', 'width', 'rippleColor', ...borderStyles.keys, ...layoutStyles.keys],
),
content: buildProps(
(tokens: ButtonTokens, theme: Theme) => {
return {
style: {
...contentStyling(tokens, theme, tokens.color, tokens),
},
};
},
['color', 'spacingIconContentAfter', 'spacingIconContentBefore', ...fontStyles.keys],
),
icon: buildProps(
(tokens: ButtonTokens) => ({
color: tokens.iconColor,
height: tokens.iconSize,
width: tokens.iconSize,
}),
['iconColor', 'iconSize'],
),
focusInnerBorder: buildProps(
(tokens: ButtonTokens) => ({
style: {
position: 'absolute',
borderWidth: tokens.borderInnerWidth,
borderColor: tokens.borderInnerColor,
borderRadius: tokens.borderInnerRadius,
},
}),
['borderInnerWidth', 'borderInnerColor', 'borderInnerRadius'],
),
},
};
export const contentStyling = (tokens: ButtonTokens, theme: Theme, contentColor: ColorValue, fontStylesTokens: FontTokens) => {
const textAdjustment = getTextMarginAdjustment();
const spacingIconContentBefore = tokens.spacingIconContentBefore
? {
marginStart: textAdjustment.marginStart + tokens.spacingIconContentBefore,
}
: {};
const spacingIconContentAfter = tokens.spacingIconContentAfter
? {
marginEnd: textAdjustment.marginEnd + tokens.spacingIconContentAfter,
}
: {};
return {
color: contentColor,
...getTextMarginAdjustment(),
...spacingIconContentBefore,
...spacingIconContentAfter,
...fontStyles.from(fontStylesTokens, theme),
};
};