@majapisoftwares/ui 6.6.0 → 6.7.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/docs/STANDARDS.md
CHANGED
|
@@ -12,7 +12,7 @@ TypeScript em modo strict, React com componentes funcionais e composição. APIs
|
|
|
12
12
|
|
|
13
13
|
`src/styles.css` é a fonte dos tokens de cor, tipografia, raio, bordas, foco, estados e estrutura. Preset base-luma do shadcn (o mesmo da home de ui.shadcn.com: cantos bem arredondados, campos com fundo suave, sombras leves) sobre o tema neutral, fonte Geist, foco visível e espaço consistente. Cores são semânticas: background, foreground, primary, muted, destructive, success e warning. Temas claro/escuro preservam a semântica. Tokens e padrões podem evoluir nesta biblioteca, nunca por overrides locais em um produto.
|
|
14
14
|
|
|
15
|
-
Primitivos shadcn ficam em src/components/ui (Button, Badge, Card, Input, Table, Sheet, Sidebar, Tooltip, DropdownMenu, ContextMenu, Breadcrumb, Avatar, Checkbox, Collapsible, Alert, Empty, Select, Separator, Skeleton, Tabs, Field e Label).
|
|
15
|
+
Primitivos shadcn ficam em src/components/ui (Button, Badge, Card, Input, Table, Sheet, Sidebar, Tooltip, DropdownMenu, ContextMenu, Breadcrumb, Avatar, Checkbox, Collapsible, Alert, Empty, Select, Separator, Skeleton, Tabs, Field e Label). Toast (com `toast` e `toastError`) é a notificação. Padrões compostos: AppShell (slots `sidebarHeader` e `footer`), WorkspaceSwitcher, UserMenu, PageHeader, MetricStrip, StatusBadge, DataTable, DetailsSheet, DetailList, Preferences, PreferenceControls e MajapiLogo. Templates React: AdminDashboard, AuthLayout, LoginForm e SignupForm. Marca, navegação, textos, dados, ações e slots são configuráveis. Todos os apps atuais e futuros devem consumir esta base pública; ela não conhece AWS ou outro domínio.
|
|
16
16
|
|
|
17
17
|
## Comportamentos de UX
|
|
18
18
|
|
|
@@ -25,7 +25,7 @@ DataTable mantém os resets de paginação fora da avaliação de row models dur
|
|
|
25
25
|
- Não repetir o que já está na tela: o breadcrumb nomeia a página, então ela não ganha um título `PageHeader` com o mesmo nome. Na sidebar, o grupo abre a página principal da ferramenta, que não aparece de novo como subitem. O mesmo vale para títulos de diálogo, rótulos e descrições que repetem um texto visível.
|
|
26
26
|
- Rótulos curtos, em uma linha: botões, itens de menu, abas e badges não quebram linha. Menus se ajustam à largura do conteúdo (não à do botão que os abre); se o texto não couber, encurte-o.
|
|
27
27
|
- Estados com texto e cor: sucesso, aviso, erro e desconhecido. Nunca traduzir ausência de informação em zero ou sucesso.
|
|
28
|
-
- Notificações usam
|
|
28
|
+
- Notificações usam o toast do shadcn (`components/toast`, sobre o Toast do Base UI), para informação e para erro: `toast.add({ description })` (ou `title` e `description`, `type` success/info/warning/loading) e `toastError(erro)` para falhas (tipo error, prioridade alta), com no máximo uma ação curta em `actionProps` (Desfazer, Tentar de novo). Preferences monta o `Toaster`. Falhas de ações (salvar, enviar, criar) vão para `toastError`, não para texto dentro do formulário ou do diálogo; o diálogo continua aberto para a pessoa corrigir e tentar de novo. Só a validação de um campo fica junto do campo (FieldError). `toast`/`Toaster` de `components/sonner` e `snackbar` de `components/snackbar` estão obsoletos e já aparecem como esse toast.
|
|
29
29
|
- Carregamento usa Skeleton, vazio usa Empty, falhas usam Alert e detalhes usam DetailsSheet com título, descrição, foco preso ao overlay, Escape e devolução do foco ao fechar.
|
|
30
30
|
- Em telas pequenas, controles têm texto de pelo menos 16px e alvo de 44px, navegação se reorganiza e tabelas têm rolagem interna, sem rolagem horizontal da página.
|
|
31
31
|
- Preferência por movimento reduzido é respeitada. A ordem de leitura deve acompanhar a ordem visual. Ícones sozinhos exigem nome acessível.
|
|
@@ -57,7 +57,7 @@ Base do shadcn AI Elements (Base UI) instalada pelo CLI: `message-scroller` (`@s
|
|
|
57
57
|
- `patterns/chat-markdown`: `ChatMarkdown` com Streamdown (sanitiza a saída do modelo, completa markdown incompleto durante o streaming e traduz os controles). Substitui o react-markdown da Numa.
|
|
58
58
|
- `hooks/use-streamed-text`: revela progressivamente uma resposta que chega inteira (Numa), respeitando movimento reduzido.
|
|
59
59
|
|
|
60
|
-
Erros de resposta aparecem na própria mensagem (Bubble `destructive`) com Tentar novamente; erros de ações fora da conversa vão para o
|
|
60
|
+
Erros de resposta aparecem na própria mensagem (Bubble `destructive`) com Tentar novamente; erros de ações fora da conversa vão para o toast (`toastError`). O catálogo demonstra em `/chat` (conversa com raciocínio, ferramentas, aprovação, erro e retry) e `/chat/new` (vazio com sugestões).
|
|
61
61
|
|
|
62
62
|
Adaptações: `MessageScrollerItem` usa `-m-2 p-2` (e `MessageScrollerContent`, `p-2`) porque `content-visibility: auto` sempre aplica contenção de pintura e cortava sombras e anéis de foco na borda de cada linha; não remova essa margem nem coloque itens em contêineres sem o padding correspondente. `message-scroller` também traduz o nome da região e do botão, troca utilitários de barra de rolagem que não existem aqui por `[scrollbar-gutter:stable]` e exporta `useMessageScrollerGutterWidth`; `attachment` usa `no-scrollbar`. `styles.css` importa `streamdown/styles.css` e adiciona o `@source` do Streamdown. `hast-util-raw` 9.2 exige `parse5` 8.1+; mantenha o lockfile sem `parse5` 8.0.
|
|
63
63
|
|
package/package.json
CHANGED
|
@@ -29,8 +29,8 @@ async function visit(path) {
|
|
|
29
29
|
)
|
|
30
30
|
)
|
|
31
31
|
violations.push(`${name}: use semantic tokens instead of local colors`);
|
|
32
|
-
if (consumer && /from\s+["'](?:sonner|@majapisoftwares\/ui\/components\/sonner)["']/.test(text))
|
|
33
|
-
violations.push(`${name}: notify with
|
|
32
|
+
if (consumer && /from\s+["'](?:sonner|@majapisoftwares\/ui\/components\/(?:sonner|snackbar))["']/.test(text))
|
|
33
|
+
violations.push(`${name}: notify with toast from @majapisoftwares/ui/components/toast`);
|
|
34
34
|
if (!consumer && /from ["']@\//.test(text))
|
|
35
35
|
violations.push(`${name}: library internals must use portable imports`);
|
|
36
36
|
}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { Toaster as Sonner, toast, type ToasterProps } from "sonner";
|
|
6
|
-
import { Orb } from "./orb";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { errorMessage, toast, toastError } from "./toast";
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* an optional action. Errors stay on screen longer and carry an icon; field
|
|
12
|
-
* validation stays next to its field.
|
|
13
|
-
*
|
|
14
|
-
* Mount `<Snackbar />` once (Preferences does) and call `snackbar(message)`
|
|
15
|
-
* or `snackbar.error(message)` from anywhere on the client.
|
|
7
|
+
* @deprecated Notifications are the shadcn toast: `toast.add({ description })`
|
|
8
|
+
* and `toastError(error)` from `components/toast`. These forward to it.
|
|
16
9
|
*/
|
|
17
10
|
|
|
18
11
|
export interface SnackbarAction {
|
|
@@ -20,81 +13,40 @@ export interface SnackbarAction {
|
|
|
20
13
|
onClick: () => void;
|
|
21
14
|
}
|
|
22
15
|
|
|
16
|
+
/** @deprecated Use `toast.add` options from `components/toast`. */
|
|
23
17
|
export interface SnackbarOptions {
|
|
24
|
-
/** One short action, such as Undo or Retry. */
|
|
25
18
|
action?: SnackbarAction;
|
|
26
|
-
/** Milliseconds on screen; info 4 s and errors 8 s by default. */
|
|
27
19
|
duration?: number;
|
|
28
|
-
/** Replaces the snackbar with the same id instead of queueing another. */
|
|
29
20
|
id?: string | number;
|
|
30
21
|
}
|
|
31
22
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
duration: value?.duration ?? duration,
|
|
37
|
-
...(value?.id !== undefined ? { id: value.id } : {}),
|
|
38
|
-
...(value?.action ? { action: { label: value.action.label, onClick: value.action.onClick } } : {}),
|
|
23
|
+
const options = (value: SnackbarOptions | undefined) => ({
|
|
24
|
+
...(value?.duration !== undefined ? { timeout: value.duration } : {}),
|
|
25
|
+
...(value?.id !== undefined ? { id: String(value.id) } : {}),
|
|
26
|
+
...(value?.action ? { actionProps: { children: value.action.label, onClick: value.action.onClick } } : {}),
|
|
39
27
|
});
|
|
40
28
|
|
|
41
|
-
/**
|
|
29
|
+
/** @deprecated Use `toast.add({ description })` from `components/toast`. */
|
|
42
30
|
function show(message: ReactNode, value?: SnackbarOptions) {
|
|
43
|
-
return toast(message, options(value
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** The message of an error or of anything thrown. */
|
|
47
|
-
export function errorMessage(error: unknown): string {
|
|
48
|
-
if (error instanceof Error) return error.message;
|
|
49
|
-
return typeof error === "string" ? error : String(error);
|
|
31
|
+
return toast.add({ description: message, ...options(value) });
|
|
50
32
|
}
|
|
51
33
|
|
|
34
|
+
/** @deprecated Use `toast` and `toastError` from `components/toast`. */
|
|
52
35
|
export const snackbar = Object.assign(show, {
|
|
53
|
-
/**
|
|
36
|
+
/** @deprecated Use `toastError(error)` from `components/toast`. */
|
|
54
37
|
error(message: unknown, value?: SnackbarOptions) {
|
|
55
|
-
|
|
56
|
-
return toast.error(text, options(value, ERROR_MS));
|
|
38
|
+
return value ? toast.add({ type: "error", priority: "high", description: errorMessage(message), ...options(value) }) : toastError(message);
|
|
57
39
|
},
|
|
58
|
-
/**
|
|
40
|
+
/** @deprecated Use `toast.close(id)` from `components/toast`. */
|
|
59
41
|
dismiss(id?: string | number) {
|
|
60
|
-
|
|
42
|
+
toast.close(id === undefined ? undefined : String(id));
|
|
61
43
|
},
|
|
62
44
|
});
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
visibleToasts={1}
|
|
71
|
-
offset={24}
|
|
72
|
-
mobileOffset={16}
|
|
73
|
-
className="snackbar group"
|
|
74
|
-
icons={{
|
|
75
|
-
success: null,
|
|
76
|
-
info: null,
|
|
77
|
-
warning: <TriangleAlertIcon className="size-4" />,
|
|
78
|
-
error: <CircleAlertIcon className="size-4 text-destructive" />,
|
|
79
|
-
loading: <Orb size={16} />,
|
|
80
|
-
}}
|
|
81
|
-
style={{ "--width": "min(36rem, calc(100vw - 2rem))" } as CSSProperties}
|
|
82
|
-
toastOptions={{
|
|
83
|
-
unstyled: true,
|
|
84
|
-
classNames: {
|
|
85
|
-
toast:
|
|
86
|
-
"cn-snackbar flex w-(--width) items-center gap-3 rounded-xl bg-foreground px-4 py-3 text-sm text-background shadow-lg data-[type=error]:pr-3",
|
|
87
|
-
content: "min-w-0 flex-1",
|
|
88
|
-
title: "leading-5 break-words",
|
|
89
|
-
description: "text-background/70",
|
|
90
|
-
icon: "flex shrink-0 items-center",
|
|
91
|
-
actionButton:
|
|
92
|
-
"shrink-0 rounded-full px-3 py-1.5 text-sm font-medium text-background underline-offset-4 hover:bg-background/10 focus-visible:outline-2 focus-visible:outline-background",
|
|
93
|
-
cancelButton: "shrink-0 rounded-full px-3 py-1.5 text-sm text-background/70 hover:bg-background/10",
|
|
94
|
-
closeButton: "hidden",
|
|
95
|
-
},
|
|
96
|
-
}}
|
|
97
|
-
{...props}
|
|
98
|
-
/>
|
|
99
|
-
);
|
|
46
|
+
export { errorMessage };
|
|
47
|
+
|
|
48
|
+
/** @deprecated Preferences mounts the toast `Toaster`; this renders nothing. */
|
|
49
|
+
export function Snackbar(props: { theme?: string }) {
|
|
50
|
+
void props;
|
|
51
|
+
return null;
|
|
100
52
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Orb } from "./orb";
|
|
4
4
|
import { Toaster as Sonner, type ToasterProps } from "sonner";
|
|
5
|
+
import { toast as manager } from "./toast";
|
|
5
6
|
import {
|
|
6
7
|
CircleCheckIcon,
|
|
7
8
|
InfoIcon,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
} from "lucide-react";
|
|
11
12
|
|
|
12
13
|
// Theme comes from the caller (Preferences passes the active theme).
|
|
13
|
-
/** @deprecated Notifications are
|
|
14
|
+
/** @deprecated Notifications are the shadcn toast: Preferences mounts its `Toaster` from `components/toast`. */
|
|
14
15
|
const Toaster = ({ theme = "system", ...props }: ToasterProps) => {
|
|
15
16
|
return (
|
|
16
17
|
<Sonner
|
|
@@ -42,5 +43,37 @@ const Toaster = ({ theme = "system", ...props }: ToasterProps) => {
|
|
|
42
43
|
};
|
|
43
44
|
|
|
44
45
|
export { Toaster };
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
type Message = React.ReactNode;
|
|
47
|
+
interface LegacyOptions {
|
|
48
|
+
description?: React.ReactNode;
|
|
49
|
+
duration?: number;
|
|
50
|
+
id?: string | number;
|
|
51
|
+
action?: { label: React.ReactNode; onClick: () => void };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const legacy = (type: string | undefined, message: Message, options?: LegacyOptions) =>
|
|
55
|
+
manager.add({
|
|
56
|
+
...(type ? { type } : {}),
|
|
57
|
+
...(type === "error" ? { priority: "high" as const } : {}),
|
|
58
|
+
// A message with a description reads as a title over it, as in sonner.
|
|
59
|
+
...(options?.description ? { title: message, description: options.description } : { description: message }),
|
|
60
|
+
...(options?.duration !== undefined ? { timeout: options.duration } : {}),
|
|
61
|
+
...(options?.id !== undefined ? { id: String(options.id) } : {}),
|
|
62
|
+
...(options?.action ? { actionProps: { children: options.action.label, onClick: options.action.onClick } } : {}),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use `toast.add(...)` and `toastError(error)` from `components/toast`
|
|
67
|
+
* (the shadcn toast). These calls already show as that toast.
|
|
68
|
+
*/
|
|
69
|
+
const toast = Object.assign((message: Message, options?: LegacyOptions) => legacy(undefined, message, options), {
|
|
70
|
+
message: (message: Message, options?: LegacyOptions) => legacy(undefined, message, options),
|
|
71
|
+
success: (message: Message, options?: LegacyOptions) => legacy("success", message, options),
|
|
72
|
+
info: (message: Message, options?: LegacyOptions) => legacy("info", message, options),
|
|
73
|
+
warning: (message: Message, options?: LegacyOptions) => legacy("warning", message, options),
|
|
74
|
+
error: (message: Message, options?: LegacyOptions) => legacy("error", message, options),
|
|
75
|
+
loading: (message: Message, options?: LegacyOptions) => legacy("loading", message, options),
|
|
76
|
+
dismiss: (id?: string | number) => manager.close(id === undefined ? undefined : String(id)),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export { toast };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Toast as ToastPrimitive } from "@base-ui/react/toast";
|
|
5
|
+
import { cn } from "cn";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CircleCheckIcon,
|
|
9
|
+
InfoIcon,
|
|
10
|
+
Loader2Icon,
|
|
11
|
+
OctagonXIcon,
|
|
12
|
+
TriangleAlertIcon,
|
|
13
|
+
XIcon,
|
|
14
|
+
} from "lucide-react";
|
|
15
|
+
|
|
16
|
+
import { useUiMessages } from "../../lib/i18n";
|
|
17
|
+
import { Button } from "./button";
|
|
18
|
+
|
|
19
|
+
const toast = ToastPrimitive.createToastManager();
|
|
20
|
+
|
|
21
|
+
function ToastProvider({ ...props }: ToastPrimitive.Provider.Props) {
|
|
22
|
+
return <ToastPrimitive.Provider {...props} />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function ToastPortal({ ...props }: ToastPrimitive.Portal.Props) {
|
|
26
|
+
return <ToastPrimitive.Portal data-slot="toast-portal" {...props} />;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function ToastViewport({ className, ...props }: ToastPrimitive.Viewport.Props) {
|
|
30
|
+
return (
|
|
31
|
+
<ToastPrimitive.Viewport
|
|
32
|
+
data-slot="toast-viewport"
|
|
33
|
+
className={cn(
|
|
34
|
+
"pointer-events-none fixed inset-x-4 bottom-4 z-[100] mx-auto w-auto max-w-sm outline-none sm:right-4 sm:left-auto sm:mx-0 sm:w-full",
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function Toast({ className, ...props }: ToastPrimitive.Root.Props) {
|
|
43
|
+
return (
|
|
44
|
+
<ToastPrimitive.Root
|
|
45
|
+
data-slot="toast"
|
|
46
|
+
className={cn(
|
|
47
|
+
"group/toast pointer-events-auto absolute right-0 bottom-0 z-[calc(1000-var(--toast-index))] w-full origin-bottom rounded-2xl border bg-popover text-popover-foreground shadow-lg will-change-transform outline-none select-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
48
|
+
"[--gap:0.75rem] [--height:var(--toast-frontmost-height,var(--toast-height))] [--offset-y:calc(var(--toast-offset-y)*-1+calc(var(--toast-index)*var(--gap)*-1)+var(--toast-swipe-movement-y))] [--peek:0.75rem] [--scale:calc(max(0,1-(var(--toast-index)*0.1)))] [--shrink:calc(1-var(--scale))]",
|
|
49
|
+
"h-(--height) [transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--peek))-(var(--shrink)*var(--height))))_scale(var(--scale))] [transition:transform_500ms_cubic-bezier(0.22,1,0.36,1),opacity_500ms,height_150ms]",
|
|
50
|
+
"after:absolute after:top-full after:left-0 after:h-[calc(var(--gap)+1px)] after:w-full after:content-['']",
|
|
51
|
+
"data-expanded:h-(--toast-height) data-expanded:[transform:translateX(var(--toast-swipe-movement-x))_translateY(var(--offset-y))]",
|
|
52
|
+
"data-limited:opacity-0 data-starting-style:[transform:translateY(150%)]",
|
|
53
|
+
"[&[data-ending-style]:not([data-limited]):not([data-swipe-direction])]:[transform:translateY(150%)]",
|
|
54
|
+
"data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))]",
|
|
55
|
+
"data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))]",
|
|
56
|
+
"data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))]",
|
|
57
|
+
"data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))]",
|
|
58
|
+
"data-expanded:data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))]",
|
|
59
|
+
"data-expanded:data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))]",
|
|
60
|
+
"data-expanded:data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))]",
|
|
61
|
+
"data-expanded:data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))]",
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
{...props}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function ToastContent({ className, ...props }: ToastPrimitive.Content.Props) {
|
|
70
|
+
return (
|
|
71
|
+
<ToastPrimitive.Content
|
|
72
|
+
data-slot="toast-content"
|
|
73
|
+
className={cn(
|
|
74
|
+
"flex h-full items-center gap-3 overflow-hidden p-4 transition-opacity duration-250 ease-[cubic-bezier(0.22,1,0.36,1)] data-behind:opacity-0 data-expanded:opacity-100",
|
|
75
|
+
className,
|
|
76
|
+
)}
|
|
77
|
+
{...props}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ToastTitle({ className, ...props }: ToastPrimitive.Title.Props) {
|
|
83
|
+
return (
|
|
84
|
+
<ToastPrimitive.Title
|
|
85
|
+
data-slot="toast-title"
|
|
86
|
+
className={cn("text-sm font-medium", className)}
|
|
87
|
+
{...props}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function ToastDescription({
|
|
93
|
+
className,
|
|
94
|
+
...props
|
|
95
|
+
}: ToastPrimitive.Description.Props) {
|
|
96
|
+
return (
|
|
97
|
+
<ToastPrimitive.Description
|
|
98
|
+
data-slot="toast-description"
|
|
99
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
100
|
+
{...props}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function ToastAction({
|
|
106
|
+
className,
|
|
107
|
+
render = <Button variant="outline" size="sm" />,
|
|
108
|
+
...props
|
|
109
|
+
}: ToastPrimitive.Action.Props) {
|
|
110
|
+
return (
|
|
111
|
+
<ToastPrimitive.Action
|
|
112
|
+
data-slot="toast-action"
|
|
113
|
+
render={render}
|
|
114
|
+
className={cn("shrink-0", className)}
|
|
115
|
+
{...props}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function ToastClose({
|
|
121
|
+
className,
|
|
122
|
+
children,
|
|
123
|
+
render = <Button variant="ghost" size="icon-sm" />,
|
|
124
|
+
...props
|
|
125
|
+
}: ToastPrimitive.Close.Props) {
|
|
126
|
+
const messages = useUiMessages();
|
|
127
|
+
return (
|
|
128
|
+
<ToastPrimitive.Close
|
|
129
|
+
data-slot="toast-close"
|
|
130
|
+
aria-label={messages.close}
|
|
131
|
+
render={render}
|
|
132
|
+
className={cn(
|
|
133
|
+
"relative shrink-0 text-muted-foreground after:absolute after:-inset-2 after:content-[''] hover:text-foreground",
|
|
134
|
+
className,
|
|
135
|
+
)}
|
|
136
|
+
{...props}
|
|
137
|
+
>
|
|
138
|
+
{children ?? <XIcon aria-hidden="true" />}
|
|
139
|
+
</ToastPrimitive.Close>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function ToastIcon({ type }: { type: string | undefined }) {
|
|
144
|
+
let icon: React.ReactNode = null;
|
|
145
|
+
|
|
146
|
+
if (type === "success") {
|
|
147
|
+
icon = <CircleCheckIcon aria-hidden="true" />;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (type === "info") {
|
|
151
|
+
icon = <InfoIcon aria-hidden="true" />;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (type === "warning") {
|
|
155
|
+
icon = <TriangleAlertIcon aria-hidden="true" />;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (type === "error") {
|
|
159
|
+
icon = <OctagonXIcon className="text-destructive" aria-hidden="true" />;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (type === "loading") {
|
|
163
|
+
icon = <Loader2Icon className="animate-spin" aria-hidden="true" />;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!icon) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<span
|
|
172
|
+
data-slot="toast-icon"
|
|
173
|
+
className="shrink-0 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4"
|
|
174
|
+
>
|
|
175
|
+
{icon}
|
|
176
|
+
</span>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function ToastList() {
|
|
181
|
+
const { toasts } = ToastPrimitive.useToastManager();
|
|
182
|
+
|
|
183
|
+
return toasts.map((toastItem) => (
|
|
184
|
+
<Toast key={toastItem.id} toast={toastItem}>
|
|
185
|
+
<ToastContent>
|
|
186
|
+
<ToastIcon type={toastItem.type} />
|
|
187
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
188
|
+
<ToastTitle />
|
|
189
|
+
<ToastDescription />
|
|
190
|
+
</div>
|
|
191
|
+
<ToastAction />
|
|
192
|
+
<ToastClose />
|
|
193
|
+
</ToastContent>
|
|
194
|
+
</Toast>
|
|
195
|
+
));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function Toaster({
|
|
199
|
+
children,
|
|
200
|
+
toastManager = toast,
|
|
201
|
+
...props
|
|
202
|
+
}: ToastPrimitive.Provider.Props) {
|
|
203
|
+
return (
|
|
204
|
+
<ToastProvider toastManager={toastManager} {...props}>
|
|
205
|
+
{children}
|
|
206
|
+
<ToastPortal>
|
|
207
|
+
<ToastViewport>
|
|
208
|
+
<ToastList />
|
|
209
|
+
</ToastViewport>
|
|
210
|
+
</ToastPortal>
|
|
211
|
+
</ToastProvider>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The message of an error or of anything thrown. */
|
|
216
|
+
function errorMessage(error: unknown): string {
|
|
217
|
+
if (error instanceof Error) return error.message;
|
|
218
|
+
return typeof error === "string" ? error : String(error);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Shows a failure (anything thrown) as an error toast. */
|
|
222
|
+
function toastError(error: unknown, title?: string) {
|
|
223
|
+
return toast.add({
|
|
224
|
+
type: "error",
|
|
225
|
+
priority: "high",
|
|
226
|
+
...(title ? { title } : {}),
|
|
227
|
+
description: errorMessage(error),
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const createToastManager = ToastPrimitive.createToastManager;
|
|
232
|
+
const useToastManager = ToastPrimitive.useToastManager;
|
|
233
|
+
|
|
234
|
+
export {
|
|
235
|
+
Toaster,
|
|
236
|
+
Toast,
|
|
237
|
+
ToastAction,
|
|
238
|
+
ToastClose,
|
|
239
|
+
ToastContent,
|
|
240
|
+
ToastDescription,
|
|
241
|
+
ToastPortal,
|
|
242
|
+
ToastProvider,
|
|
243
|
+
ToastTitle,
|
|
244
|
+
ToastViewport,
|
|
245
|
+
createToastManager,
|
|
246
|
+
errorMessage,
|
|
247
|
+
toast,
|
|
248
|
+
toastError,
|
|
249
|
+
useToastManager,
|
|
250
|
+
};
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type Locale,
|
|
17
17
|
} from "../lib/i18n";
|
|
18
18
|
import { Button } from "../components/ui/button";
|
|
19
|
-
import {
|
|
19
|
+
import { Toaster } from "../components/ui/toast";
|
|
20
20
|
import {
|
|
21
21
|
DropdownMenu,
|
|
22
22
|
DropdownMenuContent,
|
|
@@ -131,7 +131,7 @@ export function Preferences({
|
|
|
131
131
|
<PreferencesReadyContext.Provider value={ready}>
|
|
132
132
|
<LocaleProvider locale={locale}>
|
|
133
133
|
{children}
|
|
134
|
-
<
|
|
134
|
+
<Toaster />
|
|
135
135
|
</LocaleProvider>
|
|
136
136
|
</PreferencesReadyContext.Provider>
|
|
137
137
|
</PreferencesContext.Provider>
|