@spark-web/button 1.2.0 → 1.4.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 CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  title: Button
3
3
  storybookPath: forms-buttons-button--default
4
+ isExperimentalPackage: true
4
5
  ---
5
6
 
6
7
  Buttons are clickable elements that are used to trigger actions. They
@@ -5,5 +5,5 @@ export declare type ButtonLinkProps = LinkComponentProps & CommonButtonProps;
5
5
  /** The appearance of a `Button`, with the semantics of a link. */
6
6
  export declare const ButtonLink: <Comp extends import("react").ElementType<any> = "a">(props: {
7
7
  as?: Comp | undefined;
8
- ref?: import("react").Ref<Comp extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap | "set" ? (HTMLElementTagNameMap & Pick<SVGElementTagNameMap, "symbol" | "clipPath" | "filter" | "mask" | "marker" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | "set">)[Comp] : Comp extends new (...args: any) => any ? InstanceType<Comp> : undefined> | undefined;
8
+ ref?: import("react").Ref<Comp extends "symbol" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | "set" | keyof HTMLElementTagNameMap ? (HTMLElementTagNameMap & Pick<SVGElementTagNameMap, "symbol" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | "set">)[Comp] : Comp extends new (...args: any) => any ? InstanceType<Comp> : undefined> | undefined;
9
9
  } & Omit<import("react").PropsWithoutRef<import("react").ComponentProps<Comp>>, "as"> & ButtonLinkProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
@@ -1,6 +1,8 @@
1
1
  export { BaseButton } from './BaseButton';
2
2
  export { Button } from './Button';
3
3
  export { ButtonLink } from './ButtonLink';
4
+ export { useButtonStyles } from './useButtonStyles';
4
5
  export type { BaseButtonProps } from './BaseButton';
5
6
  export type { ButtonProps } from './Button';
6
7
  export type { ButtonLinkProps } from './ButtonLink';
8
+ export type { UseButtonStylesProps } from './useButtonStyles';
@@ -5,10 +5,10 @@ import type { ButtonHTMLAttributes, ReactElement } from 'react';
5
5
  import type { mapTokens } from './utils';
6
6
  export declare type ButtonSize = keyof typeof mapTokens[keyof typeof mapTokens];
7
7
  export declare type ButtonProminence = 'high' | 'low' | 'none';
8
- export declare type ButtonTone = BackgroundTone;
8
+ export declare type ButtonTone = Exclude<BackgroundTone, 'disabled'>;
9
9
  declare type ChildrenWithText = {
10
10
  label?: never;
11
- children: string | [ReactElement<IconProps>, string] | [string, ReactElement<IconProps>];
11
+ children: string | number | [ReactElement<IconProps>, string | number] | [string | number, ReactElement<IconProps>];
12
12
  };
13
13
  declare type IconOnly = {
14
14
  /**
@@ -1,10 +1,88 @@
1
- import type { BoxProps } from '@spark-web/box';
2
1
  import type { ButtonProminence, ButtonSize, ButtonTone } from './types';
3
- declare type UseButtonStylesProps = {
2
+ /**
3
+ * useButtonStyles
4
+ *
5
+ * Custom hook for styling buttons and certain links.
6
+ * Returns a tuple where the first item is an object of props to spread onto the
7
+ * underlying `Box` component, and the second item is a CSS object that can be
8
+ * passed to Emotion's `css` function.
9
+ */
10
+ export declare function useButtonStyles({ iconOnly, prominence, size, tone, }: UseButtonStylesProps): readonly [{
11
+ readonly alignItems: "center";
12
+ readonly background: "body" | "input" | "infoLight" | "criticalLight" | "positiveLight" | "cautionLight" | "muted" | "disabled" | "backdrop" | "surface" | "surfaceMuted" | "surfacePressed" | "fieldAccent" | "inputPressed" | "inputDisabled" | "accent" | "accentMuted" | "neutral" | "neutralLow" | "primary" | "primaryLow" | "primaryMuted" | "secondary" | "secondaryLow" | "secondaryMuted" | "caution" | "cautionLow" | "cautionMuted" | "critical" | "criticalLow" | "criticalMuted" | "info" | "infoLow" | "infoMuted" | "positive" | "positiveLow" | "positiveMuted" | undefined;
13
+ readonly border: import("@spark-web/theme").ResponsiveProp<"standard" | "fieldAccent" | "accent" | "accentMuted" | "neutral" | "primary" | "secondary" | "caution" | "cautionMuted" | "critical" | "criticalMuted" | "info" | "infoMuted" | "positive" | "positiveMuted" | "standardInverted" | "field" | "fieldHover" | "fieldDisabled" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive"> | undefined;
14
+ readonly borderWidth: import("@spark-web/theme").ResponsiveProp<"standard" | "large"> | undefined;
15
+ readonly borderRadius: "small" | "medium";
16
+ readonly cursor: "pointer";
17
+ readonly display: "inline-flex";
18
+ readonly gap: "small";
19
+ readonly height: "large" | "medium";
20
+ readonly justifyContent: "center";
21
+ readonly paddingX: "medium" | "xlarge" | undefined;
22
+ readonly position: "relative";
23
+ readonly width: "large" | "medium" | undefined;
24
+ }, {
25
+ readonly '&:not([aria-disabled=true])': {
26
+ readonly ':hover': {
27
+ readonly borderColor: string | undefined;
28
+ readonly backgroundColor: string | undefined;
29
+ readonly '> *': {
30
+ readonly color: string | undefined;
31
+ readonly stroke: string | undefined;
32
+ readonly transitionProperty: string;
33
+ readonly transitionTimingFunction: string;
34
+ readonly transitionDuration: string;
35
+ };
36
+ };
37
+ readonly ':active': {
38
+ readonly borderColor: string | undefined;
39
+ readonly backgroundColor: string | undefined;
40
+ readonly transform: "scale(0.98)";
41
+ readonly '> *': {
42
+ readonly color: string | undefined;
43
+ readonly stroke: string | undefined;
44
+ readonly transitionProperty: string;
45
+ readonly transitionTimingFunction: string;
46
+ readonly transitionDuration: string;
47
+ };
48
+ };
49
+ readonly ':focus': {
50
+ boxShadow: string;
51
+ outline: string;
52
+ outlineOffset: string;
53
+ } | {
54
+ outline: string;
55
+ outlineOffset: string;
56
+ };
57
+ };
58
+ readonly '&[aria-disabled=true]': {
59
+ readonly backgroundColor: string | undefined;
60
+ readonly borderColor: string | undefined;
61
+ readonly cursor: "default";
62
+ readonly '*': {
63
+ readonly color: string | undefined;
64
+ readonly stroke: string | undefined;
65
+ };
66
+ readonly ':focus': {
67
+ boxShadow: string;
68
+ outline: string;
69
+ outlineOffset: string;
70
+ } | {
71
+ outline: string;
72
+ outlineOffset: string;
73
+ };
74
+ };
75
+ readonly transitionProperty: string;
76
+ readonly transitionTimingFunction: string;
77
+ readonly transitionDuration: string;
78
+ }];
79
+ export declare type UseButtonStylesProps = {
80
+ /** Whether the children of the button is a single icon or not. */
4
81
  iconOnly: boolean;
82
+ /** Sets the visual prominence of the button. */
5
83
  prominence: ButtonProminence;
84
+ /** Sets the size of the button. */
6
85
  size: ButtonSize;
86
+ /** Sets the tone of the button. */
7
87
  tone: ButtonTone;
8
88
  };
9
- export declare function useButtonStyles({ iconOnly, prominence, size, tone, }: UseButtonStylesProps): Partial<BoxProps>;
10
- export {};
@@ -2,19 +2,30 @@ import type { BoxProps } from '@spark-web/box';
2
2
  import type { ForegroundTone } from '@spark-web/text';
3
3
  import type { BrighteTheme } from '@spark-web/theme';
4
4
  import type { ButtonProminence, ButtonTone } from './types';
5
- declare type ButtonStyles = {
5
+ declare type BaseButtonStyles = {
6
6
  background: BoxProps['background'];
7
7
  border?: BoxProps['border'];
8
8
  borderWidth?: BoxProps['borderWidth'];
9
9
  textTone?: ForegroundTone;
10
+ };
11
+ declare type HoverButtonStyles = {
10
12
  backgroundHover: keyof BrighteTheme['backgroundInteractions'];
11
13
  borderHover?: keyof BrighteTheme['border']['color'];
12
14
  textToneHover?: keyof BrighteTheme['color']['foreground'];
15
+ };
16
+ declare type ActiveButtonStyles = {
13
17
  backgroundActive: keyof BrighteTheme['backgroundInteractions'];
14
18
  borderActive?: keyof BrighteTheme['border']['color'];
15
19
  textToneActive?: keyof BrighteTheme['color']['foreground'];
16
20
  };
17
- export declare const variants: Record<ButtonProminence, Record<ButtonTone, ButtonStyles | undefined>>;
21
+ declare type DisabledButtonStyles = {
22
+ backgroundDisabled: keyof BrighteTheme['color']['background'];
23
+ borderDisabled?: keyof BrighteTheme['border']['color'];
24
+ textToneDisabled: keyof BrighteTheme['color']['foreground'];
25
+ };
26
+ declare type ButtonStyles = BaseButtonStyles & HoverButtonStyles & ActiveButtonStyles & DisabledButtonStyles;
27
+ declare type Variants = Record<ButtonProminence, Record<ButtonTone, ButtonStyles | undefined>>;
28
+ export declare const variants: Variants;
18
29
  export declare const mapTokens: {
19
30
  readonly fontSize: {
20
31
  readonly medium: "small";
@@ -8,13 +8,13 @@ var box = require('@spark-web/box');
8
8
  var utils = require('@spark-web/utils');
9
9
  var react = require('react');
10
10
  var jsxRuntime = require('react/jsx-runtime');
11
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
12
+ var css = require('@emotion/css');
11
13
  var a11y = require('@spark-web/a11y');
12
14
  var spinner = require('@spark-web/spinner');
13
15
  var text = require('@spark-web/text');
14
- var css = require('@emotion/css');
15
16
  var theme = require('@spark-web/theme');
16
17
  var link = require('@spark-web/link');
17
- var internal = require('@spark-web/utils/internal');
18
18
  var ts = require('@spark-web/utils/ts');
19
19
 
20
20
  var _excluded$2 = ["onClick", "disabled", "type"];
@@ -24,7 +24,7 @@ var BaseButton = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
24
24
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
25
25
  _ref$type = _ref.type,
26
26
  type = _ref$type === void 0 ? 'button' : _ref$type,
27
- rest = _objectWithoutProperties(_ref, _excluded$2);
27
+ consumerProps = _objectWithoutProperties(_ref, _excluded$2);
28
28
 
29
29
  var internalRef = react.useRef(null);
30
30
  var composedRef = utils.useComposedRefs(internalRef, forwardedRef);
@@ -42,11 +42,12 @@ var BaseButton = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
42
42
  var preventableClickHandler = getPreventableClickHandler(onClickProp, disabled);
43
43
  preventableClickHandler(event);
44
44
  }, [disabled, onClickProp]);
45
- return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({
46
- as: "button"
47
- }, rest), {}, {
45
+ return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
46
+ as: "button",
47
+ ref: composedRef // Hide aria-disabled attribute when button is not disabled
48
+ ,
49
+ "aria-disabled": disabled || undefined,
48
50
  onClick: onClick,
49
- ref: composedRef,
50
51
  type: type
51
52
  }));
52
53
  });
