@khanacademy/wonder-blocks-button 9.0.0 → 9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/es/index.js +7 -586
- package/dist/index.js +7 -590
- package/dist/themes/default.d.ts +5 -5
- package/dist/themes/khanmigo.d.ts +5 -5
- package/dist/themes/themed-button.d.ts +5 -5
- package/package.json +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-button
|
|
2
2
|
|
|
3
|
+
## 9.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [28fa0c0]
|
|
8
|
+
- Updated dependencies [28fa0c0]
|
|
9
|
+
- Updated dependencies [38042e2]
|
|
10
|
+
- @khanacademy/wonder-blocks-core@12.3.0
|
|
11
|
+
- @khanacademy/wonder-blocks-clickable@7.1.0
|
|
12
|
+
- @khanacademy/wonder-blocks-icon@5.1.4
|
|
13
|
+
- @khanacademy/wonder-blocks-progress-spinner@3.1.11
|
|
14
|
+
- @khanacademy/wonder-blocks-typography@3.2.1
|
|
15
|
+
|
|
16
|
+
## 9.0.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- b9e4946: Update to use REM sizing tokens internally for scalable font-sizes
|
|
21
|
+
- Updated dependencies [b9e4946]
|
|
22
|
+
- Updated dependencies [b9e4946]
|
|
23
|
+
- @khanacademy/wonder-blocks-tokens@10.0.0
|
|
24
|
+
- @khanacademy/wonder-blocks-typography@3.2.0
|
|
25
|
+
- @khanacademy/wonder-blocks-clickable@7.0.4
|
|
26
|
+
- @khanacademy/wonder-blocks-progress-spinner@3.1.10
|
|
27
|
+
- @khanacademy/wonder-blocks-core@12.2.1
|
|
28
|
+
- @khanacademy/wonder-blocks-icon@5.1.3
|
|
29
|
+
- @khanacademy/wonder-blocks-theming@3.3.0
|
|
30
|
+
|
|
3
31
|
## 9.0.0
|
|
4
32
|
|
|
5
33
|
### Major Changes
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
|
|
5
4
|
import { Link, useInRouterContext } from 'react-router-dom-v5-compat';
|
|
@@ -11,594 +10,16 @@ import { mergeTheme, createThemeContext, ThemeSwitcherContext, useScopedTheme, u
|
|
|
11
10
|
import * as tokens from '@khanacademy/wonder-blocks-tokens';
|
|
12
11
|
import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
|
|
13
12
|
|
|
14
|
-
const {
|
|
15
|
-
semanticColor
|
|
16
|
-
} = tokens;
|
|
17
|
-
const textUnderlineOffset = tokens.spacing.xxxSmall_4;
|
|
18
|
-
const focusOutline = {
|
|
19
|
-
border: semanticColor.focus.outer
|
|
20
|
-
};
|
|
21
|
-
const theme$1 = {
|
|
22
|
-
color: {
|
|
23
|
-
primary: {
|
|
24
|
-
progressive: _extends({}, semanticColor.action.primary.progressive, {
|
|
25
|
-
focus: focusOutline
|
|
26
|
-
}),
|
|
27
|
-
destructive: _extends({}, semanticColor.action.primary.destructive, {
|
|
28
|
-
focus: focusOutline
|
|
29
|
-
}),
|
|
30
|
-
disabled: semanticColor.action.primary.disabled
|
|
31
|
-
},
|
|
32
|
-
secondary: {
|
|
33
|
-
progressive: _extends({}, semanticColor.action.secondary.progressive, {
|
|
34
|
-
focus: focusOutline,
|
|
35
|
-
hover: _extends({}, semanticColor.action.secondary.progressive.hover, {
|
|
36
|
-
icon: "transparent"
|
|
37
|
-
})
|
|
38
|
-
}),
|
|
39
|
-
destructive: _extends({}, semanticColor.action.secondary.destructive, {
|
|
40
|
-
focus: focusOutline,
|
|
41
|
-
hover: _extends({}, semanticColor.action.secondary.destructive.hover, {
|
|
42
|
-
icon: "transparent"
|
|
43
|
-
})
|
|
44
|
-
}),
|
|
45
|
-
disabled: _extends({}, semanticColor.action.secondary.disabled, {
|
|
46
|
-
border: semanticColor.action.primary.disabled.border
|
|
47
|
-
})
|
|
48
|
-
},
|
|
49
|
-
tertiary: {
|
|
50
|
-
progressive: _extends({}, semanticColor.action.tertiary.progressive, {
|
|
51
|
-
focus: focusOutline
|
|
52
|
-
}),
|
|
53
|
-
destructive: _extends({}, semanticColor.action.tertiary.destructive, {
|
|
54
|
-
focus: focusOutline
|
|
55
|
-
}),
|
|
56
|
-
disabled: semanticColor.action.tertiary.disabled
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
border: {
|
|
60
|
-
width: {
|
|
61
|
-
secondary: tokens.border.width.thin,
|
|
62
|
-
focused: tokens.border.width.medium,
|
|
63
|
-
disabled: tokens.border.width.medium
|
|
64
|
-
},
|
|
65
|
-
offset: {
|
|
66
|
-
primary: tokens.spacing.xxxxSmall_2,
|
|
67
|
-
secondary: -tokens.spacing.xxxxSmall_2
|
|
68
|
-
},
|
|
69
|
-
radius: {
|
|
70
|
-
default: tokens.border.radius.radius_040,
|
|
71
|
-
small: tokens.border.radius.radius_040,
|
|
72
|
-
large: tokens.border.radius.radius_040,
|
|
73
|
-
icon: tokens.border.radius.radius_full
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
size: {
|
|
77
|
-
height: {
|
|
78
|
-
small: tokens.spacing.xLarge_32,
|
|
79
|
-
medium: 40,
|
|
80
|
-
large: 56
|
|
81
|
-
},
|
|
82
|
-
underline: {
|
|
83
|
-
hover: tokens.spacing.xxxxSmall_2,
|
|
84
|
-
active: 1
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
margin: {
|
|
88
|
-
icon: {
|
|
89
|
-
offset: -tokens.spacing.xxxxSmall_2
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
padding: {
|
|
93
|
-
xsmall: tokens.spacing.xxxxSmall_2,
|
|
94
|
-
small: tokens.spacing.xxSmall_6,
|
|
95
|
-
medium: tokens.spacing.small_12,
|
|
96
|
-
large: tokens.spacing.medium_16,
|
|
97
|
-
xLarge: tokens.spacing.xLarge_32
|
|
98
|
-
},
|
|
99
|
-
font: {
|
|
100
|
-
size: {
|
|
101
|
-
large: 18
|
|
102
|
-
},
|
|
103
|
-
lineHeight: {
|
|
104
|
-
small: tokens.font.lineHeight.small + textUnderlineOffset,
|
|
105
|
-
default: tokens.font.lineHeight.medium + textUnderlineOffset,
|
|
106
|
-
large: tokens.font.lineHeight.medium + 2 + textUnderlineOffset
|
|
107
|
-
},
|
|
108
|
-
weight: {
|
|
109
|
-
default: tokens.font.weight.bold
|
|
110
|
-
},
|
|
111
|
-
offset: {
|
|
112
|
-
default: textUnderlineOffset
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
13
|
+
const{semanticColor}=tokens;const textUnderlineOffset=tokens.sizing.size_040;const focusOutline={border:semanticColor.focus.outer};const theme$1={color:{primary:{progressive:{...semanticColor.action.primary.progressive,focus:focusOutline},destructive:{...semanticColor.action.primary.destructive,focus:focusOutline},disabled:semanticColor.action.primary.disabled},secondary:{progressive:{...semanticColor.action.secondary.progressive,focus:focusOutline,hover:{...semanticColor.action.secondary.progressive.hover,icon:"transparent"}},destructive:{...semanticColor.action.secondary.destructive,focus:focusOutline,hover:{...semanticColor.action.secondary.destructive.hover,icon:"transparent"}},disabled:{...semanticColor.action.secondary.disabled,border:semanticColor.action.primary.disabled.border}},tertiary:{progressive:{...semanticColor.action.tertiary.progressive,focus:focusOutline},destructive:{...semanticColor.action.tertiary.destructive,focus:focusOutline},disabled:semanticColor.action.tertiary.disabled}},border:{width:{secondary:tokens.border.width.thin,focused:tokens.border.width.medium,disabled:tokens.border.width.medium},offset:{primary:tokens.spacing.xxxxSmall_2,secondary:-tokens.spacing.xxxxSmall_2},radius:{default:tokens.border.radius.radius_040,small:tokens.border.radius.radius_040,large:tokens.border.radius.radius_040,icon:tokens.border.radius.radius_full}},size:{height:{small:tokens.spacing.xLarge_32,medium:40,large:56},underline:{hover:tokens.spacing.xxxxSmall_2,active:1}},margin:{icon:{offset:-tokens.spacing.xxxxSmall_2}},padding:{xsmall:tokens.spacing.xxxxSmall_2,small:tokens.spacing.xxSmall_6,medium:tokens.spacing.small_12,large:tokens.spacing.medium_16,xLarge:tokens.spacing.xLarge_32},font:{size:{large:"1.8rem"},lineHeight:{small:tokens.font.lineHeight.xMedium,default:tokens.font.lineHeight.large,large:"2.6rem"},weight:{default:tokens.font.weight.bold},offset:{default:textUnderlineOffset}}};
|
|
116
14
|
|
|
117
|
-
const secondaryBgColor
|
|
118
|
-
const theme = mergeTheme(theme$1, {
|
|
119
|
-
color: {
|
|
120
|
-
secondary: {
|
|
121
|
-
progressive: {
|
|
122
|
-
default: {
|
|
123
|
-
border: tokens.color.fadedBlue,
|
|
124
|
-
background: secondaryBgColor
|
|
125
|
-
},
|
|
126
|
-
hover: {
|
|
127
|
-
background: secondaryBgColor,
|
|
128
|
-
icon: tokens.color.fadedBlue16,
|
|
129
|
-
foreground: tokens.semanticColor.action.secondary.progressive.default.foreground
|
|
130
|
-
},
|
|
131
|
-
press: {
|
|
132
|
-
background: tokens.color.fadedBlue8
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
destructive: {
|
|
136
|
-
default: {
|
|
137
|
-
border: tokens.color.fadedRed,
|
|
138
|
-
background: secondaryBgColor
|
|
139
|
-
},
|
|
140
|
-
hover: {
|
|
141
|
-
background: secondaryBgColor,
|
|
142
|
-
icon: tokens.color.fadedRed16,
|
|
143
|
-
foreground: tokens.semanticColor.action.secondary.destructive.default.foreground
|
|
144
|
-
},
|
|
145
|
-
press: {
|
|
146
|
-
background: tokens.color.fadedRed8
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
border: {
|
|
152
|
-
radius: {
|
|
153
|
-
default: tokens.border.radius.radius_120,
|
|
154
|
-
small: tokens.border.radius.radius_080,
|
|
155
|
-
large: tokens.border.radius.radius_120
|
|
156
|
-
},
|
|
157
|
-
width: {
|
|
158
|
-
focused: tokens.border.width.thin
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
margin: {
|
|
162
|
-
icon: {
|
|
163
|
-
offset: -tokens.spacing.xSmall_8
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
font: {
|
|
167
|
-
weight: {
|
|
168
|
-
default: tokens.font.weight.regular
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
});
|
|
15
|
+
const secondaryBgColor=tokens.color.offWhite;const theme=mergeTheme(theme$1,{color:{secondary:{progressive:{default:{border:tokens.color.fadedBlue,background:secondaryBgColor},hover:{background:secondaryBgColor,icon:tokens.color.fadedBlue16,foreground:tokens.semanticColor.action.secondary.progressive.default.foreground},press:{background:tokens.color.fadedBlue8}},destructive:{default:{border:tokens.color.fadedRed,background:secondaryBgColor},hover:{background:secondaryBgColor,icon:tokens.color.fadedRed16,foreground:tokens.semanticColor.action.secondary.destructive.default.foreground},press:{background:tokens.color.fadedRed8}}}},border:{radius:{default:tokens.border.radius.radius_120,small:tokens.border.radius.radius_080,large:tokens.border.radius.radius_120},width:{focused:tokens.border.width.thin}},margin:{icon:{offset:-tokens.spacing.xSmall_8}},font:{weight:{default:tokens.font.weight.regular}}});
|
|
172
16
|
|
|
173
|
-
const themes = {
|
|
174
|
-
default: theme$1,
|
|
175
|
-
khanmigo: theme
|
|
176
|
-
};
|
|
177
|
-
const ButtonThemeContext = createThemeContext(theme$1);
|
|
178
|
-
function ThemedButton(props) {
|
|
179
|
-
const currentTheme = React.useContext(ThemeSwitcherContext);
|
|
180
|
-
const theme = themes[currentTheme] || theme$1;
|
|
181
|
-
return React.createElement(ButtonThemeContext.Provider, {
|
|
182
|
-
value: theme
|
|
183
|
-
}, props.children);
|
|
184
|
-
}
|
|
17
|
+
const themes={default:theme$1,khanmigo:theme};const ButtonThemeContext=createThemeContext(theme$1);function ThemedButton(props){const currentTheme=React.useContext(ThemeSwitcherContext);const theme=themes[currentTheme]||theme$1;return jsx(ButtonThemeContext.Provider,{value:theme,children:props.children})}
|
|
185
18
|
|
|
186
|
-
function ButtonIcon({
|
|
187
|
-
icon,
|
|
188
|
-
size,
|
|
189
|
-
style,
|
|
190
|
-
testId
|
|
191
|
-
}) {
|
|
192
|
-
const commonProps = {
|
|
193
|
-
"aria-hidden": true,
|
|
194
|
-
color: "currentColor",
|
|
195
|
-
style: style,
|
|
196
|
-
testId
|
|
197
|
-
};
|
|
198
|
-
switch (size) {
|
|
199
|
-
case "small":
|
|
200
|
-
return React.createElement(PhosphorIcon, _extends({}, commonProps, {
|
|
201
|
-
size: "small",
|
|
202
|
-
icon: icon
|
|
203
|
-
}));
|
|
204
|
-
case "medium":
|
|
205
|
-
default:
|
|
206
|
-
return React.createElement(PhosphorIcon, _extends({}, commonProps, {
|
|
207
|
-
size: "medium",
|
|
208
|
-
icon: icon
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
19
|
+
function ButtonIcon({icon,size,style,testId}){const commonProps={"aria-hidden":true,color:"currentColor",style:style,testId};switch(size){case"small":return jsx(PhosphorIcon,{...commonProps,size:"small",icon:icon});case"medium":default:return jsx(PhosphorIcon,{...commonProps,size:"medium",icon:icon})}}
|
|
212
20
|
|
|
213
|
-
const
|
|
214
|
-
const StyledA = addStyle("a");
|
|
215
|
-
const StyledButton = addStyle("button");
|
|
216
|
-
const StyledLink = addStyle(Link);
|
|
217
|
-
const ButtonCore = React.forwardRef(function ButtonCore(props, ref) {
|
|
218
|
-
const {
|
|
219
|
-
theme,
|
|
220
|
-
themeName
|
|
221
|
-
} = useScopedTheme(ButtonThemeContext);
|
|
222
|
-
const sharedStyles = useStyles(themedSharedStyles, theme);
|
|
223
|
-
const inRouterContext = useInRouterContext();
|
|
224
|
-
const {
|
|
225
|
-
children,
|
|
226
|
-
skipClientNav,
|
|
227
|
-
color,
|
|
228
|
-
disabled: disabledProp,
|
|
229
|
-
focused,
|
|
230
|
-
hovered,
|
|
231
|
-
href = undefined,
|
|
232
|
-
kind = "primary",
|
|
233
|
-
labelStyle,
|
|
234
|
-
pressed,
|
|
235
|
-
size = "medium",
|
|
236
|
-
style,
|
|
237
|
-
testId,
|
|
238
|
-
type = undefined,
|
|
239
|
-
spinner,
|
|
240
|
-
startIcon,
|
|
241
|
-
endIcon,
|
|
242
|
-
id
|
|
243
|
-
} = props,
|
|
244
|
-
restProps = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
245
|
-
const buttonStyles = _generateStyles(color, kind, size, theme, themeName);
|
|
246
|
-
const disabled = spinner || disabledProp;
|
|
247
|
-
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, startIcon && sharedStyles.withStartIcon, endIcon && sharedStyles.withEndIcon, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.pressed : focused && buttonStyles.focused), size === "small" && sharedStyles.small, size === "large" && sharedStyles.large];
|
|
248
|
-
const commonProps = _extends({
|
|
249
|
-
"data-testid": testId,
|
|
250
|
-
id: id,
|
|
251
|
-
role: "button",
|
|
252
|
-
style: [defaultStyle, style]
|
|
253
|
-
}, restProps);
|
|
254
|
-
const Label = size === "small" ? LabelSmall : LabelLarge;
|
|
255
|
-
const label = React.createElement(Label, {
|
|
256
|
-
style: [sharedStyles.text, size === "small" && sharedStyles.smallText, size === "large" && sharedStyles.largeText, labelStyle, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? [buttonStyles.hover, buttonStyles.active] : hovered && buttonStyles.hover)],
|
|
257
|
-
testId: testId ? `${testId}-inner-label` : undefined
|
|
258
|
-
}, children);
|
|
259
|
-
const sizeMapping = {
|
|
260
|
-
medium: "small",
|
|
261
|
-
small: "xsmall",
|
|
262
|
-
large: "medium"
|
|
263
|
-
};
|
|
264
|
-
const iconSize = size === "small" ? "small" : "medium";
|
|
265
|
-
const contents = React.createElement(React.Fragment, null, startIcon && React.createElement(View, {
|
|
266
|
-
style: sharedStyles.iconWrapper
|
|
267
|
-
}, React.createElement(ButtonIcon, {
|
|
268
|
-
size: iconSize,
|
|
269
|
-
icon: startIcon,
|
|
270
|
-
style: [sharedStyles.startIcon, kind === "tertiary" && sharedStyles.tertiaryStartIcon],
|
|
271
|
-
testId: testId ? `${testId}-start-icon` : undefined
|
|
272
|
-
})), label, spinner && React.createElement(CircularSpinner, {
|
|
273
|
-
style: sharedStyles.spinner,
|
|
274
|
-
size: sizeMapping[size],
|
|
275
|
-
light: kind === "primary",
|
|
276
|
-
testId: `${testId || "button"}-spinner`
|
|
277
|
-
}), endIcon && React.createElement(View, {
|
|
278
|
-
testId: testId ? `${testId}-end-icon-wrapper` : undefined,
|
|
279
|
-
style: [styles.endIcon, sharedStyles.iconWrapper, sharedStyles.endIconWrapper, kind === "tertiary" && sharedStyles.endIconWrapperTertiary, !disabled && (focused || hovered) && kind !== "primary" && buttonStyles.iconWrapperHovered]
|
|
280
|
-
}, React.createElement(ButtonIcon, {
|
|
281
|
-
size: iconSize,
|
|
282
|
-
icon: endIcon,
|
|
283
|
-
testId: testId ? `${testId}-end-icon` : undefined
|
|
284
|
-
})));
|
|
285
|
-
if (href && !disabled) {
|
|
286
|
-
return inRouterContext && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
|
|
287
|
-
to: href,
|
|
288
|
-
ref: ref
|
|
289
|
-
}), contents) : React.createElement(StyledA, _extends({}, commonProps, {
|
|
290
|
-
href: href,
|
|
291
|
-
ref: ref
|
|
292
|
-
}), contents);
|
|
293
|
-
} else {
|
|
294
|
-
return React.createElement(StyledButton, _extends({
|
|
295
|
-
type: type || "button"
|
|
296
|
-
}, commonProps, {
|
|
297
|
-
"aria-disabled": disabled,
|
|
298
|
-
ref: ref
|
|
299
|
-
}), contents);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
const themedSharedStyles = theme => ({
|
|
303
|
-
shared: {
|
|
304
|
-
position: "relative",
|
|
305
|
-
display: "inline-flex",
|
|
306
|
-
alignItems: "center",
|
|
307
|
-
justifyContent: "center",
|
|
308
|
-
height: theme.size.height.medium,
|
|
309
|
-
paddingTop: 0,
|
|
310
|
-
paddingBottom: 0,
|
|
311
|
-
paddingLeft: theme.padding.large,
|
|
312
|
-
paddingRight: theme.padding.large,
|
|
313
|
-
border: "none",
|
|
314
|
-
borderRadius: theme.border.radius.default,
|
|
315
|
-
cursor: "pointer",
|
|
316
|
-
outline: "none",
|
|
317
|
-
textDecoration: "none",
|
|
318
|
-
boxSizing: "border-box",
|
|
319
|
-
touchAction: "manipulation",
|
|
320
|
-
userSelect: "none",
|
|
321
|
-
":focus": {
|
|
322
|
-
WebkitTapHighlightColor: "rgba(0,0,0,0)"
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
disabled: {
|
|
326
|
-
cursor: "auto"
|
|
327
|
-
},
|
|
328
|
-
small: {
|
|
329
|
-
borderRadius: theme.border.radius.small,
|
|
330
|
-
height: theme.size.height.small
|
|
331
|
-
},
|
|
332
|
-
large: {
|
|
333
|
-
borderRadius: theme.border.radius.large,
|
|
334
|
-
height: theme.size.height.large
|
|
335
|
-
},
|
|
336
|
-
text: {
|
|
337
|
-
alignItems: "center",
|
|
338
|
-
fontWeight: theme.font.weight.default,
|
|
339
|
-
whiteSpace: "nowrap",
|
|
340
|
-
overflow: "hidden",
|
|
341
|
-
lineHeight: `${theme.font.lineHeight.default}px`,
|
|
342
|
-
textOverflow: "ellipsis",
|
|
343
|
-
display: "inline-block",
|
|
344
|
-
pointerEvents: "none"
|
|
345
|
-
},
|
|
346
|
-
smallText: {
|
|
347
|
-
lineHeight: `${theme.font.lineHeight.small}px`
|
|
348
|
-
},
|
|
349
|
-
largeText: {
|
|
350
|
-
fontSize: theme.font.size.large,
|
|
351
|
-
lineHeight: `${theme.font.lineHeight.large}px`
|
|
352
|
-
},
|
|
353
|
-
textWithFocus: {
|
|
354
|
-
position: "relative"
|
|
355
|
-
},
|
|
356
|
-
hiddenText: {
|
|
357
|
-
visibility: "hidden"
|
|
358
|
-
},
|
|
359
|
-
spinner: {
|
|
360
|
-
position: "absolute"
|
|
361
|
-
},
|
|
362
|
-
startIcon: {
|
|
363
|
-
marginRight: theme.padding.small,
|
|
364
|
-
marginLeft: theme.margin.icon.offset
|
|
365
|
-
},
|
|
366
|
-
tertiaryStartIcon: {
|
|
367
|
-
marginLeft: 0
|
|
368
|
-
},
|
|
369
|
-
endIcon: {
|
|
370
|
-
marginLeft: theme.padding.small
|
|
371
|
-
},
|
|
372
|
-
iconWrapper: {
|
|
373
|
-
borderRadius: theme.border.radius.icon,
|
|
374
|
-
padding: theme.padding.xsmall,
|
|
375
|
-
minWidth: "auto"
|
|
376
|
-
},
|
|
377
|
-
endIconWrapper: {
|
|
378
|
-
marginLeft: theme.padding.small,
|
|
379
|
-
marginRight: theme.margin.icon.offset
|
|
380
|
-
},
|
|
381
|
-
endIconWrapperTertiary: {
|
|
382
|
-
marginRight: 0
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
const styles = {};
|
|
386
|
-
const _generateStyles = (buttonColor = "default", kind, size, theme, themeName) => {
|
|
387
|
-
const buttonType = `${buttonColor}-${kind}-${size}-${themeName}`;
|
|
388
|
-
if (styles[buttonType]) {
|
|
389
|
-
return styles[buttonType];
|
|
390
|
-
}
|
|
391
|
-
const padding = size === "large" ? theme.padding.xLarge : theme.padding.large;
|
|
392
|
-
const colorToAction = buttonColor === "destructive" ? "destructive" : "progressive";
|
|
393
|
-
const disabledState = theme.color[kind].disabled;
|
|
394
|
-
const disabledStateStyles = {
|
|
395
|
-
borderColor: disabledState.border,
|
|
396
|
-
background: disabledState.background,
|
|
397
|
-
color: disabledState.foreground
|
|
398
|
-
};
|
|
399
|
-
let newStyles = {};
|
|
400
|
-
if (kind === "primary") {
|
|
401
|
-
const themeColorAction = theme.color.primary[colorToAction];
|
|
402
|
-
const sharedFocusHoverStyling = {
|
|
403
|
-
outlineOffset: theme.border.offset.primary,
|
|
404
|
-
outlineStyle: "solid",
|
|
405
|
-
outlineWidth: theme.border.width.focused
|
|
406
|
-
};
|
|
407
|
-
const focusStyling = _extends({}, sharedFocusHoverStyling, {
|
|
408
|
-
outlineColor: themeColorAction.focus.border
|
|
409
|
-
});
|
|
410
|
-
const hoverStyling = _extends({}, sharedFocusHoverStyling, {
|
|
411
|
-
outlineColor: themeColorAction.hover.border
|
|
412
|
-
});
|
|
413
|
-
const activePressedStyling = {
|
|
414
|
-
background: themeColorAction.press.background,
|
|
415
|
-
outlineColor: themeColorAction.press.border,
|
|
416
|
-
outlineOffset: theme.border.offset.primary,
|
|
417
|
-
outlineStyle: "solid",
|
|
418
|
-
outlineWidth: theme.border.width.focused
|
|
419
|
-
};
|
|
420
|
-
newStyles = {
|
|
421
|
-
default: {
|
|
422
|
-
background: themeColorAction.default.background,
|
|
423
|
-
color: themeColorAction.default.foreground,
|
|
424
|
-
paddingInline: padding,
|
|
425
|
-
":hover": hoverStyling,
|
|
426
|
-
":focus-visible": focusStyling,
|
|
427
|
-
":active": activePressedStyling
|
|
428
|
-
},
|
|
429
|
-
focused: focusStyling,
|
|
430
|
-
pressed: activePressedStyling,
|
|
431
|
-
disabled: _extends({}, disabledStateStyles, {
|
|
432
|
-
cursor: "not-allowed",
|
|
433
|
-
":hover": _extends({}, disabledStateStyles, {
|
|
434
|
-
outline: "none"
|
|
435
|
-
}),
|
|
436
|
-
":active": _extends({}, disabledStateStyles, {
|
|
437
|
-
outline: "none"
|
|
438
|
-
}),
|
|
439
|
-
":focus-visible": focusStyling
|
|
440
|
-
})
|
|
441
|
-
};
|
|
442
|
-
} else if (kind === "secondary") {
|
|
443
|
-
const themeColorAction = theme.color.secondary[colorToAction];
|
|
444
|
-
const sharedFocusHoverStyling = {
|
|
445
|
-
background: themeColorAction.hover.background,
|
|
446
|
-
outlineStyle: "solid",
|
|
447
|
-
outlineOffset: theme.border.offset.secondary,
|
|
448
|
-
outlineWidth: theme.border.width.focused
|
|
449
|
-
};
|
|
450
|
-
const focusStyling = _extends({}, sharedFocusHoverStyling, {
|
|
451
|
-
outlineColor: themeColorAction.focus.border
|
|
452
|
-
});
|
|
453
|
-
const hoverStyling = _extends({}, sharedFocusHoverStyling, {
|
|
454
|
-
borderColor: themeColorAction.hover.border
|
|
455
|
-
});
|
|
456
|
-
const activePressedStyling = {
|
|
457
|
-
background: themeColorAction.press.background,
|
|
458
|
-
color: themeColorAction.press.foreground,
|
|
459
|
-
outlineColor: themeColorAction.press.border,
|
|
460
|
-
outlineStyle: "solid",
|
|
461
|
-
outlineWidth: theme.border.width.focused
|
|
462
|
-
};
|
|
463
|
-
newStyles = {
|
|
464
|
-
default: {
|
|
465
|
-
background: themeColorAction.default.background,
|
|
466
|
-
color: themeColorAction.default.foreground,
|
|
467
|
-
borderColor: themeColorAction.default.border,
|
|
468
|
-
borderStyle: "solid",
|
|
469
|
-
borderWidth: theme.border.width.secondary,
|
|
470
|
-
paddingInline: padding,
|
|
471
|
-
":hover": hoverStyling,
|
|
472
|
-
":focus-visible": focusStyling,
|
|
473
|
-
":active": activePressedStyling
|
|
474
|
-
},
|
|
475
|
-
focused: focusStyling,
|
|
476
|
-
pressed: activePressedStyling,
|
|
477
|
-
disabled: _extends({}, disabledStateStyles, {
|
|
478
|
-
cursor: "not-allowed",
|
|
479
|
-
":hover": _extends({}, disabledStateStyles, {
|
|
480
|
-
outline: "none"
|
|
481
|
-
}),
|
|
482
|
-
":active": _extends({}, disabledStateStyles, {
|
|
483
|
-
outline: "none"
|
|
484
|
-
}),
|
|
485
|
-
":focus-visible": focusStyling
|
|
486
|
-
}),
|
|
487
|
-
iconWrapperHovered: {
|
|
488
|
-
backgroundColor: themeColorAction.hover.icon,
|
|
489
|
-
color: themeColorAction.hover.foreground
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
} else if (kind === "tertiary") {
|
|
493
|
-
const themeColorAction = theme.color.tertiary[colorToAction];
|
|
494
|
-
const focusStyling = {
|
|
495
|
-
outlineStyle: "solid",
|
|
496
|
-
borderColor: "transparent",
|
|
497
|
-
outlineColor: themeColorAction.focus.border,
|
|
498
|
-
outlineWidth: theme.border.width.focused,
|
|
499
|
-
borderRadius: theme.border.radius.default
|
|
500
|
-
};
|
|
501
|
-
const activePressedStyling = {
|
|
502
|
-
color: themeColorAction.press.foreground,
|
|
503
|
-
textDecoration: "underline",
|
|
504
|
-
textDecorationThickness: theme.size.underline.active,
|
|
505
|
-
textUnderlineOffset: theme.font.offset.default
|
|
506
|
-
};
|
|
507
|
-
const sharedDisabledStyling = _extends({}, disabledStateStyles, {
|
|
508
|
-
textDecoration: "none",
|
|
509
|
-
textDecorationThickness: "unset",
|
|
510
|
-
textUnderlineOffset: "unset",
|
|
511
|
-
outline: "none"
|
|
512
|
-
});
|
|
513
|
-
newStyles = {
|
|
514
|
-
default: {
|
|
515
|
-
background: themeColorAction.default.background,
|
|
516
|
-
color: themeColorAction.default.foreground,
|
|
517
|
-
paddingInline: 0,
|
|
518
|
-
":hover": {
|
|
519
|
-
textUnderlineOffset: theme.font.offset.default,
|
|
520
|
-
textDecoration: "underline",
|
|
521
|
-
textDecorationThickness: theme.size.underline.hover
|
|
522
|
-
},
|
|
523
|
-
":focus-visible": focusStyling,
|
|
524
|
-
":active": activePressedStyling
|
|
525
|
-
},
|
|
526
|
-
focused: focusStyling,
|
|
527
|
-
pressed: activePressedStyling,
|
|
528
|
-
disabled: _extends({}, disabledStateStyles, {
|
|
529
|
-
cursor: "not-allowed",
|
|
530
|
-
":hover": sharedDisabledStyling,
|
|
531
|
-
":active": sharedDisabledStyling,
|
|
532
|
-
":focus-visible": focusStyling
|
|
533
|
-
})
|
|
534
|
-
};
|
|
535
|
-
} else {
|
|
536
|
-
throw new Error("Button kind not recognized");
|
|
537
|
-
}
|
|
538
|
-
styles[buttonType] = StyleSheet.create(newStyles);
|
|
539
|
-
return styles[buttonType];
|
|
540
|
-
};
|
|
21
|
+
const StyledA=addStyle("a");const StyledButton=addStyle("button");const StyledLink=addStyle(Link);const ButtonCore=React.forwardRef(function ButtonCore(props,ref){const{theme,themeName}=useScopedTheme(ButtonThemeContext);const sharedStyles=useStyles(themedSharedStyles,theme);const inRouterContext=useInRouterContext();const{children,skipClientNav,color,disabled:disabledProp,focused,hovered,href=undefined,kind="primary",labelStyle,pressed,size="medium",style,testId,type=undefined,spinner,startIcon,endIcon,id,waiting:_,...restProps}=props;const buttonStyles=_generateStyles(color,kind,size,theme,themeName);const disabled=spinner||disabledProp;const defaultStyle=[sharedStyles.shared,disabled&&sharedStyles.disabled,startIcon&&sharedStyles.withStartIcon,endIcon&&sharedStyles.withEndIcon,buttonStyles.default,disabled&&buttonStyles.disabled,!disabled&&(pressed?buttonStyles.pressed:focused&&buttonStyles.focused),size==="small"&&sharedStyles.small,size==="large"&&sharedStyles.large];const commonProps={"data-testid":testId,id:id,role:"button",style:[defaultStyle,style],...restProps};const Label=size==="small"?LabelSmall:LabelLarge;const label=jsx(Label,{style:[sharedStyles.text,size==="small"&&sharedStyles.smallText,size==="large"&&sharedStyles.largeText,labelStyle,spinner&&sharedStyles.hiddenText,kind==="tertiary"&&sharedStyles.textWithFocus,kind==="tertiary"&&!disabled&&(pressed?[buttonStyles.hover,buttonStyles.active]:hovered&&buttonStyles.hover)],testId:testId?`${testId}-inner-label`:undefined,children:children});const sizeMapping={medium:"small",small:"xsmall",large:"medium"};const iconSize=size==="small"?"small":"medium";const contents=jsxs(React.Fragment,{children:[startIcon&&jsx(View,{style:sharedStyles.iconWrapper,children:jsx(ButtonIcon,{size:iconSize,icon:startIcon,style:[sharedStyles.startIcon,kind==="tertiary"&&sharedStyles.tertiaryStartIcon],testId:testId?`${testId}-start-icon`:undefined})}),label,spinner&&jsx(CircularSpinner,{style:sharedStyles.spinner,size:sizeMapping[size],light:kind==="primary",testId:`${testId||"button"}-spinner`}),endIcon&&jsx(View,{testId:testId?`${testId}-end-icon-wrapper`:undefined,style:[styles.endIcon,sharedStyles.iconWrapper,sharedStyles.endIconWrapper,kind==="tertiary"&&sharedStyles.endIconWrapperTertiary,!disabled&&(focused||hovered)&&kind!=="primary"&&buttonStyles.iconWrapperHovered],children:jsx(ButtonIcon,{size:iconSize,icon:endIcon,testId:testId?`${testId}-end-icon`:undefined})})]});if(href&&!disabled){return inRouterContext&&!skipClientNav&&isClientSideUrl(href)?jsx(StyledLink,{...commonProps,to:href,ref:ref,children:contents}):jsx(StyledA,{...commonProps,href:href,ref:ref,children:contents})}else {return jsx(StyledButton,{type:type||"button",...commonProps,"aria-disabled":disabled,ref:ref,children:contents})}});const themedSharedStyles=theme=>({shared:{position:"relative",display:"inline-flex",alignItems:"center",justifyContent:"center",height:theme.size.height.medium,paddingTop:0,paddingBottom:0,paddingLeft:theme.padding.large,paddingRight:theme.padding.large,border:"none",borderRadius:theme.border.radius.default,cursor:"pointer",outline:"none",textDecoration:"none",boxSizing:"border-box",touchAction:"manipulation",userSelect:"none",":focus":{WebkitTapHighlightColor:"rgba(0,0,0,0)"}},disabled:{cursor:"auto"},small:{borderRadius:theme.border.radius.small,height:theme.size.height.small},large:{borderRadius:theme.border.radius.large,height:theme.size.height.large},text:{alignItems:"center",fontWeight:theme.font.weight.default,whiteSpace:"nowrap",overflow:"hidden",lineHeight:theme.font.lineHeight.default,textOverflow:"ellipsis",display:"inline-block",pointerEvents:"none"},smallText:{lineHeight:theme.font.lineHeight.small},largeText:{fontSize:theme.font.size.large,lineHeight:theme.font.lineHeight.large},textWithFocus:{position:"relative"},hiddenText:{visibility:"hidden"},spinner:{position:"absolute"},startIcon:{marginRight:theme.padding.small,marginLeft:theme.margin.icon.offset},tertiaryStartIcon:{marginLeft:0},endIcon:{marginLeft:theme.padding.small},iconWrapper:{borderRadius:theme.border.radius.icon,padding:theme.padding.xsmall,minWidth:"auto"},endIconWrapper:{marginLeft:theme.padding.small,marginRight:theme.margin.icon.offset},endIconWrapperTertiary:{marginRight:0}});const styles={};const _generateStyles=(buttonColor="default",kind,size,theme,themeName)=>{const buttonType=`${buttonColor}-${kind}-${size}-${themeName}`;if(styles[buttonType]){return styles[buttonType]}const padding=size==="large"?theme.padding.xLarge:theme.padding.large;const colorToAction=buttonColor==="destructive"?"destructive":"progressive";const disabledState=theme.color[kind].disabled;const disabledStateStyles={borderColor:disabledState.border,background:disabledState.background,color:disabledState.foreground};let newStyles={};if(kind==="primary"){const themeColorAction=theme.color.primary[colorToAction];const sharedFocusHoverStyling={outlineOffset:theme.border.offset.primary,outlineStyle:"solid",outlineWidth:theme.border.width.focused};const focusStyling={...sharedFocusHoverStyling,outlineColor:themeColorAction.focus.border};const hoverStyling={...sharedFocusHoverStyling,outlineColor:themeColorAction.hover.border};const activePressedStyling={background:themeColorAction.press.background,outlineColor:themeColorAction.press.border,outlineOffset:theme.border.offset.primary,outlineStyle:"solid",outlineWidth:theme.border.width.focused};newStyles={default:{background:themeColorAction.default.background,color:themeColorAction.default.foreground,paddingInline:padding,":hover":hoverStyling,":focus-visible":focusStyling,":active":activePressedStyling},focused:focusStyling,pressed:activePressedStyling,disabled:{...disabledStateStyles,cursor:"not-allowed",":hover":{...disabledStateStyles,outline:"none"},":active":{...disabledStateStyles,outline:"none"},":focus-visible":focusStyling}};}else if(kind==="secondary"){const themeColorAction=theme.color.secondary[colorToAction];const sharedFocusHoverStyling={background:themeColorAction.hover.background,outlineStyle:"solid",outlineOffset:theme.border.offset.secondary,outlineWidth:theme.border.width.focused};const focusStyling={...sharedFocusHoverStyling,outlineColor:themeColorAction.focus.border};const hoverStyling={...sharedFocusHoverStyling,borderColor:themeColorAction.hover.border};const activePressedStyling={background:themeColorAction.press.background,color:themeColorAction.press.foreground,outlineColor:themeColorAction.press.border,outlineStyle:"solid",outlineWidth:theme.border.width.focused};newStyles={default:{background:themeColorAction.default.background,color:themeColorAction.default.foreground,borderColor:themeColorAction.default.border,borderStyle:"solid",borderWidth:theme.border.width.secondary,paddingInline:padding,":hover":hoverStyling,":focus-visible":focusStyling,":active":activePressedStyling},focused:focusStyling,pressed:activePressedStyling,disabled:{...disabledStateStyles,cursor:"not-allowed",":hover":{...disabledStateStyles,outline:"none"},":active":{...disabledStateStyles,outline:"none"},":focus-visible":focusStyling},iconWrapperHovered:{backgroundColor:themeColorAction.hover.icon,color:themeColorAction.hover.foreground}};}else if(kind==="tertiary"){const themeColorAction=theme.color.tertiary[colorToAction];const focusStyling={outlineStyle:"solid",borderColor:"transparent",outlineColor:themeColorAction.focus.border,outlineWidth:theme.border.width.focused,borderRadius:theme.border.radius.default};const activePressedStyling={color:themeColorAction.press.foreground,textDecoration:"underline",textDecorationThickness:theme.size.underline.active,textUnderlineOffset:theme.font.offset.default};const sharedDisabledStyling={...disabledStateStyles,textDecoration:"none",textDecorationThickness:"unset",textUnderlineOffset:"unset",outline:"none"};newStyles={default:{background:themeColorAction.default.background,color:themeColorAction.default.foreground,paddingInline:0,":hover":{textUnderlineOffset:theme.font.offset.default,textDecoration:"underline",textDecorationThickness:theme.size.underline.hover},":focus-visible":focusStyling,":active":activePressedStyling},focused:focusStyling,pressed:activePressedStyling,disabled:{...disabledStateStyles,cursor:"not-allowed",":hover":sharedDisabledStyling,":active":sharedDisabledStyling,":focus-visible":focusStyling}};}else {throw new Error("Button kind not recognized")}styles[buttonType]=StyleSheet.create(newStyles);return styles[buttonType]};
|
|
541
22
|
|
|
542
|
-
const
|
|
543
|
-
const Button = React.forwardRef(function Button(props, ref) {
|
|
544
|
-
const {
|
|
545
|
-
href = undefined,
|
|
546
|
-
type = undefined,
|
|
547
|
-
children,
|
|
548
|
-
skipClientNav,
|
|
549
|
-
onClick,
|
|
550
|
-
beforeNav = undefined,
|
|
551
|
-
safeWithNav = undefined,
|
|
552
|
-
tabIndex,
|
|
553
|
-
target,
|
|
554
|
-
rel,
|
|
555
|
-
color = "default",
|
|
556
|
-
kind = "primary",
|
|
557
|
-
size = "medium",
|
|
558
|
-
disabled = false,
|
|
559
|
-
spinner = false
|
|
560
|
-
} = props,
|
|
561
|
-
sharedButtonCoreProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
562
|
-
const inRouterContext = useInRouterContext();
|
|
563
|
-
const ClickableBehavior = getClickableBehavior(href, skipClientNav, inRouterContext);
|
|
564
|
-
const renderProp = (state, restChildProps) => {
|
|
565
|
-
return React.createElement(ThemedButton, null, React.createElement(ButtonCore, _extends({}, sharedButtonCoreProps, state, restChildProps, {
|
|
566
|
-
disabled: disabled,
|
|
567
|
-
spinner: spinner || state.waiting,
|
|
568
|
-
color: color,
|
|
569
|
-
kind: kind,
|
|
570
|
-
size: size,
|
|
571
|
-
skipClientNav: skipClientNav,
|
|
572
|
-
href: href,
|
|
573
|
-
target: target,
|
|
574
|
-
type: type,
|
|
575
|
-
tabIndex: tabIndex,
|
|
576
|
-
ref: ref
|
|
577
|
-
}), children));
|
|
578
|
-
};
|
|
579
|
-
if (beforeNav) {
|
|
580
|
-
return React.createElement(ClickableBehavior, {
|
|
581
|
-
disabled: spinner || disabled,
|
|
582
|
-
href: href,
|
|
583
|
-
role: "button",
|
|
584
|
-
type: type,
|
|
585
|
-
onClick: onClick,
|
|
586
|
-
beforeNav: beforeNav,
|
|
587
|
-
safeWithNav: safeWithNav,
|
|
588
|
-
rel: rel
|
|
589
|
-
}, renderProp);
|
|
590
|
-
} else {
|
|
591
|
-
return React.createElement(ClickableBehavior, {
|
|
592
|
-
disabled: spinner || disabled,
|
|
593
|
-
href: href,
|
|
594
|
-
role: "button",
|
|
595
|
-
type: type,
|
|
596
|
-
onClick: onClick,
|
|
597
|
-
safeWithNav: safeWithNav,
|
|
598
|
-
target: target,
|
|
599
|
-
rel: rel
|
|
600
|
-
}, renderProp);
|
|
601
|
-
}
|
|
602
|
-
});
|
|
23
|
+
const Button=React.forwardRef(function Button(props,ref){const{href=undefined,type=undefined,children,skipClientNav,onClick,beforeNav=undefined,safeWithNav=undefined,tabIndex,target,rel,color="default",kind="primary",size="medium",disabled=false,spinner=false,...sharedButtonCoreProps}=props;const inRouterContext=useInRouterContext();const ClickableBehavior=getClickableBehavior(href,skipClientNav,inRouterContext);const renderProp=(state,restChildProps)=>{return jsx(ThemedButton,{children:jsx(ButtonCore,{...sharedButtonCoreProps,...state,...restChildProps,disabled:disabled,spinner:spinner||state.waiting,color:color,kind:kind,size:size,skipClientNav:skipClientNav,href:href,target:target,type:type,tabIndex:tabIndex,ref:ref,children:children})})};if(beforeNav){return jsx(ClickableBehavior,{disabled:spinner||disabled,href:href,role:"button",type:type,onClick:onClick,beforeNav:beforeNav,safeWithNav:safeWithNav,rel:rel,children:renderProp})}else {return jsx(ClickableBehavior,{disabled:spinner||disabled,href:href,role:"button",type:type,onClick:onClick,safeWithNav:safeWithNav,target:target,rel:rel,children:renderProp})}});
|
|
603
24
|
|
|
604
25
|
export { Button as default };
|