krl-alfred 2.25.2 → 2.25.3
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/components/Dropdown/Dropdown.d.ts +2 -2
- package/dist/components/Dropdown/Dropdown.js +89 -19
- package/dist/components/Dropdown/Dropdown.styled.d.ts +2 -1
- package/dist/components/Dropdown/Dropdown.styled.js +4 -39
- package/dist/components/Dropdown/Dropdown.test.d.ts +1 -0
- package/dist/components/Dropdown/Dropdown.test.js +254 -0
- package/dist/components/Dropdown/props.d.ts +17 -9
- package/dist/components/Dropdown/props.js +3 -0
- package/dist/components/Dropdown/stories/Dropdown.stories.d.ts +44 -2
- package/dist/components/Dropdown/stories/Dropdown.stories.js +6 -3
- package/dist/components/Input/Input.d.ts +1 -1
- package/dist/components/Input/Input.js +45 -17
- package/dist/components/Input/Input.styled.js +1 -1
- package/dist/components/Input/Input.test.js +290 -7
- package/dist/components/Input/props.d.ts +5 -0
- package/dist/components/Input/props.js +5 -0
- package/dist/components/Input/stories/Input.stories.d.ts +74 -0
- package/dist/components/Input/stories/Input.stories.js +69 -1
- package/dist/components/PaymentCart/PaymentCart.d.ts +1 -1
- package/dist/components/PaymentCart/PaymentCart.js +4 -4
- package/dist/components/PaymentCart/PaymentCart.styled.js +1 -1
- package/dist/components/PaymentCart/PaymentCart.test.d.ts +1 -0
- package/dist/components/PaymentCart/PaymentCart.test.js +137 -0
- package/dist/components/PaymentCart/props.d.ts +3 -1
- package/dist/components/PaymentCart/props.js +2 -0
- package/dist/components/PaymentCart/stories/PaymentCart.stories.d.ts +63 -0
- package/dist/components/PaymentCart/stories/PaymentCart.stories.js +10 -2
- package/dist/components/ProductCardHorizontal/ProductCardHorizontal.js +1 -1
- package/dist/components/ProductCardHorizontal/ProductCardHorizontal.test.d.ts +1 -0
- package/dist/components/ProductCardHorizontal/ProductCardHorizontal.test.js +32 -0
- package/dist/components/QuantitySelector/QuantitySelector.d.ts +1 -1
- package/dist/components/QuantitySelector/QuantitySelector.js +5 -3
- package/dist/components/QuantitySelector/QuantitySelector.test.js +141 -35
- package/dist/components/QuantitySelector/props.d.ts +6 -0
- package/dist/components/QuantitySelector/props.js +3 -0
- package/dist/components/QuantitySelector/stories/QuantitySelector.stories.d.ts +43 -1
- package/dist/components/QuantitySelector/stories/QuantitySelector.stories.js +6 -0
- package/dist/components/SearchBox/SearchBox.js +76 -52
- package/dist/components/SearchBox/SearchBox.styled.js +1 -1
- package/dist/components/SearchBox/SearchBox.test.d.ts +1 -0
- package/dist/components/SearchBox/SearchBox.test.js +371 -0
- package/dist/components/SearchBox/props.d.ts +6 -0
- package/dist/components/SearchBox/props.js +3 -0
- package/dist/components/SearchBox/stories/SearchBox.stories.d.ts +23 -0
- package/dist/components/SearchBox/stories/SearchBox.stories.js +4 -0
- package/dist/components/ShoppingCartProduct/ShoppingCartProduct.d.ts +1 -1
- package/dist/components/ShoppingCartProduct/ShoppingCartProduct.js +2 -2
- package/dist/components/ShoppingCartProduct/ShoppingCartProduct.test.js +67 -0
- package/dist/components/ShoppingCartProduct/props.d.ts +6 -0
- package/dist/components/ShoppingCartProduct/props.js +3 -0
- package/dist/components/ShoppingCartProduct/stories/ShoppingCartProduct.stories.d.ts +78 -0
- package/dist/components/ShoppingCartProduct/stories/ShoppingCartProduct.stories.js +6 -0
- package/dist/components/Tooltip/Tooltip.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.js +34 -3
- package/dist/components/Tooltip/Tooltip.styled.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.styled.js +3 -3
- package/dist/components/Tooltip/Tooltip.test.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.test.js +152 -0
- package/dist/components/Tooltip/props.d.ts +1 -0
- package/dist/components/Tooltip/props.js +1 -0
- package/dist/components/Tooltip/stories/Tooltip.stories.d.ts +22 -0
- package/dist/components/Tooltip/stories/Tooltip.stories.js +2 -0
- package/dist/i18n/locales/english.json +12 -0
- package/dist/i18n/locales/turkish.json +12 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { DropdownProps } from "./props";
|
|
3
|
-
declare const Dropdown: ({ show, Toggle, list, size, isShowTopChevron, childrenVariant, right, width, top, }: DropdownProps) =>
|
|
3
|
+
declare const Dropdown: ({ show, Toggle, list, size, isShowTopChevron, childrenVariant, right, width, top, toggleAriaLabel, menuAriaLabel, onToggleKeyDown, }: DropdownProps) => React.JSX.Element;
|
|
4
4
|
export default Dropdown;
|
|
@@ -18,33 +18,103 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
18
18
|
var react_1 = require("react");
|
|
19
19
|
var props_1 = require("./props");
|
|
20
20
|
var Dropdown_styled_1 = require("./Dropdown.styled");
|
|
21
|
-
var Button_1 = __importDefault(require("../Button"));
|
|
22
21
|
var useOnClickOutside_1 = __importDefault(require("../../hooks/useOnClickOutside"));
|
|
23
22
|
var Icon_1 = __importDefault(require("../Icon"));
|
|
24
23
|
var Dropdown = function (_a) {
|
|
25
|
-
var _b = _a.show, show = _b === void 0 ? props_1.DropdownDefault.show : _b, _c = _a.Toggle, Toggle = _c === void 0 ? props_1.DropdownDefault.Toggle : _c, _d = _a.list, list = _d === void 0 ? props_1.DropdownDefault.list : _d, _e = _a.size, size = _e === void 0 ? props_1.DropdownDefault.size : _e, _f = _a.isShowTopChevron, isShowTopChevron = _f === void 0 ? props_1.DropdownDefault.isShowTopChevron : _f, _g = _a.childrenVariant, childrenVariant = _g === void 0 ? props_1.DropdownDefault.childrenVariant : _g, _h = _a.right, right = _h === void 0 ? props_1.DropdownDefault.right : _h, _j = _a.width, width = _j === void 0 ? props_1.DropdownDefault.width : _j, _k = _a.top, top = _k === void 0 ? props_1.DropdownDefault.top : _k;
|
|
26
|
-
var
|
|
24
|
+
var _b = _a.show, show = _b === void 0 ? props_1.DropdownDefault.show : _b, _c = _a.Toggle, Toggle = _c === void 0 ? props_1.DropdownDefault.Toggle : _c, _d = _a.list, list = _d === void 0 ? props_1.DropdownDefault.list : _d, _e = _a.size, size = _e === void 0 ? props_1.DropdownDefault.size : _e, _f = _a.isShowTopChevron, isShowTopChevron = _f === void 0 ? props_1.DropdownDefault.isShowTopChevron : _f, _g = _a.childrenVariant, childrenVariant = _g === void 0 ? props_1.DropdownDefault.childrenVariant : _g, _h = _a.right, right = _h === void 0 ? props_1.DropdownDefault.right : _h, _j = _a.width, width = _j === void 0 ? props_1.DropdownDefault.width : _j, _k = _a.top, top = _k === void 0 ? props_1.DropdownDefault.top : _k, _l = _a.toggleAriaLabel, toggleAriaLabel = _l === void 0 ? props_1.DropdownDefault.toggleAriaLabel : _l, _m = _a.menuAriaLabel, menuAriaLabel = _m === void 0 ? props_1.DropdownDefault.menuAriaLabel : _m, _o = _a.onToggleKeyDown, onToggleKeyDown = _o === void 0 ? props_1.DropdownDefault.onToggleKeyDown : _o;
|
|
25
|
+
var _p = (0, react_1.useState)(show), showDropdown = _p[0], setShowDropdown = _p[1];
|
|
26
|
+
var _q = (0, react_1.useState)(null), focusTarget = _q[0], setFocusTarget = _q[1];
|
|
27
|
+
var generatedId = (0, react_1.useId)();
|
|
28
|
+
var menuId = "alfred-dropdown-".concat(generatedId);
|
|
27
29
|
var dropdownRef = (0, react_1.useRef)();
|
|
28
|
-
(0,
|
|
30
|
+
var toggleRef = (0, react_1.useRef)();
|
|
31
|
+
var menuRef = (0, react_1.useRef)();
|
|
32
|
+
var closeMenu = function (restoreFocus) {
|
|
33
|
+
var _a;
|
|
34
|
+
if (restoreFocus === void 0) { restoreFocus = false; }
|
|
35
|
+
setShowDropdown(false);
|
|
36
|
+
setFocusTarget(null);
|
|
37
|
+
if (restoreFocus)
|
|
38
|
+
(_a = toggleRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
39
|
+
};
|
|
40
|
+
(0, useOnClickOutside_1.default)(dropdownRef, function () { return closeMenu(); }, true);
|
|
29
41
|
(0, react_1.useEffect)(function () {
|
|
30
42
|
setShowDropdown(show);
|
|
31
43
|
}, [show]);
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
(0, react_1.useEffect)(function () {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (!showDropdown || !focusTarget)
|
|
47
|
+
return;
|
|
48
|
+
var items = (_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="menuitem"]');
|
|
49
|
+
var index = focusTarget === 'last' ? ((items === null || items === void 0 ? void 0 : items.length) || 1) - 1 : 0;
|
|
50
|
+
(_b = items === null || items === void 0 ? void 0 : items[index]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
51
|
+
setFocusTarget(null);
|
|
52
|
+
}, [showDropdown, focusTarget]);
|
|
53
|
+
var openMenu = function (target) {
|
|
54
|
+
if (target === void 0) { target = 'first'; }
|
|
55
|
+
setFocusTarget(target);
|
|
56
|
+
setShowDropdown(true);
|
|
57
|
+
};
|
|
58
|
+
var handleToggleKeyDown = function (event) {
|
|
59
|
+
onToggleKeyDown === null || onToggleKeyDown === void 0 ? void 0 : onToggleKeyDown(event);
|
|
60
|
+
if (event.defaultPrevented)
|
|
61
|
+
return;
|
|
62
|
+
if (event.key === 'Escape') {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
closeMenu(true);
|
|
65
|
+
}
|
|
66
|
+
else if (event.key === 'ArrowUp') {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
openMenu('last');
|
|
69
|
+
}
|
|
70
|
+
else if (event.key === 'ArrowDown' || event.key === 'Enter' || event.key === ' ') {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
openMenu('first');
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var handleMenuKeyDown = function (event) {
|
|
76
|
+
var _a, _b, _c;
|
|
77
|
+
var items = Array.from(((_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="menuitem"]')) || []);
|
|
78
|
+
var currentIndex = items.indexOf(document.activeElement);
|
|
79
|
+
if (event.key === 'Escape') {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
closeMenu(true);
|
|
82
|
+
}
|
|
83
|
+
else if (event.key === 'Tab') {
|
|
84
|
+
closeMenu();
|
|
85
|
+
}
|
|
86
|
+
else if (event.key === 'Home' || event.key === 'End') {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
(_b = items[event.key === 'Home' ? 0 : items.length - 1]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
89
|
+
}
|
|
90
|
+
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
var offset = event.key === 'ArrowDown' ? 1 : -1;
|
|
93
|
+
var nextIndex = (currentIndex + offset + items.length) % items.length;
|
|
94
|
+
(_c = items[nextIndex]) === null || _c === void 0 ? void 0 : _c.focus();
|
|
95
|
+
}
|
|
96
|
+
else if ((event.key === 'Enter' || event.key === ' ') && currentIndex >= 0) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
items[currentIndex].click();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var handleItemClick = function (item, event) {
|
|
102
|
+
var _a;
|
|
103
|
+
(_a = item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, event);
|
|
104
|
+
closeMenu(true);
|
|
41
105
|
};
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
|
|
106
|
+
var renderItem = function (item, key) {
|
|
107
|
+
var content = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [item.icon ? (0, jsx_runtime_1.jsx)("span", __assign({ "aria-hidden": "true" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: item.icon }) })) : null, item.title] }));
|
|
108
|
+
var commonProps = {
|
|
109
|
+
role: 'menuitem',
|
|
110
|
+
onClick: function (event) { return handleItemClick(item, event); },
|
|
111
|
+
};
|
|
112
|
+
if (item.component) {
|
|
113
|
+
var ItemComponent = item.component;
|
|
114
|
+
return (0, jsx_runtime_1.jsx)("li", __assign({ role: "none" }, { children: (0, jsx_runtime_1.jsx)(ItemComponent, __assign({}, commonProps, { children: content })) }), key);
|
|
115
|
+
}
|
|
116
|
+
return ((0, jsx_runtime_1.jsx)("li", __assign({ role: "none" }, { children: item.slug ? ((0, jsx_runtime_1.jsx)("a", __assign({}, commonProps, { href: item.slug }, { children: content }))) : ((0, jsx_runtime_1.jsx)("button", __assign({}, commonProps, { type: "button" }, { children: content }))) }), key));
|
|
45
117
|
};
|
|
46
|
-
return ((0, jsx_runtime_1.jsxs)(Dropdown_styled_1.DropdownStyled, __assign({ ref: dropdownRef, "$show": showDropdown }, { children: [(0, jsx_runtime_1.jsx)(
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsxs)(ButtonLinkComponent, __assign({ item: item }, { children: [item.icon ? (0, jsx_runtime_1.jsx)(Icon_1.default, { name: item.icon }) : "", item.title] })) }, key));
|
|
48
|
-
}) }) }))] })));
|
|
118
|
+
return ((0, jsx_runtime_1.jsxs)(Dropdown_styled_1.DropdownStyled, __assign({ ref: dropdownRef, "$show": showDropdown }, { children: [(0, jsx_runtime_1.jsx)(Dropdown_styled_1.DropdownToggle, __assign({ ref: toggleRef, type: "button", "aria-label": toggleAriaLabel, "aria-haspopup": "menu", "aria-expanded": showDropdown, "aria-controls": menuId, onClick: function () { return setShowDropdown(function (current) { return !current; }); }, onKeyDown: handleToggleKeyDown }, { children: Toggle ? (0, jsx_runtime_1.jsx)(Toggle, { show: showDropdown }) : 'Toggle' })), showDropdown && ((0, jsx_runtime_1.jsx)(Dropdown_styled_1.DropdownMenu, __assign({ ref: menuRef, id: menuId, role: "menu", "aria-label": menuAriaLabel || toggleAriaLabel, onKeyDown: handleMenuKeyDown, "$show": showDropdown, "$size": size, "$isShowTopChevron": isShowTopChevron, "$childrenVariant": childrenVariant, "$right": right, "$width": width, "$top": top }, { children: list === null || list === void 0 ? void 0 : list.map(renderItem) })))] })));
|
|
49
119
|
};
|
|
50
120
|
exports.default = Dropdown;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { DropdownStyledProps } from "./props";
|
|
3
3
|
export declare const DropdownStyled: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof DropdownStyledProps> & DropdownStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof DropdownStyledProps> & DropdownStyledProps, never>>> & string;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const DropdownToggle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>>> & string;
|
|
5
|
+
export declare const DropdownMenu: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, keyof DropdownStyledProps> & DropdownStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, keyof DropdownStyledProps> & DropdownStyledProps, never>>> & string;
|
|
@@ -7,44 +7,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.DropdownMenu = exports.DropdownStyled = void 0;
|
|
10
|
+
exports.DropdownMenu = exports.DropdownToggle = exports.DropdownStyled = void 0;
|
|
11
11
|
var styled_components_1 = __importDefault(require("styled-components"));
|
|
12
12
|
exports.DropdownStyled = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: relative;\n"], ["\n position: relative;\n"])));
|
|
13
|
-
exports.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return "0.5rem";
|
|
17
|
-
case 'medium':
|
|
18
|
-
return "1rem";
|
|
19
|
-
default:
|
|
20
|
-
return "1rem";
|
|
21
|
-
}
|
|
22
|
-
}, function (props) {
|
|
23
|
-
switch (props.$size) {
|
|
24
|
-
case 'small':
|
|
25
|
-
return props.$width || "169px";
|
|
26
|
-
case 'medium':
|
|
27
|
-
return props.$width || "184px";
|
|
28
|
-
default:
|
|
29
|
-
return props.$width || "184px";
|
|
30
|
-
}
|
|
31
|
-
}, function (props) { return props.$isShowTopChevron ? "block" : "none"; }, function (props) {
|
|
32
|
-
switch (props.$size) {
|
|
33
|
-
case 'small':
|
|
34
|
-
return "8px 12px";
|
|
35
|
-
case 'medium':
|
|
36
|
-
return "12px";
|
|
37
|
-
default:
|
|
38
|
-
return "12px";
|
|
39
|
-
}
|
|
40
|
-
}, function (props) {
|
|
41
|
-
switch (props.$size) {
|
|
42
|
-
case 'small':
|
|
43
|
-
return "var(--caption-medium-12-15)";
|
|
44
|
-
case 'medium':
|
|
45
|
-
return "var(--body-bold-13-16)";
|
|
46
|
-
default:
|
|
47
|
-
return "var(--body-bold-13-16)";
|
|
48
|
-
}
|
|
49
|
-
}, function (props) { return props.$childrenVariant === "primary" ? "\n &:hover{\n color: var(--primary) !important;\n background-color: var(--primary-opacity-10);\n font-weight: bold;\n }\n " : "\n &:hover{\n color: var(--primary) !important;\n background-color: var(--primary-opacity-5);\n font-weight: bold;\n }\n "; });
|
|
50
|
-
var templateObject_1, templateObject_2;
|
|
13
|
+
exports.DropdownToggle = styled_components_1.default.button(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n appearance: none;\n border: 0;\n padding: 0;\n margin: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n cursor: pointer;\n\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n border-radius: 0.25rem;\n }\n"], ["\n appearance: none;\n border: 0;\n padding: 0;\n margin: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n cursor: pointer;\n\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n border-radius: 0.25rem;\n }\n"])));
|
|
14
|
+
exports.DropdownMenu = styled_components_1.default.ul(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n position: absolute;\n border-radius: 0.5rem;\n background-color: var(--bg);\n box-sizing: border-box;\n z-index: 9;\n box-shadow: 0 6px 30px 0 var(--box-shadow-color);\n right: ", ";\n top: ", ";\n padding: ", ";\n margin: 0;\n min-width: ", ";\n\n &:before {\n content: \"\";\n position: absolute;\n transform: rotate(45deg);\n right: 18px;\n transition: all 0.15s ease;\n background-color: var(--bg);\n width: 12px;\n height: 12px;\n border-radius: 3px;\n bottom: calc(100% - 6px);\n display: ", ";\n }\n\n li {\n display: block;\n margin: 0;\n padding: 0;\n\n > a,\n > button {\n appearance: none;\n cursor: pointer;\n text-decoration: none;\n text-align: left;\n border: 0;\n width: 100%;\n background: transparent;\n padding: ", ";\n font: ", ";\n display: block;\n color: var(--text);\n border-radius: 0.5rem;\n position: relative;\n\n &:hover,\n &:focus-visible {\n color: var(--primary) !important;\n background-color: ", ";\n font-weight: bold;\n outline: none;\n }\n\n > span {\n display: inline-block;\n vertical-align: middle;\n margin-right: 0.5rem;\n }\n }\n\n + li {\n margin-top: 0.25rem;\n }\n }\n"], ["\n position: absolute;\n border-radius: 0.5rem;\n background-color: var(--bg);\n box-sizing: border-box;\n z-index: 9;\n box-shadow: 0 6px 30px 0 var(--box-shadow-color);\n right: ", ";\n top: ", ";\n padding: ", ";\n margin: 0;\n min-width: ", ";\n\n &:before {\n content: \"\";\n position: absolute;\n transform: rotate(45deg);\n right: 18px;\n transition: all 0.15s ease;\n background-color: var(--bg);\n width: 12px;\n height: 12px;\n border-radius: 3px;\n bottom: calc(100% - 6px);\n display: ", ";\n }\n\n li {\n display: block;\n margin: 0;\n padding: 0;\n\n > a,\n > button {\n appearance: none;\n cursor: pointer;\n text-decoration: none;\n text-align: left;\n border: 0;\n width: 100%;\n background: transparent;\n padding: ", ";\n font: ", ";\n display: block;\n color: var(--text);\n border-radius: 0.5rem;\n position: relative;\n\n &:hover,\n &:focus-visible {\n color: var(--primary) !important;\n background-color: ", ";\n font-weight: bold;\n outline: none;\n }\n\n > span {\n display: inline-block;\n vertical-align: middle;\n margin-right: 0.5rem;\n }\n }\n\n + li {\n margin-top: 0.25rem;\n }\n }\n"])), function (props) { return props.$right || "0"; }, function (props) { return props.$top || "calc(100% + 16px)"; }, function (props) { return props.$size === 'small' ? "0.5rem" : "1rem"; }, function (props) { return props.$width || (props.$size === 'small' ? "169px" : "184px"); }, function (props) { return props.$isShowTopChevron ? "block" : "none"; }, function (props) { return props.$size === 'small' ? "8px 12px" : "12px"; }, function (props) { return props.$size === 'small' ? "var(--caption-medium-12-15)" : "var(--body-bold-13-16)"; }, function (props) { return props.$childrenVariant === "primary" ? "var(--primary-opacity-10)" : "var(--primary-opacity-5)"; });
|
|
15
|
+
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
54
|
+
var react_1 = require("@testing-library/react");
|
|
55
|
+
var user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
56
|
+
var Dropdown_1 = __importDefault(require("./Dropdown"));
|
|
57
|
+
var toggleLabel = '1234 ile biten kartın işlemleri';
|
|
58
|
+
var actions = [
|
|
59
|
+
{ title: 'Birincil kart yap', onClick: jest.fn() },
|
|
60
|
+
{ title: 'Yedek kart yap', onClick: jest.fn() },
|
|
61
|
+
{ title: 'Sil', onClick: jest.fn() },
|
|
62
|
+
];
|
|
63
|
+
var renderDropdown = function (props) {
|
|
64
|
+
if (props === void 0) { props = {}; }
|
|
65
|
+
return (0, react_1.render)((0, jsx_runtime_1.jsx)(Dropdown_1.default, __assign({ toggleAriaLabel: toggleLabel, list: actions }, props)));
|
|
66
|
+
};
|
|
67
|
+
describe('Dropdown accessibility', function () {
|
|
68
|
+
beforeEach(function () { return actions.forEach(function (item) { return item.onClick.mockClear(); }); });
|
|
69
|
+
it('connects the named button to its menu', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
+
var user, trigger;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
user = user_event_1.default.setup();
|
|
75
|
+
renderDropdown();
|
|
76
|
+
trigger = react_1.screen.getByRole('button', { name: toggleLabel });
|
|
77
|
+
expect(trigger).toHaveAttribute('type', 'button');
|
|
78
|
+
expect(trigger).toHaveAttribute('aria-haspopup', 'menu');
|
|
79
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
80
|
+
return [4 /*yield*/, user.click(trigger)];
|
|
81
|
+
case 1:
|
|
82
|
+
_a.sent();
|
|
83
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
84
|
+
expect(react_1.screen.getByRole('menu')).toHaveAttribute('id', trigger.getAttribute('aria-controls'));
|
|
85
|
+
expect(react_1.screen.getAllByRole('menuitem')).toHaveLength(3);
|
|
86
|
+
return [2 /*return*/];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}); });
|
|
90
|
+
it.each(['Enter', ' '])('opens with %s and focuses the first item', function (key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
91
|
+
var user, trigger;
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
user = user_event_1.default.setup();
|
|
96
|
+
renderDropdown();
|
|
97
|
+
trigger = react_1.screen.getByRole('button', { name: toggleLabel });
|
|
98
|
+
trigger.focus();
|
|
99
|
+
return [4 /*yield*/, user.keyboard(key === ' ' ? '[Space]' : "[".concat(key, "]"))];
|
|
100
|
+
case 1:
|
|
101
|
+
_a.sent();
|
|
102
|
+
expect(react_1.screen.getAllByRole('menuitem')[0]).toHaveFocus();
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}); });
|
|
107
|
+
it('opens at the requested edge with arrow keys', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
|
+
var user, trigger;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
user = user_event_1.default.setup();
|
|
113
|
+
renderDropdown();
|
|
114
|
+
trigger = react_1.screen.getByRole('button', { name: toggleLabel });
|
|
115
|
+
trigger.focus();
|
|
116
|
+
return [4 /*yield*/, user.keyboard('[ArrowUp]')];
|
|
117
|
+
case 1:
|
|
118
|
+
_a.sent();
|
|
119
|
+
expect(react_1.screen.getAllByRole('menuitem')[2]).toHaveFocus();
|
|
120
|
+
return [4 /*yield*/, user.keyboard('[Escape]')];
|
|
121
|
+
case 2:
|
|
122
|
+
_a.sent();
|
|
123
|
+
return [4 /*yield*/, user.keyboard('[ArrowDown]')];
|
|
124
|
+
case 3:
|
|
125
|
+
_a.sent();
|
|
126
|
+
expect(react_1.screen.getAllByRole('menuitem')[0]).toHaveFocus();
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}); });
|
|
131
|
+
it('supports arrow, Home and End navigation', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
+
var user, items;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
user = user_event_1.default.setup();
|
|
137
|
+
renderDropdown({ show: true });
|
|
138
|
+
items = react_1.screen.getAllByRole('menuitem');
|
|
139
|
+
items[0].focus();
|
|
140
|
+
return [4 /*yield*/, user.keyboard('[ArrowDown]')];
|
|
141
|
+
case 1:
|
|
142
|
+
_a.sent();
|
|
143
|
+
expect(items[1]).toHaveFocus();
|
|
144
|
+
return [4 /*yield*/, user.keyboard('[ArrowUp]')];
|
|
145
|
+
case 2:
|
|
146
|
+
_a.sent();
|
|
147
|
+
expect(items[0]).toHaveFocus();
|
|
148
|
+
return [4 /*yield*/, user.keyboard('[End]')];
|
|
149
|
+
case 3:
|
|
150
|
+
_a.sent();
|
|
151
|
+
expect(items[2]).toHaveFocus();
|
|
152
|
+
return [4 /*yield*/, user.keyboard('[Home]')];
|
|
153
|
+
case 4:
|
|
154
|
+
_a.sent();
|
|
155
|
+
expect(items[0]).toHaveFocus();
|
|
156
|
+
return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}); });
|
|
160
|
+
it('closes with Escape and restores trigger focus', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
161
|
+
var user;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
user = user_event_1.default.setup();
|
|
166
|
+
renderDropdown({ show: true });
|
|
167
|
+
react_1.screen.getAllByRole('menuitem')[0].focus();
|
|
168
|
+
return [4 /*yield*/, user.keyboard('[Escape]')];
|
|
169
|
+
case 1:
|
|
170
|
+
_a.sent();
|
|
171
|
+
expect(react_1.screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
172
|
+
expect(react_1.screen.getByRole('button', { name: toggleLabel })).toHaveFocus();
|
|
173
|
+
return [2 /*return*/];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}); });
|
|
177
|
+
it('closes on Tab without trapping focus', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
178
|
+
var user;
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
switch (_a.label) {
|
|
181
|
+
case 0:
|
|
182
|
+
user = user_event_1.default.setup();
|
|
183
|
+
(0, react_1.render)((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Dropdown_1.default, { toggleAriaLabel: toggleLabel, list: actions, show: true }), (0, jsx_runtime_1.jsx)("button", { children: "Next" })] }));
|
|
184
|
+
react_1.screen.getAllByRole('menuitem')[2].focus();
|
|
185
|
+
return [4 /*yield*/, user.tab()];
|
|
186
|
+
case 1:
|
|
187
|
+
_a.sent();
|
|
188
|
+
expect(react_1.screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
189
|
+
expect(react_1.screen.getByRole('button', { name: 'Next' })).toHaveFocus();
|
|
190
|
+
return [2 /*return*/];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}); });
|
|
194
|
+
it.each(['Enter', ' '])('runs a selected action once with %s, closes, and restores focus', function (key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
195
|
+
var user, item;
|
|
196
|
+
return __generator(this, function (_a) {
|
|
197
|
+
switch (_a.label) {
|
|
198
|
+
case 0:
|
|
199
|
+
user = user_event_1.default.setup();
|
|
200
|
+
renderDropdown({ show: true });
|
|
201
|
+
item = react_1.screen.getByRole('menuitem', { name: 'Sil' });
|
|
202
|
+
item.focus();
|
|
203
|
+
return [4 /*yield*/, user.keyboard(key === ' ' ? '[Space]' : "[".concat(key, "]"))];
|
|
204
|
+
case 1:
|
|
205
|
+
_a.sent();
|
|
206
|
+
expect(actions[2].onClick).toHaveBeenCalledTimes(1);
|
|
207
|
+
expect(react_1.screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
208
|
+
expect(react_1.screen.getByRole('button', { name: toggleLabel })).toHaveFocus();
|
|
209
|
+
return [2 /*return*/];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}); });
|
|
213
|
+
it('closes on outside click', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
214
|
+
var user;
|
|
215
|
+
return __generator(this, function (_a) {
|
|
216
|
+
switch (_a.label) {
|
|
217
|
+
case 0:
|
|
218
|
+
user = user_event_1.default.setup();
|
|
219
|
+
(0, react_1.render)((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(Dropdown_1.default, { toggleAriaLabel: toggleLabel, list: actions, show: true }), (0, jsx_runtime_1.jsx)("button", { children: "Outside" })] }));
|
|
220
|
+
return [4 /*yield*/, user.click(react_1.screen.getByRole('button', { name: 'Outside' }))];
|
|
221
|
+
case 1:
|
|
222
|
+
_a.sent();
|
|
223
|
+
expect(react_1.screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
224
|
+
return [2 /*return*/];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}); });
|
|
228
|
+
it('uses unique menu IDs for multiple dropdowns', function () {
|
|
229
|
+
(0, react_1.render)((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Dropdown_1.default, { toggleAriaLabel: "First", list: actions }), (0, jsx_runtime_1.jsx)(Dropdown_1.default, { toggleAriaLabel: "Second", list: actions })] }));
|
|
230
|
+
expect(react_1.screen.getByRole('button', { name: 'First' }).getAttribute('aria-controls'))
|
|
231
|
+
.not.toBe(react_1.screen.getByRole('button', { name: 'Second' }).getAttribute('aria-controls'));
|
|
232
|
+
});
|
|
233
|
+
it('allows a consumer to cancel internal keyboard behavior', function () {
|
|
234
|
+
renderDropdown({ onToggleKeyDown: function (event) { return event.preventDefault(); } });
|
|
235
|
+
react_1.fireEvent.keyDown(react_1.screen.getByRole('button', { name: toggleLabel }), { key: 'ArrowDown' });
|
|
236
|
+
expect(react_1.screen.queryByRole('menu')).not.toBeInTheDocument();
|
|
237
|
+
});
|
|
238
|
+
it('renders an item without a slug as a button', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
239
|
+
var user;
|
|
240
|
+
return __generator(this, function (_a) {
|
|
241
|
+
switch (_a.label) {
|
|
242
|
+
case 0:
|
|
243
|
+
user = user_event_1.default.setup();
|
|
244
|
+
renderDropdown();
|
|
245
|
+
return [4 /*yield*/, user.click(react_1.screen.getByRole('button', { name: toggleLabel }))];
|
|
246
|
+
case 1:
|
|
247
|
+
_a.sent();
|
|
248
|
+
expect(react_1.screen.getByRole('menuitem', { name: 'Sil' }).tagName).toBe('BUTTON');
|
|
249
|
+
expect(react_1.screen.queryByRole('link', { name: 'Sil' })).not.toBeInTheDocument();
|
|
250
|
+
return [2 /*return*/];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}); });
|
|
254
|
+
});
|
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const variants: readonly ["primary", "secondary"];
|
|
3
|
+
export declare const sizes: readonly ["small", "medium"];
|
|
3
4
|
export declare const iconNames: string[];
|
|
4
5
|
type SIZES = typeof sizes[number];
|
|
5
6
|
type VARIANT = typeof variants[number];
|
|
6
|
-
type ICON = typeof iconNames[
|
|
7
|
-
interface
|
|
7
|
+
type ICON = typeof iconNames[number];
|
|
8
|
+
export interface DropdownToggleContentProps {
|
|
9
|
+
show?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface DropdownListItem {
|
|
8
12
|
title?: string;
|
|
9
13
|
icon?: ICON;
|
|
10
14
|
slug?: string;
|
|
11
|
-
|
|
15
|
+
component?: React.ElementType;
|
|
16
|
+
onClick?(event?: React.MouseEvent<HTMLElement>): void;
|
|
12
17
|
}
|
|
13
18
|
interface Dropdown {
|
|
14
19
|
show?: boolean;
|
|
15
|
-
Toggle?:
|
|
16
|
-
list?:
|
|
20
|
+
Toggle?: React.ComponentType<DropdownToggleContentProps>;
|
|
21
|
+
list?: DropdownListItem[];
|
|
17
22
|
size?: SIZES;
|
|
18
23
|
isShowTopChevron?: boolean;
|
|
19
24
|
childrenVariant?: VARIANT;
|
|
20
25
|
right?: string;
|
|
21
26
|
width?: string;
|
|
22
27
|
top?: string;
|
|
28
|
+
toggleAriaLabel?: string;
|
|
29
|
+
menuAriaLabel?: string;
|
|
30
|
+
onToggleKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;
|
|
23
31
|
}
|
|
24
32
|
export interface DropdownStyledProps {
|
|
25
|
-
$show
|
|
26
|
-
$list?:
|
|
33
|
+
$show?: boolean;
|
|
34
|
+
$list?: DropdownListItem[];
|
|
27
35
|
$size?: SIZES;
|
|
28
36
|
$isShowTopChevron?: boolean;
|
|
29
37
|
$childrenVariant?: VARIANT;
|