@modoock/components 2.1.0 → 2.3.0

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,78 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef, useState, } from "react";
4
+ const SIDE_CLASS = {
5
+ top: "bottom-full left-1/2 mb-micro -translate-x-1/2",
6
+ bottom: "top-full left-1/2 mt-micro -translate-x-1/2",
7
+ left: "right-full top-1/2 mr-micro -translate-y-1/2",
8
+ right: "left-full top-1/2 ml-micro -translate-y-1/2",
9
+ };
10
+ const SIDE_MOTION = {
11
+ top: {
12
+ open: "translate-y-0 opacity-100",
13
+ closed: "translate-y-1 opacity-0",
14
+ },
15
+ bottom: {
16
+ open: "translate-y-0 opacity-100",
17
+ closed: "-translate-y-1 opacity-0",
18
+ },
19
+ left: {
20
+ open: "translate-x-0 opacity-100",
21
+ closed: "translate-x-1 opacity-0",
22
+ },
23
+ right: {
24
+ open: "translate-x-0 opacity-100",
25
+ closed: "-translate-x-1 opacity-0",
26
+ },
27
+ };
28
+ const ANIMATION_MS = 150;
29
+ /**
30
+ * Infobulle — aide secondaire au survol / focus.
31
+ * Ne remplace pas un label accessible (aria-label / texte visible).
32
+ */
33
+ export default function Tooltip({ content, children, side = "top", delay = 200, className = "", }) {
34
+ const tooltipId = useId();
35
+ const showTimer = useRef(null);
36
+ const hideTimer = useRef(null);
37
+ const [present, setPresent] = useState(false);
38
+ const [visible, setVisible] = useState(false);
39
+ const clearTimers = () => {
40
+ if (showTimer.current != null) {
41
+ window.clearTimeout(showTimer.current);
42
+ showTimer.current = null;
43
+ }
44
+ if (hideTimer.current != null) {
45
+ window.clearTimeout(hideTimer.current);
46
+ hideTimer.current = null;
47
+ }
48
+ };
49
+ const open = () => {
50
+ clearTimers();
51
+ showTimer.current = window.setTimeout(() => {
52
+ setPresent(true);
53
+ requestAnimationFrame(() => {
54
+ requestAnimationFrame(() => setVisible(true));
55
+ });
56
+ }, delay);
57
+ };
58
+ const close = () => {
59
+ clearTimers();
60
+ setVisible(false);
61
+ hideTimer.current = window.setTimeout(() => {
62
+ setPresent(false);
63
+ }, ANIMATION_MS);
64
+ };
65
+ useEffect(() => () => clearTimers(), []);
66
+ useEffect(() => {
67
+ if (!present)
68
+ return;
69
+ const onKeyDown = (event) => {
70
+ if (event.key === "Escape")
71
+ close();
72
+ };
73
+ document.addEventListener("keydown", onKeyDown);
74
+ return () => document.removeEventListener("keydown", onKeyDown);
75
+ }, [present]);
76
+ const motion = SIDE_MOTION[side];
77
+ return (_jsxs("span", { className: `relative inline-flex ${className}`, onMouseEnter: open, onMouseLeave: close, onFocus: open, onBlur: close, children: [_jsx("span", { className: "inline-flex", "aria-describedby": present ? tooltipId : undefined, children: children }), present ? (_jsx("span", { id: tooltipId, role: "tooltip", className: `pointer-events-none absolute z-50 w-max max-w-sm rounded-medium border border-border bg-surface px-component py-control text-left text-small leading-snug text-foreground shadow-lg transition-[opacity,transform] duration-150 ease-out motion-reduce:transition-none ${SIDE_CLASS[side]} ${visible ? motion.open : motion.closed}`, children: content })) : null] }));
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modoock/components",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Modoock source components for internal projects.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,9 +19,10 @@
19
19
  "build": "tsc"
20
20
  },
21
21
  "peerDependencies": {
22
+ "lucide-react": ">=1",
22
23
  "react": ">=18",
23
24
  "react-dom": ">=18",
24
- "lucide-react": ">=1"
25
+ "recharts": ">=2"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@types/react": "^19",
@@ -30,5 +31,8 @@
30
31
  "react-dom": "^19",
31
32
  "typescript": "^5"
32
33
  },
33
- "license": "MIT"
34
+ "license": "MIT",
35
+ "dependencies": {
36
+ "recharts": "^3.10.1"
37
+ }
34
38
  }