krl-alfred 2.23.3 → 2.23.5

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.
@@ -32,7 +32,8 @@ var Icon_1 = __importDefault(require("../Icon/Icon"));
32
32
  var OptionMenu_1 = __importDefault(require("../OptionMenu"));
33
33
  var Badges_1 = __importDefault(require("../Badges"));
34
34
  var CategoryMenu = function (_a) {
35
- var _b = _a.data, data = _b === void 0 ? props_1.CategoryMenuDefault.data : _b, _c = _a.subMenuRowLength, subMenuRowLength = _c === void 0 ? props_1.CategoryMenuDefault.subMenuRowLength : _c, _d = _a.showIcons, showIcons = _d === void 0 ? props_1.CategoryMenuDefault.showIcons : _d;
35
+ var _b;
36
+ var _c = _a.data, data = _c === void 0 ? props_1.CategoryMenuDefault.data : _c, _d = _a.subMenuRowLength, subMenuRowLength = _d === void 0 ? props_1.CategoryMenuDefault.subMenuRowLength : _d, _e = _a.showIcons, showIcons = _e === void 0 ? props_1.CategoryMenuDefault.showIcons : _e;
36
37
  var ButtonLinkComponent = function (_a) {
37
38
  var item = _a.item, children = _a.children;
38
39
  return item.component ? ((0, jsx_runtime_1.jsx)(item.component, { children: (0, jsx_runtime_1.jsx)("div", __assign({ className: "componentWrapper" }, { children: children })) })) : ((0, jsx_runtime_1.jsx)("a", __assign({ href: item.slug }, { children: (0, jsx_runtime_1.jsx)("div", __assign({ className: "componentWrapper" }, { children: children })) })));
@@ -41,8 +42,9 @@ var CategoryMenu = function (_a) {
41
42
  var item = __rest(_a, []);
42
43
  return ((0, jsx_runtime_1.jsxs)(CategoryMenu_styled_1.CategoryItem, __assign({ "$isActiveCategory": item.isActive, "$hasCustomItem": item.hasCustomItem }, { children: [(0, jsx_runtime_1.jsx)(ButtonLinkComponent, __assign({ item: item }, { children: (0, jsx_runtime_1.jsxs)(CategoryMenu_styled_1.CategoryItemButtonInner, { children: [(item === null || item === void 0 ? void 0 : item.badgeTextSm) && ((0, jsx_runtime_1.jsx)(CategoryMenu_styled_1.CategoryItemButtonBadgeSm, { children: (0, jsx_runtime_1.jsx)(Badges_1.default, { layout: "text", variant: "secondary", title: item === null || item === void 0 ? void 0 : item.badgeTextSm }) })), showIcons && ((0, jsx_runtime_1.jsx)(CategoryMenu_styled_1.CategoryItemButtonIcon, __assign({ "$hasAnimation": item === null || item === void 0 ? void 0 : item.badgeText }, { children: (item === null || item === void 0 ? void 0 : item.badgeText) ? ((0, jsx_runtime_1.jsx)(CategoryMenu_styled_1.CategoryItemButtonBadge, { children: item === null || item === void 0 ? void 0 : item.badgeText })) : ((0, jsx_runtime_1.jsx)(Icon_1.default, { color: ["ElSatis"].includes(item.icon) ? "var(--primary)" : null, name: item.icon, hasColorChanged: !["CampaignColorful", "Lightning", "Flash", "Valentine", "NewYear"].includes(item.icon) })) }))), (0, jsx_runtime_1.jsx)(CategoryMenu_styled_1.CategoryItemButtonTitle, __assign({ "$showIcons": showIcons }, { children: item.name }))] }) })), item.children] })));
43
44
  };
44
- return ((0, jsx_runtime_1.jsx)(CategoryMenu_styled_1.CategoryMenuWrapper, { children: data === null || data === void 0 ? void 0 : data.map(function (item) {
45
+ var hasFewCategories = ((_b = data === null || data === void 0 ? void 0 : data.length) !== null && _b !== void 0 ? _b : 0) <= 4;
46
+ return ((0, jsx_runtime_1.jsx)(CategoryMenu_styled_1.CategoryMenuWrapper, __assign({ "$hasFewCategories": hasFewCategories }, { children: data === null || data === void 0 ? void 0 : data.map(function (item) {
45
47
  return ((0, jsx_runtime_1.jsx)(MenuButton, __assign({}, item, { children: item.children.length > 0 && ((0, jsx_runtime_1.jsx)(CategoryMenu_styled_1.SubMenu, { children: (0, jsx_runtime_1.jsx)(OptionMenu_1.default, { hasActiveItem: false, data: item.children, rowLength: item.subMenuRowLength || subMenuRowLength }) })) }), item.id));
46
- }) }));
48
+ }) })));
47
49
  };
48
50
  exports.default = CategoryMenu;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CategoryMenuStyled } from "./props";
