@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,145 +0,0 @@
1
- "use strict";
2
-
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var colors = _interopRequireWildcard(require("@atlaskit/theme/colors"));
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- var values = {
12
- // Default appearance
13
- background: {
14
- default: {
15
- /**
16
- * Some colors need specific fallback colors specified
17
- * to match the original Button when no theme is active.
18
- *
19
- * This is because the `xcss` automatic token fallbacks use
20
- * the legacy themes, which do not match original colors.
21
- */
22
- // @ts-expect-error
23
- default: "var(--ds-background-neutral, ".concat(colors.N20A, ")"),
24
- hover: 'color.background.neutral.hovered',
25
- active: 'color.background.neutral.pressed',
26
- // @ts-expect-error
27
- disabled: "var(--ds-background-disabled, ".concat(colors.N20A, ")")
28
- },
29
- primary: {
30
- default: 'color.background.brand.bold',
31
- hover: 'color.background.brand.bold.hovered',
32
- active: 'color.background.brand.bold.pressed',
33
- // @ts-expect-error
34
- disabled: "var(--ds-background-disabled, ".concat(colors.N20A, ")")
35
- },
36
- warning: {
37
- default: 'color.background.warning.bold',
38
- hover: 'color.background.warning.bold.hovered',
39
- active: 'color.background.warning.bold.pressed',
40
- // @ts-expect-error
41
- disabled: "var(--ds-background-disabled, ".concat(colors.N20A, ")"),
42
- selected: {
43
- // @ts-expect-error
44
- default: "var(--ds-background-selected, ".concat(colors.Y400, ")"),
45
- // @ts-expect-error
46
- hover: "var(--ds-background-selected-hovered, ".concat(colors.Y400, ")"),
47
- // @ts-expect-error
48
- active: "var(--ds-background-selected-pressed, ".concat(colors.Y400, ")")
49
- }
50
- },
51
- danger: {
52
- default: 'color.background.danger.bold',
53
- hover: 'color.background.danger.bold.hovered',
54
- active: 'color.background.danger.bold.pressed',
55
- // @ts-expect-error
56
- disabled: "var(--ds-background-disabled, ".concat(colors.N20A, ")"),
57
- selected: {
58
- // @ts-expect-error
59
- default: "var(--ds-background-selected, ".concat(colors.R500, ")"),
60
- // @ts-expect-error
61
- hover: "var(--ds-background-selected-hovered, ".concat(colors.R500, ")"),
62
- // @ts-expect-error
63
- active: "var(--ds-background-selected-pressed, ".concat(colors.R500, ")")
64
- }
65
- },
66
- link: {
67
- default: 'color.background.neutral.subtle'
68
- },
69
- subtle: {
70
- default: 'color.background.neutral.subtle',
71
- hover: 'color.background.neutral.subtle.hovered',
72
- active: 'color.background.neutral.subtle.pressed',
73
- // @ts-expect-error
74
- disabled: "var(--ds-background-neutral-subtle, none)"
75
- },
76
- 'subtle-link': {
77
- default: 'color.background.neutral.subtle'
78
- },
79
- selected: {
80
- // @ts-expect-error
81
- default: "var(--ds-background-selected, ".concat(colors.N700, ")"),
82
- // @ts-expect-error
83
- hover: "var(--ds-background-selected-hovered, ".concat(colors.N700, ")"),
84
- // @ts-expect-error
85
- active: "var(--ds-background-selected-pressed, ".concat(colors.N700, ")")
86
- }
87
- },
88
- color: {
89
- default: {
90
- // @ts-expect-error
91
- default: "var(--ds-text, ".concat(colors.N500, ")"),
92
- // @ts-expect-error
93
- active: "var(--ds-text, ".concat(colors.B400, ")"),
94
- disabled: 'color.text.disabled'
95
- },
96
- primary: {
97
- default: 'color.text.inverse',
98
- disabled: 'color.text.disabled'
99
- },
100
- warning: {
101
- default: 'color.text.warning.inverse',
102
- disabled: 'color.text.disabled',
103
- selected: {
104
- // @ts-expect-error
105
- default: "var(--ds-text-selected, ".concat(colors.N800, ")")
106
- }
107
- },
108
- danger: {
109
- default: 'color.text.inverse',
110
- disabled: 'color.text.disabled',
111
- selected: {
112
- // @ts-expect-error
113
- default: "var(--ds-text-selected, ".concat(colors.N0, ")")
114
- }
115
- },
116
- link: {
117
- default: 'color.link',
118
- // @ts-expect-error
119
- hover: "var(--ds-link, ".concat(colors.B300, ")"),
120
- active: 'color.link.pressed',
121
- disabled: 'color.text.disabled'
122
- },
123
- subtle: {
124
- // @ts-expect-error
125
- default: "var(--ds-text, ".concat(colors.N500, ")"),
126
- // @ts-expect-error
127
- active: "var(--ds-text, ".concat(colors.B400, ")"),
128
- disabled: 'color.text.disabled'
129
- },
130
- 'subtle-link': {
131
- // @ts-expect-error
132
- default: "var(--ds-text-subtle, ".concat(colors.N200, ")"),
133
- // @ts-expect-error
134
- hover: "var(--ds-text-subtle, ".concat(colors.N90, ")"),
135
- // @ts-expect-error
136
- active: "var(--ds-text, ".concat(colors.N400, ")"),
137
- disabled: 'color.text.disabled'
138
- },
139
- selected: {
140
- // @ts-expect-error
141
- default: "var(--ds-text-selected, ".concat(colors.N20, ")")
142
- }
143
- }
144
- };
145
- var _default = exports.default = values;
@@ -1,198 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getXCSS = getXCSS;
8
- exports.heights = void 0;
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _primitives = require("@atlaskit/primitives");
11
- var _constants = require("@atlaskit/theme/constants");
12
- var _colors = _interopRequireDefault(require("./colors"));
13
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
- var fontSize = (0, _constants.fontSize)();
16
- var heights = exports.heights = {
17
- default: "".concat(32 / fontSize, "em"),
18
- compact: "".concat(24 / fontSize, "em"),
19
- none: 'auto'
20
- };
21
- var lineHeights = {
22
- default: heights.default,
23
- compact: heights.compact,
24
- none: 'inherit'
25
- };
26
- var paddingInline = {
27
- default: {
28
- default: 'space.150',
29
- withIcon: 'space.100'
30
- },
31
- compact: {
32
- default: 'space.150',
33
- withIcon: 'space.100'
34
- },
35
- none: {
36
- default: 'space.0',
37
- withIcon: 'space.0'
38
- }
39
- };
40
- var gap = {
41
- compact: 'space.050',
42
- default: 'space.050',
43
- none: 'space.0'
44
- };
45
- var verticalAlign = {
46
- default: 'middle',
47
- compact: 'middle',
48
- none: 'baseline'
49
- };
50
- var splitBorderStyles = {
51
- ':focus-visible': {
52
- zIndex: 1
53
- }
54
- };
55
- function getColor(_ref) {
56
- var group = _ref.group,
57
- key = _ref.key;
58
- return group[key] || group.default;
59
- }
60
- function getColors(_ref2) {
61
- var appearance = _ref2.appearance,
62
- _ref2$interactionStat = _ref2.interactionState,
63
- interactionState = _ref2$interactionStat === void 0 ? 'default' : _ref2$interactionStat,
64
- isDisabled = _ref2.isDisabled,
65
- isSelected = _ref2.isSelected,
66
- isHighlighted = _ref2.isHighlighted,
67
- isActiveOverSelected = _ref2.isActiveOverSelected,
68
- hasOverlay = _ref2.hasOverlay;
69
- var showSelectedState = (isSelected || isHighlighted) && !isDisabled && !isActiveOverSelected;
70
- var key = interactionState;
71
- // Overlay does not change color on interaction, revert to 'default' or resting state
72
- key = hasOverlay ? 'default' : key;
73
- key = showSelectedState && isActiveOverSelected ? 'active' : key;
74
-
75
- // Disabled colors overrule everything else
76
- key = isDisabled ? 'disabled' : key;
77
- return {
78
- backgroundColor: getColor({
79
- group: showSelectedState && _colors.default.background[appearance]['selected'] || _colors.default.background[showSelectedState ? 'selected' : appearance],
80
- key: key
81
- }),
82
- color: getColor({
83
- group: showSelectedState && _colors.default.color[appearance]['selected'] || _colors.default.color[showSelectedState ? 'selected' : appearance],
84
- key: key
85
- })
86
- };
87
- }
88
- function getXCSS(_ref3) {
89
- var appearance = _ref3.appearance,
90
- spacing = _ref3.spacing,
91
- isDisabled = _ref3.isDisabled,
92
- isSelected = _ref3.isSelected,
93
- isLoading = _ref3.isLoading,
94
- isHighlighted = _ref3.isHighlighted,
95
- isActiveOverSelected = _ref3.isActiveOverSelected,
96
- isIconButton = _ref3.isIconButton,
97
- isCircle = _ref3.isCircle,
98
- shouldFitContainer = _ref3.shouldFitContainer,
99
- isLink = _ref3.isLink,
100
- isSplit = _ref3.isSplit,
101
- isNavigationSplit = _ref3.isNavigationSplit,
102
- hasOverlay = _ref3.hasOverlay,
103
- hasIconBefore = _ref3.hasIconBefore,
104
- hasIconAfter = _ref3.hasIconAfter;
105
- var baseColors = getColors({
106
- appearance: appearance,
107
- isSelected: isSelected,
108
- isHighlighted: isHighlighted,
109
- isActiveOverSelected: isActiveOverSelected,
110
- isDisabled: isDisabled
111
- });
112
- var combinedBaseColorStyles = isLink ? _objectSpread(_objectSpread({}, baseColors), {}, {
113
- textDecoration: 'none',
114
- // Disabling visited styles (by re-declaring the base colors)
115
- ':visited': baseColors
116
- }) : isNavigationSplit && !isSelected ? _objectSpread(_objectSpread({}, baseColors), {}, {
117
- backgroundColor: 'color.background.neutral.subtle'
118
- }) : baseColors;
119
- var height = heights[spacing];
120
- var width = shouldFitContainer ? '100%' : 'auto';
121
- width = isIconButton ? isNavigationSplit ? '24px' : height : width;
122
- var defaultPaddingInlineStart = paddingInline[spacing][hasIconBefore ? 'withIcon' : 'default'];
123
- var defaultPaddingInlineEnd = paddingInline[spacing][hasIconAfter ? 'withIcon' : 'default'];
124
- var splitButtonStyles = isSplit ? splitBorderStyles : {};
125
- var getNavigationSplitButtonPaddings = function getNavigationSplitButtonPaddings() {
126
- if (isNavigationSplit) {
127
- return {
128
- paddingInlineStart: 'space.075',
129
- paddingInlineEnd: 'space.075'
130
- };
131
- }
132
- return {
133
- paddingInlineStart: isIconButton ? 'space.0' : defaultPaddingInlineStart,
134
- paddingInlineEnd: isIconButton ? 'space.0' : defaultPaddingInlineEnd
135
- };
136
- };
137
- var _getNavigationSplitBu = getNavigationSplitButtonPaddings(),
138
- paddingInlineStart = _getNavigationSplitBu.paddingInlineStart,
139
- paddingInlineEnd = _getNavigationSplitBu.paddingInlineEnd;
140
- return (0, _primitives.xcss)(_objectSpread(_objectSpread(_objectSpread({
141
- alignItems: 'baseline',
142
- borderWidth: 'border.width.0',
143
- borderRadius: isCircle && !isSplit ? 'border.radius.circle' : 'border.radius.100',
144
- boxSizing: 'border-box',
145
- display: 'inline-flex',
146
- fontSize: 'inherit',
147
- fontStyle: 'normal',
148
- fontFamily: 'inherit',
149
- fontWeight: 500,
150
- maxWidth: '100%',
151
- // Needed to position overlay
152
- position: 'relative',
153
- textAlign: 'center',
154
- transition: 'background 0.1s ease-out, box-shadow 0.15s cubic-bezier(0.47, 0.03, 0.49, 1.38)',
155
- whiteSpace: 'nowrap',
156
- height: height,
157
- lineHeight: lineHeights[spacing],
158
- paddingBlock: 'space.0',
159
- paddingInlineStart: paddingInlineStart,
160
- paddingInlineEnd: paddingInlineEnd,
161
- columnGap: gap[spacing],
162
- verticalAlign: verticalAlign[spacing],
163
- width: width,
164
- // justifyContent required for shouldFitContainer buttons with an icon inside
165
- justifyContent: 'center'
166
- }, combinedBaseColorStyles), isDisabled || hasOverlay || isLoading ? {
167
- cursor: isLoading ? 'progress' : 'not-allowed'
168
- } : {}), {}, {
169
- ':hover': _objectSpread(_objectSpread({}, getColors({
170
- appearance: appearance,
171
- isSelected: isNavigationSplit && !isSelected ? false : isSelected,
172
- isActiveOverSelected: isActiveOverSelected,
173
- isDisabled: isDisabled,
174
- interactionState: 'hover',
175
- hasOverlay: hasOverlay
176
- })), {}, {
177
- textDecoration: !isSelected && (appearance === 'link' || appearance === 'subtle-link') ? 'underline' : 'none',
178
- // background, box-shadow
179
- transitionDuration: '0s, 0.15s'
180
- }),
181
- ':active': _objectSpread(_objectSpread({}, getColors({
182
- appearance: appearance,
183
- isSelected: isNavigationSplit && !isSelected ? false : isSelected,
184
- isActiveOverSelected: isActiveOverSelected,
185
- isDisabled: isDisabled,
186
- interactionState: 'active',
187
- hasOverlay: hasOverlay
188
- })), {}, {
189
- // background, box-shadow
190
- transitionDuration: '0s, 0s'
191
- }),
192
- ':focus': {
193
- // Required due to Jira's AUI CSS reset
194
- // See https://product-fabric.atlassian.net/browse/DSP-15687
195
- textDecoration: !isSelected && (appearance === 'link' || appearance === 'subtle-link') ? 'underline' : 'none'
196
- }
197
- }, splitButtonStyles));
198
- }
@@ -1,136 +0,0 @@
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
- },
20
- primary: {
21
- default: 'color.background.brand.bold',
22
- hover: 'color.background.brand.bold.hovered',
23
- active: 'color.background.brand.bold.pressed',
24
- // @ts-expect-error
25
- disabled: `var(--ds-background-disabled, ${colors.N20A})`
26
- },
27
- warning: {
28
- default: 'color.background.warning.bold',
29
- hover: 'color.background.warning.bold.hovered',
30
- active: 'color.background.warning.bold.pressed',
31
- // @ts-expect-error
32
- disabled: `var(--ds-background-disabled, ${colors.N20A})`,
33
- selected: {
34
- // @ts-expect-error
35
- default: `var(--ds-background-selected, ${colors.Y400})`,
36
- // @ts-expect-error
37
- hover: `var(--ds-background-selected-hovered, ${colors.Y400})`,
38
- // @ts-expect-error
39
- active: `var(--ds-background-selected-pressed, ${colors.Y400})`
40
- }
41
- },
42
- danger: {
43
- default: 'color.background.danger.bold',
44
- hover: 'color.background.danger.bold.hovered',
45
- active: 'color.background.danger.bold.pressed',
46
- // @ts-expect-error
47
- disabled: `var(--ds-background-disabled, ${colors.N20A})`,
48
- selected: {
49
- // @ts-expect-error
50
- default: `var(--ds-background-selected, ${colors.R500})`,
51
- // @ts-expect-error
52
- hover: `var(--ds-background-selected-hovered, ${colors.R500})`,
53
- // @ts-expect-error
54
- active: `var(--ds-background-selected-pressed, ${colors.R500})`
55
- }
56
- },
57
- link: {
58
- default: 'color.background.neutral.subtle'
59
- },
60
- subtle: {
61
- default: 'color.background.neutral.subtle',
62
- hover: 'color.background.neutral.subtle.hovered',
63
- active: 'color.background.neutral.subtle.pressed',
64
- // @ts-expect-error
65
- disabled: "var(--ds-background-neutral-subtle, none)"
66
- },
67
- 'subtle-link': {
68
- default: 'color.background.neutral.subtle'
69
- },
70
- selected: {
71
- // @ts-expect-error
72
- default: `var(--ds-background-selected, ${colors.N700})`,
73
- // @ts-expect-error
74
- hover: `var(--ds-background-selected-hovered, ${colors.N700})`,
75
- // @ts-expect-error
76
- active: `var(--ds-background-selected-pressed, ${colors.N700})`
77
- }
78
- },
79
- color: {
80
- default: {
81
- // @ts-expect-error
82
- default: `var(--ds-text, ${colors.N500})`,
83
- // @ts-expect-error
84
- active: `var(--ds-text, ${colors.B400})`,
85
- disabled: 'color.text.disabled'
86
- },
87
- primary: {
88
- default: 'color.text.inverse',
89
- disabled: 'color.text.disabled'
90
- },
91
- warning: {
92
- default: 'color.text.warning.inverse',
93
- disabled: 'color.text.disabled',
94
- selected: {
95
- // @ts-expect-error
96
- default: `var(--ds-text-selected, ${colors.N800})`
97
- }
98
- },
99
- danger: {
100
- default: 'color.text.inverse',
101
- disabled: 'color.text.disabled',
102
- selected: {
103
- // @ts-expect-error
104
- default: `var(--ds-text-selected, ${colors.N0})`
105
- }
106
- },
107
- link: {
108
- default: 'color.link',
109
- // @ts-expect-error
110
- hover: `var(--ds-link, ${colors.B300})`,
111
- active: 'color.link.pressed',
112
- disabled: 'color.text.disabled'
113
- },
114
- subtle: {
115
- // @ts-expect-error
116
- default: `var(--ds-text, ${colors.N500})`,
117
- // @ts-expect-error
118
- active: `var(--ds-text, ${colors.B400})`,
119
- disabled: 'color.text.disabled'
120
- },
121
- 'subtle-link': {
122
- // @ts-expect-error
123
- default: `var(--ds-text-subtle, ${colors.N200})`,
124
- // @ts-expect-error
125
- hover: `var(--ds-text-subtle, ${colors.N90})`,
126
- // @ts-expect-error
127
- active: `var(--ds-text, ${colors.N400})`,
128
- disabled: 'color.text.disabled'
129
- },
130
- selected: {
131
- // @ts-expect-error
132
- default: `var(--ds-text-selected, ${colors.N20})`
133
- }
134
- }
135
- };
136
- export default values;
@@ -1,196 +0,0 @@
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
- export const heights = {
6
- default: `${32 / fontSize}em`,
7
- compact: `${24 / fontSize}em`,
8
- none: 'auto'
9
- };
10
- const lineHeights = {
11
- default: heights.default,
12
- compact: heights.compact,
13
- none: 'inherit'
14
- };
15
- const paddingInline = {
16
- default: {
17
- default: 'space.150',
18
- withIcon: 'space.100'
19
- },
20
- compact: {
21
- default: 'space.150',
22
- withIcon: 'space.100'
23
- },
24
- none: {
25
- default: 'space.0',
26
- withIcon: 'space.0'
27
- }
28
- };
29
- const gap = {
30
- compact: 'space.050',
31
- default: 'space.050',
32
- none: 'space.0'
33
- };
34
- const verticalAlign = {
35
- default: 'middle',
36
- compact: 'middle',
37
- none: 'baseline'
38
- };
39
- const splitBorderStyles = {
40
- ':focus-visible': {
41
- zIndex: 1
42
- }
43
- };
44
- function getColor({
45
- group,
46
- key
47
- }) {
48
- return group[key] || group.default;
49
- }
50
- function getColors({
51
- appearance,
52
- interactionState = 'default',
53
- isDisabled,
54
- isSelected,
55
- isHighlighted,
56
- isActiveOverSelected,
57
- hasOverlay
58
- }) {
59
- const showSelectedState = (isSelected || isHighlighted) && !isDisabled && !isActiveOverSelected;
60
- let key = interactionState;
61
- // Overlay does not change color on interaction, revert to 'default' or resting state
62
- key = hasOverlay ? 'default' : key;
63
- key = showSelectedState && isActiveOverSelected ? 'active' : key;
64
-
65
- // Disabled colors overrule everything else
66
- key = isDisabled ? 'disabled' : key;
67
- return {
68
- backgroundColor: getColor({
69
- group: showSelectedState && colors.background[appearance]['selected'] || colors.background[showSelectedState ? 'selected' : appearance],
70
- key
71
- }),
72
- color: getColor({
73
- group: showSelectedState && colors.color[appearance]['selected'] || colors.color[showSelectedState ? 'selected' : appearance],
74
- key
75
- })
76
- };
77
- }
78
- export function getXCSS({
79
- appearance,
80
- spacing,
81
- isDisabled,
82
- isSelected,
83
- isLoading,
84
- isHighlighted,
85
- isActiveOverSelected,
86
- isIconButton,
87
- isCircle,
88
- shouldFitContainer,
89
- isLink,
90
- isSplit,
91
- isNavigationSplit,
92
- hasOverlay,
93
- hasIconBefore,
94
- hasIconAfter
95
- }) {
96
- const baseColors = getColors({
97
- appearance,
98
- isSelected,
99
- isHighlighted,
100
- isActiveOverSelected,
101
- isDisabled
102
- });
103
- const combinedBaseColorStyles = isLink ? {
104
- ...baseColors,
105
- textDecoration: 'none',
106
- // Disabling visited styles (by re-declaring the base colors)
107
- ':visited': baseColors
108
- } : isNavigationSplit && !isSelected ? {
109
- ...baseColors,
110
- backgroundColor: 'color.background.neutral.subtle'
111
- } : baseColors;
112
- const height = heights[spacing];
113
- let width = shouldFitContainer ? '100%' : 'auto';
114
- width = isIconButton ? isNavigationSplit ? '24px' : height : width;
115
- const defaultPaddingInlineStart = paddingInline[spacing][hasIconBefore ? 'withIcon' : 'default'];
116
- const defaultPaddingInlineEnd = paddingInline[spacing][hasIconAfter ? 'withIcon' : 'default'];
117
- const splitButtonStyles = isSplit ? splitBorderStyles : {};
118
- const getNavigationSplitButtonPaddings = () => {
119
- if (isNavigationSplit) {
120
- return {
121
- paddingInlineStart: 'space.075',
122
- paddingInlineEnd: 'space.075'
123
- };
124
- }
125
- return {
126
- paddingInlineStart: isIconButton ? 'space.0' : defaultPaddingInlineStart,
127
- paddingInlineEnd: isIconButton ? 'space.0' : defaultPaddingInlineEnd
128
- };
129
- };
130
- const {
131
- paddingInlineStart,
132
- paddingInlineEnd
133
- } = getNavigationSplitButtonPaddings();
134
- return xcss({
135
- alignItems: 'baseline',
136
- borderWidth: 'border.width.0',
137
- borderRadius: isCircle && !isSplit ? 'border.radius.circle' : 'border.radius.100',
138
- boxSizing: 'border-box',
139
- display: 'inline-flex',
140
- fontSize: 'inherit',
141
- fontStyle: 'normal',
142
- fontFamily: 'inherit',
143
- fontWeight: 500,
144
- maxWidth: '100%',
145
- // Needed to position overlay
146
- position: 'relative',
147
- textAlign: 'center',
148
- transition: 'background 0.1s ease-out, box-shadow 0.15s cubic-bezier(0.47, 0.03, 0.49, 1.38)',
149
- whiteSpace: 'nowrap',
150
- height,
151
- lineHeight: lineHeights[spacing],
152
- paddingBlock: 'space.0',
153
- paddingInlineStart,
154
- paddingInlineEnd,
155
- columnGap: gap[spacing],
156
- verticalAlign: verticalAlign[spacing],
157
- width,
158
- // justifyContent required for shouldFitContainer buttons with an icon inside
159
- justifyContent: 'center',
160
- ...combinedBaseColorStyles,
161
- ...(isDisabled || hasOverlay || isLoading ? {
162
- cursor: isLoading ? 'progress' : 'not-allowed'
163
- } : {}),
164
- ':hover': {
165
- ...getColors({
166
- appearance,
167
- isSelected: isNavigationSplit && !isSelected ? false : isSelected,
168
- isActiveOverSelected,
169
- isDisabled,
170
- interactionState: 'hover',
171
- hasOverlay
172
- }),
173
- textDecoration: !isSelected && (appearance === 'link' || appearance === 'subtle-link') ? 'underline' : 'none',
174
- // background, box-shadow
175
- transitionDuration: '0s, 0.15s'
176
- },
177
- ':active': {
178
- ...getColors({
179
- appearance,
180
- isSelected: isNavigationSplit && !isSelected ? false : isSelected,
181
- isActiveOverSelected,
182
- isDisabled,
183
- interactionState: 'active',
184
- hasOverlay
185
- }),
186
- // background, box-shadow
187
- transitionDuration: '0s, 0s'
188
- },
189
- ':focus': {
190
- // Required due to Jira's AUI CSS reset
191
- // See https://product-fabric.atlassian.net/browse/DSP-15687
192
- textDecoration: !isSelected && (appearance === 'link' || appearance === 'subtle-link') ? 'underline' : 'none'
193
- },
194
- ...splitButtonStyles
195
- });
196
- }