@spark-web/button 1.0.3 → 1.1.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/README.md +93 -90
- package/dist/declarations/src/Button.d.ts +16 -4
- package/dist/declarations/src/ButtonLink.d.ts +1 -1
- package/dist/declarations/src/resolveButtonChildren.d.ts +3 -1
- package/dist/declarations/src/types.d.ts +6 -0
- package/dist/spark-web-button.cjs.dev.js +80 -53
- package/dist/spark-web-button.cjs.prod.js +80 -53
- package/dist/spark-web-button.esm.js +79 -33
- package/package.json +14 -10
- package/CHANGELOG.md +0 -79
- package/src/Button.stories.tsx +0 -34
- package/src/Button.test.tsx +0 -34
- package/src/Button.tsx +0 -110
- package/src/ButtonLink.tsx +0 -56
- package/src/index.ts +0 -7
- package/src/resolveButtonChildren.tsx +0 -57
- package/src/types.ts +0 -42
- package/src/useButtonStyles.ts +0 -96
- package/src/utils.ts +0 -170
|
@@ -4,37 +4,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
6
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
7
|
+
var a11y = require('@spark-web/a11y');
|
|
7
8
|
var box = require('@spark-web/box');
|
|
9
|
+
var spinner = require('@spark-web/spinner');
|
|
8
10
|
var internal = require('@spark-web/utils/internal');
|
|
9
|
-
var
|
|
11
|
+
var react = require('react');
|
|
10
12
|
var text = require('@spark-web/text');
|
|
11
13
|
var jsxRuntime = require('react/jsx-runtime');
|
|
12
14
|
var css = require('@emotion/css');
|
|
13
|
-
var a11y = require('@spark-web/a11y');
|
|
14
15
|
var theme = require('@spark-web/theme');
|
|
15
16
|
var link = require('@spark-web/link');
|
|
16
17
|
var ts = require('@spark-web/utils/ts');
|
|
17
18
|
|
|
18
|
-
function _interopNamespace(e) {
|
|
19
|
-
if (e && e.__esModule) return e;
|
|
20
|
-
var n = Object.create(null);
|
|
21
|
-
if (e) {
|
|
22
|
-
Object.keys(e).forEach(function (k) {
|
|
23
|
-
if (k !== 'default') {
|
|
24
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () { return e[k]; }
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
n["default"] = e;
|
|
33
|
-
return Object.freeze(n);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
37
|
-
|
|
38
19
|
var variants = {
|
|
39
20
|
high: {
|
|
40
21
|
primary: {
|
|
@@ -179,32 +160,39 @@ var mapTokens = {
|
|
|
179
160
|
|
|
180
161
|
var resolveButtonChildren = function resolveButtonChildren(_ref) {
|
|
181
162
|
var children = _ref.children,
|
|
163
|
+
isLoading = _ref.isLoading,
|
|
182
164
|
prominence = _ref.prominence,
|
|
183
165
|
size = _ref.size,
|
|
184
166
|
tone = _ref.tone;
|
|
185
167
|
var variant = variants[prominence][tone];
|
|
186
|
-
return
|
|
168
|
+
return react.Children.map(children, function (child) {
|
|
187
169
|
if (typeof child === 'string') {
|
|
188
|
-
return /*#__PURE__*/jsxRuntime.jsx(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
170
|
+
return /*#__PURE__*/jsxRuntime.jsx(HiddenWhenLoading, {
|
|
171
|
+
isLoading: isLoading,
|
|
172
|
+
children: /*#__PURE__*/jsxRuntime.jsx(text.Text, {
|
|
173
|
+
as: "span",
|
|
174
|
+
baseline: false,
|
|
175
|
+
overflowStrategy: "nowrap",
|
|
176
|
+
weight: "semibold",
|
|
177
|
+
size: mapTokens.fontSize[size],
|
|
178
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone,
|
|
179
|
+
children: child
|
|
180
|
+
})
|
|
196
181
|
});
|
|
197
182
|
}
|
|
198
183
|
|
|
199
|
-
if ( /*#__PURE__*/
|
|
200
|
-
return /*#__PURE__*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
184
|
+
if ( /*#__PURE__*/react.isValidElement(child)) {
|
|
185
|
+
return /*#__PURE__*/jsxRuntime.jsx(HiddenWhenLoading, {
|
|
186
|
+
isLoading: isLoading,
|
|
187
|
+
children: /*#__PURE__*/react.cloneElement(child, {
|
|
188
|
+
// Dismiss buttons need to be `xxsmall`
|
|
189
|
+
// For everything else, we force them to be `xsmall`
|
|
190
|
+
size: child.props.size === 'xxsmall' ? child.props.size : 'xsmall',
|
|
191
|
+
// If the button is low prominence with a decorative tone we want to force
|
|
192
|
+
// the tone to be the same as the button
|
|
193
|
+
// We also don't want users to override the tone of the icon inside of the button
|
|
194
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone
|
|
195
|
+
})
|
|
208
196
|
});
|
|
209
197
|
}
|
|
210
198
|
|
|
@@ -212,6 +200,19 @@ var resolveButtonChildren = function resolveButtonChildren(_ref) {
|
|
|
212
200
|
});
|
|
213
201
|
};
|
|
214
202
|
|
|
203
|
+
function HiddenWhenLoading(_ref2) {
|
|
204
|
+
var children = _ref2.children,
|
|
205
|
+
isLoading = _ref2.isLoading;
|
|
206
|
+
return /*#__PURE__*/jsxRuntime.jsx(box.Box, {
|
|
207
|
+
as: "span",
|
|
208
|
+
display: "inline-flex",
|
|
209
|
+
alignItems: "center",
|
|
210
|
+
justifyContent: "center",
|
|
211
|
+
opacity: isLoading ? 0 : undefined,
|
|
212
|
+
children: children
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
215
216
|
function useButtonStyles(_ref) {
|
|
216
217
|
var iconOnly = _ref.iconOnly,
|
|
217
218
|
prominence = _ref.prominence,
|
|
@@ -269,13 +270,13 @@ function useButtonStyles(_ref) {
|
|
|
269
270
|
return buttonStyleProps;
|
|
270
271
|
}
|
|
271
272
|
|
|
272
|
-
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "onClick", "prominence", "size", "tone", "type"];
|
|
273
|
+
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "loading", "onClick", "prominence", "size", "tone", "type"];
|
|
273
274
|
|
|
274
275
|
/**
|
|
275
276
|
* Buttons are used to initialize an action, their label should express what
|
|
276
277
|
* action will occur when the user interacts with it.
|
|
277
278
|
*/
|
|
278
|
-
var Button = /*#__PURE__*/
|
|
279
|
+
var Button = /*#__PURE__*/react.forwardRef(function (_ref, ref) {
|
|
279
280
|
var ariaControls = _ref['aria-controls'],
|
|
280
281
|
ariaDescribedBy = _ref['aria-describedby'],
|
|
281
282
|
ariaExpanded = _ref['aria-expanded'],
|
|
@@ -283,6 +284,8 @@ var Button = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
|
283
284
|
_ref$disabled = _ref.disabled,
|
|
284
285
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
285
286
|
id = _ref.id,
|
|
287
|
+
_ref$loading = _ref.loading,
|
|
288
|
+
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
286
289
|
onClick = _ref.onClick,
|
|
287
290
|
_ref$prominence = _ref.prominence,
|
|
288
291
|
prominence = _ref$prominence === void 0 ? 'high' : _ref$prominence,
|
|
@@ -300,18 +303,17 @@ var Button = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
|
300
303
|
size: size,
|
|
301
304
|
tone: tone,
|
|
302
305
|
prominence: prominence
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
var
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
});
|
|
307
|
+
var isDisabled = disabled || loading;
|
|
308
|
+
var isLoading = loading && !disabled;
|
|
309
|
+
var variant = variants[prominence][tone];
|
|
308
310
|
/**
|
|
309
311
|
* handle "disabled" behaviour w/o disabling buttons
|
|
310
312
|
* @see https://axesslab.com/disabled-buttons-suck/
|
|
311
313
|
*/
|
|
312
314
|
|
|
313
315
|
var handleClick = getPreventableClickHandler(onClick, isDisabled);
|
|
314
|
-
return /*#__PURE__*/jsxRuntime.
|
|
316
|
+
return /*#__PURE__*/jsxRuntime.jsxs(box.Box, _objectSpread(_objectSpread(_objectSpread({
|
|
315
317
|
"aria-controls": ariaControls,
|
|
316
318
|
"aria-describedby": ariaDescribedBy,
|
|
317
319
|
"aria-disabled": isDisabled,
|
|
@@ -323,14 +325,17 @@ var Button = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
|
323
325
|
ref: ref,
|
|
324
326
|
type: type
|
|
325
327
|
}, buttonStyleProps), data ? internal.buildDataAttributes(data) : undefined), {}, {
|
|
326
|
-
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
328
|
+
children: [resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
329
|
+
isLoading: isLoading,
|
|
327
330
|
prominence: prominence,
|
|
328
331
|
size: size,
|
|
329
332
|
tone: tone
|
|
330
|
-
}))
|
|
333
|
+
})), isLoading && /*#__PURE__*/jsxRuntime.jsx(Loading, {
|
|
334
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone
|
|
335
|
+
})]
|
|
331
336
|
}));
|
|
332
337
|
});
|
|
333
|
-
Button.displayName = '
|
|
338
|
+
Button.displayName = 'Button';
|
|
334
339
|
/**
|
|
335
340
|
* Prevent click events when the component is "disabled".
|
|
336
341
|
* Note: we don't want to actually disable a button element for several reasons.
|
|
@@ -347,6 +352,27 @@ function getPreventableClickHandler(onClick, disabled) {
|
|
|
347
352
|
};
|
|
348
353
|
}
|
|
349
354
|
|
|
355
|
+
function Loading(_ref2) {
|
|
356
|
+
var tone = _ref2.tone;
|
|
357
|
+
return /*#__PURE__*/jsxRuntime.jsxs(box.Box, {
|
|
358
|
+
as: "span",
|
|
359
|
+
position: "absolute",
|
|
360
|
+
top: 0,
|
|
361
|
+
bottom: 0,
|
|
362
|
+
left: 0,
|
|
363
|
+
right: 0,
|
|
364
|
+
display: "flex",
|
|
365
|
+
alignItems: "center",
|
|
366
|
+
justifyContent: "center",
|
|
367
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(a11y.VisuallyHidden, {
|
|
368
|
+
children: "button loading indicator"
|
|
369
|
+
}), /*#__PURE__*/jsxRuntime.jsx(spinner.Spinner, {
|
|
370
|
+
size: "xsmall",
|
|
371
|
+
tone: tone
|
|
372
|
+
})]
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
350
376
|
var _excluded = ["data", "href", "id", "prominence", "size", "tone"];
|
|
351
377
|
|
|
352
378
|
/** The appearance of a `Button`, with the semantics of a link. */
|
|
@@ -366,9 +392,9 @@ var ButtonLink = ts.forwardRefWithAs(function (_ref, ref) {
|
|
|
366
392
|
var iconOnly = Boolean(props.label);
|
|
367
393
|
var buttonStyleProps = useButtonStyles({
|
|
368
394
|
iconOnly: iconOnly,
|
|
395
|
+
prominence: prominence,
|
|
369
396
|
size: size,
|
|
370
|
-
tone: tone
|
|
371
|
-
prominence: prominence
|
|
397
|
+
tone: tone
|
|
372
398
|
});
|
|
373
399
|
return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread(_objectSpread({
|
|
374
400
|
"aria-label": props.label,
|
|
@@ -379,6 +405,7 @@ var ButtonLink = ts.forwardRefWithAs(function (_ref, ref) {
|
|
|
379
405
|
ref: ref
|
|
380
406
|
}, buttonStyleProps), data ? internal.buildDataAttributes(data) : undefined), {}, {
|
|
381
407
|
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
408
|
+
isLoading: false,
|
|
382
409
|
prominence: prominence,
|
|
383
410
|
size: size,
|
|
384
411
|
tone: tone
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
2
|
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
3
|
+
import { useFocusRing, VisuallyHidden } from '@spark-web/a11y';
|
|
3
4
|
import { Box } from '@spark-web/box';
|
|
5
|
+
import { Spinner } from '@spark-web/spinner';
|
|
4
6
|
import { buildDataAttributes } from '@spark-web/utils/internal';
|
|
5
|
-
import
|
|
6
|
-
import { Children, isValidElement, cloneElement } from 'react';
|
|
7
|
+
import { Children, isValidElement, cloneElement, forwardRef } from 'react';
|
|
7
8
|
import { Text } from '@spark-web/text';
|
|
8
|
-
import { jsx } from 'react/jsx-runtime';
|
|
9
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
9
10
|
import { css } from '@emotion/css';
|
|
10
|
-
import { useFocusRing } from '@spark-web/a11y';
|
|
11
11
|
import { useTheme } from '@spark-web/theme';
|
|
12
12
|
import { useLinkComponent } from '@spark-web/link';
|
|
13
13
|
import { forwardRefWithAs } from '@spark-web/utils/ts';
|
|
@@ -156,32 +156,39 @@ var mapTokens = {
|
|
|
156
156
|
|
|
157
157
|
var resolveButtonChildren = function resolveButtonChildren(_ref) {
|
|
158
158
|
var children = _ref.children,
|
|
159
|
+
isLoading = _ref.isLoading,
|
|
159
160
|
prominence = _ref.prominence,
|
|
160
161
|
size = _ref.size,
|
|
161
162
|
tone = _ref.tone;
|
|
162
163
|
var variant = variants[prominence][tone];
|
|
163
164
|
return Children.map(children, function (child) {
|
|
164
165
|
if (typeof child === 'string') {
|
|
165
|
-
return /*#__PURE__*/jsx(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
166
|
+
return /*#__PURE__*/jsx(HiddenWhenLoading, {
|
|
167
|
+
isLoading: isLoading,
|
|
168
|
+
children: /*#__PURE__*/jsx(Text, {
|
|
169
|
+
as: "span",
|
|
170
|
+
baseline: false,
|
|
171
|
+
overflowStrategy: "nowrap",
|
|
172
|
+
weight: "semibold",
|
|
173
|
+
size: mapTokens.fontSize[size],
|
|
174
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone,
|
|
175
|
+
children: child
|
|
176
|
+
})
|
|
173
177
|
});
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
if ( /*#__PURE__*/isValidElement(child)) {
|
|
177
|
-
return /*#__PURE__*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
return /*#__PURE__*/jsx(HiddenWhenLoading, {
|
|
182
|
+
isLoading: isLoading,
|
|
183
|
+
children: /*#__PURE__*/cloneElement(child, {
|
|
184
|
+
// Dismiss buttons need to be `xxsmall`
|
|
185
|
+
// For everything else, we force them to be `xsmall`
|
|
186
|
+
size: child.props.size === 'xxsmall' ? child.props.size : 'xsmall',
|
|
187
|
+
// If the button is low prominence with a decorative tone we want to force
|
|
188
|
+
// the tone to be the same as the button
|
|
189
|
+
// We also don't want users to override the tone of the icon inside of the button
|
|
190
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone
|
|
191
|
+
})
|
|
185
192
|
});
|
|
186
193
|
}
|
|
187
194
|
|
|
@@ -189,6 +196,19 @@ var resolveButtonChildren = function resolveButtonChildren(_ref) {
|
|
|
189
196
|
});
|
|
190
197
|
};
|
|
191
198
|
|
|
199
|
+
function HiddenWhenLoading(_ref2) {
|
|
200
|
+
var children = _ref2.children,
|
|
201
|
+
isLoading = _ref2.isLoading;
|
|
202
|
+
return /*#__PURE__*/jsx(Box, {
|
|
203
|
+
as: "span",
|
|
204
|
+
display: "inline-flex",
|
|
205
|
+
alignItems: "center",
|
|
206
|
+
justifyContent: "center",
|
|
207
|
+
opacity: isLoading ? 0 : undefined,
|
|
208
|
+
children: children
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
192
212
|
function useButtonStyles(_ref) {
|
|
193
213
|
var iconOnly = _ref.iconOnly,
|
|
194
214
|
prominence = _ref.prominence,
|
|
@@ -246,13 +266,13 @@ function useButtonStyles(_ref) {
|
|
|
246
266
|
return buttonStyleProps;
|
|
247
267
|
}
|
|
248
268
|
|
|
249
|
-
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "onClick", "prominence", "size", "tone", "type"];
|
|
269
|
+
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "loading", "onClick", "prominence", "size", "tone", "type"];
|
|
250
270
|
|
|
251
271
|
/**
|
|
252
272
|
* Buttons are used to initialize an action, their label should express what
|
|
253
273
|
* action will occur when the user interacts with it.
|
|
254
274
|
*/
|
|
255
|
-
var Button = /*#__PURE__*/
|
|
275
|
+
var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
256
276
|
var ariaControls = _ref['aria-controls'],
|
|
257
277
|
ariaDescribedBy = _ref['aria-describedby'],
|
|
258
278
|
ariaExpanded = _ref['aria-expanded'],
|
|
@@ -260,6 +280,8 @@ var Button = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
260
280
|
_ref$disabled = _ref.disabled,
|
|
261
281
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
262
282
|
id = _ref.id,
|
|
283
|
+
_ref$loading = _ref.loading,
|
|
284
|
+
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
263
285
|
onClick = _ref.onClick,
|
|
264
286
|
_ref$prominence = _ref.prominence,
|
|
265
287
|
prominence = _ref$prominence === void 0 ? 'high' : _ref$prominence,
|
|
@@ -277,18 +299,17 @@ var Button = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
277
299
|
size: size,
|
|
278
300
|
tone: tone,
|
|
279
301
|
prominence: prominence
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
302
|
+
});
|
|
303
|
+
var isDisabled = disabled || loading;
|
|
304
|
+
var isLoading = loading && !disabled;
|
|
305
|
+
var variant = variants[prominence][tone];
|
|
285
306
|
/**
|
|
286
307
|
* handle "disabled" behaviour w/o disabling buttons
|
|
287
308
|
* @see https://axesslab.com/disabled-buttons-suck/
|
|
288
309
|
*/
|
|
289
310
|
|
|
290
311
|
var handleClick = getPreventableClickHandler(onClick, isDisabled);
|
|
291
|
-
return /*#__PURE__*/
|
|
312
|
+
return /*#__PURE__*/jsxs(Box, _objectSpread(_objectSpread(_objectSpread({
|
|
292
313
|
"aria-controls": ariaControls,
|
|
293
314
|
"aria-describedby": ariaDescribedBy,
|
|
294
315
|
"aria-disabled": isDisabled,
|
|
@@ -300,14 +321,17 @@ var Button = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
300
321
|
ref: ref,
|
|
301
322
|
type: type
|
|
302
323
|
}, buttonStyleProps), data ? buildDataAttributes(data) : undefined), {}, {
|
|
303
|
-
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
324
|
+
children: [resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
325
|
+
isLoading: isLoading,
|
|
304
326
|
prominence: prominence,
|
|
305
327
|
size: size,
|
|
306
328
|
tone: tone
|
|
307
|
-
}))
|
|
329
|
+
})), isLoading && /*#__PURE__*/jsx(Loading, {
|
|
330
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone
|
|
331
|
+
})]
|
|
308
332
|
}));
|
|
309
333
|
});
|
|
310
|
-
Button.displayName = '
|
|
334
|
+
Button.displayName = 'Button';
|
|
311
335
|
/**
|
|
312
336
|
* Prevent click events when the component is "disabled".
|
|
313
337
|
* Note: we don't want to actually disable a button element for several reasons.
|
|
@@ -324,6 +348,27 @@ function getPreventableClickHandler(onClick, disabled) {
|
|
|
324
348
|
};
|
|
325
349
|
}
|
|
326
350
|
|
|
351
|
+
function Loading(_ref2) {
|
|
352
|
+
var tone = _ref2.tone;
|
|
353
|
+
return /*#__PURE__*/jsxs(Box, {
|
|
354
|
+
as: "span",
|
|
355
|
+
position: "absolute",
|
|
356
|
+
top: 0,
|
|
357
|
+
bottom: 0,
|
|
358
|
+
left: 0,
|
|
359
|
+
right: 0,
|
|
360
|
+
display: "flex",
|
|
361
|
+
alignItems: "center",
|
|
362
|
+
justifyContent: "center",
|
|
363
|
+
children: [/*#__PURE__*/jsx(VisuallyHidden, {
|
|
364
|
+
children: "button loading indicator"
|
|
365
|
+
}), /*#__PURE__*/jsx(Spinner, {
|
|
366
|
+
size: "xsmall",
|
|
367
|
+
tone: tone
|
|
368
|
+
})]
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
327
372
|
var _excluded = ["data", "href", "id", "prominence", "size", "tone"];
|
|
328
373
|
|
|
329
374
|
/** The appearance of a `Button`, with the semantics of a link. */
|
|
@@ -343,9 +388,9 @@ var ButtonLink = forwardRefWithAs(function (_ref, ref) {
|
|
|
343
388
|
var iconOnly = Boolean(props.label);
|
|
344
389
|
var buttonStyleProps = useButtonStyles({
|
|
345
390
|
iconOnly: iconOnly,
|
|
391
|
+
prominence: prominence,
|
|
346
392
|
size: size,
|
|
347
|
-
tone: tone
|
|
348
|
-
prominence: prominence
|
|
393
|
+
tone: tone
|
|
349
394
|
});
|
|
350
395
|
return /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread(_objectSpread({
|
|
351
396
|
"aria-label": props.label,
|
|
@@ -356,6 +401,7 @@ var ButtonLink = forwardRefWithAs(function (_ref, ref) {
|
|
|
356
401
|
ref: ref
|
|
357
402
|
}, buttonStyleProps), data ? buildDataAttributes(data) : undefined), {}, {
|
|
358
403
|
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
404
|
+
isLoading: false,
|
|
359
405
|
prominence: prominence,
|
|
360
406
|
size: size,
|
|
361
407
|
tone: tone
|
package/package.json
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-web/button",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/spark-web-button.cjs.js",
|
|
6
6
|
"module": "dist/spark-web-button.esm.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"dependencies": {
|
|
8
|
-
"@babel/runtime": "^7.
|
|
9
|
-
"@emotion/css": "^11.
|
|
10
|
-
"@spark-web/a11y": "^1.0.
|
|
11
|
-
"@spark-web/box": "^1.0.
|
|
12
|
-
"@spark-web/icon": "^1.1.
|
|
13
|
-
"@spark-web/link": "^1.0.
|
|
14
|
-
"@spark-web/
|
|
15
|
-
"@spark-web/
|
|
16
|
-
"@spark-web/
|
|
11
|
+
"@babel/runtime": "^7.18.0",
|
|
12
|
+
"@emotion/css": "^11.9.0",
|
|
13
|
+
"@spark-web/a11y": "^1.0.5",
|
|
14
|
+
"@spark-web/box": "^1.0.5",
|
|
15
|
+
"@spark-web/icon": "^1.1.3",
|
|
16
|
+
"@spark-web/link": "^1.0.5",
|
|
17
|
+
"@spark-web/spinner": "^1.0.3",
|
|
18
|
+
"@spark-web/text": "^1.0.5",
|
|
19
|
+
"@spark-web/theme": "^3.0.1",
|
|
20
|
+
"@spark-web/utils": "^1.1.3"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
"@types/react": "^17.0.12",
|
package/CHANGELOG.md
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# @spark-web/button
|
|
2
|
-
|
|
3
|
-
## 1.0.3
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#42](https://github.com/brighte-labs/spark-web/pull/42)
|
|
8
|
-
[`435779a`](https://github.com/brighte-labs/spark-web/commit/435779aa42bd635bbf43e1fd41724c666402caa2)
|
|
9
|
-
Thanks [@lukebennett88](https://github.com/lukebennett88)! - Prevent multiple
|
|
10
|
-
versions of React
|
|
11
|
-
|
|
12
|
-
- Updated dependencies
|
|
13
|
-
[[`435779a`](https://github.com/brighte-labs/spark-web/commit/435779aa42bd635bbf43e1fd41724c666402caa2)]:
|
|
14
|
-
- @spark-web/a11y@1.0.3
|
|
15
|
-
- @spark-web/box@1.0.3
|
|
16
|
-
- @spark-web/icon@1.1.1
|
|
17
|
-
- @spark-web/link@1.0.3
|
|
18
|
-
- @spark-web/text@1.0.3
|
|
19
|
-
- @spark-web/theme@2.0.2
|
|
20
|
-
- @spark-web/utils@1.1.1
|
|
21
|
-
|
|
22
|
-
## 1.0.2
|
|
23
|
-
|
|
24
|
-
### Patch Changes
|
|
25
|
-
|
|
26
|
-
- [#40](https://github.com/brighte-labs/spark-web/pull/40)
|
|
27
|
-
[`062c8ab`](https://github.com/brighte-labs/spark-web/commit/062c8ab8c7b4120f8d14c269b5f7801288c678ca)
|
|
28
|
-
Thanks [@lukebennett88](https://github.com/lukebennett88)! - Add
|
|
29
|
-
@babel/transform-runtime
|
|
30
|
-
|
|
31
|
-
- Updated dependencies
|
|
32
|
-
[[`062c8ab`](https://github.com/brighte-labs/spark-web/commit/062c8ab8c7b4120f8d14c269b5f7801288c678ca)]:
|
|
33
|
-
- @spark-web/a11y@1.0.2
|
|
34
|
-
- @spark-web/box@1.0.2
|
|
35
|
-
- @spark-web/icon@1.0.2
|
|
36
|
-
- @spark-web/link@1.0.2
|
|
37
|
-
- @spark-web/text@1.0.2
|
|
38
|
-
- @spark-web/theme@2.0.1
|
|
39
|
-
- @spark-web/utils@1.0.2
|
|
40
|
-
|
|
41
|
-
## 1.0.1
|
|
42
|
-
|
|
43
|
-
### Patch Changes
|
|
44
|
-
|
|
45
|
-
- [#36](https://github.com/brighte-labs/spark-web/pull/36)
|
|
46
|
-
[`8546f8f`](https://github.com/brighte-labs/spark-web/commit/8546f8f05daaa79ea3ff954c6c4928a7a2d0622d)
|
|
47
|
-
Thanks [@lukebennett88](https://github.com/lukebennett88)! - Update Babel
|
|
48
|
-
config
|
|
49
|
-
|
|
50
|
-
- Updated dependencies
|
|
51
|
-
[[`aebff30`](https://github.com/brighte-labs/spark-web/commit/aebff30c86cb0a9db22b545c46159ce0d1c14afb),
|
|
52
|
-
[`8546f8f`](https://github.com/brighte-labs/spark-web/commit/8546f8f05daaa79ea3ff954c6c4928a7a2d0622d)]:
|
|
53
|
-
- @spark-web/theme@2.0.0
|
|
54
|
-
- @spark-web/a11y@1.0.1
|
|
55
|
-
- @spark-web/box@1.0.1
|
|
56
|
-
- @spark-web/icon@1.0.1
|
|
57
|
-
- @spark-web/link@1.0.1
|
|
58
|
-
- @spark-web/text@1.0.1
|
|
59
|
-
- @spark-web/utils@1.0.1
|
|
60
|
-
|
|
61
|
-
## 1.0.0
|
|
62
|
-
|
|
63
|
-
### Major Changes
|
|
64
|
-
|
|
65
|
-
- [#27](https://github.com/brighte-labs/spark-web/pull/27)
|
|
66
|
-
[`4c8e398`](https://github.com/brighte-labs/spark-web/commit/4c8e3988f8a59d3dab60a6b67b1128b6ff2a5f2c)
|
|
67
|
-
Thanks [@JedWatson](https://github.com/JedWatson)! - Initial Version
|
|
68
|
-
|
|
69
|
-
### Patch Changes
|
|
70
|
-
|
|
71
|
-
- Updated dependencies
|
|
72
|
-
[[`4c8e398`](https://github.com/brighte-labs/spark-web/commit/4c8e3988f8a59d3dab60a6b67b1128b6ff2a5f2c)]:
|
|
73
|
-
- @spark-web/a11y@1.0.0
|
|
74
|
-
- @spark-web/box@1.0.0
|
|
75
|
-
- @spark-web/icon@1.0.0
|
|
76
|
-
- @spark-web/link@1.0.0
|
|
77
|
-
- @spark-web/text@1.0.0
|
|
78
|
-
- @spark-web/theme@1.0.0
|
|
79
|
-
- @spark-web/utils@1.0.0
|
package/src/Button.stories.tsx
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
2
|
-
|
|
3
|
-
import type { ButtonProps } from './Button';
|
|
4
|
-
import { Button } from './Button';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Forms / Buttons / Button',
|
|
8
|
-
component: Button,
|
|
9
|
-
} as ComponentMeta<typeof Button>;
|
|
10
|
-
|
|
11
|
-
const ButtonStory: ComponentStory<typeof Button> = (args: ButtonProps) => (
|
|
12
|
-
<Button {...args} />
|
|
13
|
-
);
|
|
14
|
-
export const Default = ButtonStory.bind({});
|
|
15
|
-
export const Tone = ButtonStory.bind({});
|
|
16
|
-
export const Disabled = ButtonStory.bind({});
|
|
17
|
-
|
|
18
|
-
Default.args = {
|
|
19
|
-
children: 'Click me!',
|
|
20
|
-
tone: 'primary',
|
|
21
|
-
onClick: () => window.alert('Clicked!'),
|
|
22
|
-
} as ButtonProps;
|
|
23
|
-
|
|
24
|
-
Tone.args = {
|
|
25
|
-
children: 'Click me!',
|
|
26
|
-
tone: 'critical',
|
|
27
|
-
onClick: () => window.alert('Clicked!'),
|
|
28
|
-
} as ButtonProps;
|
|
29
|
-
|
|
30
|
-
Disabled.args = {
|
|
31
|
-
children: 'Click me!',
|
|
32
|
-
disabled: true,
|
|
33
|
-
onClick: () => window.alert('Clicked!'),
|
|
34
|
-
} as ButtonProps;
|
package/src/Button.test.tsx
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { cleanup, render, screen } from '@testing-library/react';
|
|
2
|
-
|
|
3
|
-
import { Button } from './Button';
|
|
4
|
-
|
|
5
|
-
describe('button component', () => {
|
|
6
|
-
afterEach(cleanup);
|
|
7
|
-
|
|
8
|
-
it('should show a button with expected text', () => {
|
|
9
|
-
render(<Button>Test Button</Button>);
|
|
10
|
-
|
|
11
|
-
screen.getByText('Test Button');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should trigger button onClick function', () => {
|
|
15
|
-
const jsfn = jest.fn();
|
|
16
|
-
|
|
17
|
-
render(<Button onClick={jsfn}>Test Button</Button>);
|
|
18
|
-
screen.getByText('Test Button').click();
|
|
19
|
-
|
|
20
|
-
expect(jsfn).toBeCalled();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('Build expected data attribute', () => {
|
|
24
|
-
const { container } = render(
|
|
25
|
-
<Button data={{ button: 'test-value' }} id="test-button">
|
|
26
|
-
More Test Text
|
|
27
|
-
</Button>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
expect(container.querySelector('[data-button="test-value"]')?.id).toEqual(
|
|
31
|
-
'test-button'
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
});
|