3
- export declare const CategoryMenuWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, never>>> & string;
3
+ export declare const CategoryMenuWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, keyof CategoryMenuStyled> & CategoryMenuStyled, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, keyof CategoryMenuStyled> & CategoryMenuStyled, never>>> & string;
4
4
  export declare const CategoryItem: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, keyof CategoryMenuStyled> & CategoryMenuStyled, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, keyof CategoryMenuStyled> & CategoryMenuStyled, never>>> & string;
5
5
  export declare const CategoryItemButtonInner: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>>> & string;
6
6
  export declare const CategoryItemButtonIcon: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, keyof CategoryMenuStyled> & CategoryMenuStyled, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, keyof CategoryMenuStyled> & CategoryMenuStyled, never>>> & string;
@@ -29,7 +29,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.SubMenu = exports.CategoryItemButtonTitle = exports.CategoryItemButtonBadgeSm = exports.CategoryItemButtonBadge = exports.CategoryItemButtonIcon = exports.CategoryItemButtonInner = exports.CategoryItem = exports.CategoryMenuWrapper = void 0;
31
31
  var styled_components_1 = __importStar(require("styled-components"));
32
- exports.CategoryMenuWrapper = styled_components_1.default.ul(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n padding:0;\n margin: 12.5px auto;\n max-width: 1050px;\n a {\n text-decoration:none;\n &:not([href]){\n cursor: initial;\n *{\n cursor: initial;\n }\n }\n }\n"], ["\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n padding:0;\n margin: 12.5px auto;\n max-width: 1050px;\n a {\n text-decoration:none;\n &:not([href]){\n cursor: initial;\n *{\n cursor: initial;\n }\n }\n }\n"])));
32
+ exports.CategoryMenuWrapper = styled_components_1.default.ul(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: ", ";\n width: 100%;\n padding:0;\n margin: 12.5px auto;\n max-width: 1050px;\n a {\n text-decoration:none;\n &:not([href]){\n cursor: initial;\n *{\n cursor: initial;\n }\n }\n }\n"], ["\n display: flex;\n align-items: center;\n justify-content: ", ";\n width: 100%;\n padding:0;\n margin: 12.5px auto;\n max-width: 1050px;\n a {\n text-decoration:none;\n &:not([href]){\n cursor: initial;\n *{\n cursor: initial;\n }\n }\n }\n"])), function (props) { return props.$hasFewCategories ? 'flex-start' : 'space-between'; });
33
33
  var hoverAndActive = (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n color: var(--dark);\n &:before{\n border-color: var(--grey-10);\n box-shadow: 0 6px 30px 0 var(--box-shadow-color);\n color: var(--dark);\n }\n"], ["\n color: var(--dark);\n &:before{\n border-color: var(--grey-10);\n box-shadow: 0 6px 30px 0 var(--box-shadow-color);\n color: var(--dark);\n }\n"])));
34
34
  exports.CategoryItem = styled_components_1.default.li(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: block;\n position: relative;\n margin: 0;\n padding-bottom: 8px;\n padding-top: 8px;\n &:not(:last-child):not(:nth-last-child(2)){\n path, circle, rect {\n color : var(--dark-opacity-75);\n }\n }\n &:hover{\n &:not(:last-child):not(:nth-last-child(2)){\n path , circle, rect {\n color : var(--dark);\n }\n }\n > ul{\n opacity: 1;\n visibility: visible;\n transform: translateY(0);\n transition-delay: 0.3s;\n }\n .componentWrapper {\n > span{\n ", "\n }\n }\n }\n &:last-child , &:nth-last-child(2){\n ul{\n left: auto;\n right: 0;\n }\n }\n ", "\n ", "\n"], ["\n display: block;\n position: relative;\n margin: 0;\n padding-bottom: 8px;\n padding-top: 8px;\n &:not(:last-child):not(:nth-last-child(2)){\n path, circle, rect {\n color : var(--dark-opacity-75);\n }\n }\n &:hover{\n &:not(:last-child):not(:nth-last-child(2)){\n path , circle, rect {\n color : var(--dark);\n }\n }\n > ul{\n opacity: 1;\n visibility: visible;\n transform: translateY(0);\n transition-delay: 0.3s;\n }\n .componentWrapper {\n > span{\n ", "\n }\n }\n }\n &:last-child , &:nth-last-child(2){\n ul{\n left: auto;\n right: 0;\n }\n }\n ", "\n ", "\n"])), hoverAndActive, function (props) { return props.$isActiveCategory ? "\n .componentWrapper > span{\n ".concat(hoverAndActive, "\n }\n ") : ""; }, function (props) { return props.$hasCustomItem ? "\n display: flex;\n align-items: center;\n justify-content: center;\n &:before{\n content: '';\n background-color:var(--grey-10);\n height: 39px;\n width: 2px;\n display: block;\n vertical-align: middle;\n border-radius: 8px;\n margin-right: 6px;\n margin-left: 6px;\n }\n " : ""; });
35
35
  exports.CategoryItemButtonInner = styled_components_1.default.span(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n text-decoration: none;\n padding: 12px 16px;\n color: var(--dark-opacity-75);\n margin: 0;\n transition: all 0.2s ease-in-out;\n text-align: center;\n outline: none;\n display: block;\n position: relative;\n border: 0;\n background: transparent;\n outline: 0;\n width: 100%;\n font-family:inherit;\n cursor:pointer;\n box-sizing: border-box;\n &:before{\n content: \"\";\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n border: 1px solid transparent;\n color: var(--dark-opacity-75);\n background-color: transparent;\n border-radius: 0.5rem;\n z-index: -1;\n transition: all 0.2s ease-in-out;\n }\n"], ["\n text-decoration: none;\n padding: 12px 16px;\n color: var(--dark-opacity-75);\n margin: 0;\n transition: all 0.2s ease-in-out;\n text-align: center;\n outline: none;\n display: block;\n position: relative;\n border: 0;\n background: transparent;\n outline: 0;\n width: 100%;\n font-family:inherit;\n cursor:pointer;\n box-sizing: border-box;\n &:before{\n content: \"\";\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n border: 1px solid transparent;\n color: var(--dark-opacity-75);\n background-color: transparent;\n border-radius: 0.5rem;\n z-index: -1;\n transition: all 0.2s ease-in-out;\n }\n"])));
@@ -11,6 +11,7 @@ export interface CategoryMenuStyled {
11
11
  $hasAnimation?: boolean;
12
12
  $hasCustomItem?: boolean;
13
13
  $showIcons?: boolean;
14
+ $hasFewCategories?: boolean;
14
15
  }
15
16
  export declare const CategoryMenuDefault: CategoryMenu;
16
17
  export type CategoryMenuProps = typeof CategoryMenuDefault;
@@ -179,3 +179,166 @@ export declare const Default: {
179
179
  })[];
180
180
  };
