@spark-web/button 1.0.1 → 1.1.0
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 +94 -91
- 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 +2 -1
- package/dist/declarations/src/types.d.ts +6 -0
- package/dist/spark-web-button.cjs.dev.js +79 -54
- package/dist/spark-web-button.cjs.prod.js +79 -54
- package/dist/spark-web-button.esm.js +78 -34
- package/package.json +18 -11
- package/CHANGELOG.md +0 -41
- 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');
|
|
12
|
+
var css = require('@emotion/css');
|
|
10
13
|
var text = require('@spark-web/text');
|
|
11
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
12
|
-
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,17 @@ 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("span", {
|
|
207
|
+
className: isLoading ? css.css({
|
|
208
|
+
opacity: 0
|
|
209
|
+
}) : undefined,
|
|
210
|
+
children: children
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
215
214
|
function useButtonStyles(_ref) {
|
|
216
215
|
var iconOnly = _ref.iconOnly,
|
|
217
216
|
prominence = _ref.prominence,
|
|
@@ -269,13 +268,13 @@ function useButtonStyles(_ref) {
|
|
|
269
268
|
return buttonStyleProps;
|
|
270
269
|
}
|
|
271
270
|
|
|
272
|
-
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "onClick", "prominence", "size", "tone", "type"];
|
|
271
|
+
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "loading", "onClick", "prominence", "size", "tone", "type"];
|
|
273
272
|
|
|
274
273
|
/**
|
|
275
274
|
* Buttons are used to initialize an action, their label should express what
|
|
276
275
|
* action will occur when the user interacts with it.
|
|
277
276
|
*/
|
|
278
|
-
var Button = /*#__PURE__*/
|
|
277
|
+
var Button = /*#__PURE__*/react.forwardRef(function (_ref, ref) {
|
|
279
278
|
var ariaControls = _ref['aria-controls'],
|
|
280
279
|
ariaDescribedBy = _ref['aria-describedby'],
|
|
281
280
|
ariaExpanded = _ref['aria-expanded'],
|
|
@@ -283,6 +282,8 @@ var Button = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
|
283
282
|
_ref$disabled = _ref.disabled,
|
|
284
283
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
285
284
|
id = _ref.id,
|
|
285
|
+
_ref$loading = _ref.loading,
|
|
286
|
+
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
286
287
|
onClick = _ref.onClick,
|
|
287
288
|
_ref$prominence = _ref.prominence,
|
|
288
289
|
prominence = _ref$prominence === void 0 ? 'high' : _ref$prominence,
|
|
@@ -300,18 +301,17 @@ var Button = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
|
300
301
|
size: size,
|
|
301
302
|
tone: tone,
|
|
302
303
|
prominence: prominence
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
var
|
|
306
|
-
|
|
307
|
-
|
|
304
|
+
});
|
|
305
|
+
var isDisabled = disabled || loading;
|
|
306
|
+
var isLoading = loading && !disabled;
|
|
307
|
+
var variant = variants[prominence][tone];
|
|
308
308
|
/**
|
|
309
309
|
* handle "disabled" behaviour w/o disabling buttons
|
|
310
310
|
* @see https://axesslab.com/disabled-buttons-suck/
|
|
311
311
|
*/
|
|
312
312
|
|
|
313
313
|
var handleClick = getPreventableClickHandler(onClick, isDisabled);
|
|
314
|
-
return /*#__PURE__*/jsxRuntime.
|
|
314
|
+
return /*#__PURE__*/jsxRuntime.jsxs(box.Box, _objectSpread(_objectSpread(_objectSpread({
|
|
315
315
|
"aria-controls": ariaControls,
|
|
316
316
|
"aria-describedby": ariaDescribedBy,
|
|
317
317
|
"aria-disabled": isDisabled,
|
|
@@ -323,14 +323,17 @@ var Button = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
|
|
|
323
323
|
ref: ref,
|
|
324
324
|
type: type
|
|
325
325
|
}, buttonStyleProps), data ? internal.buildDataAttributes(data) : undefined), {}, {
|
|
326
|
-
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
326
|
+
children: [resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
327
|
+
isLoading: isLoading,
|
|
327
328
|
prominence: prominence,
|
|
328
329
|
size: size,
|
|
329
330
|
tone: tone
|
|
330
|
-
}))
|
|
331
|
+
})), isLoading && /*#__PURE__*/jsxRuntime.jsx(Loading, {
|
|
332
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone
|
|
333
|
+
})]
|
|
331
334
|
}));
|
|
332
335
|
});
|
|
333
|
-
Button.displayName = '
|
|
336
|
+
Button.displayName = 'Button';
|
|
334
337
|
/**
|
|
335
338
|
* Prevent click events when the component is "disabled".
|
|
336
339
|
* Note: we don't want to actually disable a button element for several reasons.
|
|
@@ -347,6 +350,27 @@ function getPreventableClickHandler(onClick, disabled) {
|
|
|
347
350
|
};
|
|
348
351
|
}
|
|
349
352
|
|
|
353
|
+
function Loading(_ref2) {
|
|
354
|
+
var tone = _ref2.tone;
|
|
355
|
+
return /*#__PURE__*/jsxRuntime.jsxs(box.Box, {
|
|
356
|
+
as: "span",
|
|
357
|
+
position: "absolute",
|
|
358
|
+
top: 0,
|
|
359
|
+
bottom: 0,
|
|
360
|
+
left: 0,
|
|
361
|
+
right: 0,
|
|
362
|
+
display: "flex",
|
|
363
|
+
alignItems: "center",
|
|
364
|
+
justifyContent: "center",
|
|
365
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(a11y.VisuallyHidden, {
|
|
366
|
+
children: "button loading indicator"
|
|
367
|
+
}), /*#__PURE__*/jsxRuntime.jsx(spinner.Spinner, {
|
|
368
|
+
size: "xsmall",
|
|
369
|
+
tone: tone
|
|
370
|
+
})]
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
350
374
|
var _excluded = ["data", "href", "id", "prominence", "size", "tone"];
|
|
351
375
|
|
|
352
376
|
/** The appearance of a `Button`, with the semantics of a link. */
|
|
@@ -366,9 +390,9 @@ var ButtonLink = ts.forwardRefWithAs(function (_ref, ref) {
|
|
|
366
390
|
var iconOnly = Boolean(props.label);
|
|
367
391
|
var buttonStyleProps = useButtonStyles({
|
|
368
392
|
iconOnly: iconOnly,
|
|
393
|
+
prominence: prominence,
|
|
369
394
|
size: size,
|
|
370
|
-
tone: tone
|
|
371
|
-
prominence: prominence
|
|
395
|
+
tone: tone
|
|
372
396
|
});
|
|
373
397
|
return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread(_objectSpread({
|
|
374
398
|
"aria-label": props.label,
|
|
@@ -379,6 +403,7 @@ var ButtonLink = ts.forwardRefWithAs(function (_ref, ref) {
|
|
|
379
403
|
ref: ref
|
|
380
404
|
}, buttonStyleProps), data ? internal.buildDataAttributes(data) : undefined), {}, {
|
|
381
405
|
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
406
|
+
isLoading: false,
|
|
382
407
|
prominence: prominence,
|
|
383
408
|
size: size,
|
|
384
409
|
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 { Text } from '@spark-web/text';
|
|
8
|
-
import { jsx } from 'react/jsx-runtime';
|
|
7
|
+
import { Children, isValidElement, cloneElement, forwardRef } from 'react';
|
|
9
8
|
import { css } from '@emotion/css';
|
|
10
|
-
import {
|
|
9
|
+
import { Text } from '@spark-web/text';
|
|
10
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
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,17 @@ 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("span", {
|
|
203
|
+
className: isLoading ? css({
|
|
204
|
+
opacity: 0
|
|
205
|
+
}) : undefined,
|
|
206
|
+
children: children
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
192
210
|
function useButtonStyles(_ref) {
|
|
193
211
|
var iconOnly = _ref.iconOnly,
|
|
194
212
|
prominence = _ref.prominence,
|
|
@@ -246,13 +264,13 @@ function useButtonStyles(_ref) {
|
|
|
246
264
|
return buttonStyleProps;
|
|
247
265
|
}
|
|
248
266
|
|
|
249
|
-
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "onClick", "prominence", "size", "tone", "type"];
|
|
267
|
+
var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "loading", "onClick", "prominence", "size", "tone", "type"];
|
|
250
268
|
|
|
251
269
|
/**
|
|
252
270
|
* Buttons are used to initialize an action, their label should express what
|
|
253
271
|
* action will occur when the user interacts with it.
|
|
254
272
|
*/
|
|
255
|
-
var Button = /*#__PURE__*/
|
|
273
|
+
var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
256
274
|
var ariaControls = _ref['aria-controls'],
|
|
257
275
|
ariaDescribedBy = _ref['aria-describedby'],
|
|
258
276
|
ariaExpanded = _ref['aria-expanded'],
|
|
@@ -260,6 +278,8 @@ var Button = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
260
278
|
_ref$disabled = _ref.disabled,
|
|
261
279
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
262
280
|
id = _ref.id,
|
|
281
|
+
_ref$loading = _ref.loading,
|
|
282
|
+
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
263
283
|
onClick = _ref.onClick,
|
|
264
284
|
_ref$prominence = _ref.prominence,
|
|
265
285
|
prominence = _ref$prominence === void 0 ? 'high' : _ref$prominence,
|
|
@@ -277,18 +297,17 @@ var Button = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
277
297
|
size: size,
|
|
278
298
|
tone: tone,
|
|
279
299
|
prominence: prominence
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
300
|
+
});
|
|
301
|
+
var isDisabled = disabled || loading;
|
|
302
|
+
var isLoading = loading && !disabled;
|
|
303
|
+
var variant = variants[prominence][tone];
|
|
285
304
|
/**
|
|
286
305
|
* handle "disabled" behaviour w/o disabling buttons
|
|
287
306
|
* @see https://axesslab.com/disabled-buttons-suck/
|
|
288
307
|
*/
|
|
289
308
|
|
|
290
309
|
var handleClick = getPreventableClickHandler(onClick, isDisabled);
|
|
291
|
-
return /*#__PURE__*/
|
|
310
|
+
return /*#__PURE__*/jsxs(Box, _objectSpread(_objectSpread(_objectSpread({
|
|
292
311
|
"aria-controls": ariaControls,
|
|
293
312
|
"aria-describedby": ariaDescribedBy,
|
|
294
313
|
"aria-disabled": isDisabled,
|
|
@@ -300,14 +319,17 @@ var Button = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
300
319
|
ref: ref,
|
|
301
320
|
type: type
|
|
302
321
|
}, buttonStyleProps), data ? buildDataAttributes(data) : undefined), {}, {
|
|
303
|
-
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
322
|
+
children: [resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
323
|
+
isLoading: isLoading,
|
|
304
324
|
prominence: prominence,
|
|
305
325
|
size: size,
|
|
306
326
|
tone: tone
|
|
307
|
-
}))
|
|
327
|
+
})), isLoading && /*#__PURE__*/jsx(Loading, {
|
|
328
|
+
tone: variant === null || variant === void 0 ? void 0 : variant.textTone
|
|
329
|
+
})]
|
|
308
330
|
}));
|
|
309
331
|
});
|
|
310
|
-
Button.displayName = '
|
|
332
|
+
Button.displayName = 'Button';
|
|
311
333
|
/**
|
|
312
334
|
* Prevent click events when the component is "disabled".
|
|
313
335
|
* Note: we don't want to actually disable a button element for several reasons.
|
|
@@ -324,6 +346,27 @@ function getPreventableClickHandler(onClick, disabled) {
|
|
|
324
346
|
};
|
|
325
347
|
}
|
|
326
348
|
|
|
349
|
+
function Loading(_ref2) {
|
|
350
|
+
var tone = _ref2.tone;
|
|
351
|
+
return /*#__PURE__*/jsxs(Box, {
|
|
352
|
+
as: "span",
|
|
353
|
+
position: "absolute",
|
|
354
|
+
top: 0,
|
|
355
|
+
bottom: 0,
|
|
356
|
+
left: 0,
|
|
357
|
+
right: 0,
|
|
358
|
+
display: "flex",
|
|
359
|
+
alignItems: "center",
|
|
360
|
+
justifyContent: "center",
|
|
361
|
+
children: [/*#__PURE__*/jsx(VisuallyHidden, {
|
|
362
|
+
children: "button loading indicator"
|
|
363
|
+
}), /*#__PURE__*/jsx(Spinner, {
|
|
364
|
+
size: "xsmall",
|
|
365
|
+
tone: tone
|
|
366
|
+
})]
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
327
370
|
var _excluded = ["data", "href", "id", "prominence", "size", "tone"];
|
|
328
371
|
|
|
329
372
|
/** The appearance of a `Button`, with the semantics of a link. */
|
|
@@ -343,9 +386,9 @@ var ButtonLink = forwardRefWithAs(function (_ref, ref) {
|
|
|
343
386
|
var iconOnly = Boolean(props.label);
|
|
344
387
|
var buttonStyleProps = useButtonStyles({
|
|
345
388
|
iconOnly: iconOnly,
|
|
389
|
+
prominence: prominence,
|
|
346
390
|
size: size,
|
|
347
|
-
tone: tone
|
|
348
|
-
prominence: prominence
|
|
391
|
+
tone: tone
|
|
349
392
|
});
|
|
350
393
|
return /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread(_objectSpread({
|
|
351
394
|
"aria-label": props.label,
|
|
@@ -356,6 +399,7 @@ var ButtonLink = forwardRefWithAs(function (_ref, ref) {
|
|
|
356
399
|
ref: ref
|
|
357
400
|
}, buttonStyleProps), data ? buildDataAttributes(data) : undefined), {}, {
|
|
358
401
|
children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
|
|
402
|
+
isLoading: false,
|
|
359
403
|
prominence: prominence,
|
|
360
404
|
size: size,
|
|
361
405
|
tone: tone
|
package/package.json
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-web/button",
|
|
3
|
+
"version": "1.1.0",
|
|
3
4
|
"license": "MIT",
|
|
4
|
-
"version": "1.0.1",
|
|
5
5
|
"main": "dist/spark-web-button.cjs.js",
|
|
6
6
|
"module": "dist/spark-web-button.esm.js",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@babel/runtime": "^7.14.6",
|
|
12
12
|
"@emotion/css": "^11.7.1",
|
|
13
|
-
"@spark-web/a11y": "^1.0.
|
|
14
|
-
"@spark-web/box": "^1.0.
|
|
15
|
-
"@spark-web/icon": "^1.
|
|
16
|
-
"@spark-web/link": "^1.0.
|
|
17
|
-
"@spark-web/
|
|
18
|
-
"@spark-web/
|
|
19
|
-
"@spark-web/
|
|
13
|
+
"@spark-web/a11y": "^1.0.4",
|
|
14
|
+
"@spark-web/box": "^1.0.4",
|
|
15
|
+
"@spark-web/icon": "^1.1.2",
|
|
16
|
+
"@spark-web/link": "^1.0.4",
|
|
17
|
+
"@spark-web/spinner": "^1.0.1",
|
|
18
|
+
"@spark-web/text": "^1.0.4",
|
|
19
|
+
"@spark-web/theme": "^3.0.0",
|
|
20
|
+
"@spark-web/utils": "^1.1.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/react": "^17.0.12",
|
|
20
24
|
"react": "^17.0.2"
|
|
21
25
|
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=17.0.2"
|
|
28
|
+
},
|
|
22
29
|
"engines": {
|
|
23
30
|
"node": ">= 14.13"
|
|
24
31
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# @spark-web/button
|
|
2
|
-
|
|
3
|
-
## 1.0.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#36](https://github.com/brighte-labs/spark-web/pull/36)
|
|
8
|
-
[`8546f8f`](https://github.com/brighte-labs/spark-web/commit/8546f8f05daaa79ea3ff954c6c4928a7a2d0622d)
|
|
9
|
-
Thanks [@lukebennett88](https://github.com/lukebennett88)! - Update Babel
|
|
10
|
-
config
|
|
11
|
-
|
|
12
|
-
- Updated dependencies
|
|
13
|
-
[[`aebff30`](https://github.com/brighte-labs/spark-web/commit/aebff30c86cb0a9db22b545c46159ce0d1c14afb),
|
|
14
|
-
[`8546f8f`](https://github.com/brighte-labs/spark-web/commit/8546f8f05daaa79ea3ff954c6c4928a7a2d0622d)]:
|
|
15
|
-
- @spark-web/theme@2.0.0
|
|
16
|
-
- @spark-web/a11y@1.0.1
|
|
17
|
-
- @spark-web/box@1.0.1
|
|
18
|
-
- @spark-web/icon@1.0.1
|
|
19
|
-
- @spark-web/link@1.0.1
|
|
20
|
-
- @spark-web/text@1.0.1
|
|
21
|
-
- @spark-web/utils@1.0.1
|
|
22
|
-
|
|
23
|
-
## 1.0.0
|
|
24
|
-
|
|
25
|
-
### Major Changes
|
|
26
|
-
|
|
27
|
-
- [#27](https://github.com/brighte-labs/spark-web/pull/27)
|
|
28
|
-
[`4c8e398`](https://github.com/brighte-labs/spark-web/commit/4c8e3988f8a59d3dab60a6b67b1128b6ff2a5f2c)
|
|
29
|
-
Thanks [@JedWatson](https://github.com/JedWatson)! - Initial Version
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- Updated dependencies
|
|
34
|
-
[[`4c8e398`](https://github.com/brighte-labs/spark-web/commit/4c8e3988f8a59d3dab60a6b67b1128b6ff2a5f2c)]:
|
|
35
|
-
- @spark-web/a11y@1.0.0
|
|
36
|
-
- @spark-web/box@1.0.0
|
|
37
|
-
- @spark-web/icon@1.0.0
|
|
38
|
-
- @spark-web/link@1.0.0
|
|
39
|
-
- @spark-web/text@1.0.0
|
|
40
|
-
- @spark-web/theme@1.0.0
|
|
41
|
-
- @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
|
-
});
|