@modoock/components 2.2.0 → 2.4.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.
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +1 -1
- package/dist/agenda.js +5 -5
- package/dist/button.js +1 -1
- package/dist/chart.d.ts +37 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +92 -0
- package/dist/checkbox.d.ts +24 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +25 -0
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +199 -54
- package/dist/drawer.d.ts +26 -0
- package/dist/drawer.d.ts.map +1 -0
- package/dist/drawer.js +125 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/input.js +2 -2
- package/dist/metric-bar.js +1 -1
- package/dist/modal.d.ts.map +1 -1
- package/dist/modal.js +25 -6
- package/dist/pagination.d.ts +16 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +39 -0
- package/dist/radio.d.ts +34 -0
- package/dist/radio.d.ts.map +1 -0
- package/dist/radio.js +37 -0
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +9 -5
- package/dist/skeleton.d.ts +12 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +13 -0
- package/dist/stepper.js +1 -1
- package/dist/switch.d.ts +21 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +27 -0
- package/dist/tab.js +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +7 -6
- package/dist/toast.d.ts +31 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +165 -0
- package/dist/tooltip.d.ts +18 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +78 -0
- package/package.json +7 -3
package/dist/toast.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import Icon from "./icon";
|
|
6
|
+
/* ------------------------------------------------------------------ */
|
|
7
|
+
/* Store */
|
|
8
|
+
/* ------------------------------------------------------------------ */
|
|
9
|
+
const ANIMATION_MS = 200;
|
|
10
|
+
const DEFAULT_DURATION = 4000;
|
|
11
|
+
const DEFAULT_MAX = 4;
|
|
12
|
+
let items = [];
|
|
13
|
+
let maxToasts = DEFAULT_MAX;
|
|
14
|
+
const listeners = new Set();
|
|
15
|
+
const timers = new Map();
|
|
16
|
+
function emit() {
|
|
17
|
+
for (const listener of listeners)
|
|
18
|
+
listener(items);
|
|
19
|
+
}
|
|
20
|
+
function subscribe(listener) {
|
|
21
|
+
listeners.add(listener);
|
|
22
|
+
listener(items);
|
|
23
|
+
return () => {
|
|
24
|
+
listeners.delete(listener);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function remove(id) {
|
|
28
|
+
const timer = timers.get(id);
|
|
29
|
+
if (timer != null) {
|
|
30
|
+
window.clearTimeout(timer);
|
|
31
|
+
timers.delete(id);
|
|
32
|
+
}
|
|
33
|
+
items = items.filter((item) => item.id !== id);
|
|
34
|
+
emit();
|
|
35
|
+
}
|
|
36
|
+
function dismiss(id) {
|
|
37
|
+
const current = items.find((item) => item.id === id);
|
|
38
|
+
if (!current || !current.open)
|
|
39
|
+
return;
|
|
40
|
+
items = items.map((item) => item.id === id ? { ...item, open: false } : item);
|
|
41
|
+
emit();
|
|
42
|
+
window.setTimeout(() => remove(id), ANIMATION_MS);
|
|
43
|
+
}
|
|
44
|
+
function trimToMax(max) {
|
|
45
|
+
const openItems = items.filter((item) => item.open);
|
|
46
|
+
if (openItems.length <= max)
|
|
47
|
+
return;
|
|
48
|
+
const overflow = openItems.length - max;
|
|
49
|
+
for (let i = 0; i < overflow; i += 1) {
|
|
50
|
+
dismiss(openItems[i].id);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createId() {
|
|
54
|
+
return `toast-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
55
|
+
}
|
|
56
|
+
function pushToast(options) {
|
|
57
|
+
const id = createId();
|
|
58
|
+
const duration = options.duration ?? DEFAULT_DURATION;
|
|
59
|
+
const record = {
|
|
60
|
+
id,
|
|
61
|
+
title: options.title,
|
|
62
|
+
description: options.description,
|
|
63
|
+
variant: options.variant ?? "default",
|
|
64
|
+
duration,
|
|
65
|
+
open: true,
|
|
66
|
+
};
|
|
67
|
+
items = [...items, record];
|
|
68
|
+
emit();
|
|
69
|
+
trimToMax(maxToasts);
|
|
70
|
+
if (duration > 0) {
|
|
71
|
+
const timer = window.setTimeout(() => dismiss(id), duration);
|
|
72
|
+
timers.set(id, timer);
|
|
73
|
+
}
|
|
74
|
+
return id;
|
|
75
|
+
}
|
|
76
|
+
/* ------------------------------------------------------------------ */
|
|
77
|
+
/* Imperative API */
|
|
78
|
+
/* ------------------------------------------------------------------ */
|
|
79
|
+
function createToastFn(variant) {
|
|
80
|
+
return (title, description, options) => pushToast({ ...options, title, description, variant });
|
|
81
|
+
}
|
|
82
|
+
export const toast = Object.assign((options) => pushToast(options), {
|
|
83
|
+
success: createToastFn("success"),
|
|
84
|
+
warning: createToastFn("warning"),
|
|
85
|
+
danger: createToastFn("danger"),
|
|
86
|
+
info: createToastFn("info"),
|
|
87
|
+
message: createToastFn("default"),
|
|
88
|
+
dismiss,
|
|
89
|
+
});
|
|
90
|
+
/* ------------------------------------------------------------------ */
|
|
91
|
+
/* Visual */
|
|
92
|
+
/* ------------------------------------------------------------------ */
|
|
93
|
+
const VARIANT_ICON = {
|
|
94
|
+
default: "Info",
|
|
95
|
+
success: "CircleCheck",
|
|
96
|
+
warning: "TriangleAlert",
|
|
97
|
+
danger: "CircleAlert",
|
|
98
|
+
info: "Info",
|
|
99
|
+
};
|
|
100
|
+
const VARIANT_ICON_WRAP = {
|
|
101
|
+
default: "bg-muted text-muted-foreground",
|
|
102
|
+
success: "bg-success text-white",
|
|
103
|
+
warning: "bg-warning text-white",
|
|
104
|
+
danger: "bg-danger text-white",
|
|
105
|
+
info: "bg-info text-white",
|
|
106
|
+
};
|
|
107
|
+
const VARIANT_PROGRESS = {
|
|
108
|
+
default: "bg-border-strong",
|
|
109
|
+
success: "bg-success",
|
|
110
|
+
warning: "bg-warning",
|
|
111
|
+
danger: "bg-danger",
|
|
112
|
+
info: "bg-info",
|
|
113
|
+
};
|
|
114
|
+
const POSITION_CLASS = {
|
|
115
|
+
"top-right": "top-component right-component items-end",
|
|
116
|
+
"top-left": "top-component left-component items-start",
|
|
117
|
+
"bottom-right": "bottom-component right-component items-end",
|
|
118
|
+
"bottom-left": "bottom-component left-component items-start",
|
|
119
|
+
};
|
|
120
|
+
function isTop(position) {
|
|
121
|
+
return position.startsWith("top");
|
|
122
|
+
}
|
|
123
|
+
function ToastCard({ item, fromTop, }) {
|
|
124
|
+
const [progress, setProgress] = useState(item.duration > 0 ? 1 : 0);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (item.duration <= 0 || !item.open)
|
|
127
|
+
return;
|
|
128
|
+
const frame = requestAnimationFrame(() => {
|
|
129
|
+
requestAnimationFrame(() => setProgress(0));
|
|
130
|
+
});
|
|
131
|
+
return () => cancelAnimationFrame(frame);
|
|
132
|
+
}, [item.duration, item.id, item.open]);
|
|
133
|
+
return (_jsxs("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: `pointer-events-auto relative w-[min(22rem,calc(100vw-2rem))] overflow-hidden rounded-large border border-border/80 bg-surface/90 shadow-lg backdrop-blur-md transition-[opacity,transform] duration-200 ease-out motion-reduce:transition-none ${item.open
|
|
134
|
+
? "translate-y-0 scale-100 opacity-100"
|
|
135
|
+
: fromTop
|
|
136
|
+
? "-translate-y-2 scale-[0.98] opacity-0"
|
|
137
|
+
: "translate-y-2 scale-[0.98] opacity-0"}`, children: [_jsxs("div", { className: "flex min-w-0 items-start gap-control px-component pb-control pt-component", children: [_jsx("span", { className: `grid size-9 shrink-0 place-items-center rounded-full ${VARIANT_ICON_WRAP[item.variant]}`, "aria-hidden": "true", children: _jsx(Icon, { name: VARIANT_ICON[item.variant], size: "small", variant: item.variant === "default" ? "muted" : "white" }) }), _jsxs("div", { className: "min-w-0 flex-1 pt-micro", children: [_jsx("p", { className: "text-body-medium leading-snug tracking-tight text-foreground", children: item.title }), _jsx("p", { className: "mt-0 text-small leading-snug text-muted-foreground", children: item.description })] }), _jsx("button", { type: "button", onClick: () => dismiss(item.id), className: "grid size-8 shrink-0 place-items-center rounded-full text-muted-foreground outline-none transition-colors duration-200 ease-out hover:bg-surface-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary motion-reduce:transition-none [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 [&_svg]:text-current", "aria-label": "Fermer la notification", children: _jsx(Icon, { name: "X", "aria-hidden": "true" }) })] }), item.duration > 0 ? (_jsx("div", { className: "h-0.5 w-full bg-muted", "aria-hidden": "true", children: _jsx("div", { className: `h-full origin-left ${VARIANT_PROGRESS[item.variant]} motion-reduce:transition-none`, style: {
|
|
138
|
+
transform: `scaleX(${progress})`,
|
|
139
|
+
transition: progress === 0
|
|
140
|
+
? `transform ${item.duration}ms linear`
|
|
141
|
+
: undefined,
|
|
142
|
+
} }) })) : null] }));
|
|
143
|
+
}
|
|
144
|
+
/* ------------------------------------------------------------------ */
|
|
145
|
+
/* Toaster */
|
|
146
|
+
/* ------------------------------------------------------------------ */
|
|
147
|
+
/**
|
|
148
|
+
* Conteneur des toasts — monter une seule fois (layout racine).
|
|
149
|
+
* Déclencher via `toast.success("…")` / `toast({ title, … })`.
|
|
150
|
+
*/
|
|
151
|
+
export function Toaster({ position = "bottom-right", max = DEFAULT_MAX, className = "", }) {
|
|
152
|
+
const [toasts, setToasts] = useState([]);
|
|
153
|
+
const [mounted, setMounted] = useState(false);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
maxToasts = max;
|
|
156
|
+
}, [max]);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
setMounted(true);
|
|
159
|
+
return subscribe(setToasts);
|
|
160
|
+
}, []);
|
|
161
|
+
if (!mounted)
|
|
162
|
+
return null;
|
|
163
|
+
const fromTop = isTop(position);
|
|
164
|
+
return createPortal(_jsx("div", { className: `pointer-events-none fixed z-[60] flex flex-col gap-inline ${POSITION_CLASS[position]} ${className}`, "aria-label": "Notifications", children: toasts.map((item) => (_jsx(ToastCard, { item: item, fromTop: fromTop }, item.id))) }), document.body);
|
|
165
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type TooltipSide = "top" | "right" | "bottom" | "left";
|
|
3
|
+
export interface TooltipProps {
|
|
4
|
+
/** Tooltip text (French in product copy). */
|
|
5
|
+
content: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** Placement relative to the trigger. Default `top`. */
|
|
8
|
+
side?: TooltipSide;
|
|
9
|
+
/** Delay before show (ms). Default 200. */
|
|
10
|
+
delay?: number;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Infobulle — aide secondaire au survol / focus.
|
|
15
|
+
* Ne remplace pas un label accessible (aria-label / texte visible).
|
|
16
|
+
*/
|
|
17
|
+
export default function Tooltip({ content, children, side, delay, className, }: TooltipProps): import("react").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../components/ui/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE9D,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;IACpB,wDAAwD;IACxD,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAiCD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,EAC9B,OAAO,EACP,QAAQ,EACR,IAAY,EACZ,KAAW,EACX,SAAc,GACf,EAAE,YAAY,+BA4Ed"}
|
package/dist/tooltip.js
ADDED
|
@@ -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.
|
|
3
|
+
"version": "2.4.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
|
-
"
|
|
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
|
}
|