ublo-lib 1.26.18 → 1.27.1

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.
@@ -0,0 +1,66 @@
1
+ import * as React from "react";
2
+ import Button from "dt-design-system/es/button";
3
+ import { motion } from "framer-motion";
4
+ import * as Icons from "dt-design-system/es/icons";
5
+ import classnames from "classnames";
6
+ import styles from "./collapsible.module.css";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ import { jsxs as _jsxs } from "react/jsx-runtime";
9
+ const messages = {
10
+ fr: {
11
+ open: "Afficher plus",
12
+ close: "Afficher moins"
13
+ },
14
+ en: {
15
+ open: "Open",
16
+ close: "Close"
17
+ }
18
+ };
19
+ export default function Collapsible({
20
+ gradientColor = "#fff",
21
+ height = 150,
22
+ children,
23
+ lang
24
+ }) {
25
+ const [opened, setOpened] = React.useState(false);
26
+ const [hasOverflow, setHasOverflow] = React.useState(false);
27
+ const classes = classnames(styles.collapsible, {
28
+ [styles.opened]: opened,
29
+ [styles.overflow]: hasOverflow
30
+ });
31
+ const parentRef = React.useRef(null);
32
+ const childrenRef = React.useRef(null);
33
+ const toggleOpen = () => {
34
+ setOpened(!opened);
35
+ };
36
+ const messageLang = lang === "fr" ? "fr" : "en";
37
+ const message = opened ? messages[messageLang].close : messages[messageLang].open;
38
+ React.useEffect(() => {
39
+ const parentHeight = parentRef.current?.offsetHeight;
40
+ const childrenHeight = childrenRef.current?.offsetHeight;
41
+ if (childrenHeight > parentHeight) {
42
+ setHasOverflow(true);
43
+ }
44
+ }, []);
45
+ return _jsxs(motion.div, {
46
+ ref: parentRef,
47
+ animate: {
48
+ height: opened || !hasOverflow ? "auto" : height
49
+ },
50
+ initial: {
51
+ height
52
+ },
53
+ className: classes,
54
+ style: {
55
+ "--gradient-color": gradientColor
56
+ },
57
+ children: [_jsx("div", {
58
+ ref: childrenRef,
59
+ children: children
60
+ }), hasOverflow && _jsxs(Button, {
61
+ className: styles.message,
62
+ onClick: toggleOpen,
63
+ children: [message, opened ? _jsx(Icons.ChevronUp, {}) : _jsx(Icons.ChevronDown, {})]
64
+ })]
65
+ });
66
+ }
@@ -0,0 +1,37 @@
1
+ .collapsible {
2
+ position: relative;
3
+ overflow: hidden;
4
+ }
5
+
6
+ .overflow.collapsible::after {
7
+ content: "";
8
+ position: absolute;
9
+ bottom: 0;
10
+ width: 100%;
11
+ height: 100%;
12
+ background: linear-gradient(to top, var(--gradient-color), transparent);
13
+ transition: opacity 320ms
14
+ var(--ds-transition-easing, cubic-bezier(0.4, 0.1, 0.2, 0.9));
15
+ pointer-events: none;
16
+ z-index: 1;
17
+ }
18
+
19
+ .opened.collapsible {
20
+ padding-bottom: 10px;
21
+ }
22
+
23
+ .opened.collapsible::after {
24
+ content: none;
25
+ }
26
+
27
+ .message {
28
+ position: absolute;
29
+ bottom: 10px;
30
+ left: 50%;
31
+ transform: translateX(-50%);
32
+ z-index: 2;
33
+ }
34
+
35
+ .opened .message {
36
+ bottom: 0;
37
+ }
@@ -0,0 +1,2 @@
1
+ import Collapsible from "./collapsible";
2
+ export default Collapsible;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.26.18",
3
+ "version": "1.27.1",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^3.8.3",
6
6
  "leaflet": "^1.9.1",