181
181
  };
182
+ export declare const FourCategories: {
183
+ argTypes: {
184
+ subMenuRowLength: {
185
+ control: string;
186
+ };
187
+ showIcons: {
188
+ control: string;
189
+ };
190
+ data: {
191
+ control: string;
192
+ };
193
+ };
194
+ args: {
195
+ subMenuRowLength: number;
196
+ showIcons: boolean;
197
+ data: ({
198
+ id: number;
199
+ parentId: number;
200
+ name: string;
201
+ filterName: any;
202
+ isShowHeader: boolean;
203
+ slug: string;
204
+ productCount: number;
205
+ headerMediaUrl: string;
206
+ medias: any[];
207
+ icon: string;
208
+ children: ({
209
+ id: number;
210
+ parentId: number;
211
+ name: string;
212
+ filterName: any;
213
+ isShowHeader: boolean;
214
+ slug: string;
215
+ productCount: number;
216
+ headerMediaUrl: any;
217
+ medias: any[];
218
+ children: any[];
219
+ parent: any[];
220
+ hasBadge: boolean;
221
+ badgeText: string;
222
+ } | {
223
+ id: number;
224
+ parentId: number;
225
+ name: string;
226
+ filterName: any;
227
+ isShowHeader: boolean;
228
+ slug: string;
229
+ productCount: number;
230
+ headerMediaUrl: any;
231
+ medias: any[];
232
+ children: any[];
233
+ parent: any[];
234
+ hasBadge?: undefined;
235
+ badgeText?: undefined;
236
+ })[];
237
+ parent: any[];
238
+ badgeTextSm?: undefined;
239
+ component?: undefined;
240
+ hasCustomItem?: undefined;
241
+ } | {
242
+ id: number;
243
+ parentId: number;
244
+ name: string;
245
+ filterName: any;
246
+ isShowHeader: boolean;
247
+ slug: string;
248
+ productCount: number;
249
+ headerMediaUrl: string;
250
+ medias: any[];
251
+ icon: string;
252
+ children: {
253
+ id: number;
254
+ parentId: number;
255
+ name: string;
256
+ filterName: any;
257
+ isShowHeader: boolean;
258
+ slug: string;
259
+ productCount: number;
260
+ headerMediaUrl: string;
261
+ medias: any[];
262
+ children: any[];
263
+ parent: any[];
264
+ }[];
265
+ parent: any[];
266
+ badgeTextSm?: undefined;
267
+ component?: undefined;
268
+ hasCustomItem?: undefined;
269
+ } | {
270
+ id: number;
271
+ parentId: number;
272
+ name: string;
273
+ filterName: any;
274
+ isShowHeader: boolean;
275
+ slug: string;
276
+ productCount: number;
277
+ headerMediaUrl: string;
278
+ medias: any[];
279
+ icon: string;
280
+ badgeTextSm: string;
281
+ children: {
282
+ id: number;
283
+ parentId: number;
284
+ name: string;
285
+ filterName: any;
286
+ isShowHeader: boolean;
287
+ slug: string;
288
+ productCount: number;
289
+ headerMediaUrl: string;
290
+ medias: any[];
291
+ children: any[];
292
+ parent: any[];
293
+ }[];
294
+ parent: any[];
295
+ component?: undefined;
296
+ hasCustomItem?: undefined;
297
+ } | {
298
+ id: number;
299
+ parentId: number;
300
+ name: string;
301
+ filterName: any;
302
+ isShowHeader: boolean;
303
+ slug: string;
304
+ productCount: number;
305
+ headerMediaUrl: any;
306
+ medias: any[];
307
+ icon: string;
308
+ component: ({ children }: {
309
+ children: any;
310
+ }) => import("react").JSX.Element;
311
+ children: {
312
+ id: number;
313
+ parentId: number;
314
+ name: string;
315
+ filterName: any;
316
+ isShowHeader: boolean;
317
+ slug: string;
318
+ productCount: number;
319
+ headerMediaUrl: any;
320
+ medias: any[];
321
+ children: any[];
322
+ }[];
323
+ parent?: undefined;
324
+ badgeTextSm?: undefined;
325
+ hasCustomItem?: undefined;
326
+ } | {
327
+ id: number;
328
+ parentId: number;
329
+ name: string;
330
+ filterName: any;
331
+ isShowHeader: boolean;
332
+ slug: string;
333
+ productCount: number;
334
+ headerMediaUrl: any;
335
+ medias: any[];
336
+ icon: string;
337
+ children: any[];
338
+ hasCustomItem: boolean;
339
+ parent?: undefined;
340
+ badgeTextSm?: undefined;
341
+ component?: undefined;
342
+ })[];
343
+ };
344
+ };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Default = void 0;
6
+ exports.FourCategories = exports.Default = void 0;
7
7
  var CategoryMenu_1 = __importDefault(require("../CategoryMenu"));
