krl-alfred 2.25.5 → 2.25.6

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.
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { AccordionStyledProps } from "./props";
3
+ export declare const ACCORDION_PANEL_TRANSITION_MS = 300;
3
4
  export declare const AccordionStyled: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
4
5
  export declare const AccordionTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "$size"> & AccordionStyledProps, never>>> & string;
5
6
  export declare const Wrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
6
7
  export declare const Item: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
7
- export declare const ItemTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "$size"> & AccordionStyledProps, never>>> & string;
8
+ export declare const ItemTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "$size"> & AccordionStyledProps, never>>> & string;
8
9
  export declare const ItemContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
9
10
  export declare const Footer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
@@ -7,14 +7,15 @@ 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.Footer = exports.ItemContent = exports.ItemTitle = exports.Item = exports.Wrapper = exports.AccordionTitle = exports.AccordionStyled = void 0;
10
+ exports.Footer = exports.ItemContent = exports.ItemTitle = exports.Item = exports.Wrapper = exports.AccordionTitle = exports.AccordionStyled = exports.ACCORDION_PANEL_TRANSITION_MS = void 0;
11
11
  var styled_components_1 = __importDefault(require("styled-components"));
12
12
  var devices_1 = require("../../constants/devices");
13
+ exports.ACCORDION_PANEL_TRANSITION_MS = 300;
13
14
  exports.AccordionStyled = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: block;\n"], ["\n display: block;\n"])));
