@atlaskit/button 17.12.0 → 17.12.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.
Files changed (25) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/new-button/containers/split-button/split-button.js +9 -3
  3. package/dist/cjs/new-button/variants/shared/use-button-base.js +332 -46
  4. package/dist/cjs/old-button/shared/button-base.js +1 -1
  5. package/dist/es2019/new-button/containers/split-button/split-button.js +7 -1
  6. package/dist/es2019/new-button/variants/shared/use-button-base.js +333 -45
  7. package/dist/es2019/old-button/shared/button-base.js +1 -1
  8. package/dist/esm/new-button/containers/split-button/split-button.js +7 -1
  9. package/dist/esm/new-button/variants/shared/use-button-base.js +333 -47
  10. package/dist/esm/old-button/shared/button-base.js +1 -1
  11. package/dist/types/new-button/variants/shared/use-button-base.d.ts +3 -2
  12. package/dist/types/old-button/custom-theme-button/theme.d.ts +2 -6
  13. package/dist/types-ts4.5/new-button/variants/shared/use-button-base.d.ts +3 -2
  14. package/dist/types-ts4.5/old-button/custom-theme-button/theme.d.ts +2 -6
  15. package/package.json +4 -2
  16. package/dist/cjs/new-button/variants/shared/colors.js +0 -145
  17. package/dist/cjs/new-button/variants/shared/xcss.js +0 -198
  18. package/dist/es2019/new-button/variants/shared/colors.js +0 -136
  19. package/dist/es2019/new-button/variants/shared/xcss.js +0 -196
  20. package/dist/esm/new-button/variants/shared/colors.js +0 -136
  21. package/dist/esm/new-button/variants/shared/xcss.js +0 -190
  22. package/dist/types/new-button/variants/shared/colors.d.ts +0 -20
  23. package/dist/types/new-button/variants/shared/xcss.d.ts +0 -33
  24. package/dist/types-ts4.5/new-button/variants/shared/colors.d.ts +0 -20
  25. package/dist/types-ts4.5/new-button/variants/shared/xcss.d.ts +0 -33
@@ -1,18 +1,334 @@
1
- import React, { Fragment, useCallback, useMemo, useRef } from 'react';
1
+ import React, { Fragment, useRef } from 'react';
2
+ import mergeRefs from '@atlaskit/ds-lib/merge-refs';
2
3
  import useAutoFocus from '@atlaskit/ds-lib/use-auto-focus';
3
4
  import { Box, xcss } from '@atlaskit/primitives';
5
+ import * as colors from '@atlaskit/theme/colors';
6
+ import { fontSize as getFontSize } from '@atlaskit/theme/constants';
4
7
  import { useSplitButtonContext } from '../../containers/split-button/split-button-context';
5
8
  import blockEvents from './block-events';