8
8
  var categories_1 = __importDefault(require("../../../jsons/categories"));
9
9
  exports.default = {
@@ -28,3 +28,15 @@ exports.Default = {
28
28
  data: categories_1.default,
29
29
  },
30
30
  };
31
+ exports.FourCategories = {
32
+ argTypes: {
33
+ subMenuRowLength: { control: 'number' },
34
+ showIcons: { control: 'boolean' },
35
+ data: { control: 'disabled' }
36
+ },
37
+ args: {
38
+ subMenuRowLength: 7,
39
+ showIcons: true,
40
+ data: categories_1.default.slice(0, 4),
41
+ },
42
+ };
@@ -19,132 +19,76 @@ var react_1 = require("react");
19
19
  var props_1 = require("./props");
20
20
  var OtpInput_styled_1 = require("./OtpInput.styled");
21
21
  var Icon_1 = __importDefault(require("../Icon/Icon"));
22
- var keyEnums_1 = require("../../enums/keyEnums");
23
- var keyDownEventName = 'keydown';
22
+ var normalizeOtp = function (raw, size) {
23
+ return String(raw !== null && raw !== void 0 ? raw : "")
24
+ .replace(/\D/g, "")
25
+ .slice(0, size);
26
+ };
27
+ var isMobileDevice = function () {
28
+ return typeof window !== "undefined" && /Mobi/.test(window.navigator.userAgent);
29
+ };
24
30
  var Otp = function (_a) {
25
31
  var _b = _a.value, value = _b === void 0 ? props_1.OtpInputDefault.value : _b, _c = _a.onInputChange, onInputChange = _c === void 0 ? props_1.OtpInputDefault.onInputChange : _c, _d = _a.inputSize, inputSize = _d === void 0 ? props_1.OtpInputDefault.inputSize : _d, _e = _a.hasError, hasError = _e === void 0 ? props_1.OtpInputDefault.hasError : _e, _f = _a.errorMessage, errorMessage = _f === void 0 ? props_1.OtpInputDefault.errorMessage : _f, _g = _a.autoFocus, autoFocus = _g === void 0 ? props_1.OtpInputDefault.autoFocus : _g;
26
- var _h = (0, react_1.useState)(value), otpValue = _h[0], setOtpValue = _h[1];
32
+ var _h = (0, react_1.useState)(function () { return normalizeOtp(value, inputSize); }), otpValue = _h[0], setOtpValue = _h[1];
27
33
  var inputRef = (0, react_1.useRef)(null);
34
+ var skipNextExternalSync = (0, react_1.useRef)(false);
35
+ var focusInput = function () {
36
+ var input = inputRef.current;
37
+ if (!input)
38
+ return;
39
+ input.focus({ preventScroll: true });
40
+ };
28
41
  (0, react_1.useEffect)(function () {
29
- setUserFocus();
30
- }, [hasError]);
42
+ if (autoFocus) {
43
+ focusInput();
44
+ }
45
+ }, [autoFocus]);
31
46
  (0, react_1.useEffect)(function () {
32
- if (value === undefined || value === null || value === '') {
33
- setOtpValue('');
47
+ if (hasError) {
48
+ focusInput();
34
49
  }
35
- else if (!isNaN(Number(value))) {
36
- setOtpValue(value.toString());
50
+ }, [hasError]);
51
+ (0, react_1.useEffect)(function () {
52
+ if (skipNextExternalSync.current) {
53
+ skipNextExternalSync.current = false;
54
+ return;
37
55
  }
38
- }, [value]);
39
- var addKeydownEventListener = function () {
40
- window.addEventListener(keyDownEventName, handleOnKeyDown);
41
- };
42
- var removeKeyDownEventListener = function () {
43
- window.removeEventListener(keyDownEventName, handleOnKeyDown);
56
+ var nextValue = normalizeOtp(value, inputSize);
57
+ setOtpValue(function (prev) { return (prev === nextValue ? prev : nextValue); });
58
+ }, [value, inputSize]);
59
+ var updateOtpValue = function (nextRaw) {
60
+ var nextValue = normalizeOtp(nextRaw, inputSize);
61
+ skipNextExternalSync.current = true;
62
+ setOtpValue(nextValue);
63
+ onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(nextValue);
44
64
  };
45
- var isShortcutKey = function (keyCode) {
46
- return keyCode === keyEnums_1.KeyConditions.CTRL_V;
65
+ var handleChange = function (event) {
66
+ updateOtpValue(event.target.value);
47
67
  };
48
- var isKeyboardNumber = function (keyCode) {
49
- return (keyCode > keyEnums_1.KeyConditions.KEYBOARD_MIN &&
50
- keyCode < keyEnums_1.KeyConditions.KEYBOARD_MAX);
51
- };
52
- var isNumberPad = function (keyCode) {
53
- return (keyCode > keyEnums_1.KeyConditions.NUMBERPAD_MIN &&
54
- keyCode < keyEnums_1.KeyConditions.NUMBERPAD_MAX);
55
- };
56
- var handleOnKeyDown = (0, react_1.useCallback)(function (event) {
57
- var key = event.key, keyCode = event.keyCode;
58
- if (keyCode === keyEnums_1.KeyCodesEnums.BACKSPACE ||
59
- key === keyEnums_1.KeyEnums.BACKSPACE ||
60
- keyCode === keyEnums_1.KeyCodesEnums.DELETE ||
61
- key === keyEnums_1.KeyEnums.DELETE) {
62
- event.preventDefault();
63
- removeLastCharacter();
64
- }
65
- else if (isShortcutKey(event.keyCode)) {
66
- event.preventDefault();
67
- onShortcutPaste();
68
- }
69
- else if ((isKeyboardNumber(event.keyCode) || isNumberPad(event.keyCode)) &&
70
- !isNaN(Number(event.key))) {
71
- event.preventDefault();
72
- addNewCharacter(event.key);
73
- }
74
- }, []);
75
- (0, react_1.useEffect)(function () {
76
- addKeydownEventListener();
77
- setUserFocus();
78
- return function () {
79
- removeKeyDownEventListener();
80
- };
81
- }, [handleOnKeyDown]);
82
- var removeLastCharacter = function () {
83
- var newValue = '';
84
- setOtpValue(function (prevValue) {
85
- newValue = prevValue ? prevValue.slice(0, -1) : '';
86
- return newValue;
87
- });
68
+ var handleKeyDown = function (event) {
69
+ if (event.key !== "Backspace" && event.key !== "Delete")
70
+ return;
71
+ if (otpValue.length === 0)
72
+ return;
73
+ event.preventDefault();
74
+ updateOtpValue(otpValue.slice(0, -1));
88
75
  };
89
- var addNewCharacter = function (character) {
90
- var newValue = '';
91
- setOtpValue(function (prevValue) {
92
- newValue = prevValue || '';
93
- if (!prevValue || (prevValue && prevValue.length < inputSize)) {
94
- newValue += character;
76
+ var handleBlur = function () {
77
+ if (isMobileDevice())
78
+ return;
79
+ // Keep desktop focus on OTP without forced select/click loops.
80
+ requestAnimationFrame(function () {
81
+ if (document.activeElement !== inputRef.current) {
82
+ focusInput();
95
83
  }
96
- return newValue;
97
84
  });
98
85
  };
99
- (0, react_1.useEffect)(function () {
100
- if (otpValue)
101
- onInputChange(otpValue);
102
- }, [otpValue]);
103
- var onShortcutPaste = function () {
104
- var _a;
105
- var result = false;
106
- if ((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.clipboard) {
107
- try {
108
- window.navigator.clipboard.readText().then(function (text) {
109
- insertFromClipboard(text);
110
- });
111
- result = true;
112
- }
113
- catch (_) {
114
- result = false;
115
- }
116
- }
117
- };
118
- var insertFromClipboard = function (stringData) {
119
- var intData = Number(stringData);
120
- if (!isNaN(intData)) {
121
- var formattedData = intData.toString();
122
- setOtpValue(formattedData);
123
- }
124
- };
125
- var setUserFocus = function () {
126
- if (inputRef.current) {
127
- inputRef.current.focus();
128
- inputRef.current.select();
129
- inputRef.current.click();
130
- }
131
- };
132
- var isMobileDevice = function () { return /Mobi/.test(window.navigator.userAgent); };
133
- var onInputBlur = function () {
134
- if (!isMobileDevice()) {
135
- setUserFocus();
136
- }
137
- };
138
- var onChange = function (event) {
139
- var _a;
140
- event.preventDefault();
141
- if (!isNaN(Number((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value))) {
142
- setOtpValue(event.target.value);
143
- }
144
- };
145
- return (0, jsx_runtime_1.jsxs)(OtpInput_styled_1.OtpInputWrapper, { children: [(0, jsx_runtime_1.jsx)(OtpInput_styled_1.OtpSpanWrapper, __assign({ "$inputSize": inputSize, onClick: setUserFocus }, { children: Array.from({ length: inputSize }, function (_, index) { return index; }).map(function (index) { return ((0, jsx_runtime_1.jsx)(OtpInput_styled_1.OtpSpan, __assign({ active: (otpValue ? index === otpValue.length : index === 0) ||
146
- (otpValue &&
147
- otpValue.length === inputSize &&
148
- index === inputSize - 1), filled: Boolean(otpValue === null || otpValue === void 0 ? void 0 : otpValue[index]), hasError: hasError }, { children: otpValue && otpValue[index] }), index)); }) })), hasError && (0, jsx_runtime_1.jsxs)(OtpInput_styled_1.OtpError, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] }), (0, jsx_runtime_1.jsx)("input", { type: 'tel', autoComplete: 'one-time-code', autoFocus: autoFocus, value: otpValue, maxLength: inputSize, ref: inputRef, onBlur: onInputBlur, onChange: onChange })] });
86
+ return ((0, jsx_runtime_1.jsxs)(OtpInput_styled_1.OtpInputWrapper, { children: [(0, jsx_runtime_1.jsx)(OtpInput_styled_1.OtpSpanWrapper, __assign({ "$inputSize": inputSize, onClick: focusInput }, { children: Array.from({ length: inputSize }, function (_, index) {
87
+ var digit = otpValue[index];
88
+ var isFilled = digit !== undefined;
89
+ var isActive = index === otpValue.length ||
90
+ (otpValue.length === inputSize && index === inputSize - 1);
91
+ return ((0, jsx_runtime_1.jsx)(OtpInput_styled_1.OtpSpan, __assign({ active: isActive, filled: isFilled, hasError: hasError }, { children: digit }), index));
92
+ }) })), hasError && ((0, jsx_runtime_1.jsxs)(OtpInput_styled_1.OtpError, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] })), (0, jsx_runtime_1.jsx)("input", { type: "tel", inputMode: "numeric", pattern: "[0-9]*", autoComplete: "one-time-code", autoFocus: autoFocus, value: otpValue, maxLength: inputSize, ref: inputRef, onBlur: handleBlur, onChange: handleChange, onKeyDown: handleKeyDown, "aria-invalid": hasError })] }));
149
93
  };
150
94
  exports.default = Otp;
@@ -4,6 +4,26 @@ declare const _default: {
4
4
  component: (props: any) => React.JSX.Element;
5
5
  tags: string[];
6
6
  argTypes: {
7
+ value: {
8
+ control: string;
9
+ };
10
+ inputSize: {
11
+ control: {
12
+ type: string;
13
+ min: number;
14
+ max: number;
15
+ step: number;
16
+ };
17
+ };
18
+ autoFocus: {
19
+ control: string;
20
+ };
21
+ hasError: {
22
+ control: string;
23
+ };
24
+ errorMessage: {
25
+ control: string;
26
+ };
7
27
  onInputChange: {
8
28
  action: string;
9
29
  };
@@ -16,13 +36,73 @@ export declare const Default: {
16
36
  errorMessage: string;
17
37
  hasError: boolean;
18
38
  inputSize: number;
39
+ value: string;
40
+ };
41
+ };
42
+ export declare const SixDigits: {
43
+ args: {
44
+ inputSize: number;
45
+ autoFocus: boolean;
46
+ errorMessage: string;
47
+ hasError: boolean;
48
+ value: string;
49
+ };
50
+ };
51
+ export declare const EightDigits: {
52
+ args: {
53
+ inputSize: number;
54
+ autoFocus: boolean;
55
+ errorMessage: string;
56
+ hasError: boolean;
57
+ value: string;
19
58
  };
20
59
  };
21
60
  export declare const TenDigits: {
61
+ args: {
62
+ inputSize: number;
63
+ autoFocus: boolean;
64
+ errorMessage: string;
65
+ hasError: boolean;
66
+ value: string;
67
+ };
68
+ };
69
+ export declare const WithValue: {
70
+ name: string;
71
+ args: {
72
+ inputSize: number;
73
+ value: string;
74
+ autoFocus: boolean;
75
+ errorMessage: string;
76
+ hasError: boolean;
77
+ };
78
+ };
79
+ export declare const LeadingZeros: {
80
+ name: string;
81
+ args: {
82
+ inputSize: number;
83
+ value: string;
84
+ autoFocus: boolean;
85
+ errorMessage: string;
86
+ hasError: boolean;
87
+ };
88
+ };
89
+ export declare const WithError: {
90
+ name: string;
91
+ args: {
92
+ inputSize: number;
93
+ value: string;
94
+ hasError: boolean;
95
+ errorMessage: string;
96
+ autoFocus: boolean;
97
+ };
98
+ };
99
+ export declare const WithoutAutoFocus: {
100
+ name: string;
22
101
  args: {
23
102
  autoFocus: boolean;
24
103
  errorMessage: string;
25
104
  hasError: boolean;
26
105
  inputSize: number;
106
+ value: string;
27
107
  };
28
108
  };
@@ -1,40 +1,76 @@
1
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
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TenDigits = exports.Default = void 0;
17
+ exports.WithoutAutoFocus = exports.WithError = exports.LeadingZeros = exports.WithValue = exports.TenDigits = exports.EightDigits = exports.SixDigits = exports.Default = void 0;
7
18
  var jsx_runtime_1 = require("react/jsx-runtime");
8
19
  var react_1 = require("react");
9
20
  var Otp_1 = __importDefault(require("../Otp"));
10
21
  var OtpStory = function (props) {
11
- var _a = (0, react_1.useState)(null), value = _a[0], setValue = _a[1];
12
- var onChange = function (val) {
13
- setValue(val);
14
- };
15
- return (0, jsx_runtime_1.jsx)(Otp_1.default, { value: value, onInputChange: onChange, autoFocus: props.autoFocus, errorMessage: props.errorMessage, hasError: props.hasError, inputSize: props.inputSize });
22
+ var _a;
23
+ var _b = (0, react_1.useState)((_a = props.value) !== null && _a !== void 0 ? _a : ''), value = _b[0], setValue = _b[1];
24
+ return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: { maxWidth: 480 } }, { children: [(0, jsx_runtime_1.jsx)(Otp_1.default, { value: value, onInputChange: function (nextValue) {
25
+ var _a;
26
+ setValue(nextValue);
27
+ (_a = props.onInputChange) === null || _a === void 0 ? void 0 : _a.call(props, nextValue);
28
+ }, autoFocus: props.autoFocus, errorMessage: props.errorMessage, hasError: props.hasError, inputSize: props.inputSize }), (0, jsx_runtime_1.jsxs)("p", __assign({ style: { marginTop: 16, font: 'var(--caption-semi-bold-12-15)', color: 'var(--dark-opacity-50)' } }, { children: ["De\u011Fer: ", value || '—'] }))] })));
16
29
  };
17
30
  exports.default = {
18
31
  title: 'Components/OtpInput',
19
32
  component: OtpStory,
20
33
  tags: ['autodocs'],
21
34
  argTypes: {
35
+ value: { control: 'text' },
36
+ inputSize: { control: { type: 'number', min: 4, max: 10, step: 1 } },
37
+ autoFocus: { control: 'boolean' },
38
+ hasError: { control: 'boolean' },
39
+ errorMessage: { control: 'text' },
22
40
  onInputChange: { action: 'changed' },
23
- }
41
+ },
24
42
  };