14
15
  exports.AccordionTitle = styled_components_1.default.h1(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin-bottom: 1.5rem;\n margin-top: 0;\n font : ", ";\n\n @media only screen and ", " {\n font : var(--title-bold-16-19);\n }\n"], ["\n margin-bottom: 1.5rem;\n margin-top: 0;\n font : ", ";\n\n @media only screen and ", " {\n font : var(--title-bold-16-19);\n }\n"])), function (props) { return props.$size === "large" ? "var(--headline-bold-18-22)" : "var(--title-bold-16-19)"; }, devices_1.devices.lg);
15
16
  exports.Wrapper = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\n"], ["\n\n"])));
16
17
  exports.Item = styled_components_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n &:not(:nth-child(1)) {\n margin-top: 1.5rem;\n }\n"], ["\n &:not(:nth-child(1)) {\n margin-top: 1.5rem;\n }\n"])));
17
- exports.ItemTitle = styled_components_1.default.strong(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n cursor: pointer;\n font : ", ";\n >div{\n position: relative;\n &:last-child{\n margin-left: 1rem;\n > div{\n transition: all .3s ease;\n &:first-child{\n opacity: 0;\n }\n &:last-child{\n position: absolute;\n inset: 0;\n opacity: 1;\n }\n }\n }\n }\n \n &:is(.active){\n >div{\n &:last-child{\n > div{\n &:first-child{\n opacity: 1;\n }\n &:last-child{\n transform: rotate(90deg);\n opacity: 0;\n }\n }\n }\n }\n }\n @media only screen and ", " {\n font : var(--body-bold-14-17);\n }\n"], ["\n display: flex;\n align-items: center;\n justify-content: space-between;\n cursor: pointer;\n font : ", ";\n >div{\n position: relative;\n &:last-child{\n margin-left: 1rem;\n > div{\n transition: all .3s ease;\n &:first-child{\n opacity: 0;\n }\n &:last-child{\n position: absolute;\n inset: 0;\n opacity: 1;\n }\n }\n }\n }\n \n &:is(.active){\n >div{\n &:last-child{\n > div{\n &:first-child{\n opacity: 1;\n }\n &:last-child{\n transform: rotate(90deg);\n opacity: 0;\n }\n }\n }\n }\n }\n @media only screen and ", " {\n font : var(--body-bold-14-17);\n }\n"])), function (props) { return props.$size === "large" ? "var(--title-bold-16-19)" : "var(--body-bold-14-17)"; }, devices_1.devices.lg);
18
- exports.ItemContent = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n transition: all .3s ease;\n overflow: hidden;\n position: relative;\n font : ", ";\n @media only screen and ", " {\n font : var(--body-regular-14-17);\n }\n > div{\n padding: 1rem 2rem 0 0;\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n a{\n color : var(--primary);\n &:hover , :focus , :active {\n color: var(--primary-hover);\n }\n }\n }\n"], ["\n transition: all .3s ease;\n overflow: hidden;\n position: relative;\n font : ", ";\n @media only screen and ", " {\n font : var(--body-regular-14-17);\n }\n > div{\n padding: 1rem 2rem 0 0;\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n a{\n color : var(--primary);\n &:hover , :focus , :active {\n color: var(--primary-hover);\n }\n }\n }\n"])), function (props) { return props.$size === "large" ? "var(--title-regular-16-19)" : "var(--body-regular-14-17)"; }, devices_1.devices.lg);
18
+ exports.ItemTitle = styled_components_1.default.button(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n margin: 0;\n padding: 0;\n border: 0;\n background: transparent;\n color: inherit;\n text-align: left;\n appearance: none;\n cursor: pointer;\n font : ", ";\n\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n }\n >div{\n position: relative;\n &:last-child{\n margin-left: 1rem;\n > div{\n transition: all .3s ease;\n &:first-child{\n opacity: 0;\n }\n &:last-child{\n position: absolute;\n inset: 0;\n opacity: 1;\n }\n }\n }\n }\n \n &:is(.active){\n >div{\n &:last-child{\n > div{\n &:first-child{\n opacity: 1;\n }\n &:last-child{\n transform: rotate(90deg);\n opacity: 0;\n }\n }\n }\n }\n }\n @media only screen and ", " {\n font : var(--body-bold-14-17);\n }\n"], ["\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n margin: 0;\n padding: 0;\n border: 0;\n background: transparent;\n color: inherit;\n text-align: left;\n appearance: none;\n cursor: pointer;\n font : ", ";\n\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n }\n >div{\n position: relative;\n &:last-child{\n margin-left: 1rem;\n > div{\n transition: all .3s ease;\n &:first-child{\n opacity: 0;\n }\n &:last-child{\n position: absolute;\n inset: 0;\n opacity: 1;\n }\n }\n }\n }\n \n &:is(.active){\n >div{\n &:last-child{\n > div{\n &:first-child{\n opacity: 1;\n }\n &:last-child{\n transform: rotate(90deg);\n opacity: 0;\n }\n }\n }\n }\n }\n @media only screen and ", " {\n font : var(--body-bold-14-17);\n }\n"])), function (props) { return props.$size === "large" ? "var(--title-bold-16-19)" : "var(--body-bold-14-17)"; }, devices_1.devices.lg);
19
+ exports.ItemContent = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n transition: height ", "ms ease;\n overflow: hidden;\n position: relative;\n font : ", ";\n @media only screen and ", " {\n font : var(--body-regular-14-17);\n }\n > div{\n padding: 1rem 2rem 0 0;\n a{\n color : var(--primary);\n &:hover , :focus , :active {\n color: var(--primary-hover);\n }\n }\n }\n"], ["\n transition: height ", "ms ease;\n overflow: hidden;\n position: relative;\n font : ", ";\n @media only screen and ", " {\n font : var(--body-regular-14-17);\n }\n > div{\n padding: 1rem 2rem 0 0;\n a{\n color : var(--primary);\n &:hover , :focus , :active {\n color: var(--primary-hover);\n }\n }\n }\n"])), exports.ACCORDION_PANEL_TRANSITION_MS, function (props) { return props.$size === "large" ? "var(--title-regular-16-19)" : "var(--body-regular-14-17)"; }, devices_1.devices.lg);
19
20
  exports.Footer = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n box-sizing: border-box;\n display: block;\n margin-top: 1.5rem!important;\n font : var(--body-bold-14-17);\n"], ["\n box-sizing: border-box;\n display: block;\n margin-top: 1.5rem!important;\n font : var(--body-bold-14-17);\n"])));
20
21
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,263 @@
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("react");
55
+ var react_2 = require("@testing-library/react");
56
+ var user_event_1 = __importDefault(require("@testing-library/user-event"));
57
+ var Accordion_1 = __importDefault(require("./Accordion"));
58
+ var items = [
59
+ {
60
+ question: 'İade nasıl yapılır?',
61
+ answer: 'İade için <a href="/orders">siparişlerim</a> sayfasına git.',
62
+ },
63
+ {
64
+ question: 'Hasar güvencesi nedir?',
65
+ answer: 'Basit çizikler hasardan sayılmaz.',
66
+ },
67
+ ];
68
+ var ResizeObserverMock = /** @class */ (function () {
69
+ function ResizeObserverMock(callback) {
70
+ this.target = null;
71
+ this.disconnect = jest.fn();
72
+ this.callback = callback;
73
+ ResizeObserverMock.instances.push(this);
74
+ }
75
+ ResizeObserverMock.prototype.observe = function (target) {
76
+ this.target = target;
77
+ };
78
+ ResizeObserverMock.prototype.unobserve = function () { };
79
+ ResizeObserverMock.prototype.emit = function (blockSize) {
80
+ var _this = this;
81
+ (0, react_1.act)(function () {
82
+ _this.callback([
83
+ {
84
+ target: _this.target,
85
+ borderBoxSize: [{ blockSize: blockSize, inlineSize: 100 }],
86
+ },
87
+ ], _this);
88
+ });
89
+ };
90
+ ResizeObserverMock.instances = [];
91
+ return ResizeObserverMock;
92
+ }());
93
+ var renderAccordion = function (props) {
94
+ if (props === void 0) { props = {}; }
95
+ return (0, react_2.render)((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { "aria-label": "\u00F6nce" }), (0, jsx_runtime_1.jsx)(Accordion_1.default, __assign({ data: items }, props)), (0, jsx_runtime_1.jsx)("input", { "aria-label": "sonra" })] }));
96
+ };
97
+ var questions = function () { return react_2.screen.getAllByRole('button', { name: /nasıl|nedir/ }); };
98
+ describe('Accordion', function () {
99
+ beforeEach(function () {
100
+ ResizeObserverMock.instances = [];
101
+ window.ResizeObserver = ResizeObserverMock;
102
+ jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (callback) {
103
+ callback(0);
104
+ return 1;
105
+ });
106
+ jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(function () { return undefined; });
107
+ });
108
+ afterEach(function () {
109
+ jest.restoreAllMocks();
110
+ });
111
+ it('exposes each question as a button in DOM order', function () { return __awaiter(void 0, void 0, void 0, function () {
112
+ var user, _a, first, second;
113
+ return __generator(this, function (_b) {
114
+ switch (_b.label) {
115
+ case 0:
116
+ user = user_event_1.default.setup();
117
+ renderAccordion();
118
+ _a = questions(), first = _a[0], second = _a[1];
119
+ expect(first).toHaveAttribute('type', 'button');
120
+ expect(first).toHaveAccessibleName('İade nasıl yapılır?');
121
+ expect(second).toHaveAccessibleName('Hasar güvencesi nedir?');
122
+ expect(first).toHaveAttribute('aria-expanded', 'false');
123
+ expect(first).toHaveAttribute('aria-controls');
124
+ return [4 /*yield*/, user.tab()];
125
+ case 1:
126
+ _b.sent();
127
+ expect(react_2.screen.getByRole('textbox', { name: 'önce' })).toHaveFocus();
128
+ return [4 /*yield*/, user.tab()];
129
+ case 2:
130
+ _b.sent();
131
+ expect(first).toHaveFocus();
132
+ return [4 /*yield*/, user.tab()];
133
+ case 3:
134
+ _b.sent();
135
+ expect(second).toHaveFocus();
136
+ return [4 /*yield*/, user.tab()];
137
+ case 4:
138
+ _b.sent();
139
+ expect(react_2.screen.getByRole('textbox', { name: 'sonra' })).toHaveFocus();
140
+ return [2 /*return*/];
141
+ }
142
+ });
143
+ }); });
144
+ it('toggles with click, Enter, and Space and keeps a single item open', function () { return __awaiter(void 0, void 0, void 0, function () {
145
+ var user, _a, first, second;
146
+ return __generator(this, function (_b) {
147
+ switch (_b.label) {
148
+ case 0:
149
+ user = user_event_1.default.setup();
150
+ renderAccordion();
151
+ _a = questions(), first = _a[0], second = _a[1];
152
+ return [4 /*yield*/, user.click(first)];
153
+ case 1:
154
+ _b.sent();
155
+ expect(first).toHaveAttribute('aria-expanded', 'true');
156
+ expect(first).toHaveFocus();
157
+ expect(react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' })).toHaveTextContent('siparişlerim');
158
+ return [4 /*yield*/, user.click(second)];
159
+ case 2:
160
+ _b.sent();
161
+ expect(first).toHaveAttribute('aria-expanded', 'false');
162
+ expect(second).toHaveAttribute('aria-expanded', 'true');
163
+ second.focus();
164
+ return [4 /*yield*/, user.keyboard('{Enter}')];
165
+ case 3:
166
+ _b.sent();
167
+ expect(second).toHaveAttribute('aria-expanded', 'false');
168
+ return [4 /*yield*/, user.keyboard(' ')];
169
+ case 4:
170
+ _b.sent();
171
+ expect(second).toHaveAttribute('aria-expanded', 'true');
172
+ return [2 /*return*/];
173
+ }
174
+ });
175
+ }); });
176
+ it('drops a closed panel from the accessibility tree after the transition', function () { return __awaiter(void 0, void 0, void 0, function () {
177
+ var user, panel, closedAnswer;
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0:
181
+ user = user_event_1.default.setup();
182
+ renderAccordion();
183
+ expect(react_2.screen.queryByRole('region')).not.toBeInTheDocument();
184
+ expect(react_2.screen.queryByRole('link', { name: 'siparişlerim' })).not.toBeInTheDocument();
185
+ return [4 /*yield*/, user.click(questions()[0])];
186
+ case 1:
187
+ _a.sent();
188
+ expect(react_2.screen.getByRole('link', { name: 'siparişlerim' })).toHaveAttribute('href', '/orders');
189
+ return [4 /*yield*/, user.click(questions()[0])];
190
+ case 2:
191
+ _a.sent();
192
+ panel = react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' });
193
+ (0, react_1.act)(function () {
194
+ panel.dispatchEvent(new Event('transitionend', { bubbles: true }));
195
+ });
196
+ expect(react_2.screen.queryByRole('region', { name: 'İade nasıl yapılır?' })).not.toBeInTheDocument();
197
+ closedAnswer = document.querySelector('a[href="/orders"]');
198
+ expect(closedAnswer).not.toBeNull();
199
+ expect(closedAnswer === null || closedAnswer === void 0 ? void 0 : closedAnswer.closest('[hidden]')).not.toBeNull();
200
+ return [2 /*return*/];
201
+ }
202
+ });
203
+ }); });
204
+ it('lets every item stay open when collapseAll is set', function () { return __awaiter(void 0, void 0, void 0, function () {
205
+ var user, _a, first, second;
206
+ return __generator(this, function (_b) {
207
+ switch (_b.label) {
208
+ case 0:
209
+ user = user_event_1.default.setup();
210
+ renderAccordion({ collapseAll: true });
211
+ _a = questions(), first = _a[0], second = _a[1];
212
+ expect(first).toHaveAttribute('aria-expanded', 'true');
213
+ expect(second).toHaveAttribute('aria-expanded', 'true');
214
+ return [4 /*yield*/, user.click(first)];
215
+ case 1:
216
+ _b.sent();
217
+ expect(first).toHaveAttribute('aria-expanded', 'false');
218
+ expect(second).toHaveAttribute('aria-expanded', 'true');
219
+ return [2 /*return*/];
220
+ }
221
+ });
222
+ }); });
223
+ it('tracks the open panel height when its content box changes', function () {
224
+ renderAccordion({ activeIndex: 0 });
225
+ var panel = react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' });
226
+ var observer = ResizeObserverMock.instances[0];
227
+ observer.emit(373);
228
+ expect(panel).toHaveStyle({ height: '373px' });
229
+ observer.emit(254);
230
+ expect(panel).toHaveStyle({ height: '254px' });
231
+ expect(ResizeObserverMock.instances).toHaveLength(1);
232
+ });
233
+ it('clears the height and stops observing when the panel closes', function () { return __awaiter(void 0, void 0, void 0, function () {
234
+ var user, panel, observer;
235
+ return __generator(this, function (_a) {
236
+ switch (_a.label) {
237
+ case 0:
238
+ user = user_event_1.default.setup();
239
+ renderAccordion({ activeIndex: 0 });
240
+ panel = react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' });
241
+ observer = ResizeObserverMock.instances[0];
242
+ observer.emit(373);
243
+ return [4 /*yield*/, user.click(questions()[0])];
244
+ case 1:
245
+ _a.sent();
246
+ expect(panel).toHaveStyle({ height: '0px' });
247
+ expect(observer.disconnect).toHaveBeenCalled();
248
+ return [2 /*return*/];
249
+ }
250
+ });
251
+ }); });
252
+ it('strips executable markup from the answer', function () {
253
+ (0, react_2.render)((0, jsx_runtime_1.jsx)(Accordion_1.default, { data: [
254
+ {
255
+ question: 'Güvenlik',
256
+ answer: '<p>güvenli</p><script>alert(1)</script><img src="x" onerror="alert(1)">',
257
+ },
258
+ ], activeIndex: 0 }));
259
+ expect(react_2.screen.getByText('güvenli')).toBeInTheDocument();
260
+ expect(document.querySelector('script')).not.toBeInTheDocument();
261
+ expect(document.querySelector('[onerror]')).not.toBeInTheDocument();
262
+ });
263
+ });
@@ -1,11 +1,13 @@
1
1
  import React from "react";