@@ -66,39 +67,62 @@ function getPreventableClickHandler(onClick, disabled) {
66
67
  };
67
68
  }
68
69
 
70
+ var highDisabledStyles = {
71
+ backgroundDisabled: 'disabled',
72
+ borderDisabled: 'fieldDisabled',
73
+ textToneDisabled: 'neutralInverted'
74
+ };
75
+ var highDisabledAltStyles = {
76
+ backgroundDisabled: 'neutral',
77
+ borderDisabled: 'standard',
78
+ textToneDisabled: 'placeholder'
79
+ };
80
+ var lowDisabledStyles = {
81
+ backgroundDisabled: 'inputDisabled',
82
+ textToneDisabled: 'disabled'
83
+ };
84
+ var lowDisabledAltStyles = {
85
+ backgroundDisabled: 'inputDisabled',
86
+ borderDisabled: 'fieldDisabled',
87
+ textToneDisabled: 'disabled'
88
+ };
89
+ var noneDisabledStyles = {
90
+ backgroundDisabled: 'neutral',
91
+ textToneDisabled: 'disabled'
92
+ };
69
93
  var variants = {
70
94
  high: {
71
- primary: {
95
+ primary: _objectSpread({
72
96
  background: 'primary',
73
97
  backgroundHover: 'primaryHover',
74
98
  backgroundActive: 'primaryActive'
75
- },
76
- secondary: {
99
+ }, highDisabledStyles),
100
+ secondary: _objectSpread({
77
101
  background: 'secondary',
78
102
  backgroundHover: 'secondaryHover',
79
103
  backgroundActive: 'secondaryActive'
80
- },
81
- neutral: {
104
+ }, highDisabledStyles),
105
+ neutral: _objectSpread({
82
106
  background: 'neutral',
83
107
  border: 'field',
84
108
  backgroundHover: 'neutralHover',
85
109
  backgroundActive: 'neutralActive'
86
- },
87
- positive: {
110
+ }, highDisabledAltStyles),
111
+ positive: _objectSpread({
88
112
  background: 'positive',
89
113
  backgroundHover: 'positiveHover',
90
114
  backgroundActive: 'positiveActive'
91
- },
92
- critical: {
115
+ }, highDisabledStyles),
116
+ critical: _objectSpread({
93
117
  background: 'critical',
94
118
  backgroundHover: 'criticalHover',
95
119
  backgroundActive: 'criticalActive'
96
- },
120
+ }, highDisabledStyles),
97
121
  caution: undefined,
98
122
  info: undefined
99
123
  },
100
124
  low: {
101
- primary: {
125
+ primary: _objectSpread({
102
126
  background: 'surface',
103
127
  border: 'primary',
104
128
  borderWidth: 'large',
@@ -109,8 +133,8 @@ var variants = {
109
133
  backgroundActive: 'none',
110
134
  borderActive: 'primaryActive',
111
135
  textToneActive: 'primaryActive'
112
- },
113
- secondary: {
136
+ }, lowDisabledAltStyles),
137
+ secondary: _objectSpread({
114
138
  background: 'surface',
115
139
  border: 'secondary',
116
140
  borderWidth: 'large',
@@ -121,76 +145,76 @@ var variants = {
121
145
  backgroundActive: 'none',
122
146
  borderActive: 'secondaryActive',
123
147
  textToneActive: 'secondaryActive'
124
- },
125
- neutral: {
148
+ }, lowDisabledAltStyles),
149
+ neutral: _objectSpread({
126
150
  background: 'neutralLow',
127
151
  backgroundHover: 'neutralLowHover',
128
152
  backgroundActive: 'neutralLowActive'
129
- },
130
- positive: {
153
+ }, lowDisabledStyles),
154
+ positive: _objectSpread({
131
155
  background: 'positiveLow',
132
156
  backgroundHover: 'positiveLowHover',
133
157
  backgroundActive: 'positiveLowActive'
134
- },
135
- caution: {
158
+ }, lowDisabledStyles),
159
+ caution: _objectSpread({
136
160
  background: 'cautionLow',
137
161
  backgroundHover: 'cautionLowHover',
138
162
  backgroundActive: 'cautionLowActive'
139
- },
140
- critical: {
163
+ }, lowDisabledStyles),
164
+ critical: _objectSpread({
141
165
  background: 'criticalLow',
142
166
  backgroundHover: 'criticalLowHover',
143
167
  backgroundActive: 'criticalLowActive'
144
- },
145
- info: {
168
+ }, lowDisabledStyles),
169
+ info: _objectSpread({
146
170
  background: 'infoLow',
147
171
  backgroundHover: 'infoLowHover',
148
172
  backgroundActive: 'infoLowActive'
149
- }
173
+ }, lowDisabledStyles)
150
174
  },
151
175
  none: {
152
- primary: {
176
+ primary: _objectSpread({
153
177
  background: 'surface',
154
178
  textTone: 'primaryActive',
155
179
  backgroundHover: 'primaryLowHover',
156
180
  backgroundActive: 'primaryLowActive'
157
- },
158
- secondary: {
181
+ }, noneDisabledStyles),
182
+ secondary: _objectSpread({
159
183
  background: 'surface',
160
184
  textTone: 'secondaryActive',
161
185
  backgroundHover: 'secondaryLowHover',
162
186
  backgroundActive: 'secondaryLowActive'
163
- },
164
- neutral: {
187
+ }, noneDisabledStyles),
188
+ neutral: _objectSpread({
165
189
  background: 'surface',
166
190
  textTone: 'neutral',
167
191
  backgroundHover: 'neutralLowHover',
168
192
  backgroundActive: 'neutralLowActive'
169
- },
170
- positive: {
193
+ }, noneDisabledStyles),
194
+ positive: _objectSpread({
171
195
  background: 'surface',
172
196
  textTone: 'positive',
173
197
  backgroundHover: 'positiveLowHover',
174
198
  backgroundActive: 'positiveLowActive'
175
- },
176
- caution: {
199
+ }, noneDisabledStyles),
200
+ caution: _objectSpread({
177
201
  background: 'surface',
178
202
  textTone: 'caution',
179
203
  backgroundHover: 'cautionLowHover',
180
204
  backgroundActive: 'cautionLowActive'
181
- },
182
- critical: {
205
+ }, noneDisabledStyles),
206
+ critical: _objectSpread({
183
207
  background: 'surface',
184
208
  textTone: 'critical',
185
209
  backgroundHover: 'criticalLowHover',
186
210
  backgroundActive: 'criticalLowActive'
187
- },
188
- info: {
211
+ }, noneDisabledStyles),
212
+ info: _objectSpread({
189
213
  background: 'surface',
190
214
  textTone: 'info',
191
215
  backgroundHover: 'infoLowHover',
192
216
  backgroundActive: 'infoLowActive'
193
- }
217
+ }, noneDisabledStyles)
194
218
  }
195
219
  };
196
220
  var mapTokens = {
@@ -216,7 +240,7 @@ var resolveButtonChildren = function resolveButtonChildren(_ref) {
216
240
  tone = _ref.tone;
217
241
  var variant = variants[prominence][tone];
218
242
  return react.Children.map(children, function (child) {
219
- if (typeof child === 'string') {
243
+ if (typeof child === 'string' || typeof child === 'number') {
220
244
  return /*#__PURE__*/jsxRuntime.jsx(HiddenWhenLoading, {
221
245
  isLoading: isLoading,
222
246
  children: /*#__PURE__*/jsxRuntime.jsx(text.Text, {
@@ -263,6 +287,15 @@ function HiddenWhenLoading(_ref2) {
263
287
  });
264
288
  }
265
289
 
290
+ /**
291
+ * useButtonStyles
292
+ *
293
+ * Custom hook for styling buttons and certain links.
294
+ * Returns a tuple where the first item is an object of props to spread onto the
295
+ * underlying `Box` component, and the second item is a CSS object that can be
296
+ * passed to Emotion's `css` function.
297
+ */
298
+
266
299
  function useButtonStyles(_ref) {
267
300
  var iconOnly = _ref.iconOnly,
268
301
  prominence = _ref.prominence,
@@ -272,14 +305,17 @@ function useButtonStyles(_ref) {
272
305
  var focusRingStyles = a11y.useFocusRing({
273
306
  tone: tone
274
307
  });
308
+ var disabledFocusRingStyles = a11y.useFocusRing({
309
+ tone: 'disabled'
310
+ });
275
311
  var variant = variants[prominence][tone];
276
312
  var isLarge = size === 'large';
277
- var transitionColours = {
278
- transitionProperty: 'color, background-color, border-color, text-decoration-color',
279
- transitionTimingFunction: 'cubic-bezier(0.02, 1.505, 0.745, 1.235)',
313
+ var transitionColors = {
314
+ transitionProperty: 'color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter',
315
+ transitionTimingFunction: theme$1.animation.standard.easing,
280
316
  transitionDuration: "".concat(theme$1.animation.standard.duration, "ms")
281
317
  };
282
- var buttonStyleProps = {
318
+ return [{
283
319
  alignItems: 'center',
284
320
  background: variant === null || variant === void 0 ? void 0 : variant.background,
285
321
  border: variant === null || variant === void 0 ? void 0 : variant.border,
@@ -292,32 +328,44 @@ function useButtonStyles(_ref) {
292
328
  justifyContent: 'center',
293
329
  paddingX: iconOnly ? undefined : mapTokens.spacing[size],
294
330
  position: 'relative',
295
- width: iconOnly ? mapTokens.size[size] : undefined,
296
- // interactions styles
297
- className: css.css(_objectSpread(_objectSpread({}, transitionColours), {}, {
298
- '&:hover': {
331
+ width: iconOnly ? mapTokens.size[size] : undefined
332
+ }, _objectSpread(_objectSpread({}, transitionColors), {}, {
333
+ // Styles for buttons that aren't disabled.
334
+ // Using the :not() pseudo-class so we don't have to undo the styles when
335
+ // the button is disabled.
336
+ '&:not([aria-disabled=true])': {
337
+ ':hover': {
299
338
  borderColor: variant !== null && variant !== void 0 && variant.borderHover ? theme$1.border.color[variant.borderHover] : undefined,
300
339
  backgroundColor: variant !== null && variant !== void 0 && variant.backgroundHover ? theme$1.backgroundInteractions[variant.backgroundHover] : undefined,
301
340
  // Style button text when hovering
302
- '> *': _objectSpread(_objectSpread({}, transitionColours), {}, {
341
+ '> *': _objectSpread(_objectSpread({}, transitionColors), {}, {
303
342
  color: variant !== null && variant !== void 0 && variant.textToneHover ? theme$1.color.foreground[variant.textToneHover] : undefined,
304
343
  stroke: variant !== null && variant !== void 0 && variant.textToneHover ? theme$1.color.foreground[variant.textToneHover] : undefined
305
344
  })
306
345
  },
307
- '&:active': {
346
+ ':active': {
308
347
  borderColor: variant !== null && variant !== void 0 && variant.borderActive ? theme$1.border.color[variant.borderActive] : undefined,
309
348
  backgroundColor: variant !== null && variant !== void 0 && variant.backgroundActive ? theme$1.backgroundInteractions[variant === null || variant === void 0 ? void 0 : variant.backgroundActive] : undefined,
310
349
  transform: 'scale(0.98)',
311
350
  // Style button text when it's active
312
- '> *': _objectSpread(_objectSpread({}, transitionColours), {}, {
351
+ '> *': _objectSpread(_objectSpread({}, transitionColors), {}, {
313
352
  color: variant !== null && variant !== void 0 && variant.textToneActive ? theme$1.color.foreground[variant.textToneActive] : undefined,
314
353
  stroke: variant !== null && variant !== void 0 && variant.textToneActive ? theme$1.color.foreground[variant.textToneActive] : undefined
315
354
  })
316
355
  },
317
356
  ':focus': focusRingStyles
318
- }))
319
- };
320
- return buttonStyleProps;
357
+ },
358
+ '&[aria-disabled=true]': {
359
+ backgroundColor: variant !== null && variant !== void 0 && variant.backgroundDisabled ? theme$1.color.background[variant === null || variant === void 0 ? void 0 : variant.backgroundDisabled] : undefined,
360
+ borderColor: variant !== null && variant !== void 0 && variant.borderDisabled ? theme$1.border.color[variant.borderDisabled] : undefined,
361
+ cursor: 'default',
362
+ '*': {
363
+ color: variant !== null && variant !== void 0 && variant.textToneDisabled ? theme$1.color.foreground[variant.textToneDisabled] : undefined,
364
+ stroke: variant !== null && variant !== void 0 && variant.textToneDisabled ? theme$1.color.foreground[variant.textToneDisabled] : undefined
365
+ },
366
+ ':focus': disabledFocusRingStyles
367
+ }
368
+ })];
321
369
  }
322
370
 
323
371
  var _excluded$1 = ["aria-controls", "aria-describedby", "aria-expanded", "data", "disabled", "id", "loading", "onClick", "prominence", "size", "tone", "type"];
@@ -346,21 +394,26 @@ var Button = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
346
394
  props = _objectWithoutProperties(_ref, _excluded$1);
347
395
 
348
396
  var iconOnly = Boolean(props.label);
349
- var buttonStyleProps = useButtonStyles({
397
+
398
+ var _useButtonStyles = useButtonStyles({
350
399
  iconOnly: iconOnly,
351
400
  size: size,
352
401
  tone: tone,
353
402
  prominence: prominence
354
- });
403
+ }),
404
+ _useButtonStyles2 = _slicedToArray(_useButtonStyles, 2),
405
+ boxProps = _useButtonStyles2[0],
406
+ buttonStyles = _useButtonStyles2[1];
407
+
355
408
  var isDisabled = disabled || loading;
356
409
  var isLoading = loading && !disabled;
357
410
  var variant = variants[prominence][tone];
358
- return /*#__PURE__*/jsxRuntime.jsxs(BaseButton, _objectSpread(_objectSpread({}, buttonStyleProps), {}, {
411
+ return /*#__PURE__*/jsxRuntime.jsxs(BaseButton, _objectSpread(_objectSpread({}, boxProps), {}, {
359
412
  "aria-controls": ariaControls,
360
413
  "aria-describedby": ariaDescribedBy,
361
- "aria-disabled": isDisabled,
362
414
  "aria-expanded": ariaExpanded,
363
415
  "aria-label": props.label,
416
+ className: css.css(buttonStyles),
364
417
  data: data,
365
418
  disabled: isDisabled,
366
419
  id: id,
@@ -403,7 +456,7 @@ function Loading(_ref2) {
403
456
  var _excluded = ["data", "href", "id", "prominence", "size", "tone"];
404
457
 
405
458
  /** The appearance of a `Button`, with the semantics of a link. */
406
- var ButtonLink = ts.forwardRefWithAs(function (_ref, ref) {
459
+ var ButtonLink = ts.forwardRefWithAs(function (_ref, forwardedRef) {
407
460
  var data = _ref.data,
408
461
  href = _ref.href,
409
462
  id = _ref.id,
@@ -413,25 +466,31 @@ var ButtonLink = ts.forwardRefWithAs(function (_ref, ref) {
413
466
  size = _ref$size === void 0 ? 'medium' : _ref$size,
414
467
  _ref$tone = _ref.tone,
415
468
  tone = _ref$tone === void 0 ? 'primary' : _ref$tone,
416
- props = _objectWithoutProperties(_ref, _excluded);
469
+ consumerProps = _objectWithoutProperties(_ref, _excluded);
417
470
 
418
- var LinkComponent = link.useLinkComponent(ref);
419
- var iconOnly = Boolean(props.label);
420
- var buttonStyleProps = useButtonStyles({
471
+ var LinkComponent = link.useLinkComponent(forwardedRef);
472
+ var iconOnly = Boolean(consumerProps.label);
473
+
474
+ var _useButtonStyles = useButtonStyles({
421
475
  iconOnly: iconOnly,
422
476
  prominence: prominence,
423
477
  size: size,
424
478
  tone: tone
425
- });
426
- return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread(_objectSpread({
427
- "aria-label": props.label,
479
+ }),
480
+ _useButtonStyles2 = _slicedToArray(_useButtonStyles, 2),
481
+ boxProps = _useButtonStyles2[0],
482
+ buttonStyles = _useButtonStyles2[1];
483
+
484
+ return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, boxProps), {}, {
485
+ "aria-label": consumerProps.label,
428
486
  as: LinkComponent,
429
487
  asElement: "a",
430
- id: id,
488
+ className: css.css(buttonStyles),
489
+ data: data,
431
490
  href: href,
432
- ref: ref
433
- }, buttonStyleProps), data ? internal.buildDataAttributes(data) : undefined), {}, {
434
- children: resolveButtonChildren(_objectSpread(_objectSpread({}, props), {}, {
491
+ id: id,
492
+ ref: forwardedRef,
493
+ children: resolveButtonChildren(_objectSpread(_objectSpread({}, consumerProps), {}, {
435
494
  isLoading: false,
436
495
  prominence: prominence,
437
496
  size: size,
@@ -443,3 +502,4 @@ var ButtonLink = ts.forwardRefWithAs(function (_ref, ref) {
443
502
  exports.BaseButton = BaseButton;
444
503
  exports.Button = Button;
445
504
  exports.ButtonLink = ButtonLink;
505
+ exports.useButtonStyles = useButtonStyles;