25
43
  exports.Default = {
26
44
  args: {
27
45
  autoFocus: true,
28
- errorMessage: "Hata Mesajı",
46
+ errorMessage: 'Hata Mesajı',
29
47
  hasError: false,
30
- inputSize: 4
48
+ inputSize: 4,
49
+ value: '',
31
50
  },
32
51
  };
52
+ exports.SixDigits = {
53
+ args: __assign(__assign({}, exports.Default.args), { inputSize: 6 }),
54
+ };
55
+ exports.EightDigits = {
56
+ args: __assign(__assign({}, exports.Default.args), { inputSize: 8 }),
57
+ };
33
58
  exports.TenDigits = {
34
- args: {
35
- autoFocus: true,
36
- errorMessage: "Hata Mesajı",
37
- hasError: false,
38
- inputSize: 10
39
- },
59
+ args: __assign(__assign({}, exports.Default.args), { inputSize: 10 }),
60
+ };
61
+ exports.WithValue = {
62
+ name: 'Dolu değer',
63
+ args: __assign(__assign({}, exports.Default.args), { inputSize: 6, value: '123456', autoFocus: false }),
64
+ };
65
+ exports.LeadingZeros = {
66
+ name: 'Başında sıfır (006789)',
67
+ args: __assign(__assign({}, exports.Default.args), { inputSize: 6, value: '006789', autoFocus: false }),
68
+ };
69
+ exports.WithError = {
70
+ name: 'Hata durumu',
71
+ args: __assign(__assign({}, exports.Default.args), { inputSize: 6, value: '123456', hasError: true, errorMessage: 'Doğrulama kodu hatalı. Lütfen tekrar dene.', autoFocus: false }),
72
+ };
73
+ exports.WithoutAutoFocus = {
74
+ name: 'AutoFocus kapalı',
75
+ args: __assign(__assign({}, exports.Default.args), { autoFocus: false }),
40
76
  };
