@redneckz/wildless-cms-uni-blocks 0.14.1026 → 0.14.1027
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/bundle/blocks.schema.json +1 -1
- package/bundle/bundle.umd.js +196 -163
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/model/LinkProps.d.ts +2 -0
- package/bundle/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
- package/dist/model/LinkProps.d.ts +2 -0
- package/dist/ui-kit/LinkButton/LinkButton.js +36 -2
- package/dist/ui-kit/LinkButton/LinkButton.js.map +1 -1
- package/dist/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
- package/lib/components/ButtonsBlock/ButtonsBlock.fixture.d.ts +1 -0
- package/lib/model/LinkProps.d.ts +2 -0
- package/lib/ui-kit/LinkButton/LinkButton.js +36 -2
- package/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
- package/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
- package/mobile/bundle/bundle.umd.js +196 -163
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/model/LinkProps.d.ts +2 -0
- package/mobile/bundle/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
- package/mobile/dist/model/LinkProps.d.ts +2 -0
- package/mobile/dist/ui-kit/LinkButton/LinkButton.js +36 -2
- package/mobile/dist/ui-kit/LinkButton/LinkButton.js.map +1 -1
- package/mobile/dist/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
- package/mobile/lib/model/LinkProps.d.ts +2 -0
- package/mobile/lib/ui-kit/LinkButton/LinkButton.js +36 -2
- package/mobile/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
- package/mobile/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
- package/mobile/src/model/LinkProps.ts +2 -0
- package/mobile/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
- package/mobile/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
- package/package.json +1 -1
- package/src/components/ButtonsBlock/ButtonsBlock.fixture.tsx +21 -0
- package/src/model/LinkProps.ts +2 -0
- package/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
- package/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
|
@@ -14,6 +14,8 @@ export declare type Target = '' | '_self' | '_blank' | '_parent' | '_top';
|
|
|
14
14
|
export declare type HrefProps = {
|
|
15
15
|
/** @title URL (href) */
|
|
16
16
|
href?: string;
|
|
17
|
+
/** @title Дополнительные ссылки для A/B-тестирования */
|
|
18
|
+
additionalHrefs?: string[];
|
|
17
19
|
};
|
|
18
20
|
export declare type LinkCommonProps = HrefProps & {
|
|
19
21
|
/** @default "" */
|
|
@@ -20,4 +20,15 @@ export interface LinkButtonContent extends ButtonCommonContent {
|
|
|
20
20
|
iconRight?: Picture;
|
|
21
21
|
/** @title Верхний текст */
|
|
22
22
|
aboveText?: string;
|
|
23
|
+
/** @title Уникальный идентификатор кнопки */
|
|
24
|
+
id?: string;
|
|
23
25
|
}
|
|
26
|
+
declare type LinkStoreItem = {
|
|
27
|
+
id: string;
|
|
28
|
+
lastLink: string;
|
|
29
|
+
nextDueAt: number;
|
|
30
|
+
};
|
|
31
|
+
export declare type LinkStoreSlice = {
|
|
32
|
+
links: LinkStoreItem[] | null;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -14,6 +14,8 @@ export declare type Target = '' | '_self' | '_blank' | '_parent' | '_top';
|
|
|
14
14
|
export declare type HrefProps = {
|
|
15
15
|
/** @title URL (href) */
|
|
16
16
|
href?: string;
|
|
17
|
+
/** @title Дополнительные ссылки для A/B-тестирования */
|
|
18
|
+
additionalHrefs?: string[];
|
|
17
19
|
};
|
|
18
20
|
export declare type LinkCommonProps = HrefProps & {
|
|
19
21
|
/** @default "" */
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
2
2
|
exports.LinkButton = void 0;
|
|
3
3
|
const jsx_runtime_1 = require("@redneckz/uni-jsx/jsx-runtime");
|
|
4
4
|
const uni_jsx_1 = require("@redneckz/uni-jsx");
|
|
5
|
+
const useLocalStore_1 = require("@redneckz/uni-jsx/lib/Store/useLocalStore");
|
|
5
6
|
const useLink_1 = require("../../hooks/useLink");
|
|
6
7
|
const dataAttributes_1 = require("../../utils/dataAttributes");
|
|
7
8
|
const ButtonInner_1 = require("./ButtonInner");
|
|
@@ -9,13 +10,46 @@ const getDisabledButtonClasses_1 = require("./getDisabledButtonClasses");
|
|
|
9
10
|
const getRegularButtonClasses_1 = require("./getRegularButtonClasses");
|
|
10
11
|
const useFormSubmit_1 = require("./useFormSubmit");
|
|
11
12
|
/** @deprecated */
|
|
12
|
-
exports.LinkButton = (0, uni_jsx_1.JSX)(({ disabled, children, method = 'LINK', href, ...rest }) => {
|
|
13
|
+
exports.LinkButton = (0, uni_jsx_1.JSX)(({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
|
|
13
14
|
const handleFormSubmit = (0, useFormSubmit_1.useFormSubmit)({ method, href });
|
|
15
|
+
const linksStore = (0, useLocalStore_1.useLocalStore)();
|
|
16
|
+
saveLinksToStore({ linksStore, href, id, additionalHrefs });
|
|
17
|
+
const adjustedHref = additionalHrefs
|
|
18
|
+
? (linksStore.links || []).find((store) => store.id === id)?.lastLink
|
|
19
|
+
: href;
|
|
14
20
|
const link = (0, useLink_1.useLink)();
|
|
15
|
-
const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
|
|
21
|
+
const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
|
|
16
22
|
const buttonInner = children ?? (0, jsx_runtime_1.jsx)(ButtonInner_1.ButtonInner, { ...adjustedProps });
|
|
17
23
|
return disabled ? ((0, jsx_runtime_1.jsx)(DisabledButton, { ...adjustedProps, children: buttonInner })) : ((0, jsx_runtime_1.jsx)(RegularButton, { ...adjustedProps, children: buttonInner }));
|
|
18
24
|
});
|
|
19
25
|
const RegularButton = (0, uni_jsx_1.JSX)(({ className = '', href, rel, target, ariaLabel, version, rounded, onClick, type, data, children, text, }) => ((0, jsx_runtime_1.jsx)("a", { className: (0, getRegularButtonClasses_1.getRegularButtonClasses)({ className, version, rounded }), href: href, rel: rel, target: target, "aria-label": ariaLabel || `Ссылка на ${text}`, role: href ? 'link' : 'button', onClick: onClick, type: type, ...(0, dataAttributes_1.getAspectsAttributes)(data), children: children })));
|
|
20
26
|
const DisabledButton = (0, uni_jsx_1.JSX)(({ className, ariaLabel, version, rounded, children }) => ((0, jsx_runtime_1.jsx)("button", { type: "button", "aria-disabled": "true", "aria-label": ariaLabel, tabIndex: -1, className: (0, getDisabledButtonClasses_1.getDisabledButtonClasses)({ className, rounded, version }), children: children })));
|
|
27
|
+
const getRandomHref = (href = '', additionalHrefs = []) => {
|
|
28
|
+
const hrefs = [href, ...additionalHrefs];
|
|
29
|
+
return hrefs[Math.floor(Math.random() * hrefs.length)];
|
|
30
|
+
};
|
|
31
|
+
// Отсчитываем 7 длей с текущей даты
|
|
32
|
+
const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
|
|
33
|
+
// Сохраняем или заменяем рандомную ссылку в localStorage
|
|
34
|
+
const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }) => {
|
|
35
|
+
const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
|
|
36
|
+
// Если хранилища вообще нет
|
|
37
|
+
if (!linksStore.links) {
|
|
38
|
+
linksStore.links = [];
|
|
39
|
+
}
|
|
40
|
+
if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
|
|
41
|
+
// Получаем рандомную ссылку
|
|
42
|
+
const randomHref = getRandomHref(href, additionalHrefs);
|
|
43
|
+
// При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
|
|
44
|
+
const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
|
|
45
|
+
// Добавляем новый элемент
|
|
46
|
+
updatedLinks.push({
|
|
47
|
+
id: id ?? '',
|
|
48
|
+
lastLink: randomHref,
|
|
49
|
+
nextDueAt: getTimeAfter7days(),
|
|
50
|
+
});
|
|
51
|
+
// Добавляем это все в хранилище
|
|
52
|
+
linksStore.links = updatedLinks;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
21
55
|
//# sourceMappingURL=LinkButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkButton.js","sourceRoot":"","sources":["../../../src/ui-kit/LinkButton/LinkButton.tsx"],"names":[],"mappings":";;;AAAA,+CAAwC;AACxC,iDAA8C;AAC9C,+DAAkE;AAClE,+CAA4C;AAC5C,yEAAsE;AACtE,uEAAoE;
|
|
1
|
+
{"version":3,"file":"LinkButton.js","sourceRoot":"","sources":["../../../src/ui-kit/LinkButton/LinkButton.tsx"],"names":[],"mappings":";;;AAAA,+CAAwC;AACxC,6EAA0E;AAC1E,iDAA8C;AAC9C,+DAAkE;AAClE,+CAA4C;AAC5C,yEAAsE;AACtE,uEAAoE;AAGpE,mDAAgD;AAShD,kBAAkB;AACL,QAAA,UAAU,GAAG,IAAA,aAAG,EAC3B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;IAC9E,MAAM,gBAAgB,GAAG,IAAA,6BAAa,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,MAAM,UAAU,GAAG,IAAA,6BAAa,GAAkB,CAAC;IAEnD,gBAAgB,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;IAE5D,MAAM,YAAY,GAAG,eAAe;QAClC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,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YAAY,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAExE,0BAA0B;QAC1B,YAAY,CAAC,IAAI,CAAC;YAChB,EAAE,EAAE,EAAE,IAAI,EAAE;YACZ,QAAQ,EAAE,UAAU;YACpB,SAAS,EAAE,iBAAiB,EAAE;SAC/B,CAAC,CAAC;QACH,gCAAgC;QAChC,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC;KACjC;AACH,CAAC,CAAC"}
|
|
@@ -20,4 +20,15 @@ export interface LinkButtonContent extends ButtonCommonContent {
|
|
|
20
20
|
iconRight?: Picture;
|
|
21
21
|
/** @title Верхний текст */
|
|
22
22
|
aboveText?: string;
|
|
23
|
+
/** @title Уникальный идентификатор кнопки */
|
|
24
|
+
id?: string;
|
|
23
25
|
}
|
|
26
|
+
declare type LinkStoreItem = {
|
|
27
|
+
id: string;
|
|
28
|
+
lastLink: string;
|
|
29
|
+
nextDueAt: number;
|
|
30
|
+
};
|
|
31
|
+
export declare type LinkStoreSlice = {
|
|
32
|
+
links: LinkStoreItem[] | null;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -14,6 +14,8 @@ export declare type Target = '' | '_self' | '_blank' | '_parent' | '_top';
|
|
|
14
14
|
export declare type HrefProps = {
|
|
15
15
|
/** @title URL (href) */
|
|
16
16
|
href?: string;
|
|
17
|
+
/** @title Дополнительные ссылки для A/B-тестирования */
|
|
18
|
+
additionalHrefs?: string[];
|
|
17
19
|
};
|
|
18
20
|
export declare type LinkCommonProps = HrefProps & {
|
|
19
21
|
/** @default "" */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@redneckz/uni-jsx/jsx-runtime";
|
|
2
2
|
import { JSX } from '@redneckz/uni-jsx';
|
|
3
|
+
import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
|
|
3
4
|
import { useLink } from '../../hooks/useLink.js';
|
|
4
5
|
import { getAspectsAttributes } from '../../utils/dataAttributes.js';
|
|
5
6
|
import { ButtonInner } from './ButtonInner.js';
|
|
@@ -7,13 +8,46 @@ import { getDisabledButtonClasses } from './getDisabledButtonClasses.js';
|
|
|
7
8
|
import { getRegularButtonClasses } from './getRegularButtonClasses.js';
|
|
8
9
|
import { useFormSubmit } from './useFormSubmit.js';
|
|
9
10
|
/** @deprecated */
|
|
10
|
-
export const LinkButton = JSX(({ disabled, children, method = 'LINK', href, ...rest }) => {
|
|
11
|
+
export const LinkButton = JSX(({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
|
|
11
12
|
const handleFormSubmit = useFormSubmit({ method, href });
|
|
13
|
+
const linksStore = useLocalStore();
|
|
14
|
+
saveLinksToStore({ linksStore, href, id, additionalHrefs });
|
|
15
|
+
const adjustedHref = additionalHrefs
|
|
16
|
+
? (linksStore.links || []).find((store) => store.id === id)?.lastLink
|
|
17
|
+
: href;
|
|
12
18
|
const link = useLink();
|
|
13
|
-
const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
|
|
19
|
+
const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
|
|
14
20
|
const buttonInner = children ?? _jsx(ButtonInner, { ...adjustedProps });
|
|
15
21
|
return disabled ? (_jsx(DisabledButton, { ...adjustedProps, children: buttonInner })) : (_jsx(RegularButton, { ...adjustedProps, children: buttonInner }));
|
|
16
22
|
});
|
|
17
23
|
const RegularButton = JSX(({ className = '', href, rel, target, ariaLabel, version, rounded, onClick, type, data, children, text, }) => (_jsx("a", { className: getRegularButtonClasses({ className, version, rounded }), href: href, rel: rel, target: target, "aria-label": ariaLabel || `Ссылка на ${text}`, role: href ? 'link' : 'button', onClick: onClick, type: type, ...getAspectsAttributes(data), children: children })));
|
|
18
24
|
const DisabledButton = JSX(({ className, ariaLabel, version, rounded, children }) => (_jsx("button", { type: "button", "aria-disabled": "true", "aria-label": ariaLabel, tabIndex: -1, className: getDisabledButtonClasses({ className, rounded, version }), children: children })));
|
|
25
|
+
const getRandomHref = (href = '', additionalHrefs = []) => {
|
|
26
|
+
const hrefs = [href, ...additionalHrefs];
|
|
27
|
+
return hrefs[Math.floor(Math.random() * hrefs.length)];
|
|
28
|
+
};
|
|
29
|
+
// Отсчитываем 7 длей с текущей даты
|
|
30
|
+
const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
|
|
31
|
+
// Сохраняем или заменяем рандомную ссылку в localStorage
|
|
32
|
+
const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }) => {
|
|
33
|
+
const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
|
|
34
|
+
// Если хранилища вообще нет
|
|
35
|
+
if (!linksStore.links) {
|
|
36
|
+
linksStore.links = [];
|
|
37
|
+
}
|
|
38
|
+
if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
|
|
39
|
+
// Получаем рандомную ссылку
|
|
40
|
+
const randomHref = getRandomHref(href, additionalHrefs);
|
|
41
|
+
// При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
|
|
42
|
+
const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
|
|
43
|
+
// Добавляем новый элемент
|
|
44
|
+
updatedLinks.push({
|
|
45
|
+
id: id ?? '',
|
|
46
|
+
lastLink: randomHref,
|
|
47
|
+
nextDueAt: getTimeAfter7days(),
|
|
48
|
+
});
|
|
49
|
+
// Добавляем это все в хранилище
|
|
50
|
+
linksStore.links = updatedLinks;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
19
53
|
//# sourceMappingURL=LinkButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkButton.js","sourceRoot":"","sources":["../../../src/ui-kit/LinkButton/LinkButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,OAAO,EAA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AAE,eAAe,CAAC,CAAC;QAExD,wFAAwF;QACxF,MAAM,YAAY,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAExE,0BAA0B;QAC1B,YAAY,CAAC,IAAI,CAAC;YAChB,EAAE,EAAE,EAAE,IAAI,EAAE;YACZ,QAAQ,EAAE,UAAU;YACpB,SAAS,EAAE,iBAAiB,EAAE;SAC/B,CAAC,CAAC;QACH,gCAAgC;QAChC,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC;KACjC;AACH,CAAC,CAAC"}
|
|
@@ -20,4 +20,15 @@ export interface LinkButtonContent extends ButtonCommonContent {
|
|
|
20
20
|
iconRight?: Picture;
|
|
21
21
|
/** @title Верхний текст */
|
|
22
22
|
aboveText?: string;
|
|
23
|
+
/** @title Уникальный идентификатор кнопки */
|
|
24
|
+
id?: string;
|
|
23
25
|
}
|
|
26
|
+
declare type LinkStoreItem = {
|
|
27
|
+
id: string;
|
|
28
|
+
lastLink: string;
|
|
29
|
+
nextDueAt: number;
|
|
30
|
+
};
|
|
31
|
+
export declare type LinkStoreSlice = {
|
|
32
|
+
links: LinkStoreItem[] | null;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -16,6 +16,8 @@ export type Target = '' | '_self' | '_blank' | '_parent' | '_top';
|
|
|
16
16
|
export type HrefProps = {
|
|
17
17
|
/** @title URL (href) */
|
|
18
18
|
href?: string;
|
|
19
|
+
/** @title Дополнительные ссылки для A/B-тестирования */
|
|
20
|
+
additionalHrefs?: string[];
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export type LinkCommonProps = HrefProps & {
|
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
import { JSX } from '@redneckz/uni-jsx';
|
|
2
|
+
import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
|
|
2
3
|
import { useLink } from '../../hooks/useLink';
|
|
3
4
|
import { getAspectsAttributes } from '../../utils/dataAttributes';
|
|
4
5
|
import { ButtonInner } from './ButtonInner';
|
|
5
6
|
import { getDisabledButtonClasses } from './getDisabledButtonClasses';
|
|
6
7
|
import { getRegularButtonClasses } from './getRegularButtonClasses';
|
|
8
|
+
import { type LinkStoreSlice } from './LinkButtonContent';
|
|
7
9
|
import { type LinkButtonProps } from './LinkButtonProps';
|
|
8
10
|
import { useFormSubmit } from './useFormSubmit';
|
|
9
11
|
|
|
12
|
+
type SaveLinksProps = {
|
|
13
|
+
linksStore: LinkStoreSlice;
|
|
14
|
+
id?: string;
|
|
15
|
+
href?: string;
|
|
16
|
+
additionalHrefs?: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
10
19
|
/** @deprecated */
|
|
11
20
|
export const LinkButton = JSX<LinkButtonProps>(
|
|
12
|
-
({ disabled, children, method = 'LINK', href, ...rest }) => {
|
|
21
|
+
({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
|
|
13
22
|
const handleFormSubmit = useFormSubmit({ method, href });
|
|
23
|
+
const linksStore = useLocalStore<LinkStoreSlice>();
|
|
24
|
+
|
|
25
|
+
saveLinksToStore({ linksStore, href, id, additionalHrefs });
|
|
26
|
+
|
|
27
|
+
const adjustedHref = additionalHrefs
|
|
28
|
+
? (linksStore.links || []).find((store) => store.id === id)?.lastLink
|
|
29
|
+
: href;
|
|
14
30
|
|
|
15
31
|
const link = useLink();
|
|
16
|
-
const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
|
|
32
|
+
const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
|
|
17
33
|
const buttonInner = children ?? <ButtonInner {...adjustedProps} />;
|
|
18
34
|
|
|
19
35
|
return disabled ? (
|
|
@@ -69,3 +85,39 @@ const DisabledButton = JSX<LinkButtonProps>(
|
|
|
69
85
|
</button>
|
|
70
86
|
),
|
|
71
87
|
);
|
|
88
|
+
|
|
89
|
+
const getRandomHref = (href = '', additionalHrefs: string[] = []) => {
|
|
90
|
+
const hrefs = [href, ...additionalHrefs];
|
|
91
|
+
|
|
92
|
+
return hrefs[Math.floor(Math.random() * hrefs.length)];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Отсчитываем 7 длей с текущей даты
|
|
96
|
+
const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
|
|
97
|
+
|
|
98
|
+
// Сохраняем или заменяем рандомную ссылку в localStorage
|
|
99
|
+
const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }: SaveLinksProps) => {
|
|
100
|
+
const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
|
|
101
|
+
|
|
102
|
+
// Если хранилища вообще нет
|
|
103
|
+
if (!linksStore.links) {
|
|
104
|
+
linksStore.links = [];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
|
|
108
|
+
// Получаем рандомную ссылку
|
|
109
|
+
const randomHref = getRandomHref(href, additionalHrefs);
|
|
110
|
+
|
|
111
|
+
// При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
|
|
112
|
+
const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
|
|
113
|
+
|
|
114
|
+
// Добавляем новый элемент
|
|
115
|
+
updatedLinks.push({
|
|
116
|
+
id: id ?? '',
|
|
117
|
+
lastLink: randomHref,
|
|
118
|
+
nextDueAt: getTimeAfter7days(),
|
|
119
|
+
});
|
|
120
|
+
// Добавляем это все в хранилище
|
|
121
|
+
linksStore.links = updatedLinks;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
@@ -22,4 +22,16 @@ export interface LinkButtonContent extends ButtonCommonContent {
|
|
|
22
22
|
iconRight?: Picture;
|
|
23
23
|
/** @title Верхний текст */
|
|
24
24
|
aboveText?: string;
|
|
25
|
+
/** @title Уникальный идентификатор кнопки */
|
|
26
|
+
id?: string;
|
|
25
27
|
}
|
|
28
|
+
|
|
29
|
+
type LinkStoreItem = {
|
|
30
|
+
id: string;
|
|
31
|
+
lastLink: string;
|
|
32
|
+
nextDueAt: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type LinkStoreSlice = {
|
|
36
|
+
links: LinkStoreItem[] | null;
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -18,10 +18,31 @@ const buttons: LinkButtonContent[] = [
|
|
|
18
18
|
},
|
|
19
19
|
];
|
|
20
20
|
|
|
21
|
+
const buttonsForABTesting: LinkButtonContent[] = [
|
|
22
|
+
{
|
|
23
|
+
href: '/premium-cards',
|
|
24
|
+
additionalHrefs: ['/debit-cards', '/deposits'],
|
|
25
|
+
text: 'Оформить',
|
|
26
|
+
target: '_blank',
|
|
27
|
+
version: 'primary',
|
|
28
|
+
id: 'oformite',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
href: '/details',
|
|
32
|
+
text: 'Подробнее',
|
|
33
|
+
target: '_blank',
|
|
34
|
+
version: 'secondary',
|
|
35
|
+
},
|
|
36
|
+
];
|
|
21
37
|
export default {
|
|
22
38
|
default: (
|
|
23
39
|
<div className="container grid grid-cols-12">
|
|
24
40
|
<ButtonsBlock className="col-span-12" buttons={buttons} />
|
|
25
41
|
</div>
|
|
26
42
|
),
|
|
43
|
+
abTesting: (
|
|
44
|
+
<div className="container grid grid-cols-12">
|
|
45
|
+
<ButtonsBlock className="col-span-12" buttons={buttonsForABTesting} />
|
|
46
|
+
</div>
|
|
47
|
+
),
|
|
27
48
|
};
|
package/src/model/LinkProps.ts
CHANGED
|
@@ -16,6 +16,8 @@ export type Target = '' | '_self' | '_blank' | '_parent' | '_top';
|
|
|
16
16
|
export type HrefProps = {
|
|
17
17
|
/** @title URL (href) */
|
|
18
18
|
href?: string;
|
|
19
|
+
/** @title Дополнительные ссылки для A/B-тестирования */
|
|
20
|
+
additionalHrefs?: string[];
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export type LinkCommonProps = HrefProps & {
|
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
import { JSX } from '@redneckz/uni-jsx';
|
|
2
|
+
import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
|
|
2
3
|
import { useLink } from '../../hooks/useLink';
|
|
3
4
|
import { getAspectsAttributes } from '../../utils/dataAttributes';
|
|
4
5
|
import { ButtonInner } from './ButtonInner';
|
|
5
6
|
import { getDisabledButtonClasses } from './getDisabledButtonClasses';
|
|
6
7
|
import { getRegularButtonClasses } from './getRegularButtonClasses';
|
|
8
|
+
import { type LinkStoreSlice } from './LinkButtonContent';
|
|
7
9
|
import { type LinkButtonProps } from './LinkButtonProps';
|
|
8
10
|
import { useFormSubmit } from './useFormSubmit';
|
|
9
11
|
|
|
12
|
+
type SaveLinksProps = {
|
|
13
|
+
linksStore: LinkStoreSlice;
|
|
14
|
+
id?: string;
|
|
15
|
+
href?: string;
|
|
16
|
+
additionalHrefs?: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
10
19
|
/** @deprecated */
|
|
11
20
|
export const LinkButton = JSX<LinkButtonProps>(
|
|
12
|
-
({ disabled, children, method = 'LINK', href, ...rest }) => {
|
|
21
|
+
({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
|
|
13
22
|
const handleFormSubmit = useFormSubmit({ method, href });
|
|
23
|
+
const linksStore = useLocalStore<LinkStoreSlice>();
|
|
24
|
+
|
|
25
|
+
saveLinksToStore({ linksStore, href, id, additionalHrefs });
|
|
26
|
+
|
|
27
|
+
const adjustedHref = additionalHrefs
|
|
28
|
+
? (linksStore.links || []).find((store) => store.id === id)?.lastLink
|
|
29
|
+
: href;
|
|
14
30
|
|
|
15
31
|
const link = useLink();
|
|
16
|
-
const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
|
|
32
|
+
const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
|
|
17
33
|
const buttonInner = children ?? <ButtonInner {...adjustedProps} />;
|
|
18
34
|
|
|
19
35
|
return disabled ? (
|
|
@@ -69,3 +85,39 @@ const DisabledButton = JSX<LinkButtonProps>(
|
|
|
69
85
|
</button>
|
|
70
86
|
),
|
|
71
87
|
);
|
|
88
|
+
|
|
89
|
+
const getRandomHref = (href = '', additionalHrefs: string[] = []) => {
|
|
90
|
+
const hrefs = [href, ...additionalHrefs];
|
|
91
|
+
|
|
92
|
+
return hrefs[Math.floor(Math.random() * hrefs.length)];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Отсчитываем 7 длей с текущей даты
|
|
96
|
+
const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
|
|
97
|
+
|
|
98
|
+
// Сохраняем или заменяем рандомную ссылку в localStorage
|
|
99
|
+
const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }: SaveLinksProps) => {
|
|
100
|
+
const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
|
|
101
|
+
|
|
102
|
+
// Если хранилища вообще нет
|
|
103
|
+
if (!linksStore.links) {
|
|
104
|
+
linksStore.links = [];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
|
|
108
|
+
// Получаем рандомную ссылку
|
|
109
|
+
const randomHref = getRandomHref(href, additionalHrefs);
|
|
110
|
+
|
|
111
|
+
// При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
|
|
112
|
+
const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
|
|
113
|
+
|
|
114
|
+
// Добавляем новый элемент
|
|
115
|
+
updatedLinks.push({
|
|
116
|
+
id: id ?? '',
|
|
117
|
+
lastLink: randomHref,
|
|
118
|
+
nextDueAt: getTimeAfter7days(),
|
|
119
|
+
});
|
|
120
|
+
// Добавляем это все в хранилище
|
|
121
|
+
linksStore.links = updatedLinks;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
@@ -22,4 +22,16 @@ export interface LinkButtonContent extends ButtonCommonContent {
|
|
|
22
22
|
iconRight?: Picture;
|
|
23
23
|
/** @title Верхний текст */
|
|
24
24
|
aboveText?: string;
|
|
25
|
+
/** @title Уникальный идентификатор кнопки */
|
|
26
|
+
id?: string;
|
|
25
27
|
}
|
|
28
|
+
|
|
29
|
+
type LinkStoreItem = {
|
|
30
|
+
id: string;
|
|
31
|
+
lastLink: string;
|
|
32
|
+
nextDueAt: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type LinkStoreSlice = {
|
|
36
|
+
links: LinkStoreItem[] | null;
|
|
37
|
+
};
|