6
- import { getXCSS } from './xcss';
9
+ const fontSize = getFontSize();
10
+ const buttonStyles = xcss({
11
+ display: 'inline-flex',
12
+ boxSizing: 'border-box',
13
+ width: 'auto',
14
+ maxWidth: '100%',
15
+ position: 'relative',
16
+ alignItems: 'baseline',
17
+ justifyContent: 'center',
18
+ columnGap: 'space.050',
19
+ background: `var(--ds-background-neutral, ${colors.N20A})`,
20
+ borderRadius: 'border.radius.100',
21
+ borderWidth: 'border.width.0',
22
+ // @ts-expect-error
23
+ color: `var(--ds-text, ${colors.N500})`,
24
+ fontFamily: 'inherit',
25
+ fontSize: 'inherit',
26
+ fontStyle: 'normal',
27
+ fontWeight: 500,
28
+ height: `${32 / fontSize}em`,
29
+ lineHeight: `${32 / fontSize}em`,
30
+ paddingBlock: 'space.0',
31
+ paddingInlineEnd: 'space.150',
32
+ paddingInlineStart: 'space.150',
33
+ textAlign: 'center',
34
+ transition: 'background 0.1s ease-out, box-shadow 0.15s cubic-bezier(0.47, 0.03, 0.49, 1.38)',
35
+ verticalAlign: 'middle',
36
+ whiteSpace: 'nowrap',
37
+ ':visited': {
38
+ // @ts-expect-error
39
+ color: `var(--ds-text, ${colors.N500})`
40
+ }
41
+ });
42
+ const defaultInteractiveStyles = xcss({
43
+ ':hover': {
44
+ background: "var(--ds-background-neutral-hovered, #091e4214)",
45
+ // @ts-expect-error
46
+ color: `var(--ds-text, ${colors.N500})`,
47
+ transitionDuration: '0s, 0.15s'
48
+ },
49
+ ':active': {
50
+ background: `var(--ds-background-neutral-pressed, ${colors.B75})`,
51
+ // @ts-expect-error
52
+ color: `var(--ds-text, ${colors.B400})`,
53
+ transitionDuration: '0s, 0s'
54
+ }
55
+ });
56
+ const primaryStyles = xcss({
57
+ background: "var(--ds-background-brand-bold, #0052CC)",
58
+ // @ts-expect-error
59
+ color: "var(--ds-text-inverse, #FFFFFF)",
60
+ ':visited': {
61
+ // @ts-expect-error
62
+ color: "var(--ds-text-inverse, #FFFFFF)"
63
+ }
64
+ });
65
+ const primaryInteractiveStyles = xcss({
66
+ ':hover': {
67
+ // @ts-expect-error
68
+ color: "var(--ds-text-inverse, #FFFFFF)",
69
+ background: "var(--ds-background-brand-bold-hovered, #0065FF)"
70
+ },
71
+ ':active': {
72
+ // @ts-expect-error
73
+ color: "var(--ds-text-inverse, #FFFFFF)",
74
+ background: "var(--ds-background-brand-bold-pressed, #0747A6)"
75
+ }
76
+ });
77
+ const warningStyles = xcss({
78
+ background: "var(--ds-background-warning-bold, #FFAB00)",
79
+ // @ts-expect-error
80
+ color: "var(--ds-text-warning-inverse, #172B4D)",
81
+ ':visited': {
82
+ // @ts-expect-error
83
+ color: "var(--ds-text-warning-inverse, #172B4D)"
84
+ }
85
+ });
86
+ const warningInteractiveStyles = xcss({
87
+ ':hover': {
88
+ // @ts-expect-error
89
+ color: "var(--ds-text-warning-inverse, #172B4D)",
90
+ background: "var(--ds-background-warning-bold-hovered, #FFC400)"
91
+ },
92
+ ':active': {
93
+ // @ts-expect-error
94
+ color: "var(--ds-text-warning-inverse, #172B4D)",
95
+ background: "var(--ds-background-warning-bold-pressed, #FF991F)"
96
+ }
97
+ });
98
+ const dangerStyles = xcss({
99
+ background: "var(--ds-background-danger-bold, #DE350B)",
100
+ color: 'color.text.inverse',
101
+ ':visited': {
102
+ color: 'color.text.inverse'
103
+ }
104
+ });
105
+ const dangerInteractiveStyles = xcss({
106
+ ':hover': {
107
+ color: 'color.text.inverse',
108
+ background: "var(--ds-background-danger-bold-hovered, #FF5630)"
109
+ },
110
+ ':active': {
111
+ color: 'color.text.inverse',
112
+ background: "var(--ds-background-danger-bold-pressed, #BF2600)"
113
+ }
114
+ });
115
+ const subtleStyles = xcss({
116
+ background: "var(--ds-background-neutral-subtle, transparent)",
117
+ // @ts-expect-error
118
+ color: "var(--ds-text, #42526E)",
119
+ ':visited': {
120
+ // @ts-expect-error
121
+ color: "var(--ds-text, #42526E)"
122
+ }
123
+ });
124
+ const subtleInteractiveStyles = xcss({
125
+ ':hover': {
126
+ background: "var(--ds-background-neutral-subtle-hovered, #091e4214)",
127
+ // @ts-expect-error
128
+ color: "var(--ds-text, #42526E)"
129
+ },
130
+ ':active': {
131
+ background: "var(--ds-background-neutral-subtle-pressed, #B3D4FF)",
132
+ // @ts-expect-error
133
+ color: "var(--ds-text, #42526E)"
134
+ }
135
+ });
136
+ const linkStyles = xcss({
137
+ // @ts-expect-error
138
+ color: `var(--ds-link, ${colors.B400})`,
139
+ background: "var(--ds-background-neutral-subtle, transparent)",
140
+ textDecoration: 'none',
141
+ ':hover': {
142
+ // @ts-expect-error
143
+ color: `var(--ds-link, ${colors.B300})`,
144
+ background: "var(--ds-background-neutral-subtle, transparent)"
145
+ },
146
+ ':active': {
147
+ // @ts-expect-error
148
+ color: "var(--ds-link-pressed, #0055CC)",
149
+ background: "var(--ds-background-neutral-subtle, transparent)"
150
+ },
151
+ ':visited': {
152
+ // @ts-expect-error
153
+ color: `var(--ds-link, ${colors.B400})`
154
+ }
155
+ });
156
+ const subtleLinkStyles = xcss({
157
+ // @ts-expect-error
158
+ color: `var(--ds-text-subtle, ${colors.N200})`,
159
+ background: "var(--ds-background-neutral-subtle, transparent)",
160
+ textDecoration: 'none',
161
+ ':hover': {
162
+ // @ts-expect-error
163
+ color: `var(--ds-text-subtle, ${colors.N90})`,
164
+ background: "var(--ds-background-neutral-subtle, transparent)"
165
+ },
166
+ ':active': {
167
+ // @ts-expect-error
168
+ color: `var(--ds-text, ${colors.N400})`,
169
+ background: "var(--ds-background-neutral-subtle, transparent)"
170
+ },
171
+ ':visited': {
172
+ // @ts-expect-error
173
+ color: `var(--ds-text-subtle, ${colors.N200})`
174
+ }
175
+ });
176
+
177
+ // Required due to Jira's AUI CSS reset: https://product-fabric.atlassian.net/browse/DSP-15687
178
+ const linkDecorationUnsetStyles = xcss({
179
+ textDecoration: 'none',
180
+ ':hover': {
181
+ textDecoration: 'none'
182
+ },
183
+ ':active': {
184
+ textDecoration: 'none'
185
+ },
186
+ ':focus': {
187
+ textDecoration: 'none'
188
+ }
189
+ });
190
+ const linkDecorationStyles = xcss({
191
+ ':hover': {
192
+ textDecoration: 'underline'
193
+ },
194
+ ':focus': {
195
+ textDecoration: 'underline'
196
+ }
197
+ });
198
+ const disabledStyles = xcss({
199
+ background: `var(--ds-background-disabled, ${colors.N20A})`,
200
+ // @ts-expect-error
201
+ color: "var(--ds-text-disabled, #091E424F)",
202
+ ':hover': {
203
+ background: `var(--ds-background-disabled, ${colors.N20A})`,
204
+ // @ts-expect-error
205
+ color: "var(--ds-text-disabled, #091E424F)"
206
+ },
207
+ ':active': {
208
+ background: `var(--ds-background-disabled, ${colors.N20A})`,
209
+ // @ts-expect-error
210
+ color: "var(--ds-text-disabled, #091E424F)"
211
+ }
212
+ });
213
+ const selectedStyles = xcss({
214
+ background: `var(--ds-background-selected, ${colors.N700})`,
215
+ // @ts-expect-error
216
+ color: `var(--ds-text-selected, ${colors.N20})`,
217
+ ':visited': {
218
+ // @ts-expect-error
219
+ color: `var(--ds-text-selected, ${colors.N20})`
220
+ }
221
+ });
222
+ const selectedInteractiveStyles = xcss({
223
+ ':hover': {
224
+ // @ts-expect-error
225
+ color: `var(--ds-text-selected, ${colors.N20})`,
226
+ background: `var(--ds-background-selected-hovered, ${colors.N700})`
227
+ },
228
+ ':active': {
229
+ // @ts-expect-error
230
+ color: `var(--ds-text-selected, ${colors.N20})`,
231
+ background: `var(--ds-background-selected-pressed, ${colors.N700})`
232
+ }
233
+ });
234
+
235
+ // TODO: Remove me once we kill color fallbacks
236
+ const selectedWarningStyles = xcss({
237
+ background: `var(--ds-background-selected, ${colors.Y400})`,
238
+ // @ts-expect-error
239
+ color: `var(--ds-text-selected, ${colors.N800})`,
240
+ ':hover': {
241
+ // @ts-expect-error
242
+ color: `var(--ds-text-selected, ${colors.N20})`,
243
+ background: `var(--ds-background-selected, ${colors.Y400})`
244
+ },
245
+ ':active': {
246
+ // @ts-expect-error
247
+ color: `var(--ds-text-selected, ${colors.N20})`,
248
+ background: `var(--ds-background-selected, ${colors.Y400})`
249
+ }
250
+ });
251
+
252
+ // TODO: Remove me once we kill color fallbacks
253
+ const selectedDangerStyles = xcss({
254
+ background: `var(--ds-background-selected, ${colors.R500})`,
255
+ // @ts-expect-error
256
+ color: `var(--ds-text-selected, ${colors.N20})`,
257
+ ':hover': {
258
+ // @ts-expect-error
259
+ color: `var(--ds-text-selected, ${colors.N20})`,
260
+ background: `var(--ds-background-selected, ${colors.R500})`
261
+ },
262
+ ':active': {
263
+ // @ts-expect-error
264
+ color: `var(--ds-text-selected, ${colors.N20})`,
265
+ background: `var(--ds-background-selected, ${colors.R500})`
266
+ }
267
+ });
268
+ const spacingCompactStyles = xcss({
269
+ columnGap: 'space.050',
270
+ height: `${24 / fontSize}em`,
271
+ lineHeight: `${24 / fontSize}em`,
272
+ paddingInlineEnd: 'space.150',
273
+ paddingInlineStart: 'space.150',
274
+ verticalAlign: 'middle'
275
+ });
276
+ const spacingNoneStyles = xcss({
277
+ columnGap: 'space.0',
278
+ height: 'auto',
279
+ lineHeight: 'inherit',
280
+ paddingInlineEnd: 'space.0',
281
+ paddingInlineStart: 'space.0',
282
+ verticalAlign: 'baseline'
283
+ });
284
+ const circleStyles = xcss({
285
+ borderRadius: 'border.radius.circle'
286
+ });
287
+ const fullWidthStyles = xcss({
288
+ width: '100%'
289
+ });
290
+ const loadingOverlayStyles = xcss({
291
+ cursor: 'progress'
292
+ });
293
+ const nonInteractiveStyles = xcss({
294
+ cursor: 'not-allowed'
295
+ });
296
+ const iconButtonStyles = xcss({
297
+ height: `${32 / fontSize}em`,
298
+ width: `${32 / fontSize}em`,
299
+ paddingInlineEnd: 'space.0',
300
+ paddingInlineStart: 'space.0'
301
+ });
302
+ const iconButtonCompactStyles = xcss({
303
+ width: `${24 / fontSize}em`,
304
+ height: `${24 / fontSize}em`
305
+ });
306
+ const buttonIconBeforeStyles = xcss({
307
+ paddingInlineStart: 'space.100'
308
+ });
309
+ const buttonIconAfterStyles = xcss({
310
+ paddingInlineEnd: 'space.100'
311
+ });
312
+ const splitButtonStyles = xcss({
313
+ ':focus-visible': {
314
+ zIndex: 'card'
315
+ }
316
+ });
317
+ const navigationSplitButtonStyles = xcss({
318
+ width: '24px',
319
+ backgroundColor: 'color.background.neutral.subtle',
320
+ paddingInlineEnd: 'space.075',
321
+ paddingInlineStart: 'space.075'
322
+ });
7
323
  const overlayStyles = xcss({
324
+ display: 'flex',
8
325
  position: 'absolute',
9
- insetInlineStart: 'space.0',
326
+ alignItems: 'center',
327
+ justifyContent: 'center',
328
+ insetBlockEnd: 'space.0',
10
329
  insetBlockStart: 'space.0',
11
330
  insetInlineEnd: 'space.0',
12
- insetBlockEnd: 'space.0',
13
- display: 'flex',
14
- alignItems: 'center',
15
- justifyContent: 'center'
331
+ insetInlineStart: 'space.0'
16
332
  });
