ublo-lib 1.47.79 → 1.47.80
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/es/common/components/season-switch/index.d.ts +6 -0
- package/es/common/components/season-switch/index.d.ts.map +1 -0
- package/es/common/components/season-switch/index.js +42 -0
- package/es/common/components/season-switch/index.module.css +24 -0
- package/es/common/components/season-switch/use-choose-winter.d.ts +2 -0
- package/es/common/components/season-switch/use-choose-winter.d.ts.map +1 -0
- package/es/common/components/season-switch/use-choose-winter.js +47 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/components/season-switch/index.tsx"],"names":[],"mappings":"AAcA,KAAK,KAAK,GAAG;IACX,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAE,cAAc,EAAE,EAAE,KAAK,2CAqD7D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import Router from "next/router";
|
|
4
|
+
import { useUbloContext } from "ublo/with-ublo";
|
|
5
|
+
import { fetchZone } from "ublo/fetcher";
|
|
6
|
+
import Dialog from "dt-design-system/es/dialog";
|
|
7
|
+
import useChooseWinter from "./use-choose-winter";
|
|
8
|
+
import styles from "./index.module.css";
|
|
9
|
+
const SOURCE = {
|
|
10
|
+
fr: "/choix-saison",
|
|
11
|
+
en: "/season-switch",
|
|
12
|
+
};
|
|
13
|
+
const STORAGE_KEY = "season-switch_viewed";
|
|
14
|
+
export default function SeasonSwitch({ preventOpening }) {
|
|
15
|
+
const [content, setContent] = React.useState();
|
|
16
|
+
const { config, lang } = useUbloContext();
|
|
17
|
+
const { ubloApi, site } = config;
|
|
18
|
+
const close = () => {
|
|
19
|
+
sessionStorage.setItem(STORAGE_KEY, "true");
|
|
20
|
+
setContent(undefined);
|
|
21
|
+
};
|
|
22
|
+
useChooseWinter(close, content);
|
|
23
|
+
const getContent = async () => {
|
|
24
|
+
const content = await fetchZone(ubloApi, site, lang, SOURCE[lang], "season-switch");
|
|
25
|
+
if (!content)
|
|
26
|
+
return;
|
|
27
|
+
setContent(content);
|
|
28
|
+
};
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
const alreadySeen = sessionStorage.getItem(STORAGE_KEY) ||
|
|
31
|
+
sessionStorage.getItem("cms_token");
|
|
32
|
+
if (!preventOpening && !alreadySeen) {
|
|
33
|
+
getContent();
|
|
34
|
+
}
|
|
35
|
+
}, [preventOpening]);
|
|
36
|
+
Router.ready(() => {
|
|
37
|
+
Router.events.on("routeChangeComplete", () => {
|
|
38
|
+
close();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return (_jsx(Dialog, { className: styles.seasonswitch, close: close, isOpened: !!content, showCloseButton: false, children: _jsx("div", { className: styles.inner, dangerouslySetInnerHTML: { __html: content }, "data-season-switch": "" }) }));
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
.seasonswitch {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
max-width: 100%;
|
|
5
|
+
min-height: 100%;
|
|
6
|
+
z-index: 1000;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.seasonswitch button[class*="dialog_closeButton"] {
|
|
10
|
+
background-color: transparent;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.seasonswitch button[class*="dialog_closeButton"] svg {
|
|
14
|
+
--size: 24px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.inner {
|
|
18
|
+
height: 100%;
|
|
19
|
+
width: 100%;
|
|
20
|
+
background-color: var(--season-switch);
|
|
21
|
+
display: flex;
|
|
22
|
+
align-items: center;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-choose-winter.d.ts","sourceRoot":"","sources":["../../../../src/common/components/season-switch/use-choose-winter.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,QA2D5E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const SELECTOR = ".season-switch div[data-season='winter']";
|
|
3
|
+
export default function useChooseWinter(callback, content) {
|
|
4
|
+
React.useEffect(() => {
|
|
5
|
+
if (!content)
|
|
6
|
+
return;
|
|
7
|
+
let winterElement = null;
|
|
8
|
+
let observer = null;
|
|
9
|
+
const attachListener = () => {
|
|
10
|
+
if (winterElement)
|
|
11
|
+
return true;
|
|
12
|
+
const winter = document.querySelector(SELECTOR);
|
|
13
|
+
if (winter) {
|
|
14
|
+
winterElement = winter;
|
|
15
|
+
winter.addEventListener("click", callback);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
if (attachListener()) {
|
|
21
|
+
return () => {
|
|
22
|
+
if (winterElement) {
|
|
23
|
+
winterElement.removeEventListener("click", callback);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
observer = new MutationObserver((mutations) => {
|
|
28
|
+
const hasRelevantChanges = mutations.some((mutation) => mutation.type === "childList" && mutation.addedNodes.length > 0);
|
|
29
|
+
if (hasRelevantChanges && attachListener()) {
|
|
30
|
+
observer.disconnect();
|
|
31
|
+
observer = null;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
observer.observe(document.body, {
|
|
35
|
+
childList: true,
|
|
36
|
+
subtree: true,
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
if (observer) {
|
|
40
|
+
observer.disconnect();
|
|
41
|
+
}
|
|
42
|
+
if (winterElement) {
|
|
43
|
+
winterElement.removeEventListener("click", callback);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}, [content, callback]);
|
|
47
|
+
}
|