@@ -25,7 +25,7 @@ exports.ProductCardHorizontalSmStyled = styled_components_1.default.div(template
25
25
  }, exports.Title, exports.Title);
26
26
  exports.HorizontalSmWrapper = styled_components_1.default.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n text-decoration: none;\n display: grid;\n grid-template-columns: auto 1fr 1fr;\n align-items: center;\n min-height: 66px;\n padding-top: 0.5rem;\n padding-bottom: 0.5rem;\n padding-right: 0.5rem;\n\n @media only screen and ", " {\n padding-top: 1rem;\n padding-bottom: 1rem;\n }\n"], ["\n text-decoration: none;\n display: grid;\n grid-template-columns: auto 1fr 1fr;\n align-items: center;\n min-height: 66px;\n padding-top: 0.5rem;\n padding-bottom: 0.5rem;\n padding-right: 0.5rem;\n\n @media only screen and ", " {\n padding-top: 1rem;\n padding-bottom: 1rem;\n }\n"])), devices_1.devices.sm);
27
27
  exports.ImgWrapper = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n border: ", ";\n border-radius: ", ";\n position: relative;\n overflow: hidden;\n width: ", ";\n height: ", ";\n display: flex;\n align-items: center;\n justify-content: center;\n margin-right: 1rem;\n background: white;\n transform: translateZ(0);\n\n img {\n vertical-align: middle !important;\n display: block !important;\n object-fit: cover !important;\n border-radius: ", " !important;\n }\n"], ["\n border: ", ";\n border-radius: ", ";\n position: relative;\n overflow: hidden;\n width: ", ";\n height: ", ";\n display: flex;\n align-items: center;\n justify-content: center;\n margin-right: 1rem;\n background: white;\n transform: translateZ(0);\n\n img {\n vertical-align: middle !important;\n display: block !important;\n object-fit: cover !important;\n border-radius: ", " !important;\n }\n"])), function (props) { return (props.$hasImageBorder ? "1px solid var(--dark-opacity-5)" : "none"); }, function (props) { return (props.$hasImageRounded ? "0.5rem" : "0"); }, function (props) { return (props.$imageWidth ? props.$imageWidth : "71px"); }, function (props) { return (props.$imageHeight ? props.$imageHeight : "50px"); }, function (props) { return (props.$hasImageRounded ? "0.5rem" : "0"); });
