@khanacademy/wonder-blocks-button 3.0.10 → 3.0.12

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @khanacademy/wonder-blocks-button
2
2
 
3
+ ## 3.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [496119f2]
8
+ - @khanacademy/wonder-blocks-clickable@2.4.4
9
+ - @khanacademy/wonder-blocks-core@4.6.2
10
+ - @khanacademy/wonder-blocks-progress-spinner@1.1.39
11
+ - @khanacademy/wonder-blocks-icon@1.2.35
12
+ - @khanacademy/wonder-blocks-typography@1.1.37
13
+
14
+ ## 3.0.11
15
+
16
+ ### Patch Changes
17
+
18
+ - @khanacademy/wonder-blocks-clickable@2.4.3
19
+ - @khanacademy/wonder-blocks-core@4.6.1
20
+ - @khanacademy/wonder-blocks-icon@1.2.34
21
+ - @khanacademy/wonder-blocks-progress-spinner@1.1.38
22
+ - @khanacademy/wonder-blocks-typography@1.1.36
23
+
3
24
  ## 3.0.10
4
25
 
5
26
  ### Patch Changes
package/dist/index.js ADDED
@@ -0,0 +1,411 @@
1
+ 'use strict';
2
+
3
+ var _extends = require('@babel/runtime/helpers/extends');
4
+ var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
5
+ var React = require('react');
6
+ var reactRouter = require('react-router');
7
+ var wonderBlocksClickable = require('@khanacademy/wonder-blocks-clickable');
8
+ var aphrodite = require('aphrodite');
9
+ var reactRouterDom = require('react-router-dom');
10
+ var wonderBlocksTypography = require('@khanacademy/wonder-blocks-typography');
11
+ var Color = require('@khanacademy/wonder-blocks-color');
12
+ var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
13
+ var wonderBlocksProgressSpinner = require('@khanacademy/wonder-blocks-progress-spinner');
14
+ var Icon = require('@khanacademy/wonder-blocks-icon');
15
+ var Spacing = require('@khanacademy/wonder-blocks-spacing');
16
+
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
+
19
+ function _interopNamespace(e) {
20
+ if (e && e.__esModule) return e;
21
+ var n = Object.create(null);
22
+ if (e) {
23
+ Object.keys(e).forEach(function (k) {
24
+ if (k !== 'default') {
25
+ var d = Object.getOwnPropertyDescriptor(e, k);
26
+ Object.defineProperty(n, k, d.get ? d : {
27
+ enumerable: true,
28
+ get: function () { return e[k]; }
29
+ });
30
+ }
31
+ });
32
+ }
33
+ n["default"] = e;
34
+ return Object.freeze(n);
35
+ }
36
+
37
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
38
+ var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
39
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
40
+ var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
41
+ var Icon__default = /*#__PURE__*/_interopDefaultLegacy(Icon);
42
+ var Spacing__default = /*#__PURE__*/_interopDefaultLegacy(Spacing);
43
+
44
+ const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "light", "pressed", "size", "style", "testId", "type", "spinner", "icon", "id", "waiting"];
45
+ const StyledAnchor = wonderBlocksCore.addStyle("a");
46
+ const StyledButton = wonderBlocksCore.addStyle("button");
47
+ const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
48
+ class ButtonCore extends React__namespace.Component {
49
+ renderInner(router) {
50
+ const _this$props = this.props,
51
+ {
52
+ children,
53
+ skipClientNav,
54
+ color,
55
+ disabled: disabledProp,
56
+ focused,
57
+ hovered,
58
+ href = undefined,
59
+ kind,
60
+ light,
61
+ pressed,
62
+ size,
63
+ style,
64
+ testId,
65
+ type = undefined,
66
+ spinner,
67
+ icon,
68
+ id
69
+ } = _this$props,
70
+ restProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$1);
71
+
72
+ const buttonColor = color === "destructive" ? Color.SemanticColor.controlDestructive : Color.SemanticColor.controlDefault;
73
+ const iconWidth = icon ? (size === "small" ? 16 : 24) + 8 : 0;
74
+
75
+ const buttonStyles = _generateStyles(buttonColor, kind, light, iconWidth, size);
76
+
77
+ const disabled = spinner || disabledProp;
78
+ 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 === "large" && sharedStyles.large];
79
+
80
+ const commonProps = _extends__default["default"]({
81
+ "data-test-id": testId,
82
+ id: id,
83
+ role: "button",
84
+ style: [defaultStyle, style]
85
+ }, restProps);
86
+
87
+ const Label = size === "small" ? wonderBlocksTypography.LabelSmall : wonderBlocksTypography.LabelLarge;
88
+ const iconSize = size === "small" ? "small" : "medium";
89
+ const label = React__namespace.createElement(Label, {
90
+ style: [sharedStyles.text, size === "large" && sharedStyles.largeText, icon && sharedStyles.textWithIcon, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, kind === "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)]
91
+ }, icon && React__namespace.createElement(Icon__default["default"], {
92
+ size: iconSize,
93
+ color: "currentColor",
94
+ icon: icon,
95
+ style: sharedStyles.icon
96
+ }), children);
97
+ const contents = React__namespace.createElement(React__namespace.Fragment, null, label, spinner && React__namespace.createElement(wonderBlocksProgressSpinner.CircularSpinner, {
98
+ style: sharedStyles.spinner,
99
+ size: {
100
+ medium: "small",
101
+ small: "xsmall",
102
+ large: "medium"
103
+ }[size],
104
+ light: kind === "primary",
105
+ testId: `${testId || "button"}-spinner`
106
+ }));
107
+
108
+ if (href && !disabled) {
109
+ return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends__default["default"]({}, commonProps, {
110
+ to: href
111
+ }), contents) : React__namespace.createElement(StyledAnchor, _extends__default["default"]({}, commonProps, {
112
+ href: href
113
+ }), contents);
114
+ } else {
115
+ return React__namespace.createElement(StyledButton, _extends__default["default"]({
116
+ type: type || "button"
117
+ }, commonProps, {
118
+ "aria-disabled": disabled
119
+ }), contents);
120
+ }
121
+ }
122
+
123
+ render() {
124
+ return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderInner(router));
125
+ }
126
+
127
+ }
128
+ const sharedStyles = aphrodite.StyleSheet.create({
129
+ shared: {
130
+ position: "relative",
131
+ display: "inline-flex",
132
+ alignItems: "center",
133
+ justifyContent: "center",
134
+ height: 40,
135
+ paddingTop: 0,
136
+ paddingBottom: 0,
137
+ paddingLeft: 16,
138
+ paddingRight: 16,
139
+ border: "none",
140
+ borderRadius: 4,
141
+ cursor: "pointer",
142
+ outline: "none",
143
+ textDecoration: "none",
144
+ boxSizing: "border-box",
145
+ touchAction: "manipulation",
146
+ userSelect: "none",
147
+ ":focus": {
148
+ WebkitTapHighlightColor: "rgba(0,0,0,0)"
149
+ }
150
+ },
151
+ withIcon: {
152
+ paddingLeft: 12
153
+ },
154
+ disabled: {
155
+ cursor: "auto"
156
+ },
157
+ small: {
158
+ height: 32
159
+ },
160
+ large: {
161
+ borderRadius: Spacing__default["default"].xxSmall_6,
162
+ height: 56
163
+ },
164
+ text: {
165
+ alignItems: "center",
166
+ fontWeight: "bold",
167
+ whiteSpace: "nowrap",
168
+ overflow: "hidden",
169
+ textOverflow: "ellipsis",
170
+ display: "inline-block",
171
+ pointerEvents: "none"
172
+ },
173
+ largeText: {
174
+ fontSize: 18,
175
+ lineHeight: "20px"
176
+ },
177
+ textWithIcon: {
178
+ display: "flex"
179
+ },
180
+ textWithFocus: {
181
+ position: "relative"
182
+ },
183
+ hiddenText: {
184
+ visibility: "hidden"
185
+ },
186
+ spinner: {
187
+ position: "absolute"
188
+ },
189
+ icon: {
190
+ paddingRight: Spacing__default["default"].xSmall_8
191
+ }
192
+ });
193
+ const styles = {};
194
+
195
+ const _generateStyles = (color, kind, light, iconWidth, size) => {
196
+ const buttonType = color + kind + light.toString() + iconWidth.toString() + size;
197
+
198
+ if (styles[buttonType]) {
199
+ return styles[buttonType];
200
+ }
201
+
202
+ const {
203
+ white,
204
+ white50,
205
+ white64,
206
+ offBlack32,
207
+ offBlack50,
208
+ darkBlue
209
+ } = Color__default["default"];
210
+ const fadedColor = Color.mix(Color.fade(color, 0.32), white);
211
+ const activeColor = Color.mix(offBlack32, color);
212
+ const padding = size === "large" ? Spacing__default["default"].xLarge_32 : Spacing__default["default"].medium_16;
213
+ let newStyles = {};
214
+
215
+ if (kind === "primary") {
216
+ newStyles = {
217
+ default: {
218
+ background: light ? white : color,
219
+ color: light ? color : white,
220
+ paddingLeft: padding,
221
+ paddingRight: padding
222
+ },
223
+ focus: {
224
+ boxShadow: `0 0 0 1px ${light ? darkBlue : white}, 0 0 0 3px ${light ? white : color}`
225
+ },
226
+ active: {
227
+ boxShadow: `0 0 0 1px ${light ? darkBlue : white}, 0 0 0 3px ${light ? fadedColor : activeColor}`,
228
+ background: light ? fadedColor : activeColor,
229
+ color: light ? activeColor : fadedColor
230
+ },
231
+ disabled: {
232
+ background: light ? fadedColor : offBlack32,
233
+ color: light ? color : white64,
234
+ cursor: "default",
235
+ ":focus": {
236
+ boxShadow: `0 0 0 1px ${light ? offBlack32 : white}, 0 0 0 3px ${light ? fadedColor : offBlack32}`
237
+ }
238
+ }
239
+ };
240
+ } else if (kind === "secondary") {
241
+ newStyles = {
242
+ default: {
243
+ background: "none",
244
+ color: light ? white : color,
245
+ borderColor: light ? white50 : offBlack50,
246
+ borderStyle: "solid",
247
+ borderWidth: 1,
248
+ paddingLeft: iconWidth ? padding - 4 : padding,
249
+ paddingRight: padding
250
+ },
251
+ focus: {
252
+ background: light ? "transparent" : white,
253
+ borderColor: light ? white : color,
254
+ borderWidth: 2,
255
+ paddingLeft: iconWidth ? padding - 5 : padding - 1,
256
+ paddingRight: padding - 1
257
+ },
258
+ active: {
259
+ background: light ? activeColor : fadedColor,
260
+ color: light ? fadedColor : activeColor,
261
+ borderColor: light ? fadedColor : activeColor,
262
+ borderWidth: 2,
263
+ paddingLeft: iconWidth ? padding - 5 : padding - 1,
264
+ paddingRight: padding - 1
265
+ },
266
+ disabled: {
267
+ color: light ? white50 : offBlack32,
268
+ borderColor: light ? fadedColor : offBlack32,
269
+ cursor: "default",
270
+ ":focus": {
271
+ borderColor: light ? white50 : offBlack32,
272
+ borderWidth: 2,
273
+ paddingLeft: iconWidth ? padding - 5 : padding - 1,
274
+ paddingRight: padding - 1
275
+ }
276
+ }
277
+ };
278
+ } else if (kind === "tertiary") {
279
+ newStyles = {
280
+ default: {
281
+ background: "none",
282
+ color: light ? white : color,
283
+ paddingLeft: 0,
284
+ paddingRight: 0
285
+ },
286
+ focus: {
287
+ ":after": {
288
+ content: "''",
289
+ position: "absolute",
290
+ height: 2,
291
+ width: `calc(100% - ${iconWidth}px)`,
292
+ right: 0,
293
+ bottom: 0,
294
+ background: light ? white : color,
295
+ borderRadius: 2
296
+ }
297
+ },
298
+ active: {
299
+ color: light ? fadedColor : activeColor,
300
+ ":after": {
301
+ content: "''",
302
+ position: "absolute",
303
+ height: 2,
304
+ width: `calc(100% - ${iconWidth}px)`,
305
+ right: 0,
306
+ bottom: -1,
307
+ background: light ? fadedColor : activeColor,
308
+ borderRadius: 2
309
+ }
310
+ },
311
+ disabled: {
312
+ color: light ? fadedColor : offBlack32,
313
+ cursor: "default",
314
+ ":focus": {
315
+ ":after": {
316
+ content: "''",
317
+ position: "absolute",
318
+ height: 2,
319
+ width: `calc(100% - ${iconWidth}px)`,
320
+ right: 0,
321
+ bottom: `calc(50% - 11px)`,
322
+ background: light ? white : offBlack32,
323
+ borderRadius: 2
324
+ }
325
+ }
326
+ }
327
+ };
328
+ } else {
329
+ throw new Error("Button kind not recognized");
330
+ }
331
+
332
+ styles[buttonType] = aphrodite.StyleSheet.create(newStyles);
333
+ return styles[buttonType];
334
+ };
335
+
336
+ const _excluded = ["href", "type", "children", "skipClientNav", "spinner", "disabled", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel"];
337
+ class Button extends React__namespace.Component {
338
+ renderClickableBehavior(router) {
339
+ const _this$props = this.props,
340
+ {
341
+ href = undefined,
342
+ type = undefined,
343
+ children,
344
+ skipClientNav,
345
+ spinner,
346
+ disabled,
347
+ onClick,
348
+ beforeNav = undefined,
349
+ safeWithNav = undefined,
350
+ tabIndex,
351
+ target,
352
+ rel
353
+ } = _this$props,
354
+ sharedButtonCoreProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
355
+
356
+ const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
357
+
358
+ const renderProp = (state, _ref) => {
359
+ let restChildProps = _extends__default["default"]({}, _ref);
360
+
361
+ return React__namespace.createElement(ButtonCore, _extends__default["default"]({}, sharedButtonCoreProps, state, restChildProps, {
362
+ disabled: disabled,
363
+ spinner: spinner || state.waiting,
364
+ skipClientNav: skipClientNav,
365
+ href: href,
366
+ target: target,
367
+ type: type,
368
+ tabIndex: tabIndex
369
+ }), children);
370
+ };
371
+
372
+ if (beforeNav) {
373
+ return React__namespace.createElement(ClickableBehavior, {
374
+ disabled: spinner || disabled,
375
+ href: href,
376
+ role: "button",
377
+ type: type,
378
+ onClick: onClick,
379
+ beforeNav: beforeNav,
380
+ safeWithNav: safeWithNav,
381
+ rel: rel
382
+ }, renderProp);
383
+ } else {
384
+ return React__namespace.createElement(ClickableBehavior, {
385
+ disabled: spinner || disabled,
386
+ href: href,
387
+ role: "button",
388
+ type: type,
389
+ onClick: onClick,
390
+ safeWithNav: safeWithNav,
391
+ target: target,
392
+ rel: rel
393
+ }, renderProp);
394
+ }
395
+ }
396
+
397
+ render() {
398
+ return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
399
+ }
400
+
401
+ }
402
+ Button.defaultProps = {
403
+ color: "default",
404
+ kind: "primary",
405
+ light: false,
406
+ size: "medium",
407
+ disabled: false,
408
+ spinner: false
409
+ };
410
+
411
+ module.exports = Button;
@@ -0,0 +1,2 @@
1
+ // @flow
2
+ export * from "../src/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-button",
3
- "version": "3.0.10",
3
+ "version": "3.0.12",
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.18.6",
19
- "@khanacademy/wonder-blocks-clickable": "^2.4.2",
19
+ "@khanacademy/wonder-blocks-clickable": "^2.4.4",
20
20
  "@khanacademy/wonder-blocks-color": "^1.2.0",
21
- "@khanacademy/wonder-blocks-core": "^4.6.0",
22
- "@khanacademy/wonder-blocks-icon": "^1.2.33",
23
- "@khanacademy/wonder-blocks-progress-spinner": "^1.1.37",
21
+ "@khanacademy/wonder-blocks-core": "^4.6.2",
22
+ "@khanacademy/wonder-blocks-icon": "^1.2.35",
23
+ "@khanacademy/wonder-blocks-progress-spinner": "^1.1.39",
24
24
  "@khanacademy/wonder-blocks-spacing": "^3.0.5",
25
- "@khanacademy/wonder-blocks-typography": "^1.1.35"
25
+ "@khanacademy/wonder-blocks-typography": "^1.1.37"
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.5.0"
34
+ "wb-dev-build-settings": "^0.7.0"
35
35
  }
36
36
  }