@atlaskit/button 16.9.3 → 16.10.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/CHANGELOG.md +16 -0
- package/dist/cjs/entry-points/button-group.js +1 -1
- package/dist/cjs/entry-points/custom-theme-button.js +1 -1
- package/dist/cjs/entry-points/loading-button.js +1 -1
- package/dist/cjs/entry-points/new.js +34 -0
- package/dist/cjs/entry-points/standard-button.js +1 -1
- package/dist/cjs/entry-points/unsafe.js +13 -0
- package/dist/cjs/new-button/variants/default/button.js +100 -0
- package/dist/cjs/new-button/variants/default/link.js +106 -0
- package/dist/cjs/new-button/variants/default/use-default-button.js +90 -0
- package/dist/cjs/new-button/variants/icon/button.js +96 -0
- package/dist/cjs/new-button/variants/icon/link.js +102 -0
- package/dist/cjs/new-button/variants/icon/use-icon-button.js +82 -0
- package/dist/cjs/new-button/variants/shared/block-events.js +33 -0
- package/dist/cjs/new-button/variants/shared/colors.js +130 -0
- package/dist/cjs/new-button/variants/shared/use-button-base.js +140 -0
- package/dist/cjs/new-button/variants/shared/xcss.js +191 -0
- package/dist/cjs/new-button/variants/types.js +5 -0
- package/dist/cjs/old-button/custom-theme-button/custom-theme-button-types.js +5 -0
- package/dist/cjs/{custom-theme-button → old-button/custom-theme-button}/custom-theme-button.js +2 -2
- package/dist/cjs/{custom-theme-button → old-button/custom-theme-button}/theme.js +2 -2
- package/dist/cjs/{shared → old-button/shared}/button-base.js +2 -2
- package/dist/cjs/{shared → old-button/shared}/css.js +2 -2
- package/dist/cjs/old-button/types.js +5 -0
- package/dist/cjs/utils/appearances.js +9 -0
- package/dist/cjs/utils/spacing.js +9 -0
- package/dist/cjs/utils/variants.js +35 -0
- package/dist/es2019/entry-points/button-group.js +1 -1
- package/dist/es2019/entry-points/custom-theme-button.js +1 -1
- package/dist/es2019/entry-points/loading-button.js +1 -1
- package/dist/es2019/entry-points/new.js +4 -0
- package/dist/es2019/entry-points/standard-button.js +1 -1
- package/dist/es2019/entry-points/unsafe.js +1 -0
- package/dist/es2019/new-button/variants/default/button.js +91 -0
- package/dist/es2019/new-button/variants/default/link.js +98 -0
- package/dist/es2019/new-button/variants/default/use-default-button.js +80 -0
- package/dist/es2019/new-button/variants/icon/button.js +87 -0
- package/dist/es2019/new-button/variants/icon/link.js +94 -0
- package/dist/es2019/new-button/variants/icon/use-icon-button.js +77 -0
- package/dist/es2019/new-button/variants/shared/block-events.js +27 -0
- package/dist/es2019/new-button/variants/shared/colors.js +120 -0
- package/dist/es2019/new-button/variants/shared/use-button-base.js +120 -0
- package/dist/es2019/new-button/variants/shared/xcss.js +182 -0
- package/dist/es2019/{shared → old-button/shared}/button-base.js +2 -5
- package/dist/es2019/old-button/types.js +1 -0
- package/dist/es2019/utils/appearances.js +2 -0
- package/dist/es2019/utils/spacing.js +2 -0
- package/dist/es2019/utils/variants.js +20 -0
- package/dist/esm/entry-points/button-group.js +1 -1
- package/dist/esm/entry-points/custom-theme-button.js +1 -1
- package/dist/esm/entry-points/loading-button.js +1 -1
- package/dist/esm/entry-points/new.js +4 -0
- package/dist/esm/entry-points/standard-button.js +1 -1
- package/dist/esm/entry-points/unsafe.js +1 -0
- package/dist/esm/new-button/variants/default/button.js +92 -0
- package/dist/esm/new-button/variants/default/link.js +98 -0
- package/dist/esm/new-button/variants/default/types.js +1 -0
- package/dist/esm/new-button/variants/default/use-default-button.js +79 -0
- package/dist/esm/new-button/variants/icon/button.js +88 -0
- package/dist/esm/new-button/variants/icon/link.js +94 -0
- package/dist/esm/new-button/variants/icon/types.js +1 -0
- package/dist/esm/new-button/variants/icon/use-icon-button.js +74 -0
- package/dist/esm/new-button/variants/shared/block-events.js +27 -0
- package/dist/esm/new-button/variants/shared/colors.js +120 -0
- package/dist/esm/new-button/variants/shared/use-button-base.js +131 -0
- package/dist/esm/new-button/variants/shared/xcss.js +178 -0
- package/dist/esm/new-button/variants/types.js +1 -0
- package/dist/esm/old-button/custom-theme-button/custom-theme-button-types.js +1 -0
- package/dist/esm/{custom-theme-button → old-button/custom-theme-button}/custom-theme-button.js +2 -2
- package/dist/esm/{custom-theme-button → old-button/custom-theme-button}/theme.js +2 -2
- package/dist/esm/{shared → old-button/shared}/button-base.js +2 -2
- package/dist/esm/{shared → old-button/shared}/css.js +2 -2
- package/dist/esm/old-button/types.js +1 -0
- package/dist/esm/utils/appearances.js +2 -0
- package/dist/esm/utils/spacing.js +2 -0
- package/dist/esm/utils/variants.js +22 -0
- package/dist/types/{button-group.d.ts → containers/button-group.d.ts} +1 -1
- package/dist/types/entry-points/button-group.d.ts +1 -1
- package/dist/types/entry-points/custom-theme-button.d.ts +2 -2
- package/dist/types/entry-points/loading-button.d.ts +2 -2
- package/dist/types/entry-points/new.d.ts +5 -0
- package/dist/types/entry-points/standard-button.d.ts +2 -2
- package/dist/types/entry-points/types.d.ts +1 -1
- package/dist/types/entry-points/unsafe.d.ts +1 -0
- package/dist/types/new-button/variants/default/button.d.ts +19 -0
- package/dist/types/new-button/variants/default/link.d.ts +17 -0
- package/dist/types/new-button/variants/default/types.d.ts +15 -0
- package/dist/types/new-button/variants/default/use-default-button.d.ts +15 -0
- package/dist/types/new-button/variants/icon/button.d.ts +17 -0
- package/dist/types/new-button/variants/icon/link.d.ts +17 -0
- package/dist/types/new-button/variants/icon/types.d.ts +8 -0
- package/dist/types/new-button/variants/icon/use-icon-button.d.ts +15 -0
- package/dist/types/new-button/variants/shared/block-events.d.ts +2 -0
- package/dist/types/new-button/variants/shared/colors.d.ts +18 -0
- package/dist/types/new-button/variants/shared/use-button-base.d.ts +37 -0
- package/dist/types/new-button/variants/shared/xcss.d.ts +24 -0
- package/dist/types/new-button/variants/types.d.ts +69 -0
- package/dist/{types-ts4.5 → types/old-button}/custom-theme-button/custom-theme-button.d.ts +1 -1
- package/dist/types/utils/appearances.d.ts +3 -0
- package/dist/types/utils/spacing.d.ts +3 -0
- package/dist/types/utils/variants.d.ts +15 -0
- package/dist/types-ts4.5/{button-group.d.ts → containers/button-group.d.ts} +1 -1
- package/dist/types-ts4.5/entry-points/button-group.d.ts +1 -1
- package/dist/types-ts4.5/entry-points/custom-theme-button.d.ts +2 -2
- package/dist/types-ts4.5/entry-points/loading-button.d.ts +2 -2
- package/dist/types-ts4.5/entry-points/new.d.ts +5 -0
- package/dist/types-ts4.5/entry-points/standard-button.d.ts +2 -2
- package/dist/types-ts4.5/entry-points/types.d.ts +1 -1
- package/dist/types-ts4.5/entry-points/unsafe.d.ts +1 -0
- package/dist/types-ts4.5/new-button/variants/default/button.d.ts +19 -0
- package/dist/types-ts4.5/new-button/variants/default/link.d.ts +17 -0
- package/dist/types-ts4.5/new-button/variants/default/types.d.ts +15 -0
- package/dist/types-ts4.5/new-button/variants/default/use-default-button.d.ts +15 -0
- package/dist/types-ts4.5/new-button/variants/icon/button.d.ts +17 -0
- package/dist/types-ts4.5/new-button/variants/icon/link.d.ts +17 -0
- package/dist/types-ts4.5/new-button/variants/icon/types.d.ts +8 -0
- package/dist/types-ts4.5/new-button/variants/icon/use-icon-button.d.ts +15 -0
- package/dist/types-ts4.5/new-button/variants/shared/block-events.d.ts +2 -0
- package/dist/types-ts4.5/new-button/variants/shared/colors.d.ts +18 -0
- package/dist/types-ts4.5/new-button/variants/shared/use-button-base.d.ts +37 -0
- package/dist/types-ts4.5/new-button/variants/shared/xcss.d.ts +24 -0
- package/dist/types-ts4.5/new-button/variants/types.d.ts +69 -0
- package/dist/{types → types-ts4.5/old-button}/custom-theme-button/custom-theme-button.d.ts +1 -1
- package/dist/types-ts4.5/utils/appearances.d.ts +3 -0
- package/dist/types-ts4.5/utils/spacing.d.ts +3 -0
- package/dist/types-ts4.5/utils/variants.d.ts +15 -0
- package/extract-react-types/custom-theme-button-props.tsx +1 -1
- package/extract-react-types/loading-button-props.tsx +1 -1
- package/extract-react-types/shared-props.tsx +1 -1
- package/package.json +9 -6
- package/unsafe/package.json +15 -0
- /package/dist/cjs/{button-group.js → containers/button-group.js} +0 -0
- /package/dist/cjs/{types.js → new-button/variants/default/types.js} +0 -0
- /package/dist/cjs/{custom-theme-button/custom-theme-button-types.js → new-button/variants/icon/types.js} +0 -0
- /package/dist/cjs/{button.js → old-button/button.js} +0 -0
- /package/dist/cjs/{custom-theme-button → old-button/custom-theme-button}/index.js +0 -0
- /package/dist/cjs/{loading-button.js → old-button/loading-button.js} +0 -0
- /package/dist/cjs/{shared → old-button/shared}/block-events.js +0 -0
- /package/dist/cjs/{shared → old-button/shared}/colors.js +0 -0
- /package/dist/cjs/{shared → old-button/shared}/get-if-visually-hidden-children.js +0 -0
- /package/dist/cjs/{shared → old-button/shared}/get-is-only-single-icon.js +0 -0
- /package/dist/cjs/{shared → old-button/shared}/loading-spinner.js +0 -0
- /package/dist/es2019/{button-group.js → containers/button-group.js} +0 -0
- /package/dist/es2019/{types.js → new-button/variants/default/types.js} +0 -0
- /package/dist/{esm → es2019/new-button/variants/icon}/types.js +0 -0
- /package/dist/es2019/{custom-theme-button/custom-theme-button-types.js → new-button/variants/types.js} +0 -0
- /package/dist/es2019/{button.js → old-button/button.js} +0 -0
- /package/dist/{esm → es2019/old-button}/custom-theme-button/custom-theme-button-types.js +0 -0
- /package/dist/es2019/{custom-theme-button → old-button/custom-theme-button}/custom-theme-button.js +0 -0
- /package/dist/es2019/{custom-theme-button → old-button/custom-theme-button}/index.js +0 -0
- /package/dist/es2019/{custom-theme-button → old-button/custom-theme-button}/theme.js +0 -0
- /package/dist/es2019/{loading-button.js → old-button/loading-button.js} +0 -0
- /package/dist/es2019/{shared → old-button/shared}/block-events.js +0 -0
- /package/dist/es2019/{shared → old-button/shared}/colors.js +0 -0
- /package/dist/es2019/{shared → old-button/shared}/css.js +0 -0
- /package/dist/es2019/{shared → old-button/shared}/get-if-visually-hidden-children.js +0 -0
- /package/dist/es2019/{shared → old-button/shared}/get-is-only-single-icon.js +0 -0
- /package/dist/es2019/{shared → old-button/shared}/loading-spinner.js +0 -0
- /package/dist/esm/{button-group.js → containers/button-group.js} +0 -0
- /package/dist/esm/{button.js → old-button/button.js} +0 -0
- /package/dist/esm/{custom-theme-button → old-button/custom-theme-button}/index.js +0 -0
- /package/dist/esm/{loading-button.js → old-button/loading-button.js} +0 -0
- /package/dist/esm/{shared → old-button/shared}/block-events.js +0 -0
- /package/dist/esm/{shared → old-button/shared}/colors.js +0 -0
- /package/dist/esm/{shared → old-button/shared}/get-if-visually-hidden-children.js +0 -0
- /package/dist/esm/{shared → old-button/shared}/get-is-only-single-icon.js +0 -0
- /package/dist/esm/{shared → old-button/shared}/loading-spinner.js +0 -0
- /package/dist/types/{button.d.ts → old-button/button.d.ts} +0 -0
- /package/dist/types/{custom-theme-button → old-button/custom-theme-button}/custom-theme-button-types.d.ts +0 -0
- /package/dist/types/{custom-theme-button → old-button/custom-theme-button}/index.d.ts +0 -0
- /package/dist/types/{custom-theme-button → old-button/custom-theme-button}/theme.d.ts +0 -0
- /package/dist/types/{loading-button.d.ts → old-button/loading-button.d.ts} +0 -0
- /package/dist/types/{shared → old-button/shared}/block-events.d.ts +0 -0
- /package/dist/types/{shared → old-button/shared}/button-base.d.ts +0 -0
- /package/dist/types/{shared → old-button/shared}/colors.d.ts +0 -0
- /package/dist/types/{shared → old-button/shared}/css.d.ts +0 -0
- /package/dist/types/{shared → old-button/shared}/get-if-visually-hidden-children.d.ts +0 -0
- /package/dist/types/{shared → old-button/shared}/get-is-only-single-icon.d.ts +0 -0
- /package/dist/types/{shared → old-button/shared}/loading-spinner.d.ts +0 -0
- /package/dist/types/{types.d.ts → old-button/types.d.ts} +0 -0
- /package/dist/types-ts4.5/{button.d.ts → old-button/button.d.ts} +0 -0
- /package/dist/types-ts4.5/{custom-theme-button → old-button/custom-theme-button}/custom-theme-button-types.d.ts +0 -0
- /package/dist/types-ts4.5/{custom-theme-button → old-button/custom-theme-button}/index.d.ts +0 -0
- /package/dist/types-ts4.5/{custom-theme-button → old-button/custom-theme-button}/theme.d.ts +0 -0
- /package/dist/types-ts4.5/{loading-button.d.ts → old-button/loading-button.d.ts} +0 -0
- /package/dist/types-ts4.5/{shared → old-button/shared}/block-events.d.ts +0 -0
- /package/dist/types-ts4.5/{shared → old-button/shared}/button-base.d.ts +0 -0
- /package/dist/types-ts4.5/{shared → old-button/shared}/colors.d.ts +0 -0
- /package/dist/types-ts4.5/{shared → old-button/shared}/css.d.ts +0 -0
- /package/dist/types-ts4.5/{shared → old-button/shared}/get-if-visually-hidden-children.d.ts +0 -0
- /package/dist/types-ts4.5/{shared → old-button/shared}/get-is-only-single-icon.d.ts +0 -0
- /package/dist/types-ts4.5/{shared → old-button/shared}/loading-spinner.d.ts +0 -0
- /package/dist/types-ts4.5/{types.d.ts → old-button/types.d.ts} +0 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as colors from '@atlaskit/theme/colors';
|
|
2
|
+
const values = {
|
|
3
|
+
// Default appearance
|
|
4
|
+
background: {
|
|
5
|
+
default: {
|
|
6
|
+
/**
|
|
7
|
+
* Some colors need specific fallback colors specified
|
|
8
|
+
* to match the original Button when no theme is active.
|
|
9
|
+
*
|
|
10
|
+
* This is because the `xcss` automatic token fallbacks use
|
|
11
|
+
* the legacy themes, which do not match original colors.
|
|
12
|
+
*/
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
default: `var(--ds-background-neutral, ${colors.N20A})`,
|
|
15
|
+
hover: 'color.background.neutral.hovered',
|
|
16
|
+
active: 'color.background.neutral.pressed',
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
disabled: `var(--ds-background-disabled, ${colors.N20A})`,
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
selected: `var(--ds-background-selected, ${colors.N700})`
|
|
21
|
+
},
|
|
22
|
+
primary: {
|
|
23
|
+
default: 'color.background.brand.bold',
|
|
24
|
+
hover: 'color.background.brand.bold.hovered',
|
|
25
|
+
active: 'color.background.brand.bold.pressed',
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
disabled: `var(--ds-background-disabled, ${colors.N20A})`,
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
selected: `var(--ds-background-selected, ${colors.N700})`
|
|
30
|
+
},
|
|
31
|
+
warning: {
|
|
32
|
+
default: 'color.background.warning.bold',
|
|
33
|
+
hover: 'color.background.warning.bold.hovered',
|
|
34
|
+
active: 'color.background.warning.bold.pressed',
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
disabled: `var(--ds-background-disabled, ${colors.N20A})`,
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
selected: `var(--ds-background-selected, ${colors.Y400})`
|
|
39
|
+
},
|
|
40
|
+
danger: {
|
|
41
|
+
default: 'color.background.danger.bold',
|
|
42
|
+
hover: 'color.background.danger.bold.hovered',
|
|
43
|
+
active: 'color.background.danger.bold.pressed',
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
disabled: `var(--ds-background-disabled, ${colors.N20A})`,
|
|
46
|
+
// @ts-expect-error
|
|
47
|
+
selected: `var(--ds-background-selected, ${colors.R500})`
|
|
48
|
+
},
|
|
49
|
+
link: {
|
|
50
|
+
default: 'color.background.neutral.subtle',
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
selected: `var(--ds-background-selected, ${colors.N700})`
|
|
53
|
+
},
|
|
54
|
+
subtle: {
|
|
55
|
+
default: 'color.background.neutral.subtle',
|
|
56
|
+
hover: 'color.background.neutral.subtle.hovered',
|
|
57
|
+
active: 'color.background.neutral.subtle.pressed',
|
|
58
|
+
// @ts-expect-error
|
|
59
|
+
disabled: "var(--ds-background-neutral-subtle, none)",
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
selected: `var(--ds-background-selected, ${colors.N700})`
|
|
62
|
+
},
|
|
63
|
+
'subtle-link': {
|
|
64
|
+
default: 'color.background.neutral.subtle',
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
selected: `var(--ds-background-selected, ${colors.N700})`
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
color: {
|
|
70
|
+
default: {
|
|
71
|
+
default: 'color.text',
|
|
72
|
+
active: 'color.text',
|
|
73
|
+
disabled: 'color.text.disabled',
|
|
74
|
+
// @ts-expect-error
|
|
75
|
+
selected: `var(--ds-text-selected, ${colors.N20})`
|
|
76
|
+
},
|
|
77
|
+
primary: {
|
|
78
|
+
default: 'color.text.inverse',
|
|
79
|
+
disabled: 'color.text.disabled',
|
|
80
|
+
// @ts-expect-error
|
|
81
|
+
selected: `var(--ds-text-selected, ${colors.N20})`
|
|
82
|
+
},
|
|
83
|
+
warning: {
|
|
84
|
+
default: 'color.text.warning.inverse',
|
|
85
|
+
disabled: 'color.text.disabled',
|
|
86
|
+
// @ts-expect-error
|
|
87
|
+
selected: `var(--ds-text-selected, ${colors.N800})`
|
|
88
|
+
},
|
|
89
|
+
danger: {
|
|
90
|
+
default: 'color.text.inverse',
|
|
91
|
+
disabled: 'color.text.disabled',
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
selected: `var(--ds-text-selected, ${colors.N0})`
|
|
94
|
+
},
|
|
95
|
+
link: {
|
|
96
|
+
default: 'color.link',
|
|
97
|
+
hover: 'color.link',
|
|
98
|
+
active: 'color.link.pressed',
|
|
99
|
+
disabled: 'color.text.disabled',
|
|
100
|
+
// @ts-expect-error
|
|
101
|
+
selected: `var(--ds-text-selected, ${colors.N20})`
|
|
102
|
+
},
|
|
103
|
+
subtle: {
|
|
104
|
+
default: 'color.text',
|
|
105
|
+
active: 'color.text',
|
|
106
|
+
disabled: 'color.text.disabled',
|
|
107
|
+
// @ts-expect-error
|
|
108
|
+
selected: `var(--ds-text-selected, ${colors.N20})`
|
|
109
|
+
},
|
|
110
|
+
'subtle-link': {
|
|
111
|
+
default: 'color.text.subtle',
|
|
112
|
+
hover: 'color.text.subtle',
|
|
113
|
+
active: 'color.text',
|
|
114
|
+
disabled: 'color.text.disabled',
|
|
115
|
+
// @ts-expect-error
|
|
116
|
+
selected: `var(--ds-text-selected, ${colors.N20})`
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
export default values;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { Fragment, useCallback, useContext, useMemo, useRef } from 'react';
|
|
2
|
+
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
3
|
+
import noop from '@atlaskit/ds-lib/noop';
|
|
4
|
+
import useAutoFocus from '@atlaskit/ds-lib/use-auto-focus';
|
|
5
|
+
// eslint-disable-next-line no-duplicate-imports
|
|
6
|
+
import InteractionContext from '@atlaskit/interaction-context';
|
|
7
|
+
import { Box } from '@atlaskit/primitives';
|
|
8
|
+
import blockEvents from './block-events';
|
|
9
|
+
import { getXCSS, overlayStyles } from './xcss';
|
|
10
|
+
|
|
11
|
+
// Include modified onClick with analytics
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* __Use button base__
|
|
15
|
+
*
|
|
16
|
+
* A React hook that accepts a set of common Button props,
|
|
17
|
+
* and processes them to return consistent base props for usage
|
|
18
|
+
* across various Button components.
|
|
19
|
+
*
|
|
20
|
+
* It also:
|
|
21
|
+
* - Implements auto focus when enabled.
|
|
22
|
+
* - Appends the `onClick` event with UFO analytics tracking.
|
|
23
|
+
*
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
const useButtonBase = ({
|
|
27
|
+
analyticsContext,
|
|
28
|
+
appearance = 'default',
|
|
29
|
+
autoFocus = false,
|
|
30
|
+
buttonType,
|
|
31
|
+
interactionName,
|
|
32
|
+
isDisabled = false,
|
|
33
|
+
isSelected = false,
|
|
34
|
+
// TODO: Separate Icon Button styling from button base
|
|
35
|
+
isIconButton = false,
|
|
36
|
+
// TODO: Separate icon slot styling from button base
|
|
37
|
+
hasIconBefore = false,
|
|
38
|
+
hasIconAfter = false,
|
|
39
|
+
children,
|
|
40
|
+
onClick: providedOnClick = noop,
|
|
41
|
+
onMouseDownCapture,
|
|
42
|
+
onMouseUpCapture,
|
|
43
|
+
onKeyDownCapture,
|
|
44
|
+
onKeyUpCapture,
|
|
45
|
+
onTouchStartCapture,
|
|
46
|
+
onTouchEndCapture,
|
|
47
|
+
onPointerDownCapture,
|
|
48
|
+
onPointerUpCapture,
|
|
49
|
+
onClickCapture,
|
|
50
|
+
overlay,
|
|
51
|
+
ref,
|
|
52
|
+
shouldFitContainer = false,
|
|
53
|
+
spacing = 'default'
|
|
54
|
+
}) => {
|
|
55
|
+
const ourRef = useRef();
|
|
56
|
+
const setRef = useCallback(node => {
|
|
57
|
+
ourRef.current = node;
|
|
58
|
+
if (ref === null) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (typeof ref === 'function') {
|
|
62
|
+
ref(node);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
ref.current = node;
|
|
68
|
+
}, [ourRef, ref]);
|
|
69
|
+
useAutoFocus(ourRef, autoFocus);
|
|
70
|
+
const interactionContext = useContext(InteractionContext);
|
|
71
|
+
const handleClick = useCallback((e, analyticsEvent) => {
|
|
72
|
+
interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
|
|
73
|
+
providedOnClick(e, analyticsEvent);
|
|
74
|
+
}, [providedOnClick, interactionContext, interactionName]);
|
|
75
|
+
const onClick = usePlatformLeafEventHandler({
|
|
76
|
+
fn: handleClick,
|
|
77
|
+
action: 'clicked',
|
|
78
|
+
componentName: 'button',
|
|
79
|
+
packageName: "@atlaskit/button",
|
|
80
|
+
packageVersion: "16.10.0",
|
|
81
|
+
analyticsData: analyticsContext,
|
|
82
|
+
actionSubject: buttonType
|
|
83
|
+
});
|
|
84
|
+
const buttonXCSS = useMemo(() => getXCSS({
|
|
85
|
+
appearance,
|
|
86
|
+
spacing,
|
|
87
|
+
isDisabled,
|
|
88
|
+
isSelected,
|
|
89
|
+
shouldFitContainer,
|
|
90
|
+
isIconButton,
|
|
91
|
+
hasOverlay: Boolean(overlay),
|
|
92
|
+
isLink: buttonType === 'link',
|
|
93
|
+
hasIconBefore,
|
|
94
|
+
hasIconAfter
|
|
95
|
+
}), [appearance, buttonType, spacing, isDisabled, isSelected, isIconButton, shouldFitContainer, overlay, hasIconBefore, hasIconAfter]);
|
|
96
|
+
const isEffectivelyDisabled = isDisabled || Boolean(overlay);
|
|
97
|
+
return {
|
|
98
|
+
ref: setRef,
|
|
99
|
+
xcss: buttonXCSS,
|
|
100
|
+
// Consider overlay buttons to be effectively disabled
|
|
101
|
+
isDisabled: isEffectivelyDisabled,
|
|
102
|
+
children: /*#__PURE__*/React.createElement(Fragment, null, children, overlay ? /*#__PURE__*/React.createElement(Box, {
|
|
103
|
+
as: "span",
|
|
104
|
+
xcss: overlayStyles
|
|
105
|
+
}, overlay) : null),
|
|
106
|
+
...blockEvents(isEffectivelyDisabled, {
|
|
107
|
+
onClick,
|
|
108
|
+
onMouseDownCapture,
|
|
109
|
+
onMouseUpCapture,
|
|
110
|
+
onKeyDownCapture,
|
|
111
|
+
onKeyUpCapture,
|
|
112
|
+
onTouchStartCapture,
|
|
113
|
+
onTouchEndCapture,
|
|
114
|
+
onPointerDownCapture,
|
|
115
|
+
onPointerUpCapture,
|
|
116
|
+
onClickCapture
|
|
117
|
+
})
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
export default useButtonBase;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { xcss } from '@atlaskit/primitives';
|
|
2
|
+
import { fontSize as getFontSize } from '@atlaskit/theme/constants';
|
|
3
|
+
import colors from './colors';
|
|
4
|
+
const fontSize = getFontSize();
|
|
5
|
+
const heights = {
|
|
6
|
+
default: `${32 / fontSize}em`,
|
|
7
|
+
compact: `${24 / fontSize}em`,
|
|
8
|
+
none: 'auto'
|
|
9
|
+
};
|
|
10
|
+
const paddingInline = {
|
|
11
|
+
default: {
|
|
12
|
+
default: 'space.150',
|
|
13
|
+
withIcon: 'space.100'
|
|
14
|
+
},
|
|
15
|
+
compact: {
|
|
16
|
+
default: 'space.150',
|
|
17
|
+
withIcon: 'space.100'
|
|
18
|
+
},
|
|
19
|
+
none: {
|
|
20
|
+
default: 'space.0',
|
|
21
|
+
withIcon: 'space.0'
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const gap = {
|
|
25
|
+
compact: 'space.050',
|
|
26
|
+
default: 'space.050',
|
|
27
|
+
none: 'space.0'
|
|
28
|
+
};
|
|
29
|
+
const verticalAlign = {
|
|
30
|
+
default: 'middle',
|
|
31
|
+
compact: 'middle',
|
|
32
|
+
none: 'baseline'
|
|
33
|
+
};
|
|
34
|
+
function getColor({
|
|
35
|
+
group,
|
|
36
|
+
key
|
|
37
|
+
}) {
|
|
38
|
+
return group[key] || group.default;
|
|
39
|
+
}
|
|
40
|
+
function getColors({
|
|
41
|
+
appearance,
|
|
42
|
+
interactionState = 'default',
|
|
43
|
+
isDisabled,
|
|
44
|
+
isSelected,
|
|
45
|
+
hasOverlay
|
|
46
|
+
}) {
|
|
47
|
+
let key = interactionState;
|
|
48
|
+
// Overlay does not change color on interaction, revert to 'default' or resting state
|
|
49
|
+
key = hasOverlay ? 'default' : key;
|
|
50
|
+
key = isSelected ? 'selected' : key;
|
|
51
|
+
// Disabled colors overrule everything else
|
|
52
|
+
key = isDisabled ? 'disabled' : key;
|
|
53
|
+
return {
|
|
54
|
+
backgroundColor: getColor({
|
|
55
|
+
group: colors.background[appearance],
|
|
56
|
+
key
|
|
57
|
+
}),
|
|
58
|
+
color: `${getColor({
|
|
59
|
+
group: colors.color[appearance],
|
|
60
|
+
key
|
|
61
|
+
})}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function getXCSS({
|
|
65
|
+
appearance,
|
|
66
|
+
spacing,
|
|
67
|
+
isDisabled,
|
|
68
|
+
isSelected,
|
|
69
|
+
isIconButton,
|
|
70
|
+
shouldFitContainer,
|
|
71
|
+
isLink,
|
|
72
|
+
hasOverlay,
|
|
73
|
+
hasIconBefore,
|
|
74
|
+
hasIconAfter
|
|
75
|
+
}) {
|
|
76
|
+
const baseColors = getColors({
|
|
77
|
+
appearance,
|
|
78
|
+
isSelected,
|
|
79
|
+
isDisabled
|
|
80
|
+
});
|
|
81
|
+
const combinedBaseColorStyles = isLink ? {
|
|
82
|
+
...baseColors,
|
|
83
|
+
textDecoration: 'none',
|
|
84
|
+
// Disabling visited styles (by re-declaring the base colors)
|
|
85
|
+
':visited': baseColors
|
|
86
|
+
} : baseColors;
|
|
87
|
+
const height = heights[spacing];
|
|
88
|
+
let width = shouldFitContainer ? '100%' : 'auto';
|
|
89
|
+
width = isIconButton ? height : width;
|
|
90
|
+
const paddingInlineStart = paddingInline[spacing][hasIconBefore ? 'withIcon' : 'default'];
|
|
91
|
+
const paddingInlineEnd = paddingInline[spacing][hasIconAfter ? 'withIcon' : 'default'];
|
|
92
|
+
return xcss({
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
borderWidth: 'border.width.0',
|
|
95
|
+
borderRadius: 'border.radius.100',
|
|
96
|
+
boxSizing: 'border-box',
|
|
97
|
+
display: 'inline-flex',
|
|
98
|
+
fontSize: 'inherit',
|
|
99
|
+
fontStyle: 'normal',
|
|
100
|
+
fontFamily: 'inherit',
|
|
101
|
+
fontWeight: 500,
|
|
102
|
+
maxWidth: '100%',
|
|
103
|
+
// Needed to position overlay
|
|
104
|
+
position: 'relative',
|
|
105
|
+
textAlign: 'center',
|
|
106
|
+
transition: 'background 0.1s ease-out, box-shadow 0.15s cubic-bezier(0.47, 0.03, 0.49, 1.38)',
|
|
107
|
+
whiteSpace: 'nowrap',
|
|
108
|
+
height,
|
|
109
|
+
paddingBlock: 'space.0',
|
|
110
|
+
paddingInlineStart: isIconButton ? 'space.0' : paddingInlineStart,
|
|
111
|
+
paddingInlineEnd: isIconButton ? 'space.0' : paddingInlineEnd,
|
|
112
|
+
columnGap: gap[spacing],
|
|
113
|
+
verticalAlign: verticalAlign[spacing],
|
|
114
|
+
width,
|
|
115
|
+
// justifyContent required for shouldFitContainer buttons with an icon inside
|
|
116
|
+
justifyContent: 'center',
|
|
117
|
+
...combinedBaseColorStyles,
|
|
118
|
+
...(isDisabled || hasOverlay ? {
|
|
119
|
+
cursor: 'not-allowed'
|
|
120
|
+
} : {}),
|
|
121
|
+
':hover': {
|
|
122
|
+
...getColors({
|
|
123
|
+
appearance,
|
|
124
|
+
isSelected,
|
|
125
|
+
isDisabled,
|
|
126
|
+
interactionState: 'hover',
|
|
127
|
+
hasOverlay
|
|
128
|
+
}),
|
|
129
|
+
textDecoration: !isSelected && (appearance === 'link' || appearance === 'subtle-link') ? 'underline' : 'none',
|
|
130
|
+
// background, box-shadow
|
|
131
|
+
transitionDuration: '0s, 0.15s'
|
|
132
|
+
},
|
|
133
|
+
':active': {
|
|
134
|
+
...getColors({
|
|
135
|
+
appearance,
|
|
136
|
+
isSelected,
|
|
137
|
+
isDisabled,
|
|
138
|
+
interactionState: 'active',
|
|
139
|
+
hasOverlay
|
|
140
|
+
}),
|
|
141
|
+
// background, box-shadow
|
|
142
|
+
transitionDuration: '0s, 0s'
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
export const iconStyles = xcss({
|
|
147
|
+
display: 'flex',
|
|
148
|
+
// icon size cannot grow and shrink
|
|
149
|
+
flexGrow: 0,
|
|
150
|
+
flexShrink: 0,
|
|
151
|
+
alignSelf: 'center',
|
|
152
|
+
fontSize: 0,
|
|
153
|
+
lineHeight: 0,
|
|
154
|
+
userSelect: 'none'
|
|
155
|
+
});
|
|
156
|
+
export const contentStyles = xcss({
|
|
157
|
+
// content can grow and shrink
|
|
158
|
+
flexGrow: 1,
|
|
159
|
+
flexShrink: 1,
|
|
160
|
+
// ellipsis for overflow text
|
|
161
|
+
overflow: 'hidden',
|
|
162
|
+
textOverflow: 'ellipsis',
|
|
163
|
+
whiteSpace: 'nowrap'
|
|
164
|
+
});
|
|
165
|
+
export function getFadingStyles({
|
|
166
|
+
hasOverlay
|
|
167
|
+
}) {
|
|
168
|
+
return xcss({
|
|
169
|
+
opacity: hasOverlay ? 0 : 1,
|
|
170
|
+
transition: 'opacity 0.3s'
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export const overlayStyles = xcss({
|
|
174
|
+
position: 'absolute',
|
|
175
|
+
left: 'space.0',
|
|
176
|
+
top: 'space.0',
|
|
177
|
+
right: 'space.0',
|
|
178
|
+
bottom: 'space.0',
|
|
179
|
+
display: 'flex',
|
|
180
|
+
alignItems: 'center',
|
|
181
|
+
justifyContent: 'center'
|
|
182
|
+
});
|
|
@@ -69,10 +69,7 @@ export default /*#__PURE__*/React.forwardRef(function ButtonBase(props, ref) {
|
|
|
69
69
|
// Pulling out so it doesn't spread on rendered component
|
|
70
70
|
shouldFitContainer,
|
|
71
71
|
spacing = 'default',
|
|
72
|
-
|
|
73
|
-
// html elements. Set to `0` for custom components to ensure other elements can
|
|
74
|
-
// be focused (although the custom component could be a <button> or <a>...)
|
|
75
|
-
tabIndex = !props.component && getBooleanFF('platform.design-system-team.clove-sprint-a11y-button_5rz5j') ? undefined : 0,
|
|
72
|
+
tabIndex = 0,
|
|
76
73
|
type = !href ? 'button' : undefined,
|
|
77
74
|
testId,
|
|
78
75
|
...rest
|
|
@@ -105,7 +102,7 @@ export default /*#__PURE__*/React.forwardRef(function ButtonBase(props, ref) {
|
|
|
105
102
|
action: 'clicked',
|
|
106
103
|
componentName: 'button',
|
|
107
104
|
packageName: "@atlaskit/button",
|
|
108
|
-
packageVersion: "16.
|
|
105
|
+
packageVersion: "16.10.0",
|
|
109
106
|
analyticsData: analyticsContext
|
|
110
107
|
});
|
|
111
108
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
/* eslint-disable @repo/internal/react/no-unsafe-spread-props */
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import Button from '../new-button/variants/default/button';
|
|
5
|
+
import LinkButton from '../new-button/variants/default/link';
|
|
6
|
+
// Add required default props to variants
|
|
7
|
+
const LinkButtonRender = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(LinkButton, _extends({
|
|
8
|
+
ref: ref,
|
|
9
|
+
href: "#"
|
|
10
|
+
}, props), props.children));
|
|
11
|
+
export const variants = [{
|
|
12
|
+
name: 'Button',
|
|
13
|
+
Component: Button,
|
|
14
|
+
elementType: HTMLButtonElement
|
|
15
|
+
}, {
|
|
16
|
+
name: 'LinkButton',
|
|
17
|
+
Component: LinkButtonRender,
|
|
18
|
+
elementType: HTMLAnchorElement
|
|
19
|
+
}];
|
|
20
|
+
export default variants;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from '../button-group';
|
|
1
|
+
export { default } from '../containers/button-group';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default, Theme } from '../custom-theme-button';
|
|
1
|
+
export { default, Theme } from '../old-button/custom-theme-button';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from '../loading-button';
|
|
1
|
+
export { default } from '../old-button/loading-button';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default } from '../new-button/variants/default/button';
|
|
2
|
+
export { default as LinkButton } from '../new-button/variants/default/link';
|
|
3
|
+
export { default as IconButton } from '../new-button/variants/icon/button';
|
|
4
|
+
export { default as LinkIconButton } from '../new-button/variants/icon/link';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as UNSAFE_BUTTON } from '../new-button/variants/default/button';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["analyticsContext", "autoFocus", "appearance", "spacing", "isDisabled", "isSelected", "iconBefore", "iconAfter", "children", "shouldFitContainer", "interactionName", "overlay", "onClick", "onMouseDownCapture", "onMouseUpCapture", "onKeyDownCapture", "onKeyUpCapture", "onTouchStartCapture", "onTouchEndCapture", "onPointerDownCapture", "onPointerUpCapture", "onClickCapture", "type", "testId"];
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import UNSAFE_PRESSABLE from '@atlaskit/primitives/pressable';
|
|
6
|
+
import useDefaultButton from './use-default-button';
|
|
7
|
+
/**
|
|
8
|
+
* __Button__
|
|
9
|
+
*
|
|
10
|
+
* @warning __UNSAFE__ Button is not yet safe for production use.
|
|
11
|
+
*
|
|
12
|
+
* A button triggers an event or action.
|
|
13
|
+
*
|
|
14
|
+
* - [Examples](https://atlassian.design/components/button/examples)
|
|
15
|
+
* - [Code](https://atlassian.design/components/button/code)
|
|
16
|
+
* - [Usage](https://atlassian.design/components/button/usage)
|
|
17
|
+
*/
|
|
18
|
+
var Button = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function Button(_ref, ref) {
|
|
19
|
+
var analyticsContext = _ref.analyticsContext,
|
|
20
|
+
autoFocus = _ref.autoFocus,
|
|
21
|
+
appearance = _ref.appearance,
|
|
22
|
+
spacing = _ref.spacing,
|
|
23
|
+
isDisabled = _ref.isDisabled,
|
|
24
|
+
isSelected = _ref.isSelected,
|
|
25
|
+
iconBefore = _ref.iconBefore,
|
|
26
|
+
iconAfter = _ref.iconAfter,
|
|
27
|
+
children = _ref.children,
|
|
28
|
+
shouldFitContainer = _ref.shouldFitContainer,
|
|
29
|
+
interactionName = _ref.interactionName,
|
|
30
|
+
overlay = _ref.overlay,
|
|
31
|
+
onClick = _ref.onClick,
|
|
32
|
+
onMouseDownCapture = _ref.onMouseDownCapture,
|
|
33
|
+
onMouseUpCapture = _ref.onMouseUpCapture,
|
|
34
|
+
onKeyDownCapture = _ref.onKeyDownCapture,
|
|
35
|
+
onKeyUpCapture = _ref.onKeyUpCapture,
|
|
36
|
+
onTouchStartCapture = _ref.onTouchStartCapture,
|
|
37
|
+
onTouchEndCapture = _ref.onTouchEndCapture,
|
|
38
|
+
onPointerDownCapture = _ref.onPointerDownCapture,
|
|
39
|
+
onPointerUpCapture = _ref.onPointerUpCapture,
|
|
40
|
+
onClickCapture = _ref.onClickCapture,
|
|
41
|
+
_ref$type = _ref.type,
|
|
42
|
+
type = _ref$type === void 0 ? 'button' : _ref$type,
|
|
43
|
+
testId = _ref.testId,
|
|
44
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
45
|
+
var baseProps = useDefaultButton({
|
|
46
|
+
analyticsContext: analyticsContext,
|
|
47
|
+
appearance: appearance,
|
|
48
|
+
autoFocus: autoFocus,
|
|
49
|
+
buttonType: 'button',
|
|
50
|
+
children: children,
|
|
51
|
+
iconBefore: iconBefore,
|
|
52
|
+
iconAfter: iconAfter,
|
|
53
|
+
interactionName: interactionName,
|
|
54
|
+
isDisabled: isDisabled,
|
|
55
|
+
isSelected: isSelected,
|
|
56
|
+
onClick: onClick,
|
|
57
|
+
onMouseDownCapture: onMouseDownCapture,
|
|
58
|
+
onMouseUpCapture: onMouseUpCapture,
|
|
59
|
+
onKeyDownCapture: onKeyDownCapture,
|
|
60
|
+
onKeyUpCapture: onKeyUpCapture,
|
|
61
|
+
onTouchStartCapture: onTouchStartCapture,
|
|
62
|
+
onTouchEndCapture: onTouchEndCapture,
|
|
63
|
+
onPointerDownCapture: onPointerDownCapture,
|
|
64
|
+
onPointerUpCapture: onPointerUpCapture,
|
|
65
|
+
onClickCapture: onClickCapture,
|
|
66
|
+
overlay: overlay,
|
|
67
|
+
ref: ref,
|
|
68
|
+
shouldFitContainer: shouldFitContainer,
|
|
69
|
+
spacing: spacing
|
|
70
|
+
});
|
|
71
|
+
return /*#__PURE__*/React.createElement(UNSAFE_PRESSABLE
|
|
72
|
+
// TODO: Remove spread props
|
|
73
|
+
, _extends({}, rest, {
|
|
74
|
+
ref: baseProps.ref,
|
|
75
|
+
xcss: baseProps.xcss,
|
|
76
|
+
isDisabled: baseProps.isDisabled,
|
|
77
|
+
onClick: baseProps.onClick,
|
|
78
|
+
onMouseDownCapture: baseProps.onMouseDownCapture,
|
|
79
|
+
onMouseUpCapture: baseProps.onMouseUpCapture,
|
|
80
|
+
onKeyDownCapture: baseProps.onKeyDownCapture,
|
|
81
|
+
onKeyUpCapture: baseProps.onKeyUpCapture,
|
|
82
|
+
onTouchStartCapture: baseProps.onTouchStartCapture,
|
|
83
|
+
onTouchEndCapture: baseProps.onTouchEndCapture,
|
|
84
|
+
onPointerDownCapture: baseProps.onPointerDownCapture,
|
|
85
|
+
onPointerUpCapture: baseProps.onPointerUpCapture,
|
|
86
|
+
onClickCapture: baseProps.onClickCapture,
|
|
87
|
+
type: type,
|
|
88
|
+
testId: testId
|
|
89
|
+
}), baseProps.children);
|
|
90
|
+
}));
|
|
91
|
+
Button.displayName = 'Button';
|
|
92
|
+
export default Button;
|