17
333
 
18
334
  /**
@@ -31,7 +347,6 @@ const overlayStyles = xcss({
31
347
  const useButtonBase = ({
32
348
  appearance: propAppearance = 'default',
33
349
  autoFocus = false,
34
- buttonType,
35
350
  isDisabled: propIsDisabled = false,
36
351
  isLoading = false,
37
352
  isSelected = false,
@@ -57,51 +372,24 @@ const useButtonBase = ({
57
372
  shouldFitContainer = false,
58
373
  spacing: propSpacing = 'default'
59
374
  }) => {
60
- const ourRef = useRef();
375
+ const localRef = useRef(null);
61
376
  const splitButtonContext = useSplitButtonContext();
62
377
  const isSplitButton = Boolean(splitButtonContext);
63
378
  const isNavigationSplitButton = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isNavigationSplitButton) || false;
64
379
  const appearance = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.appearance) || propAppearance;
65
380
  const spacing = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.spacing) || propSpacing;
66
381
  const isDisabled = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isDisabled) || propIsDisabled;
67
- const isHighlighted = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isHighlighted) || false;
68
- const isActiveOverSelected = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isActiveOverSelected) || false;
69
- const setRef = useCallback(node => {
70
- ourRef.current = node;
71
- if (ref === null) {
72
- return;
73
- }
74
- if (typeof ref === 'function') {
75
- ref(node);
76
- return;
77
- }
78
-
79
- // @ts-ignore
80
- ref.current = node;
81
- }, [ourRef, ref]);
82
- useAutoFocus(ourRef, autoFocus);
83
- const buttonXCSS = useMemo(() => getXCSS({
84
- appearance,
85
- spacing,
86
- isDisabled,
87
- isLoading,
88
- isSelected,
89
- isHighlighted,
90
- isActiveOverSelected,
91
- shouldFitContainer,
92
- isIconButton,
93
- isCircle,
94
- hasOverlay: Boolean(overlay),
95
- isLink: buttonType === 'link',
96
- hasIconBefore,
97
- hasIconAfter,
98
- isSplit: isSplitButton,
99
- isNavigationSplit: isNavigationSplitButton
100
- }), [appearance, buttonType, spacing, isDisabled, isLoading, isSelected, isHighlighted, isActiveOverSelected, isIconButton, isCircle, shouldFitContainer, overlay, hasIconBefore, hasIconAfter, isSplitButton, isNavigationSplitButton]);
382
+ const hasOverlay = Boolean(overlay);
383
+ const isInteractive = !isDisabled && !isLoading && !hasOverlay;
101
384
  const isEffectivelyDisabled = isDisabled || Boolean(overlay);
385
+ useAutoFocus(localRef, autoFocus);
102
386
  return {
103
- ref: setRef,
104
- xcss: buttonXCSS,
387
+ ref: mergeRefs([localRef, ref]),
388
+ xcss: [buttonStyles, appearance === 'default' && isInteractive && defaultInteractiveStyles, appearance === 'primary' && primaryStyles, appearance === 'primary' && isInteractive && primaryInteractiveStyles, appearance === 'warning' && warningStyles, appearance === 'warning' && isInteractive && warningInteractiveStyles, appearance === 'danger' && dangerStyles, appearance === 'danger' && isInteractive && dangerInteractiveStyles, appearance === 'subtle' && subtleStyles, appearance === 'subtle' && isInteractive && subtleInteractiveStyles, appearance === 'link' && linkStyles, appearance === 'subtle-link' && subtleLinkStyles, !isSelected && (appearance === 'link' || appearance === 'subtle-link') ? linkDecorationStyles : linkDecorationUnsetStyles, isSelected && selectedStyles, isSelected && isInteractive && selectedInteractiveStyles,
389
+ // TODO: remove me once we kill color fallbacks
390
+ isSelected && appearance === 'danger' && selectedDangerStyles,
391
+ // TODO: remove me once we kill color fallbacks
392
+ isSelected && appearance === 'warning' && selectedWarningStyles, isDisabled && disabledStyles, isCircle && !isSplitButton && circleStyles, spacing === 'compact' && spacingCompactStyles, spacing === 'none' && spacingNoneStyles, spacing !== 'none' && hasIconBefore && buttonIconBeforeStyles, spacing !== 'none' && hasIconAfter && buttonIconAfterStyles, isIconButton && iconButtonStyles, isIconButton && spacing === 'compact' && iconButtonCompactStyles, shouldFitContainer && fullWidthStyles, isLoading && loadingOverlayStyles, (isDisabled || hasOverlay && !isLoading) && nonInteractiveStyles, isSplitButton && splitButtonStyles, isNavigationSplitButton && navigationSplitButtonStyles],
105
393
  // Consider overlay buttons to be effectively disabled
106
394
  isDisabled: isEffectivelyDisabled,
107
395
  children: /*#__PURE__*/React.createElement(Fragment, null, children, overlay ? /*#__PURE__*/React.createElement(Box, {
@@ -102,7 +102,7 @@ export default /*#__PURE__*/React.forwardRef(function ButtonBase(props, ref) {
102
102
  action: 'clicked',
103
103
  componentName: 'button',
104
104
  packageName: "@atlaskit/button",
105
- packageVersion: "17.12.0",
105
+ packageVersion: "17.12.2",
106
106
  analyticsData: analyticsContext
107
107
  });
108
108
 
@@ -1,7 +1,13 @@
1
1
  /** @jsx jsx */
2
2
 
3
3
  import { css, jsx } from '@emotion/react';
4
- import { heights } from '../../variants/shared/xcss';
4
+ import { fontSize as getFontSize } from '@atlaskit/theme/constants';
5
+ var fontSize = getFontSize();
6
+ var heights = {
7
+ default: "".concat(32 / fontSize, "em"),
8
+ compact: "".concat(24 / fontSize, "em"),
9
+ none: 'auto'
10
+ };
5
11
  import { SplitButtonContext } from './split-button-context';
6
12
  import { getActions } from './utils';
7
13
  var baseDividerStyles = css({