@primer/components 31.2.1-rc.48ecca6e → 31.2.1-rc.7fa29a87
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 +2 -0
- package/dist/browser.esm.js +194 -190
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +204 -200
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +27 -52
- package/lib/ActionList/Item.jsx +17 -40
- package/lib/NewButton/button.js +34 -42
- package/lib/NewButton/button.jsx +24 -23
- package/lib/utils/testing.d.ts +6 -60
- package/lib-esm/ActionList/Item.js +28 -53
- package/lib-esm/NewButton/button.js +31 -42
- package/lib-esm/theme-preval.js +66 -366
- package/lib-esm/utils/testing.d.ts +6 -60
- package/package-lock.json +7 -7
- package/package.json +2 -2
- package/src/ActionList/Item.tsx +17 -46
- package/src/NewButton/button.tsx +82 -78
- package/src/__tests__/__snapshots__/ActionList.test.tsx.snap +5 -5
- package/src/__tests__/__snapshots__/Autocomplete.test.tsx.snap +25 -25
- package/src/__tests__/__snapshots__/NewButton.test.tsx.snap +5 -0
- package/stats.html +1 -1
package/lib/ActionList/Item.js
CHANGED
@@ -35,39 +35,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
35
35
|
|
36
36
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
37
37
|
|
38
|
-
/**
|
39
|
-
* These colors are not yet in our default theme. Need to remove this once they are added.
|
40
|
-
*/
|
41
|
-
const customItemThemes = {
|
42
|
-
default: {
|
43
|
-
hover: {
|
44
|
-
light: 'rgba(46, 77, 108, 0.06)',
|
45
|
-
dark: 'rgba(201, 206, 212, 0.12)',
|
46
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.12)'
|
47
|
-
},
|
48
|
-
focus: {
|
49
|
-
light: 'rgba(54, 77, 100, 0.16)',
|
50
|
-
dark: 'rgba(201, 206, 212, 0.24)',
|
51
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.24)'
|
52
|
-
}
|
53
|
-
},
|
54
|
-
danger: {
|
55
|
-
hover: {
|
56
|
-
light: 'rgba(234, 74, 90, 0.08)',
|
57
|
-
dark: 'rgba(248, 81, 73, 0.16)',
|
58
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.16)'
|
59
|
-
},
|
60
|
-
focus: {
|
61
|
-
light: 'rgba(234, 74, 90, 0.14)',
|
62
|
-
dark: 'rgba(248, 81, 73, 0.24)',
|
63
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.24)'
|
64
|
-
}
|
65
|
-
}
|
66
|
-
};
|
67
|
-
/**
|
68
|
-
* Contract for props passed to the `Item` component.
|
69
|
-
*/
|
70
|
-
|
71
38
|
const getItemVariant = (variant = 'default', disabled) => {
|
72
39
|
if (disabled) {
|
73
40
|
return {
|
@@ -84,7 +51,10 @@ const getItemVariant = (variant = 'default', disabled) => {
|
|
84
51
|
color: (0, _constants.get)('colors.danger.fg'),
|
85
52
|
iconColor: (0, _constants.get)('colors.danger.fg'),
|
86
53
|
annotationColor: (0, _constants.get)('colors.fg.muted'),
|
87
|
-
hoverCursor: 'pointer'
|
54
|
+
hoverCursor: 'pointer',
|
55
|
+
hoverBg: (0, _constants.get)('colors.actionListItem.danger.hoverBg'),
|
56
|
+
focusBg: (0, _constants.get)('colors.actionListItem.danger.activeBg'),
|
57
|
+
hoverText: (0, _constants.get)('colors.actionListItem.danger.hoverText')
|
88
58
|
};
|
89
59
|
|
90
60
|
default:
|
@@ -92,7 +62,9 @@ const getItemVariant = (variant = 'default', disabled) => {
|
|
92
62
|
color: (0, _constants.get)('colors.fg.default'),
|
93
63
|
iconColor: (0, _constants.get)('colors.fg.muted'),
|
94
64
|
annotationColor: (0, _constants.get)('colors.fg.muted'),
|
95
|
-
hoverCursor: 'pointer'
|
65
|
+
hoverCursor: 'pointer',
|
66
|
+
hoverBg: (0, _constants.get)('colors.actionListItem.default.hoverBg'),
|
67
|
+
focusBg: (0, _constants.get)('colors.actionListItem.default.activeBg')
|
96
68
|
};
|
97
69
|
}
|
98
70
|
};
|
@@ -110,12 +82,16 @@ const MainContent = _styledComponents.default.div.withConfig({
|
|
110
82
|
const StyledItem = _styledComponents.default.div.withConfig({
|
111
83
|
displayName: "Item__StyledItem",
|
112
84
|
componentId: "jqpvy8-2"
|
113
|
-
})(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;text-decoration:none;@media (hover:hover) and (pointer:fine){:hover{background:var(--item-hover-bg-override,", ");cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], (0, _constants.get)('space.2'), (0, _constants.get)('radii.2'), ({
|
85
|
+
})(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;text-decoration:none;@media (hover:hover) and (pointer:fine){:hover{background:var( --item-hover-bg-override,", " );color:", ";cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], (0, _constants.get)('space.2'), (0, _constants.get)('radii.2'), ({
|
114
86
|
variant,
|
115
87
|
item
|
116
88
|
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).color, ({
|
117
|
-
|
118
|
-
|
89
|
+
variant,
|
90
|
+
item
|
91
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverBg, ({
|
92
|
+
variant,
|
93
|
+
item
|
94
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverText, ({
|
119
95
|
variant,
|
120
96
|
item
|
121
97
|
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverCursor, _Divider.StyledDivider, _Header.StyledHeader, ({
|
@@ -123,14 +99,18 @@ const StyledItem = _styledComponents.default.div.withConfig({
|
|
123
99
|
}) => showDivider ? `1px` : '0', DividedContent, (0, _constants.get)('colors.border.muted'), ({
|
124
100
|
showDivider
|
125
101
|
}) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, _focusZone.activeDescendantActivatedDirectly, ({
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
}) =>
|
132
|
-
|
133
|
-
|
102
|
+
variant,
|
103
|
+
item
|
104
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, _focusZone.isActiveDescendantAttribute, _focusZone.activeDescendantActivatedIndirectly, ({
|
105
|
+
variant,
|
106
|
+
item
|
107
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverBg, ({
|
108
|
+
variant,
|
109
|
+
item
|
110
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, ({
|
111
|
+
variant,
|
112
|
+
item
|
113
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, _sx.default);
|
134
114
|
|
135
115
|
const TextContainer = _styledComponents.default.span.withConfig({
|
136
116
|
displayName: "Item__TextContainer",
|
@@ -229,9 +209,6 @@ const Item = /*#__PURE__*/_react.default.forwardRef((itemProps, ref) => {
|
|
229
209
|
onAction === null || onAction === void 0 ? void 0 : onAction(itemProps, event);
|
230
210
|
}
|
231
211
|
}, [onAction, disabled, itemProps, onClick]);
|
232
|
-
const customItemTheme = customItemThemes[variant];
|
233
|
-
const hoverBackground = (0, _ThemeProvider.useColorSchemeVar)(customItemTheme.hover, 'inherit');
|
234
|
-
const focusBackground = (0, _ThemeProvider.useColorSchemeVar)(customItemTheme.focus, 'inherit');
|
235
212
|
const {
|
236
213
|
theme
|
237
214
|
} = (0, _ThemeProvider.useTheme)();
|
@@ -247,9 +224,7 @@ const Item = /*#__PURE__*/_react.default.forwardRef((itemProps, ref) => {
|
|
247
224
|
}, props, {
|
248
225
|
"data-id": id,
|
249
226
|
onKeyPress: keyPressHandler,
|
250
|
-
onClick: clickHandler
|
251
|
-
hoverBackground: disabled ? 'inherit' : hoverBackground,
|
252
|
-
focusBackground: disabled ? 'inherit' : focusBackground
|
227
|
+
onClick: clickHandler
|
253
228
|
}), !!selected === selected && /*#__PURE__*/_react.default.createElement(BaseVisualContainer, null, selectionVariant === 'multiple' ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(MultiSelectIcon, {
|
254
229
|
selected: selected,
|
255
230
|
width: "16",
|
package/lib/ActionList/Item.jsx
CHANGED
@@ -34,35 +34,6 @@ const Divider_1 = require("./Divider");
|
|
34
34
|
const ThemeProvider_1 = require("../ThemeProvider");
|
35
35
|
const focusZone_1 = require("../behaviors/focusZone");
|
36
36
|
const ssr_1 = require("@react-aria/ssr");
|
37
|
-
/**
|
38
|
-
* These colors are not yet in our default theme. Need to remove this once they are added.
|
39
|
-
*/
|
40
|
-
const customItemThemes = {
|
41
|
-
default: {
|
42
|
-
hover: {
|
43
|
-
light: 'rgba(46, 77, 108, 0.06)',
|
44
|
-
dark: 'rgba(201, 206, 212, 0.12)',
|
45
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.12)'
|
46
|
-
},
|
47
|
-
focus: {
|
48
|
-
light: 'rgba(54, 77, 100, 0.16)',
|
49
|
-
dark: 'rgba(201, 206, 212, 0.24)',
|
50
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.24)'
|
51
|
-
}
|
52
|
-
},
|
53
|
-
danger: {
|
54
|
-
hover: {
|
55
|
-
light: 'rgba(234, 74, 90, 0.08)',
|
56
|
-
dark: 'rgba(248, 81, 73, 0.16)',
|
57
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.16)'
|
58
|
-
},
|
59
|
-
focus: {
|
60
|
-
light: 'rgba(234, 74, 90, 0.14)',
|
61
|
-
dark: 'rgba(248, 81, 73, 0.24)',
|
62
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.24)'
|
63
|
-
}
|
64
|
-
}
|
65
|
-
};
|
66
37
|
const getItemVariant = (variant = 'default', disabled) => {
|
67
38
|
if (disabled) {
|
68
39
|
return {
|
@@ -78,14 +49,19 @@ const getItemVariant = (variant = 'default', disabled) => {
|
|
78
49
|
color: constants_1.get('colors.danger.fg'),
|
79
50
|
iconColor: constants_1.get('colors.danger.fg'),
|
80
51
|
annotationColor: constants_1.get('colors.fg.muted'),
|
81
|
-
hoverCursor: 'pointer'
|
52
|
+
hoverCursor: 'pointer',
|
53
|
+
hoverBg: constants_1.get('colors.actionListItem.danger.hoverBg'),
|
54
|
+
focusBg: constants_1.get('colors.actionListItem.danger.activeBg'),
|
55
|
+
hoverText: constants_1.get('colors.actionListItem.danger.hoverText')
|
82
56
|
};
|
83
57
|
default:
|
84
58
|
return {
|
85
59
|
color: constants_1.get('colors.fg.default'),
|
86
60
|
iconColor: constants_1.get('colors.fg.muted'),
|
87
61
|
annotationColor: constants_1.get('colors.fg.muted'),
|
88
|
-
hoverCursor: 'pointer'
|
62
|
+
hoverCursor: 'pointer',
|
63
|
+
hoverBg: constants_1.get('colors.actionListItem.default.hoverBg'),
|
64
|
+
focusBg: constants_1.get('colors.actionListItem.default.activeBg')
|
89
65
|
};
|
90
66
|
}
|
91
67
|
};
|
@@ -121,7 +97,11 @@ const StyledItem = styled_components_1.default.div `
|
|
121
97
|
@media (hover: hover) and (pointer: fine) {
|
122
98
|
:hover {
|
123
99
|
// allow override in case another item in the list is active/focused
|
124
|
-
background: var(
|
100
|
+
background: var(
|
101
|
+
--item-hover-bg-override,
|
102
|
+
${({ variant, item }) => getItemVariant(variant, item?.disabled).hoverBg}
|
103
|
+
);
|
104
|
+
color: ${({ variant, item }) => getItemVariant(variant, item?.disabled).hoverText};
|
125
105
|
cursor: ${({ variant, item }) => getItemVariant(variant, item?.disabled).hoverCursor};
|
126
106
|
}
|
127
107
|
}
|
@@ -167,19 +147,19 @@ const StyledItem = styled_components_1.default.div `
|
|
167
147
|
|
168
148
|
// Active Descendant
|
169
149
|
&[${focusZone_1.isActiveDescendantAttribute}='${focusZone_1.activeDescendantActivatedDirectly}'] {
|
170
|
-
background: ${({
|
150
|
+
background: ${({ variant, item }) => getItemVariant(variant, item?.disabled).focusBg};
|
171
151
|
}
|
172
152
|
&[${focusZone_1.isActiveDescendantAttribute}='${focusZone_1.activeDescendantActivatedIndirectly}'] {
|
173
|
-
background: ${({
|
153
|
+
background: ${({ variant, item }) => getItemVariant(variant, item?.disabled).hoverBg};
|
174
154
|
}
|
175
155
|
|
176
156
|
&:focus {
|
177
|
-
background: ${({
|
157
|
+
background: ${({ variant, item }) => getItemVariant(variant, item?.disabled).focusBg};
|
178
158
|
outline: none;
|
179
159
|
}
|
180
160
|
|
181
161
|
&:active {
|
182
|
-
background: ${({
|
162
|
+
background: ${({ variant, item }) => getItemVariant(variant, item?.disabled).focusBg};
|
183
163
|
}
|
184
164
|
|
185
165
|
${sx_1.default}
|
@@ -264,11 +244,8 @@ exports.Item = react_1.default.forwardRef((itemProps, ref) => {
|
|
264
244
|
onAction?.(itemProps, event);
|
265
245
|
}
|
266
246
|
}, [onAction, disabled, itemProps, onClick]);
|
267
|
-
const customItemTheme = customItemThemes[variant];
|
268
|
-
const hoverBackground = ThemeProvider_1.useColorSchemeVar(customItemTheme.hover, 'inherit');
|
269
|
-
const focusBackground = ThemeProvider_1.useColorSchemeVar(customItemTheme.focus, 'inherit');
|
270
247
|
const { theme } = ThemeProvider_1.useTheme();
|
271
|
-
return (<StyledItem ref={ref} as={Component} tabIndex={disabled ? undefined : -1} variant={variant} showDivider={showDivider} aria-selected={selected} aria-labelledby={text ? labelId : undefined} aria-describedby={description ? descriptionId : undefined} {...props} data-id={id} onKeyPress={keyPressHandler} onClick={clickHandler}
|
248
|
+
return (<StyledItem ref={ref} as={Component} tabIndex={disabled ? undefined : -1} variant={variant} showDivider={showDivider} aria-selected={selected} aria-labelledby={text ? labelId : undefined} aria-describedby={description ? descriptionId : undefined} {...props} data-id={id} onKeyPress={keyPressHandler} onClick={clickHandler}>
|
272
249
|
{!!selected === selected && (<BaseVisualContainer>
|
273
250
|
{selectionVariant === 'multiple' ? (<>
|
274
251
|
{/**
|
package/lib/NewButton/button.js
CHANGED
@@ -23,6 +23,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
23
23
|
|
24
24
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
25
25
|
|
26
|
+
const TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
|
27
|
+
|
26
28
|
const getVariantStyles = (variant = 'default', theme) => {
|
27
29
|
const style = {
|
28
30
|
default: {
|
@@ -146,7 +148,7 @@ const getVariantStyles = (variant = 'default', theme) => {
|
|
146
148
|
borderColor: 'btn.outline.focusBorder',
|
147
149
|
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.focusShadow}`
|
148
150
|
},
|
149
|
-
'&:active': {
|
151
|
+
'&:active:not([disabled])': {
|
150
152
|
color: 'btn.outline.selectedText',
|
151
153
|
backgroundColor: 'btn.outline.selectedBg',
|
152
154
|
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.selectedShadow}`,
|
@@ -217,6 +219,7 @@ const ButtonBase = _styledComponents.default.button.withConfig({
|
|
217
219
|
|
218
220
|
const Button = /*#__PURE__*/(0, _react.forwardRef)(({
|
219
221
|
children,
|
222
|
+
sx: sxProp = {},
|
220
223
|
...props
|
221
224
|
}, forwardedRef) => {
|
222
225
|
const {
|
@@ -224,12 +227,9 @@ const Button = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
224
227
|
leadingIcon: LeadingIcon,
|
225
228
|
trailingIcon: TrailingIcon,
|
226
229
|
variant = 'default',
|
227
|
-
size = 'medium'
|
228
|
-
sx: sxProp = {}
|
230
|
+
size = 'medium'
|
229
231
|
} = props;
|
230
232
|
const iconOnly = !!Icon;
|
231
|
-
const TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
|
232
|
-
|
233
233
|
const {
|
234
234
|
theme
|
235
235
|
} = (0, _ThemeProvider.useTheme)();
|
@@ -270,46 +270,38 @@ const Button = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
270
270
|
gridArea: 'trailingIcon'
|
271
271
|
}
|
272
272
|
};
|
273
|
-
const variableStyles = { ...getSizeStyles(size, variant, iconOnly),
|
274
|
-
...getVariantStyles(variant, theme)
|
275
|
-
};
|
276
|
-
const componentStyles = { ...styles,
|
277
|
-
...variableStyles
|
278
|
-
};
|
279
273
|
const iconWrapStyles = {
|
280
274
|
display: 'inline-block'
|
281
275
|
};
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
}, /*#__PURE__*/_react.default.createElement(TrailingIcon, null)))
|
312
|
-
);
|
276
|
+
|
277
|
+
const sxStyles = _sx.merge.all([styles, getSizeStyles(size, variant, iconOnly), getVariantStyles(variant, theme), sxProp]);
|
278
|
+
|
279
|
+
return /*#__PURE__*/_react.default.createElement(ButtonBase, _extends({
|
280
|
+
sx: sxStyles,
|
281
|
+
ref: forwardedRef
|
282
|
+
}, props), LeadingIcon && /*#__PURE__*/_react.default.createElement(_Box.default, {
|
283
|
+
as: "span",
|
284
|
+
"data-component": "leadingIcon",
|
285
|
+
sx: iconWrapStyles,
|
286
|
+
"aria-hidden": !iconOnly
|
287
|
+
}, /*#__PURE__*/_react.default.createElement(LeadingIcon, null)), /*#__PURE__*/_react.default.createElement("span", {
|
288
|
+
"data-component": "text",
|
289
|
+
hidden: Icon ? true : false
|
290
|
+
}, children), Icon && /*#__PURE__*/_react.default.createElement(_Box.default, {
|
291
|
+
"data-component": "icon-only",
|
292
|
+
as: "span",
|
293
|
+
sx: {
|
294
|
+
display: 'inline-block'
|
295
|
+
},
|
296
|
+
"aria-hidden": !iconOnly
|
297
|
+
}, /*#__PURE__*/_react.default.createElement(Icon, null)), TrailingIcon && /*#__PURE__*/_react.default.createElement(_Box.default, {
|
298
|
+
as: "span",
|
299
|
+
"data-component": "trailingIcon",
|
300
|
+
sx: { ...iconWrapStyles,
|
301
|
+
ml: 2
|
302
|
+
},
|
303
|
+
"aria-hidden": !iconOnly
|
304
|
+
}, /*#__PURE__*/_react.default.createElement(TrailingIcon, null)));
|
313
305
|
});
|
314
306
|
exports.Button = Button;
|
315
307
|
Button.displayName = 'Button';
|
package/lib/NewButton/button.jsx
CHANGED
@@ -28,6 +28,7 @@ const Box_1 = __importDefault(require("../Box"));
|
|
28
28
|
const styled_components_1 = __importDefault(require("styled-components"));
|
29
29
|
const sx_1 = __importStar(require("../sx"));
|
30
30
|
const ThemeProvider_1 = require("../ThemeProvider");
|
31
|
+
const TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
|
31
32
|
const getVariantStyles = (variant = 'default', theme) => {
|
32
33
|
const style = {
|
33
34
|
default: {
|
@@ -151,7 +152,7 @@ const getVariantStyles = (variant = 'default', theme) => {
|
|
151
152
|
borderColor: 'btn.outline.focusBorder',
|
152
153
|
boxShadow: `${theme?.shadows.btn.outline.focusShadow}`
|
153
154
|
},
|
154
|
-
'&:active': {
|
155
|
+
'&:active:not([disabled])': {
|
155
156
|
color: 'btn.outline.selectedText',
|
156
157
|
backgroundColor: 'btn.outline.selectedBg',
|
157
158
|
boxShadow: `${theme?.shadows.btn.outline.selectedShadow}`,
|
@@ -208,10 +209,9 @@ const getSizeStyles = (size = 'medium', variant = 'default', iconOnly) => {
|
|
208
209
|
};
|
209
210
|
};
|
210
211
|
const ButtonBase = styled_components_1.default.button(sx_1.default);
|
211
|
-
const Button = react_1.forwardRef(({ children, ...props }, forwardedRef) => {
|
212
|
-
const { icon: Icon, leadingIcon: LeadingIcon, trailingIcon: TrailingIcon, variant = 'default', size = 'medium'
|
212
|
+
const Button = react_1.forwardRef(({ children, sx: sxProp = {}, ...props }, forwardedRef) => {
|
213
|
+
const { icon: Icon, leadingIcon: LeadingIcon, trailingIcon: TrailingIcon, variant = 'default', size = 'medium' } = props;
|
213
214
|
const iconOnly = !!Icon;
|
214
|
-
const TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
|
215
215
|
const { theme } = ThemeProvider_1.useTheme();
|
216
216
|
const styles = {
|
217
217
|
borderRadius: '2',
|
@@ -250,28 +250,29 @@ const Button = react_1.forwardRef(({ children, ...props }, forwardedRef) => {
|
|
250
250
|
gridArea: 'trailingIcon'
|
251
251
|
}
|
252
252
|
};
|
253
|
-
const variableStyles = { ...getSizeStyles(size, variant, iconOnly), ...getVariantStyles(variant, theme) };
|
254
|
-
const componentStyles = { ...styles, ...variableStyles };
|
255
253
|
const iconWrapStyles = {
|
256
254
|
display: 'inline-block'
|
257
255
|
};
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
</
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
256
|
+
const sxStyles = sx_1.merge.all([
|
257
|
+
styles,
|
258
|
+
getSizeStyles(size, variant, iconOnly),
|
259
|
+
getVariantStyles(variant, theme),
|
260
|
+
sxProp
|
261
|
+
]);
|
262
|
+
return (<ButtonBase sx={sxStyles} ref={forwardedRef} {...props}>
|
263
|
+
{LeadingIcon && (<Box_1.default as="span" data-component="leadingIcon" sx={iconWrapStyles} aria-hidden={!iconOnly}>
|
264
|
+
<LeadingIcon />
|
265
|
+
</Box_1.default>)}
|
266
|
+
<span data-component="text" hidden={Icon ? true : false}>
|
267
|
+
{children}
|
268
|
+
</span>
|
269
|
+
{Icon && (<Box_1.default data-component="icon-only" as="span" sx={{ display: 'inline-block' }} aria-hidden={!iconOnly}>
|
270
|
+
<Icon />
|
271
|
+
</Box_1.default>)}
|
272
|
+
{TrailingIcon && (<Box_1.default as="span" data-component="trailingIcon" sx={{ ...iconWrapStyles, ml: 2 }} aria-hidden={!iconOnly}>
|
273
|
+
<TrailingIcon />
|
274
|
+
</Box_1.default>)}
|
275
|
+
</ButtonBase>);
|
275
276
|
});
|
276
277
|
exports.Button = Button;
|
277
278
|
Button.displayName = 'Button';
|
package/lib/utils/testing.d.ts
CHANGED
@@ -231,67 +231,13 @@ export declare function render(component: React.ReactElement, theme?: {
|
|
231
231
|
gradientOut: string;
|
232
232
|
};
|
233
233
|
mktg: {
|
234
|
-
success: string;
|
235
|
-
info: string;
|
236
|
-
bgShadeGradient: {
|
237
|
-
top: string;
|
238
|
-
bottom: string;
|
239
|
-
};
|
240
234
|
btn: {
|
241
|
-
bg:
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
bottom: string;
|
248
|
-
};
|
249
|
-
text: string;
|
250
|
-
primary: {
|
251
|
-
bg: {
|
252
|
-
top: string;
|
253
|
-
bottom: string;
|
254
|
-
};
|
255
|
-
bgOverlay: {
|
256
|
-
top: string;
|
257
|
-
bottom: string;
|
258
|
-
};
|
259
|
-
text: string;
|
260
|
-
};
|
261
|
-
enterprise: {
|
262
|
-
bg: {
|
263
|
-
top: string;
|
264
|
-
bottom: string;
|
265
|
-
};
|
266
|
-
bgOverlay: {
|
267
|
-
top: string;
|
268
|
-
bottom: string;
|
269
|
-
};
|
270
|
-
text: string;
|
271
|
-
};
|
272
|
-
outline: {
|
273
|
-
text: string;
|
274
|
-
border: string;
|
275
|
-
hover: {
|
276
|
-
text: string;
|
277
|
-
border: string;
|
278
|
-
};
|
279
|
-
focus: {
|
280
|
-
border: string;
|
281
|
-
borderInset: string;
|
282
|
-
};
|
283
|
-
};
|
284
|
-
dark: {
|
285
|
-
text: string;
|
286
|
-
border: string;
|
287
|
-
hover: {
|
288
|
-
text: string;
|
289
|
-
border: string;
|
290
|
-
};
|
291
|
-
focus: {
|
292
|
-
border: string;
|
293
|
-
borderInset: string;
|
294
|
-
};
|
235
|
+
bg: string;
|
236
|
+
shadow: {
|
237
|
+
outline: string;
|
238
|
+
focus: string;
|
239
|
+
hover: string;
|
240
|
+
hoverMuted: string;
|
295
241
|
};
|
296
242
|
};
|
297
243
|
};
|
@@ -8,43 +8,10 @@ import Truncate from '../Truncate';
|
|
8
8
|
import styled from 'styled-components';
|
9
9
|
import { StyledHeader } from './Header';
|
10
10
|
import { StyledDivider } from './Divider';
|
11
|
-
import {
|
11
|
+
import { useTheme } from '../ThemeProvider';
|
12
12
|
import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '../behaviors/focusZone';
|
13
13
|
import { useSSRSafeId } from '@react-aria/ssr';
|
14
14
|
|
15
|
-
/**
|
16
|
-
* These colors are not yet in our default theme. Need to remove this once they are added.
|
17
|
-
*/
|
18
|
-
const customItemThemes = {
|
19
|
-
default: {
|
20
|
-
hover: {
|
21
|
-
light: 'rgba(46, 77, 108, 0.06)',
|
22
|
-
dark: 'rgba(201, 206, 212, 0.12)',
|
23
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.12)'
|
24
|
-
},
|
25
|
-
focus: {
|
26
|
-
light: 'rgba(54, 77, 100, 0.16)',
|
27
|
-
dark: 'rgba(201, 206, 212, 0.24)',
|
28
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.24)'
|
29
|
-
}
|
30
|
-
},
|
31
|
-
danger: {
|
32
|
-
hover: {
|
33
|
-
light: 'rgba(234, 74, 90, 0.08)',
|
34
|
-
dark: 'rgba(248, 81, 73, 0.16)',
|
35
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.16)'
|
36
|
-
},
|
37
|
-
focus: {
|
38
|
-
light: 'rgba(234, 74, 90, 0.14)',
|
39
|
-
dark: 'rgba(248, 81, 73, 0.24)',
|
40
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.24)'
|
41
|
-
}
|
42
|
-
}
|
43
|
-
};
|
44
|
-
/**
|
45
|
-
* Contract for props passed to the `Item` component.
|
46
|
-
*/
|
47
|
-
|
48
15
|
const getItemVariant = (variant = 'default', disabled) => {
|
49
16
|
if (disabled) {
|
50
17
|
return {
|
@@ -61,7 +28,10 @@ const getItemVariant = (variant = 'default', disabled) => {
|
|
61
28
|
color: get('colors.danger.fg'),
|
62
29
|
iconColor: get('colors.danger.fg'),
|
63
30
|
annotationColor: get('colors.fg.muted'),
|
64
|
-
hoverCursor: 'pointer'
|
31
|
+
hoverCursor: 'pointer',
|
32
|
+
hoverBg: get('colors.actionListItem.danger.hoverBg'),
|
33
|
+
focusBg: get('colors.actionListItem.danger.activeBg'),
|
34
|
+
hoverText: get('colors.actionListItem.danger.hoverText')
|
65
35
|
};
|
66
36
|
|
67
37
|
default:
|
@@ -69,7 +39,9 @@ const getItemVariant = (variant = 'default', disabled) => {
|
|
69
39
|
color: get('colors.fg.default'),
|
70
40
|
iconColor: get('colors.fg.muted'),
|
71
41
|
annotationColor: get('colors.fg.muted'),
|
72
|
-
hoverCursor: 'pointer'
|
42
|
+
hoverCursor: 'pointer',
|
43
|
+
hoverBg: get('colors.actionListItem.default.hoverBg'),
|
44
|
+
focusBg: get('colors.actionListItem.default.activeBg')
|
73
45
|
};
|
74
46
|
}
|
75
47
|
};
|
@@ -85,12 +57,16 @@ const MainContent = styled.div.withConfig({
|
|
85
57
|
const StyledItem = styled.div.withConfig({
|
86
58
|
displayName: "Item__StyledItem",
|
87
59
|
componentId: "jqpvy8-2"
|
88
|
-
})(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;text-decoration:none;@media (hover:hover) and (pointer:fine){:hover{background:var(--item-hover-bg-override,", ");cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], get('space.2'), get('radii.2'), ({
|
60
|
+
})(["padding:6px ", ";display:flex;border-radius:", ";color:", ";transition:background 33.333ms linear;text-decoration:none;@media (hover:hover) and (pointer:fine){:hover{background:var( --item-hover-bg-override,", " );color:", ";cursor:", ";}}:not(:first-of-type):not(", " + &):not(", " + &){margin-top:", ";", "::before{content:' ';display:block;position:absolute;width:100%;top:-7px;border:0 solid ", ";border-top-width:", ";}}&:hover ", "::before,:hover + * ", "::before{border-color:var(--item-hover-divider-border-color-override,transparent) !important;}&:focus ", "::before,:focus + * ", "::before,&[", "] ", "::before,[", "] + & ", "::before{border-color:transparent !important;}&[", "='", "']{background:", ";}&[", "='", "']{background:", ";}&:focus{background:", ";outline:none;}&:active{background:", ";}", ""], get('space.2'), get('radii.2'), ({
|
89
61
|
variant,
|
90
62
|
item
|
91
63
|
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).color, ({
|
92
|
-
|
93
|
-
|
64
|
+
variant,
|
65
|
+
item
|
66
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverBg, ({
|
67
|
+
variant,
|
68
|
+
item
|
69
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverText, ({
|
94
70
|
variant,
|
95
71
|
item
|
96
72
|
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverCursor, StyledDivider, StyledHeader, ({
|
@@ -98,14 +74,18 @@ const StyledItem = styled.div.withConfig({
|
|
98
74
|
}) => showDivider ? `1px` : '0', DividedContent, get('colors.border.muted'), ({
|
99
75
|
showDivider
|
100
76
|
}) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent, isActiveDescendantAttribute, DividedContent, isActiveDescendantAttribute, DividedContent, isActiveDescendantAttribute, activeDescendantActivatedDirectly, ({
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
}) =>
|
107
|
-
|
108
|
-
|
77
|
+
variant,
|
78
|
+
item
|
79
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, isActiveDescendantAttribute, activeDescendantActivatedIndirectly, ({
|
80
|
+
variant,
|
81
|
+
item
|
82
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverBg, ({
|
83
|
+
variant,
|
84
|
+
item
|
85
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, ({
|
86
|
+
variant,
|
87
|
+
item
|
88
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, sx);
|
109
89
|
export const TextContainer = styled.span.withConfig({
|
110
90
|
displayName: "Item__TextContainer",
|
111
91
|
componentId: "jqpvy8-3"
|
@@ -196,9 +176,6 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
196
176
|
onAction === null || onAction === void 0 ? void 0 : onAction(itemProps, event);
|
197
177
|
}
|
198
178
|
}, [onAction, disabled, itemProps, onClick]);
|
199
|
-
const customItemTheme = customItemThemes[variant];
|
200
|
-
const hoverBackground = useColorSchemeVar(customItemTheme.hover, 'inherit');
|
201
|
-
const focusBackground = useColorSchemeVar(customItemTheme.focus, 'inherit');
|
202
179
|
const {
|
203
180
|
theme
|
204
181
|
} = useTheme();
|
@@ -214,9 +191,7 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
214
191
|
}, props, {
|
215
192
|
"data-id": id,
|
216
193
|
onKeyPress: keyPressHandler,
|
217
|
-
onClick: clickHandler
|
218
|
-
hoverBackground: disabled ? 'inherit' : hoverBackground,
|
219
|
-
focusBackground: disabled ? 'inherit' : focusBackground
|
194
|
+
onClick: clickHandler
|
220
195
|
}), !!selected === selected && /*#__PURE__*/React.createElement(BaseVisualContainer, null, selectionVariant === 'multiple' ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MultiSelectIcon, {
|
221
196
|
selected: selected,
|
222
197
|
width: "16",
|