2
- declare const AccordionItem: ({ title, content, index, collapseAll, size, active, setActive }: {
3
- title: any;
4
- content: any;
5
- index: any;
6
- collapseAll: any;
7
- size: any;
8
- active: any;
9
- setActive: any;
10
- }) => React.JSX.Element;
2
+ import { AccordionStyledProps } from "./props";
3
+ type AccordionItemProps = {
4
+ title?: string;
5
+ content?: string;
6
+ index: number;
7
+ collapseAll?: boolean;
8
+ size?: AccordionStyledProps["$size"];
9
+ active: number | null;
10
+ setActive: (index: number | null) => void;
11
+ };
12
+ declare const AccordionItem: ({ title, content, index, collapseAll, size, active, setActive, }: AccordionItemProps) => React.JSX.Element;
11
13
  export default AccordionItem;
@@ -16,32 +16,102 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var jsx_runtime_1 = require("react/jsx-runtime");
18
18
  var react_1 = require("react");
19
+ var dompurify_1 = __importDefault(require("dompurify"));
19
20
  var Accordion_styled_1 = require("./Accordion.styled");
20
21
  var Icon_1 = __importDefault(require("../Icon/Icon"));
22
+ var readBorderBoxBlockSize = function (entry) {
23
+ var box = entry.borderBoxSize;
24
+ var first = Array.isArray(box) ? box[0] : box;
25
+ if (first && typeof first.blockSize === "number") {
26
+ return first.blockSize;
27
+ }
28
+ return entry.target.offsetHeight;
29
+ };
21
30
  var AccordionItem = function (_a) {
22
31
  var title = _a.title, content = _a.content, index = _a.index, collapseAll = _a.collapseAll, size = _a.size, active = _a.active, setActive = _a.setActive;
32
+ var baseId = (0, react_1.useId)();
33
+ var buttonId = "".concat(baseId, "-button");
34
+ var panelId = "".concat(baseId, "-panel");
35
+ var contentRef = (0, react_1.useRef)(null);
36
+ var panelRef = (0, react_1.useRef)(null);
37
+ var heightRef = (0, react_1.useRef)(0);
23
38
  var _b = (0, react_1.useState)(0), height = _b[0], setHeight = _b[1];
24
39
  var _c = (0, react_1.useState)(collapseAll ? true : false), activeItem = _c[0], setActiveItem = _c[1];
25
- var itemRef = (0, react_1.useRef)();
40
+ var isOpen = active === index || activeItem;
41
+ var _d = (0, react_1.useState)(!isOpen), hidePanel = _d[0], setHidePanel = _d[1];
42
+ var answerHtml = dompurify_1.default.sanitize(typeof content === "string" ? content : "");
43
+ var applyHeight = function (next) {
44
+ if (Object.is(heightRef.current, next))
45
+ return;
46
+ heightRef.current = next;
47
+ setHeight(next);
48
+ };
49
+ (0, react_1.useLayoutEffect)(function () {
50
+ if (!isOpen)
51
+ return;
52
+ applyHeight(0);
53
+ }, [isOpen]);
54
+ (0, react_1.useLayoutEffect)(function () {
55
+ if (isOpen && hidePanel)
56
+ setHidePanel(false);
57
+ }, [isOpen, hidePanel]);
26
58
  (0, react_1.useEffect)(function () {
27
- var _a, _b;
28
- setHeight((active === index || activeItem) ? (_b = (_a = itemRef === null || itemRef === void 0 ? void 0 : itemRef.current) === null || _a === void 0 ? void 0 : _a.children[0]) === null || _b === void 0 ? void 0 : _b.clientHeight : 0);
29
- }, [active, activeItem, index]);
59
+ if (isOpen || hidePanel)
60
+ return undefined;
61
+ var panel = panelRef.current;
62
+ if (!panel)
63
+ return undefined;
64
+ var hide = function () { return setHidePanel(true); };
65
+ var onTransitionEnd = function (event) {
66
+ if (event.target !== panel || (event.propertyName && event.propertyName !== "height"))
67
+ return;
68
+ hide();
69
+ };
70
+ panel.addEventListener("transitionend", onTransitionEnd);
71
+ var timeoutId = window.setTimeout(hide, Accordion_styled_1.ACCORDION_PANEL_TRANSITION_MS);
72
+ return function () {
73
+ panel.removeEventListener("transitionend", onTransitionEnd);
74
+ window.clearTimeout(timeoutId);
75
+ };
76
+ }, [isOpen, hidePanel]);
30
77
  (0, react_1.useEffect)(function () {
31
- setTimeout(function () {
32
- var _a, _b;
33
- setHeight((active === index || activeItem) ? (_b = (_a = itemRef === null || itemRef === void 0 ? void 0 : itemRef.current) === null || _a === void 0 ? void 0 : _a.children[0]) === null || _b === void 0 ? void 0 : _b.clientHeight : 0);
34
- }, 500);
35
- }, [collapseAll]);
78
+ var node = contentRef.current;
79
+ if (!isOpen || hidePanel || !node) {
80
+ return undefined;
81
+ }
82
+ var observer;
83
+ // Kapalı yükseklik (0) bir kare boyansın; aksi halde geçiş başlamaz.
84
+ var frame = window.requestAnimationFrame(function () {
85
+ applyHeight(node.offsetHeight);
86
+ if (typeof ResizeObserver === "undefined")
87
+ return;
88
+ observer = new ResizeObserver(function (entries) {
89
+ var entry = entries[0];
90
+ if (!entry)
91
+ return;
92
+ applyHeight(readBorderBoxBlockSize(entry));
93
+ });
94
+ observer.observe(node);
95
+ });
96
+ return function () {
97
+ window.cancelAnimationFrame(frame);
98
+ observer === null || observer === void 0 ? void 0 : observer.disconnect();
99
+ };
100
+ }, [isOpen, hidePanel, answerHtml]);
36
101
  var handleCollapse = function () {
37
102
  if (collapseAll) {
38
- setActiveItem(!activeItem);
39
- }
40
- else {
41
- setActive(active === index ? null : index);
42
- setActiveItem(false);
103
+ var nextOpen = !activeItem;
104
+ if (nextOpen)
105
+ setHidePanel(false);
106
+ setActiveItem(nextOpen);
107
+ return;
43
108
  }
109
+ var nextActive = active === index ? null : index;
110
+ if (nextActive === index)
111
+ setHidePanel(false);
112
+ setActive(nextActive);
113
+ setActiveItem(false);
44
114
  };
