@khanacademy/wonder-blocks-button 2.11.3 → 2.11.6
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 +33 -0
- package/dist/es/index.js +17 -66
- package/package.json +7 -7
- package/src/components/button.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-button
|
|
2
2
|
|
|
3
|
+
## 2.11.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5f4a4297]
|
|
8
|
+
- Updated dependencies [2b96fd59]
|
|
9
|
+
- @khanacademy/wonder-blocks-core@4.3.2
|
|
10
|
+
- @khanacademy/wonder-blocks-clickable@2.2.7
|
|
11
|
+
- @khanacademy/wonder-blocks-icon@1.2.28
|
|
12
|
+
- @khanacademy/wonder-blocks-progress-spinner@1.1.32
|
|
13
|
+
- @khanacademy/wonder-blocks-typography@1.1.32
|
|
14
|
+
|
|
15
|
+
## 2.11.5
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- @khanacademy/wonder-blocks-clickable@2.2.6
|
|
20
|
+
- @khanacademy/wonder-blocks-core@4.3.1
|
|
21
|
+
- @khanacademy/wonder-blocks-icon@1.2.27
|
|
22
|
+
- @khanacademy/wonder-blocks-progress-spinner@1.1.31
|
|
23
|
+
- @khanacademy/wonder-blocks-typography@1.1.31
|
|
24
|
+
|
|
25
|
+
## 2.11.4
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [246a921d]
|
|
30
|
+
- @khanacademy/wonder-blocks-core@4.3.0
|
|
31
|
+
- @khanacademy/wonder-blocks-clickable@2.2.5
|
|
32
|
+
- @khanacademy/wonder-blocks-icon@1.2.26
|
|
33
|
+
- @khanacademy/wonder-blocks-progress-spinner@1.1.30
|
|
34
|
+
- @khanacademy/wonder-blocks-typography@1.1.30
|
|
35
|
+
|
|
3
36
|
## 2.11.3
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -46,8 +46,7 @@ class ButtonCore extends React.Component {
|
|
|
46
46
|
const buttonStyles = _generateStyles(buttonColor, kind, light, iconWidth, size);
|
|
47
47
|
|
|
48
48
|
const disabled = spinner || disabledProp;
|
|
49
|
-
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, icon && sharedStyles.withIcon, buttonStyles.default, disabled && buttonStyles.disabled,
|
|
50
|
-
kind !== "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus), size === "small" && sharedStyles.small, size === "xlarge" && sharedStyles.xlarge];
|
|
49
|
+
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, icon && sharedStyles.withIcon, buttonStyles.default, disabled && buttonStyles.disabled, kind !== "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus), size === "small" && sharedStyles.small, size === "xlarge" && sharedStyles.xlarge];
|
|
51
50
|
|
|
52
51
|
const commonProps = _extends({
|
|
53
52
|
"data-test-id": testId,
|
|
@@ -57,16 +56,15 @@ class ButtonCore extends React.Component {
|
|
|
57
56
|
}, restProps);
|
|
58
57
|
|
|
59
58
|
const Label = size === "small" ? LabelSmall : LabelLarge;
|
|
60
|
-
const label =
|
|
61
|
-
style: [sharedStyles.text, size === "xlarge" && sharedStyles.xlargeText, icon && sharedStyles.textWithIcon, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus,
|
|
62
|
-
|
|
63
|
-
}, icon && /*#__PURE__*/React.createElement(Icon, {
|
|
59
|
+
const label = React.createElement(Label, {
|
|
60
|
+
style: [sharedStyles.text, size === "xlarge" && sharedStyles.xlargeText, icon && sharedStyles.textWithIcon, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)]
|
|
61
|
+
}, icon && React.createElement(Icon, {
|
|
64
62
|
size: size,
|
|
65
63
|
color: "currentColor",
|
|
66
64
|
icon: icon,
|
|
67
65
|
style: sharedStyles.icon
|
|
68
66
|
}), children);
|
|
69
|
-
const contents =
|
|
67
|
+
const contents = React.createElement(React.Fragment, null, label, spinner && React.createElement(CircularSpinner, {
|
|
70
68
|
style: sharedStyles.spinner,
|
|
71
69
|
size: {
|
|
72
70
|
medium: "small",
|
|
@@ -77,13 +75,13 @@ class ButtonCore extends React.Component {
|
|
|
77
75
|
}));
|
|
78
76
|
|
|
79
77
|
if (href && !disabled) {
|
|
80
|
-
return router && !skipClientNav && isClientSideUrl(href) ?
|
|
78
|
+
return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
|
|
81
79
|
to: href
|
|
82
|
-
}), contents) :
|
|
80
|
+
}), contents) : React.createElement(StyledAnchor, _extends({}, commonProps, {
|
|
83
81
|
href: href
|
|
84
82
|
}), contents);
|
|
85
83
|
} else {
|
|
86
|
-
return
|
|
84
|
+
return React.createElement(StyledButton, _extends({
|
|
87
85
|
type: type || "button"
|
|
88
86
|
}, commonProps, {
|
|
89
87
|
"aria-disabled": disabled
|
|
@@ -92,7 +90,7 @@ class ButtonCore extends React.Component {
|
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
render() {
|
|
95
|
-
return
|
|
93
|
+
return React.createElement(__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
}
|
|
@@ -113,17 +111,13 @@ const sharedStyles = StyleSheet.create({
|
|
|
113
111
|
outline: "none",
|
|
114
112
|
textDecoration: "none",
|
|
115
113
|
boxSizing: "border-box",
|
|
116
|
-
// This removes the 300ms click delay on mobile browsers by indicating that
|
|
117
|
-
// "double-tap to zoom" shouldn't be used on this element.
|
|
118
114
|
touchAction: "manipulation",
|
|
119
115
|
userSelect: "none",
|
|
120
116
|
":focus": {
|
|
121
|
-
// Mobile: Removes a blue highlight style shown when the user clicks a button
|
|
122
117
|
WebkitTapHighlightColor: "rgba(0,0,0,0)"
|
|
123
118
|
}
|
|
124
119
|
},
|
|
125
120
|
withIcon: {
|
|
126
|
-
// The left padding for the button with icon should have 4px less padding
|
|
127
121
|
paddingLeft: 12
|
|
128
122
|
},
|
|
129
123
|
disabled: {
|
|
@@ -142,21 +136,17 @@ const sharedStyles = StyleSheet.create({
|
|
|
142
136
|
overflow: "hidden",
|
|
143
137
|
textOverflow: "ellipsis",
|
|
144
138
|
display: "inline-block",
|
|
145
|
-
|
|
146
|
-
pointerEvents: "none" // fix Safari bug where the browser was eating mouse events
|
|
147
|
-
|
|
139
|
+
pointerEvents: "none"
|
|
148
140
|
},
|
|
149
141
|
xlargeText: {
|
|
150
142
|
fontSize: 18,
|
|
151
143
|
lineHeight: "20px"
|
|
152
144
|
},
|
|
153
145
|
textWithIcon: {
|
|
154
|
-
display: "flex"
|
|
155
|
-
|
|
146
|
+
display: "flex"
|
|
156
147
|
},
|
|
157
148
|
textWithFocus: {
|
|
158
|
-
position: "relative"
|
|
159
|
-
|
|
149
|
+
position: "relative"
|
|
160
150
|
},
|
|
161
151
|
hiddenText: {
|
|
162
152
|
visibility: "hidden"
|
|
@@ -199,10 +189,6 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
199
189
|
paddingRight: padding
|
|
200
190
|
},
|
|
201
191
|
focus: {
|
|
202
|
-
// This assumes a background of white for the regular button and
|
|
203
|
-
// a background of darkBlue for the light version. The inner
|
|
204
|
-
// box shadow/ring is also small enough for a slight variation
|
|
205
|
-
// in the background color not to matter too much.
|
|
206
192
|
boxShadow: `0 0 0 1px ${light ? darkBlue : white}, 0 0 0 3px ${light ? white : color}`
|
|
207
193
|
},
|
|
208
194
|
active: {
|
|
@@ -234,8 +220,6 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
234
220
|
background: light ? "transparent" : white,
|
|
235
221
|
borderColor: light ? white : color,
|
|
236
222
|
borderWidth: 2,
|
|
237
|
-
// The left padding for the button with icon should have 4px
|
|
238
|
-
// less padding
|
|
239
223
|
paddingLeft: iconWidth ? padding - 5 : padding - 1,
|
|
240
224
|
paddingRight: padding - 1
|
|
241
225
|
},
|
|
@@ -244,10 +228,6 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
244
228
|
color: light ? fadedColor : activeColor,
|
|
245
229
|
borderColor: light ? fadedColor : activeColor,
|
|
246
230
|
borderWidth: 2,
|
|
247
|
-
// We need to reduce padding to offset the difference
|
|
248
|
-
// caused by the border becoming thicker on focus.
|
|
249
|
-
// The left padding for the button with icon should have 4px
|
|
250
|
-
// less padding
|
|
251
231
|
paddingLeft: iconWidth ? padding - 5 : padding - 1,
|
|
252
232
|
paddingRight: padding - 1
|
|
253
233
|
},
|
|
@@ -258,17 +238,12 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
258
238
|
":focus": {
|
|
259
239
|
borderColor: light ? white50 : offBlack32,
|
|
260
240
|
borderWidth: 2,
|
|
261
|
-
// We need to reduce padding to offset the difference
|
|
262
|
-
// caused by the border becoming thicker on focus.
|
|
263
|
-
// The left padding for the button with icon should have 4px
|
|
264
|
-
// less padding
|
|
265
241
|
paddingLeft: iconWidth ? padding - 5 : padding - 1,
|
|
266
242
|
paddingRight: padding - 1
|
|
267
243
|
}
|
|
268
244
|
}
|
|
269
245
|
};
|
|
270
246
|
} else if (kind === "tertiary") {
|
|
271
|
-
// TODO(FEI-4229): Make tertiary buttons focusable
|
|
272
247
|
newStyles = {
|
|
273
248
|
default: {
|
|
274
249
|
background: "none",
|
|
@@ -316,27 +291,6 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
316
291
|
|
|
317
292
|
const _excluded = ["href", "type", "children", "skipClientNav", "spinner", "disabled", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel"],
|
|
318
293
|
_excluded2 = ["tabIndex"];
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Reusable button component.
|
|
322
|
-
*
|
|
323
|
-
* Consisting of a [`ClickableBehavior`](#clickablebehavior) surrounding a
|
|
324
|
-
* `ButtonCore`. `ClickableBehavior` handles interactions and state changes.
|
|
325
|
-
* `ButtonCore` is a stateless component which displays the different states
|
|
326
|
-
* the `Button` can take.
|
|
327
|
-
*
|
|
328
|
-
* ### Usage
|
|
329
|
-
*
|
|
330
|
-
* ```jsx
|
|
331
|
-
* import Button from "@khanacademy/wonder-blocks-button";
|
|
332
|
-
*
|
|
333
|
-
* <Button
|
|
334
|
-
* onClick={(e) => console.log("Hello, world!")}
|
|
335
|
-
* >
|
|
336
|
-
* Hello, world!
|
|
337
|
-
* </Button>
|
|
338
|
-
* ```
|
|
339
|
-
*/
|
|
340
294
|
class Button extends React.Component {
|
|
341
295
|
renderClickableBehavior(router) {
|
|
342
296
|
const _this$props = this.props,
|
|
@@ -364,22 +318,19 @@ class Button extends React.Component {
|
|
|
364
318
|
} = _ref,
|
|
365
319
|
restChildProps = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
366
320
|
|
|
367
|
-
return
|
|
321
|
+
return React.createElement(ButtonCore, _extends({}, sharedButtonCoreProps, state, restChildProps, {
|
|
368
322
|
disabled: disabled,
|
|
369
323
|
spinner: spinner || state.waiting,
|
|
370
324
|
skipClientNav: skipClientNav,
|
|
371
325
|
href: href,
|
|
372
326
|
target: target,
|
|
373
|
-
type: type
|
|
374
|
-
// it to override the tabIndex provide to use by
|
|
375
|
-
// ClickableBehavior.
|
|
376
|
-
,
|
|
327
|
+
type: type,
|
|
377
328
|
tabIndex: tabIndex || clickableTabIndex
|
|
378
329
|
}), children);
|
|
379
330
|
};
|
|
380
331
|
|
|
381
332
|
if (beforeNav) {
|
|
382
|
-
return
|
|
333
|
+
return React.createElement(ClickableBehavior, {
|
|
383
334
|
disabled: spinner || disabled,
|
|
384
335
|
href: href,
|
|
385
336
|
role: "button",
|
|
@@ -390,7 +341,7 @@ class Button extends React.Component {
|
|
|
390
341
|
rel: rel
|
|
391
342
|
}, renderProp);
|
|
392
343
|
} else {
|
|
393
|
-
return
|
|
344
|
+
return React.createElement(ClickableBehavior, {
|
|
394
345
|
disabled: spinner || disabled,
|
|
395
346
|
href: href,
|
|
396
347
|
role: "button",
|
|
@@ -404,7 +355,7 @@ class Button extends React.Component {
|
|
|
404
355
|
}
|
|
405
356
|
|
|
406
357
|
render() {
|
|
407
|
-
return
|
|
358
|
+
return React.createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
408
359
|
}
|
|
409
360
|
|
|
410
361
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-button",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.6",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.16.3",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^2.2.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^2.2.7",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^1.1.20",
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^4.2
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^1.2.
|
|
23
|
-
"@khanacademy/wonder-blocks-progress-spinner": "^1.1.
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^4.3.2",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^1.2.28",
|
|
23
|
+
"@khanacademy/wonder-blocks-progress-spinner": "^1.1.32",
|
|
24
24
|
"@khanacademy/wonder-blocks-spacing": "^3.0.5",
|
|
25
|
-
"@khanacademy/wonder-blocks-typography": "^1.1.
|
|
25
|
+
"@khanacademy/wonder-blocks-typography": "^1.1.32"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"aphrodite": "^1.2.5",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"react-router-dom": "5.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"wb-dev-build-settings": "^0.
|
|
34
|
+
"wb-dev-build-settings": "^0.4.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/components/button.js
CHANGED