@vitality-ds/components 5.5.0 → 5.6.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/dist/Button/constants.js +14 -7
- package/dist/Button/index.js +7 -3
- package/dist/Button/logic.spec.js +12 -6
- package/dist/Button/primitives/index.js +12 -3
- package/dist/Button/primitives/styles/BaseButton.styles.js +6 -2
- package/dist/Button/primitives/styles/BaseContentContainer.styles.js +3 -0
- package/dist/DropdownMenu/components/DropdownMenuItem/styles/BaseItem.styles.js +6 -3
- package/dist/Form/CheckboxList/index.js +5 -4
- package/dist/Form/CheckboxList/index.spec.js +70 -0
- package/dist/Input/Checkbox/styles/BaseCheckboxText.styles.js +2 -1
- package/dist/Input/RadioButtons/components/RadioButton/styles/BaseRadioButton.styles.js +2 -1
- package/dist/Input/RadioButtons/components/RadioButton/styles/BaseRadioLabel.styles.js +2 -1
- package/dist/Input/RadioButtons/index.js +8 -4
- package/dist/Input/RadioButtons/index.spec.js +51 -0
- package/dist/Input/TextInput/components/ShortcutAdornment/index.js +8 -3
- package/dist/Shortcuts/constants.js +36 -0
- package/dist/Shortcuts/hooks/useOS.js +31 -0
- package/dist/Shortcuts/index.js +29 -4
- package/dist/Shortcuts/logic.js +47 -0
- package/dist/Shortcuts/logic.spec.js +149 -0
- package/dist/Shortcuts/styled.js +2 -2
- package/dist/Shortcuts/styles/BaseShortcut.styles.js +306 -21
- package/dist/Shortcuts/styles/BaseShortcutGroup.styles.js +4 -2
- package/dist/Shortcuts/styles/helpers.js +54 -0
- package/dist/components/src/Button/logic.d.ts +14 -6
- package/dist/components/src/Button/primitives/styled.d.ts +8 -0
- package/dist/components/src/Button/primitives/styles/BaseButton.styles.d.ts +5 -0
- package/dist/components/src/Button/primitives/styles/BaseContentContainer.styles.d.ts +3 -0
- package/dist/components/src/Button/primitives/types.d.ts +6 -0
- package/dist/components/src/Button/types.d.ts +3 -0
- package/dist/components/src/DropdownMenu/components/CheckableDropdownMenuItem/styled.d.ts +10 -1
- package/dist/components/src/DropdownMenu/components/DropdownMenuItem/styled.d.ts +10 -1
- package/dist/components/src/DropdownMenu/components/DropdownMenuItem/styles/BaseItem.styles.d.ts +10 -1
- package/dist/components/src/DropdownMenu/components/Submenu/styled.d.ts +10 -1
- package/dist/components/src/Form/CheckboxList/index.d.ts +1 -1
- package/dist/components/src/Form/CheckboxList/types.d.ts +4 -0
- package/dist/components/src/Input/Checkbox/styled.d.ts +1 -0
- package/dist/components/src/Input/Checkbox/styles/BaseCheckboxText.styles.d.ts +1 -0
- package/dist/components/src/Input/RadioButtons/components/RadioButton/styled.d.ts +1 -0
- package/dist/components/src/Input/RadioButtons/components/RadioButton/styles/BaseRadioLabel.styles.d.ts +1 -0
- package/dist/components/src/Input/TextInput/components/ShortcutAdornment/index.d.ts +1 -1
- package/dist/components/src/Input/TextInput/components/ShortcutAdornment/types.d.ts +1 -1
- package/dist/components/src/Link/styled.d.ts +5 -0
- package/dist/components/src/Shortcuts/constants.d.ts +6 -0
- package/dist/components/src/Shortcuts/hooks/useOS.d.ts +13 -0
- package/dist/components/src/Shortcuts/index.d.ts +1 -1
- package/dist/components/src/Shortcuts/logic.d.ts +31 -0
- package/dist/components/src/Shortcuts/logic.spec.d.ts +1 -0
- package/dist/components/src/Shortcuts/styled.d.ts +43 -18
- package/dist/components/src/Shortcuts/styles/BaseShortcut.styles.d.ts +54 -16
- package/dist/components/src/Shortcuts/styles/helpers.d.ts +9 -0
- package/dist/components/src/Shortcuts/types.d.ts +4 -2
- package/dist/esm/Button/constants.js +14 -7
- package/dist/esm/Button/index.js +7 -3
- package/dist/esm/Button/logic.spec.js +12 -6
- package/dist/esm/Button/primitives/index.js +12 -3
- package/dist/esm/Button/primitives/styles/BaseButton.styles.js +6 -2
- package/dist/esm/Button/primitives/styles/BaseContentContainer.styles.js +3 -0
- package/dist/esm/DropdownMenu/components/DropdownMenuItem/styles/BaseItem.styles.js +6 -3
- package/dist/esm/Form/CheckboxList/index.js +5 -4
- package/dist/esm/Form/CheckboxList/index.spec.js +70 -0
- package/dist/esm/Input/Checkbox/styles/BaseCheckboxText.styles.js +2 -1
- package/dist/esm/Input/RadioButtons/components/RadioButton/styles/BaseRadioButton.styles.js +2 -1
- package/dist/esm/Input/RadioButtons/components/RadioButton/styles/BaseRadioLabel.styles.js +2 -1
- package/dist/esm/Input/RadioButtons/index.js +8 -4
- package/dist/esm/Input/RadioButtons/index.spec.js +51 -0
- package/dist/esm/Input/TextInput/components/ShortcutAdornment/index.js +8 -3
- package/dist/esm/Shortcuts/constants.js +30 -0
- package/dist/esm/Shortcuts/hooks/useOS.js +24 -0
- package/dist/esm/Shortcuts/index.js +29 -4
- package/dist/esm/Shortcuts/logic.js +41 -0
- package/dist/esm/Shortcuts/logic.spec.js +147 -0
- package/dist/esm/Shortcuts/styled.js +2 -2
- package/dist/esm/Shortcuts/styles/BaseShortcut.styles.js +307 -22
- package/dist/esm/Shortcuts/styles/BaseShortcutGroup.styles.js +4 -2
- package/dist/esm/Shortcuts/styles/helpers.js +48 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/Button/constants.js
CHANGED
|
@@ -9,36 +9,43 @@ var APPEARANCES = exports.APPEARANCES = {
|
|
|
9
9
|
standard: {
|
|
10
10
|
color: "neutral",
|
|
11
11
|
variant: "subtle",
|
|
12
|
-
spinnerColor: null
|
|
12
|
+
spinnerColor: null,
|
|
13
|
+
shortcutsVariant: "onUiElementBackground"
|
|
13
14
|
},
|
|
14
15
|
onSurface: {
|
|
15
16
|
color: "neutral",
|
|
16
17
|
variant: "onSurface",
|
|
17
|
-
spinnerColor: null
|
|
18
|
+
spinnerColor: null,
|
|
19
|
+
shortcutsVariant: "onSurfaceBackground"
|
|
18
20
|
},
|
|
19
21
|
primary: {
|
|
20
22
|
color: "primary",
|
|
21
23
|
variant: "solid",
|
|
22
|
-
spinnerColor: "primary"
|
|
24
|
+
spinnerColor: "primary",
|
|
25
|
+
shortcutsVariant: "onSolidBackground"
|
|
23
26
|
},
|
|
24
27
|
destructive: {
|
|
25
28
|
color: "critical",
|
|
26
29
|
variant: "solid",
|
|
27
|
-
spinnerColor: "critical"
|
|
30
|
+
spinnerColor: "critical",
|
|
31
|
+
shortcutsVariant: "onSolidBackground"
|
|
28
32
|
},
|
|
29
33
|
warning: {
|
|
30
34
|
color: "warning",
|
|
31
35
|
variant: "solid",
|
|
32
|
-
spinnerColor: "warning"
|
|
36
|
+
spinnerColor: "warning",
|
|
37
|
+
shortcutsVariant: "onSolidBackground"
|
|
33
38
|
},
|
|
34
39
|
ghost: {
|
|
35
40
|
color: "neutral",
|
|
36
41
|
variant: "ghost",
|
|
37
|
-
spinnerColor: null
|
|
42
|
+
spinnerColor: null,
|
|
43
|
+
shortcutsVariant: "ghost"
|
|
38
44
|
},
|
|
39
45
|
link: {
|
|
40
46
|
color: "primary",
|
|
41
47
|
variant: "link",
|
|
42
|
-
spinnerColor: null
|
|
48
|
+
spinnerColor: null,
|
|
49
|
+
shortcutsVariant: "link"
|
|
43
50
|
}
|
|
44
51
|
};
|
package/dist/Button/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
var _logic = require("./logic");
|
|
12
12
|
var _primitives = _interopRequireDefault(require("./primitives"));
|
|
13
|
-
var _excluded = ["appearance", "as", "children", "className", "css", "iconLeft", "iconRight", "size", "style", "variant", "isLoading"];
|
|
13
|
+
var _excluded = ["appearance", "as", "children", "className", "css", "iconLeft", "iconRight", "size", "style", "variant", "isLoading", "shortcut"];
|
|
14
14
|
var Button = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
15
15
|
var _ref$appearance = _ref.appearance,
|
|
16
16
|
appearance = _ref$appearance === void 0 ? "standard" : _ref$appearance,
|
|
@@ -25,11 +25,13 @@ var Button = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
25
25
|
style = _ref.style,
|
|
26
26
|
ignoredVariant = _ref.variant,
|
|
27
27
|
isLoading = _ref.isLoading,
|
|
28
|
+
shortcut = _ref.shortcut,
|
|
28
29
|
restProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
29
30
|
var _getAppearance = (0, _logic.getAppearance)(appearance),
|
|
30
31
|
color = _getAppearance.color,
|
|
31
32
|
variant = _getAppearance.variant,
|
|
32
|
-
spinnerColor = _getAppearance.spinnerColor
|
|
33
|
+
spinnerColor = _getAppearance.spinnerColor,
|
|
34
|
+
shortcutsVariant = _getAppearance.shortcutsVariant;
|
|
33
35
|
return /*#__PURE__*/_react["default"].createElement(_primitives["default"], (0, _extends2["default"])({
|
|
34
36
|
color: color,
|
|
35
37
|
variant: variant,
|
|
@@ -38,7 +40,9 @@ var Button = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
38
40
|
iconRight: iconRight,
|
|
39
41
|
size: size,
|
|
40
42
|
ref: ref,
|
|
41
|
-
isLoading: isLoading
|
|
43
|
+
isLoading: isLoading,
|
|
44
|
+
shortcut: shortcut,
|
|
45
|
+
shortcutsVariant: shortcutsVariant
|
|
42
46
|
}, restProps), children);
|
|
43
47
|
});
|
|
44
48
|
Button.displayName = "Button";
|
|
@@ -7,7 +7,8 @@ describe("getAppearance", function () {
|
|
|
7
7
|
expect(appearance).toEqual({
|
|
8
8
|
color: "primary",
|
|
9
9
|
variant: "solid",
|
|
10
|
-
spinnerColor: "primary"
|
|
10
|
+
spinnerColor: "primary",
|
|
11
|
+
shortcutsVariant: "onSolidBackground"
|
|
11
12
|
});
|
|
12
13
|
});
|
|
13
14
|
it("should return the correct appearance object when given a valid key (destructive)", function () {
|
|
@@ -15,7 +16,8 @@ describe("getAppearance", function () {
|
|
|
15
16
|
expect(appearance).toEqual({
|
|
16
17
|
color: "critical",
|
|
17
18
|
variant: "solid",
|
|
18
|
-
spinnerColor: "critical"
|
|
19
|
+
spinnerColor: "critical",
|
|
20
|
+
shortcutsVariant: "onSolidBackground"
|
|
19
21
|
});
|
|
20
22
|
});
|
|
21
23
|
it("should return the correct appearance object when given a valid key (standard)", function () {
|
|
@@ -23,7 +25,8 @@ describe("getAppearance", function () {
|
|
|
23
25
|
expect(appearance).toEqual({
|
|
24
26
|
color: "neutral",
|
|
25
27
|
variant: "subtle",
|
|
26
|
-
spinnerColor: null
|
|
28
|
+
spinnerColor: null,
|
|
29
|
+
shortcutsVariant: "onUiElementBackground"
|
|
27
30
|
});
|
|
28
31
|
});
|
|
29
32
|
it("should return the correct appearance object when given a valid key (warning)", function () {
|
|
@@ -31,7 +34,8 @@ describe("getAppearance", function () {
|
|
|
31
34
|
expect(appearance).toEqual({
|
|
32
35
|
color: "warning",
|
|
33
36
|
variant: "solid",
|
|
34
|
-
spinnerColor: "warning"
|
|
37
|
+
spinnerColor: "warning",
|
|
38
|
+
shortcutsVariant: "onSolidBackground"
|
|
35
39
|
});
|
|
36
40
|
});
|
|
37
41
|
it("should return the correct appearance object when given a valid key (ghost)", function () {
|
|
@@ -39,7 +43,8 @@ describe("getAppearance", function () {
|
|
|
39
43
|
expect(appearance).toEqual({
|
|
40
44
|
color: "neutral",
|
|
41
45
|
variant: "ghost",
|
|
42
|
-
spinnerColor: null
|
|
46
|
+
spinnerColor: null,
|
|
47
|
+
shortcutsVariant: "ghost"
|
|
43
48
|
});
|
|
44
49
|
});
|
|
45
50
|
it("should return the correct appearance object when given a valid key (link)", function () {
|
|
@@ -47,7 +52,8 @@ describe("getAppearance", function () {
|
|
|
47
52
|
expect(appearance).toEqual({
|
|
48
53
|
color: "primary",
|
|
49
54
|
variant: "link",
|
|
50
|
-
spinnerColor: null
|
|
55
|
+
spinnerColor: null,
|
|
56
|
+
shortcutsVariant: "link"
|
|
51
57
|
});
|
|
52
58
|
});
|
|
53
59
|
});
|
|
@@ -8,10 +8,11 @@ exports["default"] = void 0;
|
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
var _Shortcuts = _interopRequireDefault(require("../../Shortcuts"));
|
|
11
12
|
var _Spinner = _interopRequireDefault(require("../../Spinner"));
|
|
12
13
|
var _ButtonIcon = require("../components/ButtonIcon");
|
|
13
14
|
var _styled = require("./styled");
|
|
14
|
-
var _excluded = ["as", "children", "className", "css", "iconLeft", "iconRight", "size", "style", "variant", "isLoading", "color", "spinnerColor"];
|
|
15
|
+
var _excluded = ["as", "children", "className", "css", "iconLeft", "iconRight", "size", "style", "variant", "isLoading", "color", "spinnerColor", "shortcut", "shortcutsVariant"];
|
|
15
16
|
var ButtonPrimitive = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
16
17
|
var as = _ref.as,
|
|
17
18
|
children = _ref.children,
|
|
@@ -26,19 +27,27 @@ var ButtonPrimitive = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
|
|
|
26
27
|
isLoading = _ref.isLoading,
|
|
27
28
|
color = _ref.color,
|
|
28
29
|
spinnerColor = _ref.spinnerColor,
|
|
30
|
+
shortcut = _ref.shortcut,
|
|
31
|
+
shortcutsVariant = _ref.shortcutsVariant,
|
|
29
32
|
restProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
30
33
|
return /*#__PURE__*/_react["default"].createElement(_styled.BaseButton, (0, _extends2["default"])({
|
|
31
34
|
ref: ref,
|
|
32
35
|
size: size,
|
|
33
36
|
isLoading: isLoading,
|
|
34
37
|
color: color,
|
|
35
|
-
variant: variant
|
|
38
|
+
variant: variant,
|
|
39
|
+
hasShortcut: !!shortcut
|
|
36
40
|
}, restProps), /*#__PURE__*/_react["default"].createElement(_styled.BaseContentContainer, {
|
|
37
41
|
isLoading: isLoading
|
|
38
42
|
}, iconLeft && /*#__PURE__*/_react["default"].createElement(_ButtonIcon.ButtonIcon, {
|
|
39
43
|
spacing: "end",
|
|
40
44
|
size: size
|
|
41
|
-
}, iconLeft), children,
|
|
45
|
+
}, iconLeft), children, shortcut && /*#__PURE__*/_react["default"].createElement(_Shortcuts["default"], {
|
|
46
|
+
keys: shortcut,
|
|
47
|
+
variant: shortcutsVariant,
|
|
48
|
+
color: color,
|
|
49
|
+
combineKeys: true
|
|
50
|
+
}), iconRight && /*#__PURE__*/_react["default"].createElement(_ButtonIcon.ButtonIcon, {
|
|
42
51
|
spacing: "start",
|
|
43
52
|
size: size
|
|
44
53
|
}, iconRight)), isLoading && /*#__PURE__*/_react["default"].createElement(_styled.BaseLoadingContainer, {
|
|
@@ -7,14 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _system = require("@vitality-ds/system");
|
|
10
|
-
var _constants = require("../constants");
|
|
11
10
|
var _helpers = require("./helpers");
|
|
12
11
|
var text = _system.colorUseCases.text;
|
|
13
12
|
var _default = exports["default"] = (0, _system.css)({
|
|
14
13
|
fontFamily: "$button",
|
|
15
14
|
fontSize: "$button",
|
|
16
15
|
fontWeight: "$button",
|
|
17
|
-
lineHeight: "
|
|
16
|
+
lineHeight: "$button",
|
|
18
17
|
letterSpacing: "$button",
|
|
19
18
|
borderRadius: "$default",
|
|
20
19
|
border: "none",
|
|
@@ -79,6 +78,11 @@ var _default = exports["default"] = (0, _system.css)({
|
|
|
79
78
|
"true": {
|
|
80
79
|
pointerEvents: "none"
|
|
81
80
|
}
|
|
81
|
+
},
|
|
82
|
+
hasShortcut: {
|
|
83
|
+
"true": {
|
|
84
|
+
paddingInlineEnd: "$md"
|
|
85
|
+
}
|
|
82
86
|
}
|
|
83
87
|
},
|
|
84
88
|
compoundVariants: [
|
|
@@ -30,10 +30,13 @@ var _default = exports["default"] = (0, _system.css)((0, _defineProperty2["defau
|
|
|
30
30
|
}), "&[aria-disabled='true']", (0, _defineProperty2["default"])({}, "&, ".concat(_styled2.BaseDropdownMenuItemIcon, ", ").concat(_styled.BaseShortcut), {
|
|
31
31
|
color: (0, _system.getColorScaleValueByUseCase)("neutral", text.disabled),
|
|
32
32
|
pointerEvents: "none"
|
|
33
|
-
})), "&:hover:not([aria-disabled='true']), &:focus", (0, _defineProperty2["default"])((0, _defineProperty2["default"])({
|
|
34
|
-
backgroundColor: (0, _system.getColorScaleValueByUseCase)("primary", backgrounds.uiElementSolid)
|
|
35
|
-
}, "&, ".concat(_styled2.BaseDropdownMenuItemIcon, ", ").concat(_styled.BaseShortcut), {
|
|
33
|
+
})), "&:hover:not([aria-disabled='true']), &:focus", (0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({
|
|
34
|
+
backgroundColor: (0, _system.getColorScaleValueByUseCase)("primary", backgrounds.uiElementSolid),
|
|
36
35
|
color: (0, _system.getColorScaleValueByUseCase)("primary", text.onSolidBackgrounds)
|
|
36
|
+
}, "".concat(_styled2.BaseDropdownMenuItemIcon, ", ").concat(_styled.BaseShortcut), {
|
|
37
|
+
color: (0, _system.getColorScaleValueByUseCase)("primary", text.hiContrastOnSolidBackgrounds)
|
|
38
|
+
}), "".concat(_styled.BaseShortcut), {
|
|
39
|
+
backgroundColor: (0, _system.getColorScaleValueByUseCase)("primary", backgrounds.uiElementSolid_selected)
|
|
37
40
|
}), "outline", "none")), "&:active:not([aria-disabled='true'])", {
|
|
38
41
|
backgroundColor: (0, _system.getColorScaleValueByUseCase)("primary", backgrounds.uiElementSolid_active)
|
|
39
42
|
}), "&[data-state='open']", {
|
|
@@ -21,7 +21,8 @@ function CheckboxList(_ref) {
|
|
|
21
21
|
direction = _ref.direction,
|
|
22
22
|
value = _ref.value,
|
|
23
23
|
checkboxListName = _ref.name,
|
|
24
|
-
ariaLabelledBy = _ref.ariaLabelledBy
|
|
24
|
+
ariaLabelledBy = _ref.ariaLabelledBy,
|
|
25
|
+
disabled = _ref.disabled;
|
|
25
26
|
var _useCheckedItems = (0, _useCheckedItems2["default"])(value),
|
|
26
27
|
checkedItems = _useCheckedItems.checkedItems,
|
|
27
28
|
setCheckedItems = _useCheckedItems.setCheckedItems;
|
|
@@ -37,11 +38,11 @@ function CheckboxList(_ref) {
|
|
|
37
38
|
var label = _ref2.label,
|
|
38
39
|
id = _ref2.id,
|
|
39
40
|
optionValue = _ref2.value,
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
name = _ref2.name,
|
|
42
|
+
optionDisabled = _ref2.disabled;
|
|
42
43
|
return /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
|
|
43
44
|
key: optionValue,
|
|
44
|
-
disabled: disabled,
|
|
45
|
+
disabled: disabled || optionDisabled,
|
|
45
46
|
label: label,
|
|
46
47
|
id: id,
|
|
47
48
|
value: optionValue,
|
|
@@ -79,4 +79,74 @@ describe("CheckboxList", function () {
|
|
|
79
79
|
expect(checkbox.at(1).prop("checked")).toEqual(false);
|
|
80
80
|
expect(checkbox.at(1).prop("disabled")).toBeFalsy();
|
|
81
81
|
});
|
|
82
|
+
it("should disable all checkboxes when disabled prop is true", function () {
|
|
83
|
+
var wrapper = mount({
|
|
84
|
+
disabled: true
|
|
85
|
+
});
|
|
86
|
+
var checkbox = wrapper.find(_Checkbox["default"]);
|
|
87
|
+
expect(checkbox).toHaveLength(2);
|
|
88
|
+
expect(checkbox.at(0).prop("disabled")).toBe(true);
|
|
89
|
+
expect(checkbox.at(1).prop("disabled")).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
it("should disable individual checkboxes via options", function () {
|
|
92
|
+
var customOptions = [{
|
|
93
|
+
label: "foo",
|
|
94
|
+
value: "foo",
|
|
95
|
+
id: "foo",
|
|
96
|
+
name: "foo",
|
|
97
|
+
onChange: function onChange() {
|
|
98
|
+
return "";
|
|
99
|
+
},
|
|
100
|
+
checked: false,
|
|
101
|
+
disabled: true
|
|
102
|
+
}, {
|
|
103
|
+
label: "bar",
|
|
104
|
+
value: "bar",
|
|
105
|
+
id: "bar",
|
|
106
|
+
name: "bar",
|
|
107
|
+
onChange: function onChange() {
|
|
108
|
+
return "";
|
|
109
|
+
},
|
|
110
|
+
checked: false,
|
|
111
|
+
disabled: false
|
|
112
|
+
}];
|
|
113
|
+
var wrapper = mount({
|
|
114
|
+
options: customOptions
|
|
115
|
+
});
|
|
116
|
+
var checkbox = wrapper.find(_Checkbox["default"]);
|
|
117
|
+
expect(checkbox).toHaveLength(2);
|
|
118
|
+
expect(checkbox.at(0).prop("disabled")).toBe(true);
|
|
119
|
+
expect(checkbox.at(1).prop("disabled")).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
it("should disable all checkboxes when both disabled prop and individual option disabled are set", function () {
|
|
122
|
+
var customOptions = [{
|
|
123
|
+
label: "foo",
|
|
124
|
+
value: "foo",
|
|
125
|
+
id: "foo",
|
|
126
|
+
name: "foo",
|
|
127
|
+
onChange: function onChange() {
|
|
128
|
+
return "";
|
|
129
|
+
},
|
|
130
|
+
checked: false,
|
|
131
|
+
disabled: true
|
|
132
|
+
}, {
|
|
133
|
+
label: "bar",
|
|
134
|
+
value: "bar",
|
|
135
|
+
id: "bar",
|
|
136
|
+
name: "bar",
|
|
137
|
+
onChange: function onChange() {
|
|
138
|
+
return "";
|
|
139
|
+
},
|
|
140
|
+
checked: false,
|
|
141
|
+
disabled: false
|
|
142
|
+
}];
|
|
143
|
+
var wrapper = mount({
|
|
144
|
+
disabled: true,
|
|
145
|
+
options: customOptions
|
|
146
|
+
});
|
|
147
|
+
var checkbox = wrapper.find(_Checkbox["default"]);
|
|
148
|
+
expect(checkbox).toHaveLength(2);
|
|
149
|
+
expect(checkbox.at(0).prop("disabled")).toBe(true);
|
|
150
|
+
expect(checkbox.at(1).prop("disabled")).toBe(true);
|
|
151
|
+
});
|
|
82
152
|
});
|
|
@@ -15,7 +15,8 @@ var _default = exports["default"] = (0, _system.css)({
|
|
|
15
15
|
variants: {
|
|
16
16
|
disabled: {
|
|
17
17
|
"true": {
|
|
18
|
-
color: (0, _system.getColorScaleValueByUseCase)("neutral", text.disabled)
|
|
18
|
+
color: (0, _system.getColorScaleValueByUseCase)("neutral", text.disabled),
|
|
19
|
+
cursor: "not-allowed"
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -31,7 +31,8 @@ var _default = exports["default"] = (0, _system.css)({
|
|
|
31
31
|
boxShadow: "0 0 0 2px ".concat((0, _system.getColorScaleValueByUseCase)("primary", borders.focusRing))
|
|
32
32
|
},
|
|
33
33
|
"&:disabled": {
|
|
34
|
-
borderColor: (0, _system.getColorScaleValueByUseCase)("neutral", borders.uiElement_disabled)
|
|
34
|
+
borderColor: (0, _system.getColorScaleValueByUseCase)("neutral", borders.uiElement_disabled),
|
|
35
|
+
cursor: "not-allowed"
|
|
35
36
|
},
|
|
36
37
|
"&[data-state='checked']": {
|
|
37
38
|
borderColor: (0, _system.getColorScaleValueByUseCase)("primary", backgrounds.uiElementSolid),
|
|
@@ -16,7 +16,8 @@ var _default = exports["default"] = (0, _system.css)({
|
|
|
16
16
|
variants: {
|
|
17
17
|
disabled: {
|
|
18
18
|
"true": {
|
|
19
|
-
color: (0, _system.getColorScaleValueByUseCase)("neutral", text.disabled)
|
|
19
|
+
color: (0, _system.getColorScaleValueByUseCase)("neutral", text.disabled),
|
|
20
|
+
cursor: "not-allowed"
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -10,8 +10,8 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
var _RadioButton = _interopRequireDefault(require("./components/RadioButton"));
|
|
12
12
|
var _styled = require("./styled");
|
|
13
|
-
var _excluded = ["onChange", "options", "direction", "value", "name", "css", "asChild", "as", "style", "className"],
|
|
14
|
-
_excluded2 = ["id"];
|
|
13
|
+
var _excluded = ["onChange", "options", "direction", "value", "name", "css", "asChild", "as", "style", "className", "disabled"],
|
|
14
|
+
_excluded2 = ["id", "disabled"];
|
|
15
15
|
var RadioButtons = /*#__PURE__*/_react["default"].forwardRef(function (_ref, forwardedRef) {
|
|
16
16
|
var onChange = _ref.onChange,
|
|
17
17
|
options = _ref.options,
|
|
@@ -24,19 +24,23 @@ var RadioButtons = /*#__PURE__*/_react["default"].forwardRef(function (_ref, for
|
|
|
24
24
|
as = _ref.as,
|
|
25
25
|
style = _ref.style,
|
|
26
26
|
className = _ref.className,
|
|
27
|
+
disabled = _ref.disabled,
|
|
27
28
|
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
28
29
|
return /*#__PURE__*/_react["default"].createElement(_styled.BaseRadioButtonsContainer, (0, _extends2["default"])({
|
|
29
30
|
onValueChange: onChange,
|
|
30
31
|
orientation: direction,
|
|
31
32
|
value: value,
|
|
32
33
|
name: name,
|
|
33
|
-
ref: forwardedRef
|
|
34
|
+
ref: forwardedRef,
|
|
35
|
+
disabled: disabled
|
|
34
36
|
}, props), options === null || options === void 0 ? void 0 : options.map(function (_ref2) {
|
|
35
37
|
var id = _ref2.id,
|
|
38
|
+
optionDisabled = _ref2.disabled,
|
|
36
39
|
restProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded2);
|
|
37
40
|
return /*#__PURE__*/_react["default"].createElement(_RadioButton["default"], (0, _extends2["default"])({}, restProps, {
|
|
38
41
|
key: id,
|
|
39
|
-
id: id
|
|
42
|
+
id: id,
|
|
43
|
+
disabled: disabled || optionDisabled
|
|
40
44
|
}));
|
|
41
45
|
}));
|
|
42
46
|
});
|
|
@@ -110,4 +110,55 @@ describe("<RadioButtons />", function () {
|
|
|
110
110
|
expect(radioTwo.getAttribute("aria-checked")).toBe("true");
|
|
111
111
|
expect(radioThree.getAttribute("aria-checked")).toBe("false");
|
|
112
112
|
});
|
|
113
|
+
it("should disable all radio buttons when disabled prop is true", function () {
|
|
114
|
+
(0, _react.render)(/*#__PURE__*/_react2["default"].createElement(_index["default"], (0, _extends2["default"])({
|
|
115
|
+
onChange: function onChange() {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}, mockProps, {
|
|
119
|
+
disabled: true
|
|
120
|
+
})));
|
|
121
|
+
var radioOne = _react.screen.getByLabelText("Radio One Label");
|
|
122
|
+
var radioTwo = _react.screen.getByLabelText("Radio Two Label");
|
|
123
|
+
var radioThree = _react.screen.getByLabelText("Radio Three Label");
|
|
124
|
+
expect(radioOne.getAttribute("data-disabled")).toBe("");
|
|
125
|
+
expect(radioTwo.getAttribute("data-disabled")).toBe("");
|
|
126
|
+
expect(radioThree.getAttribute("data-disabled")).toBe("");
|
|
127
|
+
});
|
|
128
|
+
it("should disable individual radio buttons via options", function () {
|
|
129
|
+
(0, _react.render)(/*#__PURE__*/_react2["default"].createElement(_index["default"], (0, _extends2["default"])({
|
|
130
|
+
onChange: function onChange() {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}, mockProps)));
|
|
134
|
+
var radioOne = _react.screen.getByLabelText("Radio One Label");
|
|
135
|
+
var radioTwo = _react.screen.getByLabelText("Radio Two Label");
|
|
136
|
+
var radioThree = _react.screen.getByLabelText("Radio Three Label");
|
|
137
|
+
expect(radioOne.getAttribute("data-disabled")).toBe(null);
|
|
138
|
+
expect(radioTwo.getAttribute("data-disabled")).toBe(null);
|
|
139
|
+
expect(radioThree.getAttribute("data-disabled")).toBe("");
|
|
140
|
+
});
|
|
141
|
+
it("should disable all radio buttons when both disabled prop and individual option disabled are set", function () {
|
|
142
|
+
(0, _react.render)(/*#__PURE__*/_react2["default"].createElement(_index["default"], (0, _extends2["default"])({
|
|
143
|
+
onChange: function onChange() {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}, mockProps, {
|
|
147
|
+
disabled: true
|
|
148
|
+
})));
|
|
149
|
+
var radioOne = _react.screen.getByLabelText("Radio One Label");
|
|
150
|
+
var radioTwo = _react.screen.getByLabelText("Radio Two Label");
|
|
151
|
+
var radioThree = _react.screen.getByLabelText("Radio Three Label");
|
|
152
|
+
expect(radioOne.getAttribute("data-disabled")).toBe("");
|
|
153
|
+
expect(radioTwo.getAttribute("data-disabled")).toBe("");
|
|
154
|
+
expect(radioThree.getAttribute("data-disabled")).toBe("");
|
|
155
|
+
var mockOnChange = jest.fn();
|
|
156
|
+
(0, _react.render)(/*#__PURE__*/_react2["default"].createElement(_index["default"], (0, _extends2["default"])({
|
|
157
|
+
onChange: mockOnChange
|
|
158
|
+
}, mockProps, {
|
|
159
|
+
disabled: true
|
|
160
|
+
})));
|
|
161
|
+
_react.fireEvent.click(_react.screen.getByLabelText("Radio One Label"));
|
|
162
|
+
expect(mockOnChange).not.toHaveBeenCalled();
|
|
163
|
+
});
|
|
113
164
|
});
|
|
@@ -8,9 +8,14 @@ exports["default"] = ShortcutAdornment;
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _Shortcuts = _interopRequireDefault(require("../../../../Shortcuts"));
|
|
10
10
|
function ShortcutAdornment(_ref) {
|
|
11
|
-
var keys = _ref.keys
|
|
11
|
+
var keys = _ref.keys,
|
|
12
|
+
combineKeys = _ref.combineKeys,
|
|
13
|
+
color = _ref.color,
|
|
14
|
+
variant = _ref.variant;
|
|
12
15
|
return /*#__PURE__*/_react["default"].createElement(_Shortcuts["default"], {
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
keys: keys,
|
|
17
|
+
combineKeys: combineKeys,
|
|
18
|
+
color: color,
|
|
19
|
+
variant: variant
|
|
15
20
|
});
|
|
16
21
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WINDOWS_KEY_MAP = exports.MAC_KEY_MAP = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Key mappings for platform-specific modifier keys.
|
|
9
|
+
* Mac uses symbols, Windows/Linux uses text labels.
|
|
10
|
+
*/
|
|
11
|
+
var MAC_KEY_MAP = exports.MAC_KEY_MAP = {
|
|
12
|
+
cmd: "⌘",
|
|
13
|
+
command: "⌘",
|
|
14
|
+
ctrl: "⌃",
|
|
15
|
+
control: "⌃",
|
|
16
|
+
alt: "⌥",
|
|
17
|
+
option: "⌥",
|
|
18
|
+
opt: "⌥",
|
|
19
|
+
shift: "⇧",
|
|
20
|
+
meta: "⌘",
|
|
21
|
+
enter: "⏎",
|
|
22
|
+
"return": "⏎"
|
|
23
|
+
};
|
|
24
|
+
var WINDOWS_KEY_MAP = exports.WINDOWS_KEY_MAP = {
|
|
25
|
+
cmd: "Ctrl",
|
|
26
|
+
command: "Ctrl",
|
|
27
|
+
ctrl: "Ctrl",
|
|
28
|
+
control: "Ctrl",
|
|
29
|
+
alt: "Alt",
|
|
30
|
+
option: "Alt",
|
|
31
|
+
opt: "Alt",
|
|
32
|
+
shift: "Shift",
|
|
33
|
+
meta: "Win",
|
|
34
|
+
enter: "Enter",
|
|
35
|
+
"return": "Enter"
|
|
36
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _logic = require("../logic");
|
|
11
|
+
/**
|
|
12
|
+
* Hook to detect the user's operating system.
|
|
13
|
+
* Uses the modern User-Agent Client Hints API (navigator.userAgentData).
|
|
14
|
+
*
|
|
15
|
+
* @returns The detected operating system: "mac" | "windows" | "linux" | "unknown"
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const os = useOS();
|
|
19
|
+
* const modifierKey = os === "mac" ? "⌘" : "Ctrl";
|
|
20
|
+
*/
|
|
21
|
+
var useOS = function useOS() {
|
|
22
|
+
var _useState = (0, _react.useState)("unknown"),
|
|
23
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
24
|
+
os = _useState2[0],
|
|
25
|
+
setOS = _useState2[1];
|
|
26
|
+
(0, _react.useEffect)(function () {
|
|
27
|
+
setOS((0, _logic.getOS)());
|
|
28
|
+
}, []);
|
|
29
|
+
return os;
|
|
30
|
+
};
|
|
31
|
+
var _default = exports["default"] = useOS;
|
package/dist/Shortcuts/index.js
CHANGED
|
@@ -6,14 +6,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = Shortcuts;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _useOS = _interopRequireDefault(require("./hooks/useOS"));
|
|
10
|
+
var _logic = require("./logic");
|
|
9
11
|
var _styled = require("./styled");
|
|
10
12
|
function Shortcuts(_ref) {
|
|
11
|
-
var variant = _ref.variant,
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
var _ref$variant = _ref.variant,
|
|
14
|
+
variant = _ref$variant === void 0 ? "uiElement" : _ref$variant,
|
|
15
|
+
keys = _ref.keys,
|
|
16
|
+
combineKeys = _ref.combineKeys,
|
|
17
|
+
_ref$color = _ref.color,
|
|
18
|
+
color = _ref$color === void 0 ? "neutral" : _ref$color;
|
|
19
|
+
var os = (0, _useOS["default"])();
|
|
20
|
+
var transformedKeys = (0, _logic.transformKeys)(keys !== null && keys !== void 0 ? keys : [], os);
|
|
21
|
+
if (combineKeys) {
|
|
22
|
+
var keyOccurrences = {};
|
|
23
|
+
return /*#__PURE__*/_react["default"].createElement(_styled.BaseShortcut, {
|
|
24
|
+
separateCombinedKeys: true,
|
|
25
|
+
as: "span",
|
|
26
|
+
variant: variant,
|
|
27
|
+
color: color
|
|
28
|
+
}, transformedKeys === null || transformedKeys === void 0 ? void 0 : transformedKeys.map(function (key) {
|
|
29
|
+
var _keyOccurrences$key;
|
|
30
|
+
keyOccurrences[key] = ((_keyOccurrences$key = keyOccurrences[key]) !== null && _keyOccurrences$key !== void 0 ? _keyOccurrences$key : 0) + 1;
|
|
31
|
+
var reactKey = "".concat(key, "-").concat(keyOccurrences[key]);
|
|
32
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
|
|
33
|
+
key: reactKey
|
|
34
|
+
}, /*#__PURE__*/_react["default"].createElement("kbd", null, key));
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return /*#__PURE__*/_react["default"].createElement(_styled.BaseShortcutGroup, null, transformedKeys === null || transformedKeys === void 0 ? void 0 : transformedKeys.map(function (key) {
|
|
14
38
|
return /*#__PURE__*/_react["default"].createElement(_styled.BaseShortcut, {
|
|
15
39
|
key: key,
|
|
16
|
-
variant: variant
|
|
40
|
+
variant: variant,
|
|
41
|
+
color: color
|
|
17
42
|
}, key);
|
|
18
43
|
}));
|
|
19
44
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformKeys = exports.transformKey = exports.getOS = void 0;
|
|
7
|
+
var _constants = require("./constants");
|
|
8
|
+
var getOS = exports.getOS = function getOS() {
|
|
9
|
+
var _navigator$userAgentD, _navigator$userAgentD2, _navigator$userAgentD3;
|
|
10
|
+
if (typeof navigator === "undefined") return null;
|
|
11
|
+
var platform = (_navigator$userAgentD = (_navigator$userAgentD2 = navigator.userAgentData) === null || _navigator$userAgentD2 === void 0 ? void 0 : (_navigator$userAgentD3 = _navigator$userAgentD2.platform) === null || _navigator$userAgentD3 === void 0 ? void 0 : _navigator$userAgentD3.toLowerCase()) !== null && _navigator$userAgentD !== void 0 ? _navigator$userAgentD : null;
|
|
12
|
+
if (platform !== null && platform !== void 0 && platform.includes("mac")) return "mac";
|
|
13
|
+
if (platform !== null && platform !== void 0 && platform.includes("win")) return "windows";
|
|
14
|
+
if (platform !== null && platform !== void 0 && platform.includes("linux")) return "linux";
|
|
15
|
+
return platform;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Transforms a key label to its platform-specific representation.
|
|
20
|
+
*
|
|
21
|
+
* @param key - The key to transform (e.g., "cmd", "ctrl", "shift")
|
|
22
|
+
* @param os - The target operating system
|
|
23
|
+
* @returns The platform-appropriate key label
|
|
24
|
+
*/
|
|
25
|
+
var transformKey = exports.transformKey = function transformKey(key, os) {
|
|
26
|
+
var _keyMap$normalizedKey;
|
|
27
|
+
var normalizedKey = key.toLowerCase().trim();
|
|
28
|
+
var keyMap = os === "mac" ? _constants.MAC_KEY_MAP : _constants.WINDOWS_KEY_MAP;
|
|
29
|
+
return (_keyMap$normalizedKey = keyMap[normalizedKey]) !== null && _keyMap$normalizedKey !== void 0 ? _keyMap$normalizedKey : key;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Transforms an array of keys to their platform-specific representations.
|
|
34
|
+
*
|
|
35
|
+
* @param keys - Array of key labels
|
|
36
|
+
* @param os - The target operating system
|
|
37
|
+
* @returns Array of platform-appropriate key labels
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* transformKeys(["cmd", "shift", "P"], "mac") // ["⌘", "⇧", "P"]
|
|
41
|
+
* transformKeys(["cmd", "shift", "P"], "windows") // ["Ctrl", "Shift", "P"]
|
|
42
|
+
*/
|
|
43
|
+
var transformKeys = exports.transformKeys = function transformKeys(keys, os) {
|
|
44
|
+
return keys.map(function (key) {
|
|
45
|
+
return transformKey(key, os);
|
|
46
|
+
});
|
|
47
|
+
};
|