@khanacademy/wonder-blocks-button 2.9.13 → 2.10.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/dist/es/index.js +17 -15
- package/dist/index.js +188 -249
- package/package.json +14 -14
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +240 -11
- package/src/__tests__/generated-snapshot.test.js +74 -12
- package/src/components/__docs__/accessibility.stories.mdx +92 -0
- package/src/components/__docs__/best-practices.stories.mdx +107 -0
- package/src/components/__docs__/button.argtypes.js +231 -0
- package/src/components/__docs__/navigation-callbacks.stories.mdx +68 -0
- package/src/components/__tests__/button.test.js +11 -0
- package/src/components/button-core.js +10 -9
- package/src/components/button.js +20 -16
- package/src/components/button.md +134 -23
- package/src/components/button.stories.js +413 -104
package/dist/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
2
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
3
3
|
import { Component, createElement, Fragment } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { __RouterContext } from 'react-router';
|
|
5
5
|
import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
|
|
6
6
|
import { StyleSheet } from 'aphrodite';
|
|
7
7
|
import { Link } from 'react-router-dom';
|
|
@@ -17,7 +17,7 @@ const StyledAnchor = addStyle("a");
|
|
|
17
17
|
const StyledButton = addStyle("button");
|
|
18
18
|
const StyledLink = addStyle(Link);
|
|
19
19
|
class ButtonCore extends Component {
|
|
20
|
-
|
|
20
|
+
renderInner(router) {
|
|
21
21
|
const _this$props = this.props,
|
|
22
22
|
{
|
|
23
23
|
children,
|
|
@@ -40,9 +40,6 @@ class ButtonCore extends Component {
|
|
|
40
40
|
} = _this$props,
|
|
41
41
|
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
42
42
|
|
|
43
|
-
const {
|
|
44
|
-
router
|
|
45
|
-
} = this.context;
|
|
46
43
|
const buttonColor = color === "destructive" ? SemanticColor.controlDestructive : SemanticColor.controlDefault;
|
|
47
44
|
const iconWidth = icon ? (size === "small" ? 16 : 24) + 8 : 0;
|
|
48
45
|
|
|
@@ -94,10 +91,11 @@ class ButtonCore extends Component {
|
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
93
|
|
|
94
|
+
render() {
|
|
95
|
+
return /*#__PURE__*/createElement(__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
96
|
+
}
|
|
97
|
+
|
|
97
98
|
}
|
|
98
|
-
ButtonCore.contextTypes = {
|
|
99
|
-
router: any
|
|
100
|
-
};
|
|
101
99
|
const sharedStyles = StyleSheet.create({
|
|
102
100
|
shared: {
|
|
103
101
|
position: "relative",
|
|
@@ -311,17 +309,20 @@ const _excluded$1 = ["href", "type", "children", "skipClientNav", "spinner", "di
|
|
|
311
309
|
* `ButtonCore` is a stateless component which displays the different states
|
|
312
310
|
* the `Button` can take.
|
|
313
311
|
*
|
|
314
|
-
*
|
|
312
|
+
* ### Usage
|
|
313
|
+
*
|
|
315
314
|
* ```jsx
|
|
315
|
+
* import Button from "@khanacademy/wonder-blocks-button";
|
|
316
|
+
*
|
|
316
317
|
* <Button
|
|
317
318
|
* onClick={(e) => console.log("Hello, world!")}
|
|
318
319
|
* >
|
|
319
|
-
*
|
|
320
|
+
* Hello, world!
|
|
320
321
|
* </Button>
|
|
321
322
|
* ```
|
|
322
323
|
*/
|
|
323
324
|
class Button extends Component {
|
|
324
|
-
|
|
325
|
+
renderClickableBehavior(router) {
|
|
325
326
|
const _this$props = this.props,
|
|
326
327
|
{
|
|
327
328
|
href = undefined,
|
|
@@ -339,7 +340,7 @@ class Button extends Component {
|
|
|
339
340
|
} = _this$props,
|
|
340
341
|
sharedButtonCoreProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
341
342
|
|
|
342
|
-
const ClickableBehavior = getClickableBehavior(href, skipClientNav,
|
|
343
|
+
const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
|
|
343
344
|
|
|
344
345
|
const renderProp = (state, _ref) => {
|
|
345
346
|
let {
|
|
@@ -386,10 +387,11 @@ class Button extends Component {
|
|
|
386
387
|
}
|
|
387
388
|
}
|
|
388
389
|
|
|
390
|
+
render() {
|
|
391
|
+
return /*#__PURE__*/createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
392
|
+
}
|
|
393
|
+
|
|
389
394
|
}
|
|
390
|
-
Button.contextTypes = {
|
|
391
|
-
router: any
|
|
392
|
-
};
|
|
393
395
|
Button.defaultProps = {
|
|
394
396
|
color: "default",
|
|
395
397
|
kind: "primary",
|
package/dist/index.js
CHANGED
|
@@ -95,169 +95,190 @@ module.exports = require("react");
|
|
|
95
95
|
/* 1 */
|
|
96
96
|
/***/ (function(module, exports) {
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
module.exports = _extends = Object.assign || function (target) {
|
|
100
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
101
|
-
var source = arguments[i];
|
|
102
|
-
|
|
103
|
-
for (var key in source) {
|
|
104
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
105
|
-
target[key] = source[key];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return target;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
114
|
-
return _extends.apply(this, arguments);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
module.exports = _extends;
|
|
118
|
-
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
98
|
+
module.exports = require("@khanacademy/wonder-blocks-color");
|
|
119
99
|
|
|
120
100
|
/***/ }),
|
|
121
101
|
/* 2 */
|
|
122
102
|
/***/ (function(module, exports) {
|
|
123
103
|
|
|
124
|
-
module.exports = require("
|
|
104
|
+
module.exports = require("react-router");
|
|
125
105
|
|
|
126
106
|
/***/ }),
|
|
127
107
|
/* 3 */
|
|
128
108
|
/***/ (function(module, exports) {
|
|
129
109
|
|
|
130
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
131
|
-
if (source == null) return {};
|
|
132
|
-
var target = {};
|
|
133
|
-
var sourceKeys = Object.keys(source);
|
|
134
|
-
var key, i;
|
|
135
|
-
|
|
136
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
137
|
-
key = sourceKeys[i];
|
|
138
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
139
|
-
target[key] = source[key];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return target;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
module.exports = _objectWithoutPropertiesLoose;
|
|
146
|
-
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
147
|
-
|
|
148
|
-
/***/ }),
|
|
149
|
-
/* 4 */
|
|
150
|
-
/***/ (function(module, exports) {
|
|
151
|
-
|
|
152
|
-
module.exports = require("prop-types");
|
|
153
|
-
|
|
154
|
-
/***/ }),
|
|
155
|
-
/* 5 */
|
|
156
|
-
/***/ (function(module, exports) {
|
|
157
|
-
|
|
158
110
|
module.exports = require("@khanacademy/wonder-blocks-clickable");
|
|
159
111
|
|
|
160
112
|
/***/ }),
|
|
161
|
-
/*
|
|
113
|
+
/* 4 */
|
|
162
114
|
/***/ (function(module, exports) {
|
|
163
115
|
|
|
164
116
|
module.exports = require("@khanacademy/wonder-blocks-core");
|
|
165
117
|
|
|
166
118
|
/***/ }),
|
|
167
|
-
/*
|
|
119
|
+
/* 5 */
|
|
168
120
|
/***/ (function(module, exports) {
|
|
169
121
|
|
|
170
122
|
module.exports = require("@khanacademy/wonder-blocks-spacing");
|
|
171
123
|
|
|
172
124
|
/***/ }),
|
|
173
|
-
/*
|
|
125
|
+
/* 6 */
|
|
174
126
|
/***/ (function(module, exports) {
|
|
175
127
|
|
|
176
128
|
module.exports = require("aphrodite");
|
|
177
129
|
|
|
178
130
|
/***/ }),
|
|
179
|
-
/*
|
|
131
|
+
/* 7 */
|
|
180
132
|
/***/ (function(module, exports) {
|
|
181
133
|
|
|
182
134
|
module.exports = require("@khanacademy/wonder-blocks-typography");
|
|
183
135
|
|
|
184
136
|
/***/ }),
|
|
185
|
-
/*
|
|
186
|
-
/***/ (function(module, exports) {
|
|
187
|
-
|
|
188
|
-
module.exports = require("react-router-dom");
|
|
189
|
-
|
|
190
|
-
/***/ }),
|
|
191
|
-
/* 11 */
|
|
192
|
-
/***/ (function(module, exports) {
|
|
193
|
-
|
|
194
|
-
module.exports = require("@khanacademy/wonder-blocks-progress-spinner");
|
|
195
|
-
|
|
196
|
-
/***/ }),
|
|
197
|
-
/* 12 */
|
|
198
|
-
/***/ (function(module, exports) {
|
|
199
|
-
|
|
200
|
-
module.exports = require("@khanacademy/wonder-blocks-icon");
|
|
201
|
-
|
|
202
|
-
/***/ }),
|
|
203
|
-
/* 13 */
|
|
137
|
+
/* 8 */
|
|
204
138
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
205
139
|
|
|
206
140
|
"use strict";
|
|
207
|
-
|
|
208
|
-
__webpack_require__
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
var
|
|
215
|
-
var
|
|
216
|
-
|
|
217
|
-
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js
|
|
218
|
-
var objectWithoutPropertiesLoose = __webpack_require__(3);
|
|
219
|
-
var objectWithoutPropertiesLoose_default = /*#__PURE__*/__webpack_require__.n(objectWithoutPropertiesLoose);
|
|
141
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Button; });
|
|
142
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
143
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
144
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
|
|
145
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_router__WEBPACK_IMPORTED_MODULE_1__);
|
|
146
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
|
|
147
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__);
|
|
148
|
+
/* harmony import */ var _button_core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9);
|
|
149
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
220
150
|
|
|
221
|
-
// EXTERNAL MODULE: external "react"
|
|
222
|
-
var external_react_ = __webpack_require__(0);
|
|
223
151
|
|
|
224
|
-
// EXTERNAL MODULE: external "prop-types"
|
|
225
|
-
var external_prop_types_ = __webpack_require__(4);
|
|
226
152
|
|
|
227
|
-
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-clickable"
|
|
228
|
-
var wonder_blocks_clickable_ = __webpack_require__(5);
|
|
229
153
|
|
|
230
|
-
// EXTERNAL MODULE: external "aphrodite"
|
|
231
|
-
var external_aphrodite_ = __webpack_require__(8);
|
|
232
154
|
|
|
233
|
-
// EXTERNAL MODULE: external "react-router-dom"
|
|
234
|
-
var external_react_router_dom_ = __webpack_require__(10);
|
|
235
155
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Reusable button component.
|
|
158
|
+
*
|
|
159
|
+
* Consisting of a [`ClickableBehavior`](#clickablebehavior) surrounding a
|
|
160
|
+
* `ButtonCore`. `ClickableBehavior` handles interactions and state changes.
|
|
161
|
+
* `ButtonCore` is a stateless component which displays the different states
|
|
162
|
+
* the `Button` can take.
|
|
163
|
+
*
|
|
164
|
+
* ### Usage
|
|
165
|
+
*
|
|
166
|
+
* ```jsx
|
|
167
|
+
* import Button from "@khanacademy/wonder-blocks-button";
|
|
168
|
+
*
|
|
169
|
+
* <Button
|
|
170
|
+
* onClick={(e) => console.log("Hello, world!")}
|
|
171
|
+
* >
|
|
172
|
+
* Hello, world!
|
|
173
|
+
* </Button>
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
class Button extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
177
|
+
renderClickableBehavior(router) {
|
|
178
|
+
const {
|
|
179
|
+
href = undefined,
|
|
180
|
+
type = undefined,
|
|
181
|
+
children,
|
|
182
|
+
skipClientNav,
|
|
183
|
+
spinner,
|
|
184
|
+
disabled,
|
|
185
|
+
onClick,
|
|
186
|
+
beforeNav = undefined,
|
|
187
|
+
safeWithNav = undefined,
|
|
188
|
+
tabIndex,
|
|
189
|
+
target,
|
|
190
|
+
rel,
|
|
191
|
+
...sharedButtonCoreProps
|
|
192
|
+
} = this.props;
|
|
193
|
+
const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__["getClickableBehavior"])(href, skipClientNav, router);
|
|
194
|
+
|
|
195
|
+
const renderProp = (state, {
|
|
196
|
+
tabIndex: clickableTabIndex,
|
|
197
|
+
...restChildProps
|
|
198
|
+
}) => {
|
|
199
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_button_core_js__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"], _extends({}, sharedButtonCoreProps, state, restChildProps, {
|
|
200
|
+
disabled: disabled,
|
|
201
|
+
spinner: spinner || state.waiting,
|
|
202
|
+
skipClientNav: skipClientNav,
|
|
203
|
+
href: href,
|
|
204
|
+
target: target,
|
|
205
|
+
type: type // If tabIndex is provide to the component we allow
|
|
206
|
+
// it to override the tabIndex provide to use by
|
|
207
|
+
// ClickableBehavior.
|
|
208
|
+
,
|
|
209
|
+
tabIndex: tabIndex || clickableTabIndex
|
|
210
|
+
}), children);
|
|
211
|
+
};
|
|
245
212
|
|
|
246
|
-
|
|
247
|
-
|
|
213
|
+
if (beforeNav) {
|
|
214
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ClickableBehavior, {
|
|
215
|
+
disabled: spinner || disabled,
|
|
216
|
+
href: href,
|
|
217
|
+
role: "button",
|
|
218
|
+
type: type,
|
|
219
|
+
onClick: onClick,
|
|
220
|
+
beforeNav: beforeNav,
|
|
221
|
+
safeWithNav: safeWithNav,
|
|
222
|
+
rel: rel
|
|
223
|
+
}, renderProp);
|
|
224
|
+
} else {
|
|
225
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ClickableBehavior, {
|
|
226
|
+
disabled: spinner || disabled,
|
|
227
|
+
href: href,
|
|
228
|
+
role: "button",
|
|
229
|
+
type: type,
|
|
230
|
+
onClick: onClick,
|
|
231
|
+
safeWithNav: safeWithNav,
|
|
232
|
+
target: target,
|
|
233
|
+
rel: rel
|
|
234
|
+
}, renderProp);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
248
237
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
238
|
+
render() {
|
|
239
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router__WEBPACK_IMPORTED_MODULE_1__["__RouterContext"].Consumer, null, router => this.renderClickableBehavior(router));
|
|
240
|
+
}
|
|
252
241
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
242
|
+
}
|
|
243
|
+
Button.defaultProps = {
|
|
244
|
+
color: "default",
|
|
245
|
+
kind: "primary",
|
|
246
|
+
light: false,
|
|
247
|
+
size: "medium",
|
|
248
|
+
disabled: false,
|
|
249
|
+
spinner: false
|
|
250
|
+
};
|
|
256
251
|
|
|
257
|
-
|
|
252
|
+
/***/ }),
|
|
253
|
+
/* 9 */
|
|
254
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
258
255
|
|
|
256
|
+
"use strict";
|
|
257
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ButtonCore; });
|
|
258
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
259
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
260
|
+
/* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6);
|
|
261
|
+
/* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_1__);
|
|
262
|
+
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
|
|
263
|
+
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_2__);
|
|
264
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2);
|
|
265
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(react_router__WEBPACK_IMPORTED_MODULE_3__);
|
|
266
|
+
/* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7);
|
|
267
|
+
/* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__);
|
|
268
|
+
/* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(1);
|
|
269
|
+
/* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__);
|
|
270
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(4);
|
|
271
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_6__);
|
|
272
|
+
/* harmony import */ var _khanacademy_wonder_blocks_progress_spinner__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(11);
|
|
273
|
+
/* harmony import */ var _khanacademy_wonder_blocks_progress_spinner__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_progress_spinner__WEBPACK_IMPORTED_MODULE_7__);
|
|
274
|
+
/* harmony import */ var _khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(12);
|
|
275
|
+
/* harmony import */ var _khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_8__);
|
|
276
|
+
/* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(5);
|
|
277
|
+
/* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_9__);
|
|
278
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(3);
|
|
279
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_10__);
|
|
280
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
259
281
|
|
|
260
|
-
const _excluded = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "light", "pressed", "size", "style", "testId", "type", "spinner", "icon", "id", "waiting"];
|
|
261
282
|
|
|
262
283
|
|
|
263
284
|
|
|
@@ -269,13 +290,12 @@ const _excluded = ["children", "skipClientNav", "color", "disabled", "focused",
|
|
|
269
290
|
|
|
270
291
|
|
|
271
292
|
|
|
272
|
-
const StyledAnchor = Object(
|
|
273
|
-
const StyledButton = Object(
|
|
274
|
-
const StyledLink = Object(
|
|
275
|
-
class
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
{
|
|
293
|
+
const StyledAnchor = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_6__["addStyle"])("a");
|
|
294
|
+
const StyledButton = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_6__["addStyle"])("button");
|
|
295
|
+
const StyledLink = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_6__["addStyle"])(react_router_dom__WEBPACK_IMPORTED_MODULE_2__["Link"]);
|
|
296
|
+
class ButtonCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
297
|
+
renderInner(router) {
|
|
298
|
+
const {
|
|
279
299
|
children,
|
|
280
300
|
skipClientNav,
|
|
281
301
|
color,
|
|
@@ -292,14 +312,11 @@ class button_core_ButtonCore extends external_react_["Component"] {
|
|
|
292
312
|
type = undefined,
|
|
293
313
|
spinner,
|
|
294
314
|
icon,
|
|
295
|
-
id
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const
|
|
300
|
-
router
|
|
301
|
-
} = this.context;
|
|
302
|
-
const buttonColor = color === "destructive" ? wonder_blocks_color_["SemanticColor"].controlDestructive : wonder_blocks_color_["SemanticColor"].controlDefault;
|
|
315
|
+
id,
|
|
316
|
+
waiting: _,
|
|
317
|
+
...restProps
|
|
318
|
+
} = this.props;
|
|
319
|
+
const buttonColor = color === "destructive" ? _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["SemanticColor"].controlDestructive : _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["SemanticColor"].controlDefault;
|
|
303
320
|
const iconWidth = icon ? (size === "small" ? 16 : 24) + 8 : 0;
|
|
304
321
|
|
|
305
322
|
const buttonStyles = _generateStyles(buttonColor, kind, light, iconWidth, size);
|
|
@@ -307,25 +324,24 @@ class button_core_ButtonCore extends external_react_["Component"] {
|
|
|
307
324
|
const disabled = spinner || disabledProp;
|
|
308
325
|
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, icon && sharedStyles.withIcon, buttonStyles.default, disabled && buttonStyles.disabled, // apply focus effect only to default and secondary buttons
|
|
309
326
|
kind !== "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus), size === "small" && sharedStyles.small, size === "xlarge" && sharedStyles.xlarge];
|
|
310
|
-
|
|
311
|
-
const commonProps = extends_default()({
|
|
327
|
+
const commonProps = {
|
|
312
328
|
"data-test-id": testId,
|
|
313
329
|
id: id,
|
|
314
330
|
role: "button",
|
|
315
|
-
style: [defaultStyle, style]
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const Label = size === "small" ?
|
|
319
|
-
const label = /*#__PURE__*/
|
|
331
|
+
style: [defaultStyle, style],
|
|
332
|
+
...restProps
|
|
333
|
+
};
|
|
334
|
+
const Label = size === "small" ? _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelSmall"] : _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelLarge"];
|
|
335
|
+
const label = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](Label, {
|
|
320
336
|
style: [sharedStyles.text, size === "xlarge" && sharedStyles.xlargeText, icon && sharedStyles.textWithIcon, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, // apply focus effect on the label instead
|
|
321
337
|
kind === "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)]
|
|
322
|
-
}, icon && /*#__PURE__*/
|
|
338
|
+
}, icon && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_8___default.a, {
|
|
323
339
|
size: size,
|
|
324
340
|
color: "currentColor",
|
|
325
341
|
icon: icon,
|
|
326
342
|
style: sharedStyles.icon
|
|
327
343
|
}), children);
|
|
328
|
-
const contents = /*#__PURE__*/
|
|
344
|
+
const contents = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react__WEBPACK_IMPORTED_MODULE_0__["Fragment"], null, label, spinner && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_progress_spinner__WEBPACK_IMPORTED_MODULE_7__["CircularSpinner"], {
|
|
329
345
|
style: sharedStyles.spinner,
|
|
330
346
|
size: {
|
|
331
347
|
medium: "small",
|
|
@@ -336,13 +352,13 @@ class button_core_ButtonCore extends external_react_["Component"] {
|
|
|
336
352
|
}));
|
|
337
353
|
|
|
338
354
|
if (href && !disabled) {
|
|
339
|
-
return router && !skipClientNav && Object(
|
|
355
|
+
return router && !skipClientNav && Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_10__["isClientSideUrl"])(href) ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledLink, _extends({}, commonProps, {
|
|
340
356
|
to: href
|
|
341
|
-
}), contents) : /*#__PURE__*/
|
|
357
|
+
}), contents) : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledAnchor, _extends({}, commonProps, {
|
|
342
358
|
href: href
|
|
343
359
|
}), contents);
|
|
344
360
|
} else {
|
|
345
|
-
return /*#__PURE__*/
|
|
361
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledButton, _extends({
|
|
346
362
|
type: type || "button"
|
|
347
363
|
}, commonProps, {
|
|
348
364
|
disabled: disabled
|
|
@@ -350,11 +366,12 @@ class button_core_ButtonCore extends external_react_["Component"] {
|
|
|
350
366
|
}
|
|
351
367
|
}
|
|
352
368
|
|
|
369
|
+
render() {
|
|
370
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router__WEBPACK_IMPORTED_MODULE_3__["__RouterContext"].Consumer, null, router => this.renderInner(router));
|
|
371
|
+
}
|
|
372
|
+
|
|
353
373
|
}
|
|
354
|
-
|
|
355
|
-
router: external_prop_types_["any"]
|
|
356
|
-
};
|
|
357
|
-
const sharedStyles = external_aphrodite_["StyleSheet"].create({
|
|
374
|
+
const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
|
|
358
375
|
shared: {
|
|
359
376
|
position: "relative",
|
|
360
377
|
display: "inline-flex",
|
|
@@ -423,7 +440,7 @@ const sharedStyles = external_aphrodite_["StyleSheet"].create({
|
|
|
423
440
|
position: "absolute"
|
|
424
441
|
},
|
|
425
442
|
icon: {
|
|
426
|
-
paddingRight:
|
|
443
|
+
paddingRight: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_9___default.a.xSmall_8
|
|
427
444
|
}
|
|
428
445
|
});
|
|
429
446
|
const styles = {};
|
|
@@ -442,10 +459,10 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
442
459
|
offBlack32,
|
|
443
460
|
offBlack50,
|
|
444
461
|
darkBlue
|
|
445
|
-
} =
|
|
446
|
-
const fadedColor = Object(
|
|
447
|
-
const activeColor = Object(
|
|
448
|
-
const padding = size === "xlarge" ?
|
|
462
|
+
} = _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5___default.a;
|
|
463
|
+
const fadedColor = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["fade"])(color, 0.32), white);
|
|
464
|
+
const activeColor = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["mix"])(offBlack32, color);
|
|
465
|
+
const padding = size === "xlarge" ? _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_9___default.a.xLarge_32 : _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_9___default.a.medium_16;
|
|
449
466
|
let newStyles = {};
|
|
450
467
|
|
|
451
468
|
if (kind === "primary") {
|
|
@@ -552,115 +569,37 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
552
569
|
throw new Error("Button kind not recognized");
|
|
553
570
|
}
|
|
554
571
|
|
|
555
|
-
styles[buttonType] =
|
|
572
|
+
styles[buttonType] = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create(newStyles);
|
|
556
573
|
return styles[buttonType];
|
|
557
574
|
};
|
|
558
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-button/src/components/button.js
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const button_excluded = ["href", "type", "children", "skipClientNav", "spinner", "disabled", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel"],
|
|
562
|
-
_excluded2 = ["tabIndex"];
|
|
563
|
-
|
|
564
575
|
|
|
576
|
+
/***/ }),
|
|
577
|
+
/* 10 */
|
|
578
|
+
/***/ (function(module, exports) {
|
|
565
579
|
|
|
580
|
+
module.exports = require("react-router-dom");
|
|
566
581
|
|
|
582
|
+
/***/ }),
|
|
583
|
+
/* 11 */
|
|
584
|
+
/***/ (function(module, exports) {
|
|
567
585
|
|
|
568
|
-
|
|
569
|
-
* Reusable button component.
|
|
570
|
-
*
|
|
571
|
-
* Consisting of a [`ClickableBehavior`](#clickablebehavior) surrounding a
|
|
572
|
-
* `ButtonCore`. `ClickableBehavior` handles interactions and state changes.
|
|
573
|
-
* `ButtonCore` is a stateless component which displays the different states
|
|
574
|
-
* the `Button` can take.
|
|
575
|
-
*
|
|
576
|
-
* Example usage:
|
|
577
|
-
* ```jsx
|
|
578
|
-
* <Button
|
|
579
|
-
* onClick={(e) => console.log("Hello, world!")}
|
|
580
|
-
* >
|
|
581
|
-
* Label
|
|
582
|
-
* </Button>
|
|
583
|
-
* ```
|
|
584
|
-
*/
|
|
585
|
-
class button_Button extends external_react_["Component"] {
|
|
586
|
-
render() {
|
|
587
|
-
const _this$props = this.props,
|
|
588
|
-
{
|
|
589
|
-
href = undefined,
|
|
590
|
-
type = undefined,
|
|
591
|
-
children,
|
|
592
|
-
skipClientNav,
|
|
593
|
-
spinner,
|
|
594
|
-
disabled,
|
|
595
|
-
onClick,
|
|
596
|
-
beforeNav = undefined,
|
|
597
|
-
safeWithNav = undefined,
|
|
598
|
-
tabIndex,
|
|
599
|
-
target,
|
|
600
|
-
rel
|
|
601
|
-
} = _this$props,
|
|
602
|
-
sharedButtonCoreProps = objectWithoutPropertiesLoose_default()(_this$props, button_excluded);
|
|
586
|
+
module.exports = require("@khanacademy/wonder-blocks-progress-spinner");
|
|
603
587
|
|
|
604
|
-
|
|
588
|
+
/***/ }),
|
|
589
|
+
/* 12 */
|
|
590
|
+
/***/ (function(module, exports) {
|
|
605
591
|
|
|
606
|
-
|
|
607
|
-
let {
|
|
608
|
-
tabIndex: clickableTabIndex
|
|
609
|
-
} = _ref,
|
|
610
|
-
restChildProps = objectWithoutPropertiesLoose_default()(_ref, _excluded2);
|
|
592
|
+
module.exports = require("@khanacademy/wonder-blocks-icon");
|
|
611
593
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
skipClientNav: skipClientNav,
|
|
616
|
-
href: href,
|
|
617
|
-
target: target,
|
|
618
|
-
type: type // If tabIndex is provide to the component we allow
|
|
619
|
-
// it to override the tabIndex provide to use by
|
|
620
|
-
// ClickableBehavior.
|
|
621
|
-
,
|
|
622
|
-
tabIndex: tabIndex || clickableTabIndex
|
|
623
|
-
}), children);
|
|
624
|
-
};
|
|
594
|
+
/***/ }),
|
|
595
|
+
/* 13 */
|
|
596
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
625
597
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
role: "button",
|
|
631
|
-
type: type,
|
|
632
|
-
onClick: onClick,
|
|
633
|
-
beforeNav: beforeNav,
|
|
634
|
-
safeWithNav: safeWithNav,
|
|
635
|
-
rel: rel
|
|
636
|
-
}, renderProp);
|
|
637
|
-
} else {
|
|
638
|
-
return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
|
|
639
|
-
disabled: spinner || disabled,
|
|
640
|
-
href: href,
|
|
641
|
-
role: "button",
|
|
642
|
-
type: type,
|
|
643
|
-
onClick: onClick,
|
|
644
|
-
safeWithNav: safeWithNav,
|
|
645
|
-
target: target,
|
|
646
|
-
rel: rel
|
|
647
|
-
}, renderProp);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
598
|
+
"use strict";
|
|
599
|
+
__webpack_require__.r(__webpack_exports__);
|
|
600
|
+
/* harmony import */ var _components_button_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
|
|
601
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _components_button_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
|
|
650
602
|
|
|
651
|
-
}
|
|
652
|
-
button_Button.contextTypes = {
|
|
653
|
-
router: external_prop_types_["any"]
|
|
654
|
-
};
|
|
655
|
-
button_Button.defaultProps = {
|
|
656
|
-
color: "default",
|
|
657
|
-
kind: "primary",
|
|
658
|
-
light: false,
|
|
659
|
-
size: "medium",
|
|
660
|
-
disabled: false,
|
|
661
|
-
spinner: false
|
|
662
|
-
};
|
|
663
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-button/src/index.js
|
|
664
603
|
|
|
665
604
|
|
|
666
605
|
|