45
- return ((0, jsx_runtime_1.jsxs)(Accordion_styled_1.Item, { children: [(0, jsx_runtime_1.jsxs)(Accordion_styled_1.ItemTitle, __assign({ "$size": size, onClick: handleCollapse, className: (active === index || activeItem) ? "active" : null }, { children: [(0, jsx_runtime_1.jsx)("div", { children: title }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "NegativeSmall" }), (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "PlusSmall" })] })] })), (0, jsx_runtime_1.jsx)(Accordion_styled_1.ItemContent, __assign({ "$size": size, ref: itemRef, style: { height: height } }, { children: (0, jsx_runtime_1.jsx)("div", { dangerouslySetInnerHTML: { __html: content } }) }))] }));
115
+ return ((0, jsx_runtime_1.jsxs)(Accordion_styled_1.Item, { children: [(0, jsx_runtime_1.jsxs)(Accordion_styled_1.ItemTitle, __assign({ type: "button", id: buttonId, "$size": size, "aria-expanded": isOpen, "aria-controls": panelId, onClick: handleCollapse, className: isOpen ? "active" : undefined }, { children: [(0, jsx_runtime_1.jsx)("div", { children: title }), (0, jsx_runtime_1.jsxs)("div", __assign({ "aria-hidden": "true" }, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "NegativeSmall" }), (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "PlusSmall" })] }))] })), (0, jsx_runtime_1.jsx)(Accordion_styled_1.ItemContent, __assign({ id: panelId, role: "region", "aria-labelledby": buttonId, hidden: hidePanel, "$size": size, ref: panelRef, style: { height: isOpen ? height : 0 } }, { children: (0, jsx_runtime_1.jsx)("div", { ref: contentRef, dangerouslySetInnerHTML: { __html: answerHtml } }) }))] }));
46
116
  };
47
117
  exports.default = AccordionItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "krl-alfred",
3
- "version": "2.25.5",
3
+ "version": "2.25.6",
4
4
  "files": [
5
5
  "dist"
6
6
  ],