28
- exports.TextWrapper = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n padding-right: ", ";\n"], ["\n padding-right: ", ";\n"])), function (props) { return (props.$hasPeriod ? "1rem" : "0.5rem"); });
28
+ exports.TextWrapper = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n padding-right: 0.5rem;\n"], ["\n padding-right: 0.5rem;\n"])));
29
29
  exports.PriceContent = styled_components_1.default.div(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (props) {
30
30
  return (props === null || props === void 0 ? void 0 : props.$infoPosition) === "left"
31
31
  ? "\n text-align: start;\n display: flex;\n align-items: flex-end;\n margin-top: 8px;\n "
@@ -194,6 +194,6 @@ var SelectBox = (0, react_1.forwardRef)(function (_a, ref) {
194
194
  MenuList: MenuList,
195
195
  LoadingIndicator: LoadingIndicator,
196
196
  MultiValue: MultiValue
197
- }, options: options || [], instanceId: instanceId, getOptionLabel: getOptionLabel, formatOptionLabel: formatOptionLabel, filterOption: wrappedFilterOption, isSearchable: isSearchable, name: name, menuIsOpen: menuIsOpen, onChange: onChange, classNamePrefix: "customSelect", className: (0, classnames_1.default)("customSelect", (_d = {}, _d['isSearchable'] = isSearchable && hasShowSearchIcon, _d), (_e = {}, _e['lightBg'] = lightBg, _e)), placeholder: placeholder, noOptionsMessage: function () { return 'Sonuç bulunamadı'; }, captureMenuScroll: false, isClearable: isClearable, defaultValue: defaultValue, isMulti: isMulti, closeMenuOnSelect: !isMulti, hideSelectedOptions: false }, restOther, { ref: ref, id: id }))) })), description && (0, jsx_runtime_1.jsx)(Input_styled_1.FieldDescription, { children: description }), hasError && ((0, jsx_runtime_1.jsxs)("div", __assign({ className: "error" }, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] })))] })));
197
+ }, options: options || [], instanceId: instanceId, getOptionLabel: getOptionLabel, formatOptionLabel: formatOptionLabel, filterOption: wrappedFilterOption, isSearchable: isSearchable, name: name, menuIsOpen: menuIsOpen, onChange: onChange, classNamePrefix: "customSelect", className: (0, classnames_1.default)("customSelect", (_d = {}, _d['isSearchable'] = isSearchable && hasShowSearchIcon, _d), (_e = {}, _e['lightBg'] = lightBg, _e)), placeholder: placeholder, noOptionsMessage: function () { return 'Sonuç bulunamadı'; }, captureMenuScroll: false, isClearable: isClearable, defaultValue: defaultValue, isMulti: isMulti, closeMenuOnSelect: !isMulti, hideSelectedOptions: false }, restOther, { ref: ref, id: id }))) })), description && (0, jsx_runtime_1.jsx)(Input_styled_1.FieldDescription, { children: description }), hasError && errorMessage && ((0, jsx_runtime_1.jsxs)("div", __assign({ className: "error" }, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] })))] })));
198
198
  });
199
199
  exports.default = SelectBox;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "krl-alfred",
3
- "version": "2.23.3",
3
+ "version": "2.23.5",
4
4
  "files": [
5
5
  "dist"
6
6
  ],