@sereno-ds/ui 0.24.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.
Files changed (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/dist/_internal/CharCount.d.ts +9 -0
  4. package/dist/_internal/CharCount.js +25 -0
  5. package/dist/_internal/CharCount.js.map +1 -0
  6. package/dist/_internal/Field.d.ts +17 -0
  7. package/dist/_internal/Field.js +55 -0
  8. package/dist/_internal/Field.js.map +1 -0
  9. package/dist/_internal/mask.d.ts +12 -0
  10. package/dist/_internal/mask.js +56 -0
  11. package/dist/_internal/mask.js.map +1 -0
  12. package/dist/_internal/style.d.ts +12 -0
  13. package/dist/_internal/style.js +5 -0
  14. package/dist/_internal/style.js.map +1 -0
  15. package/dist/core/Avatar.d.ts +14 -0
  16. package/dist/core/Avatar.js +62 -0
  17. package/dist/core/Avatar.js.map +1 -0
  18. package/dist/core/Badge.d.ts +16 -0
  19. package/dist/core/Badge.js +49 -0
  20. package/dist/core/Badge.js.map +1 -0
  21. package/dist/core/Brand.d.ts +18 -0
  22. package/dist/core/Brand.js +58 -0
  23. package/dist/core/Brand.js.map +1 -0
  24. package/dist/core/Button.d.ts +31 -0
  25. package/dist/core/Button.js +100 -0
  26. package/dist/core/Button.js.map +1 -0
  27. package/dist/core/Card.d.ts +15 -0
  28. package/dist/core/Card.js +34 -0
  29. package/dist/core/Card.js.map +1 -0
  30. package/dist/core/IconButton.d.ts +18 -0
  31. package/dist/core/IconButton.js +64 -0
  32. package/dist/core/IconButton.js.map +1 -0
  33. package/dist/core/Menu.d.ts +69 -0
  34. package/dist/core/Menu.js +278 -0
  35. package/dist/core/Menu.js.map +1 -0
  36. package/dist/core/Table.d.ts +92 -0
  37. package/dist/core/Table.js +162 -0
  38. package/dist/core/Table.js.map +1 -0
  39. package/dist/feedback/Alert.d.ts +27 -0
  40. package/dist/feedback/Alert.js +68 -0
  41. package/dist/feedback/Alert.js.map +1 -0
  42. package/dist/feedback/Dialog.d.ts +36 -0
  43. package/dist/feedback/Dialog.js +218 -0
  44. package/dist/feedback/Dialog.js.map +1 -0
  45. package/dist/feedback/EmptyState.d.ts +13 -0
  46. package/dist/feedback/EmptyState.js +70 -0
  47. package/dist/feedback/EmptyState.js.map +1 -0
  48. package/dist/feedback/Skeleton.d.ts +23 -0
  49. package/dist/feedback/Skeleton.js +44 -0
  50. package/dist/feedback/Skeleton.js.map +1 -0
  51. package/dist/feedback/Toast.d.ts +23 -0
  52. package/dist/feedback/Toast.js +85 -0
  53. package/dist/feedback/Toast.js.map +1 -0
  54. package/dist/feedback/ToastProvider.d.ts +69 -0
  55. package/dist/feedback/ToastProvider.js +183 -0
  56. package/dist/feedback/ToastProvider.js.map +1 -0
  57. package/dist/forms/AvatarUpload.d.ts +57 -0
  58. package/dist/forms/AvatarUpload.js +579 -0
  59. package/dist/forms/AvatarUpload.js.map +1 -0
  60. package/dist/forms/Checkbox.d.ts +15 -0
  61. package/dist/forms/Checkbox.js +57 -0
  62. package/dist/forms/Checkbox.js.map +1 -0
  63. package/dist/forms/DateTimePicker.d.ts +43 -0
  64. package/dist/forms/DateTimePicker.js +391 -0
  65. package/dist/forms/DateTimePicker.js.map +1 -0
  66. package/dist/forms/FileUpload.d.ts +39 -0
  67. package/dist/forms/FileUpload.js +376 -0
  68. package/dist/forms/FileUpload.js.map +1 -0
  69. package/dist/forms/Input.d.ts +35 -0
  70. package/dist/forms/Input.js +143 -0
  71. package/dist/forms/Input.js.map +1 -0
  72. package/dist/forms/Radio.d.ts +18 -0
  73. package/dist/forms/Radio.js +50 -0
  74. package/dist/forms/Radio.js.map +1 -0
  75. package/dist/forms/SearchInput.d.ts +23 -0
  76. package/dist/forms/SearchInput.js +70 -0
  77. package/dist/forms/SearchInput.js.map +1 -0
  78. package/dist/forms/Select.d.ts +40 -0
  79. package/dist/forms/Select.js +524 -0
  80. package/dist/forms/Select.js.map +1 -0
  81. package/dist/forms/Switch.d.ts +20 -0
  82. package/dist/forms/Switch.js +76 -0
  83. package/dist/forms/Switch.js.map +1 -0
  84. package/dist/forms/Textarea.d.ts +19 -0
  85. package/dist/forms/Textarea.js +65 -0
  86. package/dist/forms/Textarea.js.map +1 -0
  87. package/dist/index.d.ts +33 -0
  88. package/dist/index.js +73 -0
  89. package/dist/index.js.map +1 -0
  90. package/dist/navigation/BottomNav.d.ts +17 -0
  91. package/dist/navigation/BottomNav.js +72 -0
  92. package/dist/navigation/BottomNav.js.map +1 -0
  93. package/dist/navigation/SidebarNav.d.ts +53 -0
  94. package/dist/navigation/SidebarNav.js +594 -0
  95. package/dist/navigation/SidebarNav.js.map +1 -0
  96. package/dist/navigation/Stepper.d.ts +33 -0
  97. package/dist/navigation/Stepper.js +87 -0
  98. package/dist/navigation/Stepper.js.map +1 -0
  99. package/dist/navigation/Tabs.d.ts +23 -0
  100. package/dist/navigation/Tabs.js +174 -0
  101. package/dist/navigation/Tabs.js.map +1 -0
  102. package/dist/navigation/TopBar.d.ts +17 -0
  103. package/dist/navigation/TopBar.js +65 -0
  104. package/dist/navigation/TopBar.js.map +1 -0
  105. package/dist/styles.css +258 -0
  106. package/dist/theme/ThemeProvider.d.ts +12 -0
  107. package/dist/theme/ThemeProvider.js +10 -0
  108. package/dist/theme/ThemeProvider.js.map +1 -0
  109. package/dist/theme/ThemeToggle.d.ts +14 -0
  110. package/dist/theme/ThemeToggle.js +25 -0
  111. package/dist/theme/ThemeToggle.js.map +1 -0
  112. package/package.json +79 -0
@@ -0,0 +1,85 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { X } from "lucide-react";
4
+ import { sx } from "../_internal/style";
5
+ const TONES = {
6
+ success: ["--status-success-bg", "--status-success-fg"],
7
+ warning: ["--status-warning-bg", "--status-warning-fg"],
8
+ error: ["--status-error-bg", "--status-error-fg"],
9
+ info: ["--status-info-bg", "--status-info-fg"],
10
+ neutral: ["--bg-inverse", "--text-inverse"]
11
+ };
12
+ function Toast({ tone = "neutral", title, description, icon, action, onClose, progress, style, ...rest }) {
13
+ const [bg, fg] = TONES[tone] || TONES.neutral;
14
+ return /* @__PURE__ */ jsxs(
15
+ "div",
16
+ {
17
+ role: "status",
18
+ ...rest,
19
+ style: sx({
20
+ position: "relative",
21
+ display: "flex",
22
+ gap: "var(--space-3)",
23
+ // Single-line toasts read better vertically centred; with a description
24
+ // the row items align to the first line instead.
25
+ alignItems: description ? "flex-start" : "center",
26
+ padding: "var(--space-3) var(--space-4)",
27
+ borderRadius: "var(--radius-md)",
28
+ background: "var(" + bg + ")",
29
+ color: "var(" + fg + ")",
30
+ boxShadow: "var(--shadow-lg)",
31
+ border: "var(--border-width-hairline) solid " + (tone === "neutral" ? "transparent" : "color-mix(in srgb,currentColor 18%,transparent)"),
32
+ maxWidth: 420,
33
+ overflow: progress ? "hidden" : void 0,
34
+ animation: "sereno-slide-up var(--duration-normal) var(--ease-out)",
35
+ ...style
36
+ }),
37
+ children: [
38
+ icon && /* @__PURE__ */ jsx("span", { style: sx({ display: "flex", flex: "0 0 auto", marginTop: 1 }), children: icon }),
39
+ /* @__PURE__ */ jsxs("div", { style: sx({ flex: 1, minWidth: 0, display: "flex", flexDirection: "column", gap: 2 }), children: [
40
+ /* @__PURE__ */ jsx("span", { style: sx({ fontFamily: "var(--font-body)", fontSize: "var(--text-sm)", fontWeight: "var(--weight-semibold)" }), children: title }),
41
+ description && /* @__PURE__ */ jsx("span", { style: sx({ fontFamily: "var(--font-body)", fontSize: "var(--text-xs)", opacity: 0.85, lineHeight: 1.45 }), children: description })
42
+ ] }),
43
+ action,
44
+ onClose && /* @__PURE__ */ jsx(
45
+ "button",
46
+ {
47
+ type: "button",
48
+ onClick: onClose,
49
+ "aria-label": "Fechar",
50
+ className: "sereno-dismiss",
51
+ style: sx({
52
+ flex: "0 0 auto",
53
+ display: "inline-flex",
54
+ alignItems: "center",
55
+ justifyContent: "center",
56
+ width: 28,
57
+ height: 28,
58
+ margin: "-3px -6px 0 0",
59
+ border: "none",
60
+ borderRadius: "var(--radius-sm)",
61
+ background: "transparent",
62
+ color: "currentColor",
63
+ opacity: 0.6,
64
+ cursor: "pointer"
65
+ }),
66
+ children: /* @__PURE__ */ jsx(X, { size: 16, strokeWidth: 2 })
67
+ }
68
+ ),
69
+ progress && progress.ms > 0 && Number.isFinite(progress.ms) && /* @__PURE__ */ jsx(
70
+ "span",
71
+ {
72
+ "aria-hidden": true,
73
+ className: "sereno-toast-bar",
74
+ "data-paused": progress.paused ? "true" : void 0,
75
+ style: sx({ animationDuration: progress.ms + "ms" })
76
+ }
77
+ )
78
+ ]
79
+ }
80
+ );
81
+ }
82
+ export {
83
+ Toast
84
+ };
85
+ //# sourceMappingURL=Toast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/feedback/Toast.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { X } from 'lucide-react';\nimport { sx } from '../_internal/style';\n\n/** Transient confirmation of a completed action. One line of title, optional detail. */\nexport interface ToastProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Semantic tone (same five as Badge / Alert). `neutral` is the plain dark toast. */\n tone?: 'success' | 'warning' | 'error' | 'info' | 'neutral';\n title: string;\n description?: string;\n icon?: React.ReactNode;\n action?: React.ReactNode;\n onClose?: () => void;\n /**\n * Auto-dismiss countdown bar along the bottom edge. `ms` is the full duration;\n * `paused` freezes it. `ToastProvider` wires this — you rarely set it by hand.\n */\n progress?: { ms: number; paused?: boolean };\n}\n\nconst TONES: Record<NonNullable<ToastProps['tone']>, [string, string]> = {\n success: ['--status-success-bg', '--status-success-fg'],\n warning: ['--status-warning-bg', '--status-warning-fg'],\n error: ['--status-error-bg', '--status-error-fg'],\n info: ['--status-info-bg', '--status-info-fg'],\n neutral: ['--bg-inverse', '--text-inverse'],\n};\n\nexport function Toast({ tone = 'neutral', title, description, icon, action, onClose, progress, style, ...rest }: ToastProps) {\n const [bg, fg] = TONES[tone] || TONES.neutral;\n return (\n <div\n role=\"status\"\n {...rest}\n style={sx({\n position: 'relative',\n display: 'flex',\n gap: 'var(--space-3)',\n // Single-line toasts read better vertically centred; with a description\n // the row items align to the first line instead.\n alignItems: description ? 'flex-start' : 'center',\n padding: 'var(--space-3) var(--space-4)',\n borderRadius: 'var(--radius-md)',\n background: 'var(' + bg + ')',\n color: 'var(' + fg + ')',\n boxShadow: 'var(--shadow-lg)',\n border: 'var(--border-width-hairline) solid ' + (tone === 'neutral' ? 'transparent' : 'color-mix(in srgb,currentColor 18%,transparent)'),\n maxWidth: 420,\n overflow: progress ? 'hidden' : undefined,\n animation: 'sereno-slide-up var(--duration-normal) var(--ease-out)',\n ...style,\n })}\n >\n {icon && <span style={sx({ display: 'flex', flex: '0 0 auto', marginTop: 1 })}>{icon}</span>}\n <div style={sx({ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 2 })}>\n <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-sm)', fontWeight: 'var(--weight-semibold)' })}>{title}</span>\n {description && <span style={sx({ fontFamily: 'var(--font-body)', fontSize: 'var(--text-xs)', opacity: 0.85, lineHeight: 1.45 })}>{description}</span>}\n </div>\n {action}\n {onClose && (\n <button\n type=\"button\"\n onClick={onClose}\n aria-label=\"Fechar\"\n className=\"sereno-dismiss\"\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: 28,\n height: 28,\n margin: '-3px -6px 0 0',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n color: 'currentColor',\n opacity: 0.6,\n cursor: 'pointer',\n })}\n >\n <X size={16} strokeWidth={2} />\n </button>\n )}\n {progress && progress.ms > 0 && Number.isFinite(progress.ms) && (\n <span\n aria-hidden\n className=\"sereno-toast-bar\"\n data-paused={progress.paused ? 'true' : undefined}\n style={sx({ animationDuration: progress.ms + 'ms' })}\n />\n )}\n </div>\n );\n}"],"mappings":";AAuDe,cACT,YADS;AApDf,SAAS,SAAS;AACl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Y,oBAAoB,UAAU,kBAAkB,SAAS,MAAM,YAAY,KAAK,CAAC,GAAI,uBAAY;AAAA,WACjJ;AAAA,QACC;AAAA,QACA,WACC;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,SAAS;AAAA,YACT,cAAW;AAAA,YACX,WAAU;AAAA,YACV,OAAO,GAAG;AAAA,cACR,MAAM;AAAA,cACN,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,cAChB,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,QAAQ;AAAA,cACR,QAAQ;AAAA,cACR,cAAc;AAAA,cACd,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,SAAS;AAAA,cACT,QAAQ;AAAA,YACV,CAAC;AAAA,YAED,8BAAC,KAAE,MAAM,IAAI,aAAa,GAAG;AAAA;AAAA,QAC/B;AAAA,QAED,YAAY,SAAS,KAAK,KAAK,OAAO,SAAS,SAAS,EAAE,KACzD;AAAA,UAAC;AAAA;AAAA,YACC,eAAW;AAAA,YACX,WAAU;AAAA,YACV,eAAa,SAAS,SAAS,SAAS;AAAA,YACxC,OAAO,GAAG,EAAE,mBAAmB,SAAS,KAAK,KAAK,CAAC;AAAA;AAAA,QACrD;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
@@ -0,0 +1,69 @@
1
+ import * as React from 'react';
2
+ import { ToastProps } from './Toast.js';
3
+
4
+ /**
5
+ * The toast *system* — a portal viewport plus a queue — layered on top of the
6
+ * presentational `Toast`. Wrap the app once:
7
+ *
8
+ * ```tsx
9
+ * <ToastProvider position="bottom-right">
10
+ * <App />
11
+ * </ToastProvider>
12
+ * ```
13
+ *
14
+ * then fire from anywhere under it:
15
+ *
16
+ * ```tsx
17
+ * const { toast, dismiss } = useToast();
18
+ * toast.success('Booking confirmed', { description: 'The client was notified.' });
19
+ * toast('Link copied'); // neutral, title only
20
+ * const id = toast.info('Syncing…', { duration: 0 }); // sticks until dismiss(id)
21
+ * ```
22
+ *
23
+ * Toasts stack (newest nearest the edge), show a countdown bar, auto-dismiss
24
+ * after `duration`, pause that timer (and the bar) while hovered/focused, and
25
+ * cap at `max` — the oldest drops. Needs the `sereno-toast-*` keyframes from
26
+ * `@sereno-ds/ui/styles.css`.
27
+ */
28
+ type Tone = NonNullable<ToastProps['tone']>;
29
+ interface ToastOptions {
30
+ title: string;
31
+ description?: string;
32
+ tone?: Tone;
33
+ icon?: React.ReactNode;
34
+ /** Inline control on the right — an "Undo" / "View" `Button variant="link"`. */
35
+ action?: React.ReactNode;
36
+ /** ms until auto-dismiss. `0` (or `Infinity`) keeps it until dismissed. Defaults to the provider's `duration`. */
37
+ duration?: number;
38
+ }
39
+ /** `msg` shorthand: a bare string becomes the `title`; an object is the full options. */
40
+ type ToastInput = string | ToastOptions;
41
+ type ToneFn = (msg: ToastInput, opts?: Partial<ToastOptions>) => string;
42
+ interface ToastApi {
43
+ /** `toast('Saved')` or `toast('Saved', { description, action, duration })`. Neutral tone. */
44
+ (msg: ToastInput, opts?: Partial<ToastOptions>): string;
45
+ success: ToneFn;
46
+ error: ToneFn;
47
+ warning: ToneFn;
48
+ info: ToneFn;
49
+ neutral: ToneFn;
50
+ }
51
+ interface ToastContextValue {
52
+ toast: ToastApi;
53
+ /** `dismiss(id)` removes one; `dismiss()` clears them all. */
54
+ dismiss: (id?: string) => void;
55
+ }
56
+ type ToastPosition = 'bottom-right' | 'bottom-left' | 'bottom-center' | 'top-right' | 'top-left' | 'top-center';
57
+ interface ToastProviderProps {
58
+ children: React.ReactNode;
59
+ /** Viewport corner. Default `bottom-right`. */
60
+ position?: ToastPosition;
61
+ /** Most toasts on screen at once; the oldest drops when a new one arrives. Default `3`. */
62
+ max?: number;
63
+ /** Default auto-dismiss, in ms. Default `4000`. */
64
+ duration?: number;
65
+ }
66
+ declare function ToastProvider({ children, position, max, duration }: ToastProviderProps): React.JSX.Element;
67
+ declare function useToast(): ToastContextValue;
68
+
69
+ export { type ToastApi, type ToastContextValue, type ToastInput, type ToastOptions, type ToastPosition, ToastProvider, type ToastProviderProps, useToast };
@@ -0,0 +1,183 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { createPortal } from "react-dom";
5
+ import { Toast } from "./Toast";
6
+ import { sx } from "../_internal/style";
7
+ const ToastContext = React.createContext(null);
8
+ const EXIT_MS = 180;
9
+ let seq = 0;
10
+ const nextId = () => `t${Date.now().toString(36)}-${(seq++).toString(36)}`;
11
+ const norm = (msg) => typeof msg === "string" ? { title: msg } : msg;
12
+ const timed = (ms) => ms > 0 && Number.isFinite(ms);
13
+ function ToastProvider({ children, position = "bottom-right", max = 3, duration = 4e3 }) {
14
+ const [entries, setEntries] = React.useState([]);
15
+ const [pausedIds, setPausedIds] = React.useState(() => /* @__PURE__ */ new Set());
16
+ const [mounted, setMounted] = React.useState(false);
17
+ React.useEffect(() => setMounted(true), []);
18
+ const timers = React.useRef(/* @__PURE__ */ new Map());
19
+ const forget = React.useCallback((id) => {
20
+ setPausedIds((s) => {
21
+ if (!s.has(id)) return s;
22
+ const n = new Set(s);
23
+ n.delete(id);
24
+ return n;
25
+ });
26
+ }, []);
27
+ const drop = React.useCallback(
28
+ (id) => {
29
+ const t = timers.current.get(id);
30
+ if (t) clearTimeout(t.handle);
31
+ timers.current.delete(id);
32
+ setEntries((list) => list.map((e) => e.id === id ? { ...e, leaving: true } : e));
33
+ setTimeout(() => {
34
+ setEntries((list) => list.filter((e) => e.id !== id));
35
+ forget(id);
36
+ }, EXIT_MS);
37
+ },
38
+ [forget]
39
+ );
40
+ const arm = React.useCallback(
41
+ (id, ms) => {
42
+ if (!timed(ms)) return;
43
+ const handle = setTimeout(() => drop(id), ms);
44
+ timers.current.set(id, { handle, endsAt: Date.now() + ms, left: ms });
45
+ },
46
+ [drop]
47
+ );
48
+ const pause = React.useCallback((id) => {
49
+ const t = timers.current.get(id);
50
+ if (!t) return;
51
+ clearTimeout(t.handle);
52
+ t.left = Math.max(0, t.endsAt - Date.now());
53
+ setPausedIds((s) => s.has(id) ? s : new Set(s).add(id));
54
+ }, []);
55
+ const resume = React.useCallback(
56
+ (id) => {
57
+ const t = timers.current.get(id);
58
+ if (t) {
59
+ t.handle = setTimeout(() => drop(id), t.left);
60
+ t.endsAt = Date.now() + t.left;
61
+ }
62
+ forget(id);
63
+ },
64
+ [drop, forget]
65
+ );
66
+ const add = React.useCallback(
67
+ (opts) => {
68
+ const id = nextId();
69
+ const ms = opts.duration ?? duration;
70
+ setEntries((list) => {
71
+ const next = [...list, { ...opts, id, ms }];
72
+ while (next.filter((e) => !e.leaving).length > max) {
73
+ const victim = next.find((e) => !e.leaving);
74
+ if (!victim) break;
75
+ const vt = timers.current.get(victim.id);
76
+ if (vt) clearTimeout(vt.handle);
77
+ timers.current.delete(victim.id);
78
+ victim.leaving = true;
79
+ setTimeout(() => {
80
+ setEntries((l) => l.filter((e) => e.id !== victim.id));
81
+ forget(victim.id);
82
+ }, EXIT_MS);
83
+ }
84
+ return next;
85
+ });
86
+ arm(id, ms);
87
+ return id;
88
+ },
89
+ [arm, duration, forget, max]
90
+ );
91
+ const fire = React.useCallback(
92
+ (msg, opts, tone) => add({ title: "", ...norm(msg), ...opts, ...tone ? { tone } : {} }),
93
+ [add]
94
+ );
95
+ const toast = React.useMemo(() => {
96
+ const base = (msg, opts) => fire(msg, opts);
97
+ const make = (tone) => (msg, opts) => fire(msg, opts, tone);
98
+ return Object.assign(base, {
99
+ success: make("success"),
100
+ error: make("error"),
101
+ warning: make("warning"),
102
+ info: make("info"),
103
+ neutral: make("neutral")
104
+ });
105
+ }, [fire]);
106
+ const dismiss = React.useCallback(
107
+ (id) => {
108
+ if (id) {
109
+ drop(id);
110
+ return;
111
+ }
112
+ entries.forEach((e) => !e.leaving && drop(e.id));
113
+ },
114
+ [drop, entries]
115
+ );
116
+ const value = React.useMemo(() => ({ toast, dismiss }), [toast, dismiss]);
117
+ React.useEffect(() => {
118
+ const map = timers.current;
119
+ return () => map.forEach((t) => clearTimeout(t.handle));
120
+ }, []);
121
+ const [edge, side] = position.split("-");
122
+ const viewport = sx({
123
+ position: "fixed",
124
+ zIndex: 1200,
125
+ display: "flex",
126
+ // Newest nearest the anchored edge: normal flow for bottom, reversed for top.
127
+ flexDirection: edge === "bottom" ? "column" : "column-reverse",
128
+ gap: "var(--space-3)",
129
+ width: "min(420px, calc(100vw - var(--space-8)))",
130
+ maxHeight: "100dvh",
131
+ padding: "var(--space-4)",
132
+ pointerEvents: "none",
133
+ [edge]: 0,
134
+ // Every toast is full-width of the viewport, so the stack edges line up on
135
+ // any side; `alignItems` only matters if a toast were ever narrower.
136
+ alignItems: "stretch",
137
+ ...side === "center" ? { left: "50%", transform: "translateX(-50%)" } : { [side]: 0 }
138
+ });
139
+ return /* @__PURE__ */ jsxs(ToastContext.Provider, { value, children: [
140
+ children,
141
+ mounted && entries.length > 0 && createPortal(
142
+ /* @__PURE__ */ jsx("div", { role: "region", "aria-label": "Notifications", style: viewport, children: entries.map((e) => /* @__PURE__ */ jsx(
143
+ "div",
144
+ {
145
+ className: "sereno-toast-item",
146
+ "data-edge": edge,
147
+ "data-leaving": e.leaving ? "true" : void 0,
148
+ onMouseEnter: () => pause(e.id),
149
+ onMouseLeave: () => resume(e.id),
150
+ onFocusCapture: () => pause(e.id),
151
+ onBlurCapture: () => resume(e.id),
152
+ style: sx({ pointerEvents: "auto", width: "100%" }),
153
+ children: /* @__PURE__ */ jsx(
154
+ Toast,
155
+ {
156
+ tone: e.tone,
157
+ title: e.title,
158
+ description: e.description,
159
+ icon: e.icon,
160
+ action: e.action,
161
+ role: e.tone === "error" ? "alert" : "status",
162
+ onClose: () => drop(e.id),
163
+ progress: timed(e.ms) && !e.leaving ? { ms: e.ms, paused: pausedIds.has(e.id) } : void 0,
164
+ style: { width: "100%", maxWidth: "none" }
165
+ }
166
+ )
167
+ },
168
+ e.id
169
+ )) }),
170
+ document.body
171
+ )
172
+ ] });
173
+ }
174
+ function useToast() {
175
+ const ctx = React.useContext(ToastContext);
176
+ if (!ctx) throw new Error("useToast() must be called inside <ToastProvider>.");
177
+ return ctx;
178
+ }
179
+ export {
180
+ ToastProvider,
181
+ useToast
182
+ };
183
+ //# sourceMappingURL=ToastProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/feedback/ToastProvider.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Toast, type ToastProps } from './Toast';\nimport { sx } from '../_internal/style';\n\n/**\n * The toast *system* — a portal viewport plus a queue — layered on top of the\n * presentational `Toast`. Wrap the app once:\n *\n * ```tsx\n * <ToastProvider position=\"bottom-right\">\n * <App />\n * </ToastProvider>\n * ```\n *\n * then fire from anywhere under it:\n *\n * ```tsx\n * const { toast, dismiss } = useToast();\n * toast.success('Booking confirmed', { description: 'The client was notified.' });\n * toast('Link copied'); // neutral, title only\n * const id = toast.info('Syncing…', { duration: 0 }); // sticks until dismiss(id)\n * ```\n *\n * Toasts stack (newest nearest the edge), show a countdown bar, auto-dismiss\n * after `duration`, pause that timer (and the bar) while hovered/focused, and\n * cap at `max` — the oldest drops. Needs the `sereno-toast-*` keyframes from\n * `@sereno-ds/ui/styles.css`.\n */\n\ntype Tone = NonNullable<ToastProps['tone']>;\n\nexport interface ToastOptions {\n title: string;\n description?: string;\n tone?: Tone;\n icon?: React.ReactNode;\n /** Inline control on the right — an \"Undo\" / \"View\" `Button variant=\"link\"`. */\n action?: React.ReactNode;\n /** ms until auto-dismiss. `0` (or `Infinity`) keeps it until dismissed. Defaults to the provider's `duration`. */\n duration?: number;\n}\n\n/** `msg` shorthand: a bare string becomes the `title`; an object is the full options. */\nexport type ToastInput = string | ToastOptions;\n\ntype ToneFn = (msg: ToastInput, opts?: Partial<ToastOptions>) => string;\n\nexport interface ToastApi {\n /** `toast('Saved')` or `toast('Saved', { description, action, duration })`. Neutral tone. */\n (msg: ToastInput, opts?: Partial<ToastOptions>): string;\n success: ToneFn;\n error: ToneFn;\n warning: ToneFn;\n info: ToneFn;\n neutral: ToneFn;\n}\n\nexport interface ToastContextValue {\n toast: ToastApi;\n /** `dismiss(id)` removes one; `dismiss()` clears them all. */\n dismiss: (id?: string) => void;\n}\n\nconst ToastContext = React.createContext<ToastContextValue | null>(null);\n\nexport type ToastPosition =\n | 'bottom-right'\n | 'bottom-left'\n | 'bottom-center'\n | 'top-right'\n | 'top-left'\n | 'top-center';\n\nexport interface ToastProviderProps {\n children: React.ReactNode;\n /** Viewport corner. Default `bottom-right`. */\n position?: ToastPosition;\n /** Most toasts on screen at once; the oldest drops when a new one arrives. Default `3`. */\n max?: number;\n /** Default auto-dismiss, in ms. Default `4000`. */\n duration?: number;\n}\n\ninterface Entry extends ToastOptions {\n id: string;\n /** Resolved auto-dismiss (ms) — `opts.duration ?? provider duration`. `0` / `Infinity` = sticky. */\n ms: number;\n leaving?: boolean;\n}\n\nconst EXIT_MS = 180;\nlet seq = 0;\nconst nextId = () => `t${Date.now().toString(36)}-${(seq++).toString(36)}`;\n\nconst norm = (msg: ToastInput): Partial<ToastOptions> => (typeof msg === 'string' ? { title: msg } : msg);\nconst timed = (ms: number) => ms > 0 && Number.isFinite(ms);\n\nexport function ToastProvider({ children, position = 'bottom-right', max = 3, duration = 4000 }: ToastProviderProps) {\n const [entries, setEntries] = React.useState<Entry[]>([]);\n const [pausedIds, setPausedIds] = React.useState<ReadonlySet<string>>(() => new Set());\n\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n\n // Per-toast auto-dismiss timers, so hover/focus can pause and resume them.\n const timers = React.useRef(new Map<string, { handle: ReturnType<typeof setTimeout>; endsAt: number; left: number }>());\n\n const forget = React.useCallback((id: string) => {\n setPausedIds((s) => {\n if (!s.has(id)) return s;\n const n = new Set(s);\n n.delete(id);\n return n;\n });\n }, []);\n\n const drop = React.useCallback(\n (id: string) => {\n const t = timers.current.get(id);\n if (t) clearTimeout(t.handle);\n timers.current.delete(id);\n setEntries((list) => list.map((e) => (e.id === id ? { ...e, leaving: true } : e)));\n setTimeout(() => {\n setEntries((list) => list.filter((e) => e.id !== id));\n forget(id);\n }, EXIT_MS);\n },\n [forget],\n );\n\n const arm = React.useCallback(\n (id: string, ms: number) => {\n if (!timed(ms)) return;\n const handle = setTimeout(() => drop(id), ms);\n timers.current.set(id, { handle, endsAt: Date.now() + ms, left: ms });\n },\n [drop],\n );\n\n const pause = React.useCallback((id: string) => {\n const t = timers.current.get(id);\n if (!t) return;\n clearTimeout(t.handle);\n t.left = Math.max(0, t.endsAt - Date.now());\n setPausedIds((s) => (s.has(id) ? s : new Set(s).add(id)));\n }, []);\n\n const resume = React.useCallback(\n (id: string) => {\n const t = timers.current.get(id);\n if (t) {\n t.handle = setTimeout(() => drop(id), t.left);\n t.endsAt = Date.now() + t.left;\n }\n forget(id);\n },\n [drop, forget],\n );\n\n const add = React.useCallback(\n (opts: ToastOptions) => {\n const id = nextId();\n const ms = opts.duration ?? duration;\n setEntries((list) => {\n const next: Entry[] = [...list, { ...opts, id, ms }];\n // Cap: hard-drop the oldest that isn't already leaving.\n while (next.filter((e) => !e.leaving).length > max) {\n const victim = next.find((e) => !e.leaving);\n if (!victim) break;\n const vt = timers.current.get(victim.id);\n if (vt) clearTimeout(vt.handle);\n timers.current.delete(victim.id);\n victim.leaving = true;\n setTimeout(() => {\n setEntries((l) => l.filter((e) => e.id !== victim.id));\n forget(victim.id);\n }, EXIT_MS);\n }\n return next;\n });\n arm(id, ms);\n return id;\n },\n [arm, duration, forget, max],\n );\n\n // Tone-specific methods always paint their tone; bare `toast(...)` respects a\n // `tone` in the message / options and otherwise stays neutral.\n const fire = React.useCallback(\n (msg: ToastInput, opts?: Partial<ToastOptions>, tone?: Tone) =>\n add({ title: '', ...norm(msg), ...opts, ...(tone ? { tone } : {}) } as ToastOptions),\n [add],\n );\n\n /* eslint-disable react-hooks/refs -- `fire` transitively reaches the `timers` ref, but only when a\n consumer invokes toast.*() from an event handler — never during render. `useMemo` just keeps\n the callable API object's identity stable. */\n const toast = React.useMemo<ToastApi>(() => {\n const base = (msg: ToastInput, opts?: Partial<ToastOptions>) => fire(msg, opts);\n const make = (tone: Tone): ToneFn => (msg, opts) => fire(msg, opts, tone);\n return Object.assign(base, {\n success: make('success'),\n error: make('error'),\n warning: make('warning'),\n info: make('info'),\n neutral: make('neutral'),\n }) as ToastApi;\n }, [fire]);\n /* eslint-enable react-hooks/refs */\n\n const dismiss = React.useCallback(\n (id?: string) => {\n if (id) {\n drop(id);\n return;\n }\n entries.forEach((e) => !e.leaving && drop(e.id));\n },\n [drop, entries],\n );\n\n const value = React.useMemo<ToastContextValue>(() => ({ toast, dismiss }), [toast, dismiss]);\n\n // Clear every pending timer on unmount.\n React.useEffect(() => {\n const map = timers.current;\n return () => map.forEach((t) => clearTimeout(t.handle));\n }, []);\n\n const [edge, side] = position.split('-') as ['top' | 'bottom', 'right' | 'left' | 'center'];\n const viewport = sx({\n position: 'fixed',\n zIndex: 1200,\n display: 'flex',\n // Newest nearest the anchored edge: normal flow for bottom, reversed for top.\n flexDirection: edge === 'bottom' ? 'column' : 'column-reverse',\n gap: 'var(--space-3)',\n width: 'min(420px, calc(100vw - var(--space-8)))',\n maxHeight: '100dvh',\n padding: 'var(--space-4)',\n pointerEvents: 'none',\n [edge]: 0,\n // Every toast is full-width of the viewport, so the stack edges line up on\n // any side; `alignItems` only matters if a toast were ever narrower.\n alignItems: 'stretch',\n ...(side === 'center' ? { left: '50%', transform: 'translateX(-50%)' } : { [side]: 0 }),\n });\n\n return (\n <ToastContext.Provider value={value}>\n {children}\n {mounted &&\n entries.length > 0 &&\n createPortal(\n <div role=\"region\" aria-label=\"Notifications\" style={viewport}>\n {entries.map((e) => (\n <div\n key={e.id}\n className=\"sereno-toast-item\"\n data-edge={edge}\n data-leaving={e.leaving ? 'true' : undefined}\n onMouseEnter={() => pause(e.id)}\n onMouseLeave={() => resume(e.id)}\n onFocusCapture={() => pause(e.id)}\n onBlurCapture={() => resume(e.id)}\n style={sx({ pointerEvents: 'auto', width: '100%' })}\n >\n <Toast\n tone={e.tone}\n title={e.title}\n description={e.description}\n icon={e.icon}\n action={e.action}\n role={e.tone === 'error' ? 'alert' : 'status'}\n onClose={() => drop(e.id)}\n progress={timed(e.ms) && !e.leaving ? { ms: e.ms, paused: pausedIds.has(e.id) } : undefined}\n style={{ width: '100%', maxWidth: 'none' }}\n />\n </div>\n ))}\n </div>,\n document.body,\n )}\n </ToastContext.Provider>\n );\n}\n\nexport function useToast(): ToastContextValue {\n const ctx = React.useContext(ToastContext);\n if (!ctx) throw new Error('useToast() must be called inside <ToastProvider>.');\n return ctx;\n}\n"],"mappings":";AA6PI,SAkBY,KAlBZ;AA3PJ,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,aAA8B;AACvC,SAAS,UAAU;AA6DnB,MAAM,eAAe,MAAM,cAAwC,IAAI;AA2BvE,MAAM,UAAU;AAChB,IAAI,MAAM;AACV,MAAM,SAAS,MAAM,IAAI,KAAK,IAAI,EAAE,SAAS,EAAE,CAAC,KAAK,OAAO,SAAS,EAAE,CAAC;AAExE,MAAM,OAAO,CAAC,QAA4C,OAAO,QAAQ,WAAW,EAAE,OAAO,IAAI,IAAI;AACrG,MAAM,QAAQ,CAAC,OAAe,KAAK,KAAK,OAAO,SAAS,EAAE;AAEnD,SAAS,cAAc,EAAE,UAAU,WAAW,gBAAgB,MAAM,GAAG,WAAW,IAAK,GAAuB;AACnH,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAkB,CAAC,CAAC;AACxD,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAA8B,MAAM,oBAAI,IAAI,CAAC;AAErF,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAS,KAAK;AAElD,QAAM,UAAU,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAG1C,QAAM,SAAS,MAAM,OAAO,oBAAI,IAAqF,CAAC;AAEtH,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;AAC5C,QAAM,MAAM,MAAM,WAAW,YAAY;AACzC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,mDAAmD;AAC7E,SAAO;AACT;","names":[]}
@@ -0,0 +1,57 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * Profile-photo picker: an avatar disc with a camera button. Pick from the
5
+ * library (or the camera on touch), frame the face in a circular crop, and it
6
+ * hands back a **cropped, downscaled** `File` (JPEG). For attachments / documents
7
+ * / multiple files use `FileUpload` instead.
8
+ *
9
+ * Client-side only downscales and re-encodes; it does not decode HEIC (no
10
+ * browser but Safari can) — that is a server-side job. HEIC picks are rejected
11
+ * with a message.
12
+ */
13
+ /** User-facing strings — English by default; pass overrides for another locale. */
14
+ interface AvatarUploadLabels {
15
+ trigger: string;
16
+ upload: string;
17
+ takePhoto: string;
18
+ remove: string;
19
+ cropTitle: string;
20
+ cropHint: string;
21
+ cameraTitle: string;
22
+ cameraHint: string;
23
+ capture: string;
24
+ cancel: string;
25
+ save: string;
26
+ zoom: string;
27
+ heicError: string;
28
+ notImage: string;
29
+ tooLarge: (mb: number) => string;
30
+ unreadable: string;
31
+ cameraError: string;
32
+ }
33
+ interface AvatarUploadProps {
34
+ /** Full name — drives the initials fallback and the alt text. */
35
+ name?: string;
36
+ /** Current photo: a `File` (freshly cropped) or an existing URL string. */
37
+ value?: File | string | null;
38
+ onChange?: (file: File | null) => void;
39
+ /** Disc diameter in px. */
40
+ size?: number;
41
+ /** Exported square size in px — the crop is drawn to this. */
42
+ outputSize?: number;
43
+ /** Reject picks larger than this (before crop). */
44
+ maxSizeMB?: number;
45
+ /** Override the English UI strings (menu, crop dialog, messages). */
46
+ labels?: Partial<AvatarUploadLabels>;
47
+ label?: string;
48
+ hint?: string;
49
+ error?: string;
50
+ required?: boolean;
51
+ disabled?: boolean;
52
+ id?: string;
53
+ containerStyle?: React.CSSProperties;
54
+ }
55
+ declare function AvatarUpload({ name, value, onChange, size, outputSize, maxSizeMB, labels: labelsProp, label, hint, error, required, disabled, id, containerStyle, }: AvatarUploadProps): React.JSX.Element;
56
+
57
+ export { AvatarUpload, type AvatarUploadLabels, type AvatarUploadProps };