@alquimia-ai/ui 1.2.0 → 1.2.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.
- package/dist/components/hooks/index.js +1 -1
- package/dist/components/hooks/index.js.map +1 -1
- package/dist/components/hooks/index.mjs +1 -1
- package/dist/components/hooks/index.mjs.map +1 -1
- package/dist/components/molecules/index.d.mts +15 -2
- package/dist/components/molecules/index.d.ts +15 -2
- package/dist/components/molecules/index.js +837 -725
- package/dist/components/molecules/index.js.map +1 -1
- package/dist/components/molecules/index.mjs +819 -707
- package/dist/components/molecules/index.mjs.map +1 -1
- package/dist/components/organisms/index.js +260 -149
- package/dist/components/organisms/index.js.map +1 -1
- package/dist/components/organisms/index.mjs +258 -147
- package/dist/components/organisms/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +265 -153
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -151
- package/dist/index.mjs.map +1 -1
- package/package.json +52 -32
- package/src/components/atoms/index.ts +32 -0
- package/src/components/atoms/ui/alert.tsx +59 -0
- package/src/components/atoms/ui/aspect-ratio.tsx +7 -0
- package/src/components/atoms/ui/avatar.tsx +50 -0
- package/src/components/atoms/ui/badge.tsx +36 -0
- package/src/components/atoms/ui/breadcrumb.tsx +120 -0
- package/src/components/atoms/ui/button.tsx +56 -0
- package/src/components/atoms/ui/card.tsx +87 -0
- package/src/components/atoms/ui/checkbox.tsx +31 -0
- package/src/components/atoms/ui/command.tsx +155 -0
- package/src/components/atoms/ui/dialog.tsx +125 -0
- package/src/components/atoms/ui/drawer.tsx +119 -0
- package/src/components/atoms/ui/input.tsx +26 -0
- package/src/components/atoms/ui/label.tsx +26 -0
- package/src/components/atoms/ui/loader.tsx +52 -0
- package/src/components/atoms/ui/popover.tsx +31 -0
- package/src/components/atoms/ui/rich-text.tsx +19 -0
- package/src/components/atoms/ui/scroll-area.tsx +48 -0
- package/src/components/atoms/ui/select.tsx +160 -0
- package/src/components/atoms/ui/skeleton.tsx +15 -0
- package/src/components/atoms/ui/slider.tsx +29 -0
- package/src/components/atoms/ui/switch.tsx +30 -0
- package/src/components/atoms/ui/table.tsx +118 -0
- package/src/components/atoms/ui/tabs.tsx +56 -0
- package/src/components/atoms/ui/text-area/index.tsx +24 -0
- package/src/components/atoms/ui/textarea.tsx +25 -0
- package/src/components/atoms/ui/think-indicator.tsx +103 -0
- package/src/components/atoms/ui/toast.tsx +129 -0
- package/src/components/atoms/ui/toaster.tsx +38 -0
- package/src/components/atoms/ui/toggle.tsx +45 -0
- package/src/components/atoms/ui/typography/index.tsx +30 -0
- package/src/components/hooks/index.ts +4 -0
- package/src/components/hooks/use-document.tsx +44 -0
- package/src/components/hooks/use-resize-observer.ts +28 -0
- package/src/components/hooks/use-text-streaming.ts +63 -0
- package/src/components/hooks/use-toast.ts +194 -0
- package/src/components/index.ts +1 -0
- package/src/components/molecules/alert-dialog.tsx +141 -0
- package/src/components/molecules/assistant-button.tsx +148 -0
- package/src/components/molecules/call-out.tsx +163 -0
- package/src/components/molecules/carousel.tsx +262 -0
- package/src/components/molecules/documents/document-selector.tsx +79 -0
- package/src/components/molecules/documents/document-viewer.tsx +85 -0
- package/src/components/molecules/documents/index.ts +2 -0
- package/src/components/molecules/index.ts +11 -0
- package/src/components/molecules/navigation-menu.tsx +128 -0
- package/src/components/molecules/page-container.tsx +17 -0
- package/src/components/molecules/rating-comment.tsx +93 -0
- package/src/components/molecules/rating-stars.tsx +136 -0
- package/src/components/molecules/rating-thumbs.tsx +90 -0
- package/src/components/molecules/sidebar.tsx +107 -0
- package/src/components/molecules/sonner.tsx +30 -0
- package/src/components/molecules/viewers/index.ts +2 -0
- package/src/components/molecules/viewers/pdf-viewer.tsx +138 -0
- package/src/components/molecules/viewers/plain-text-viewer.tsx +40 -0
- package/src/components/organisms/assistant.tsx +271 -0
- package/src/components/organisms/index.ts +6 -0
- package/src/components/organisms/rating-dialog.tsx +104 -0
- package/src/components/organisms/speechToText.tsx +92 -0
- package/src/components/organisms/whisper.tsx +106 -0
- package/src/components/templates/cards/index.ts +2 -0
- package/src/components/templates/cards/with-image-heading-description-avatar.tsx +94 -0
- package/src/components/templates/cards/with-image-heading-description.tsx +63 -0
- package/src/components/templates/hero/index.tsx +39 -0
- package/src/components/templates/index.ts +4 -0
- package/src/components/templates/messages-window.tsx +15 -0
- package/src/components/templates/query-box.tsx +13 -0
- package/src/components/ui/input.tsx +25 -0
- package/src/components/ui/select.tsx +163 -0
- package/src/index.ts +7 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils.ts +34 -0
- package/src/styles/call-out.css +153 -0
- package/src/styles/drawer.css +28 -0
- package/src/styles/globals.css +69 -0
- package/src/styles/prose.css +51 -0
- package/src/styles/ratings.css +27 -0
- package/src/styles/themes/base-alquimia.css +95 -0
- package/src/styles/themes/base-nordic.css +83 -0
- package/src/styles/themes/base-primary.css +85 -0
- package/src/styles/themes/base.css +8 -0
- package/src/types/index.ts +1 -0
- package/src/types/type.ts +76 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useToast } from "../../hooks/use-toast";
|
|
5
|
+
import {
|
|
6
|
+
Toast,
|
|
7
|
+
ToastClose,
|
|
8
|
+
ToastDescription,
|
|
9
|
+
ToastProvider,
|
|
10
|
+
ToastTitle,
|
|
11
|
+
ToastViewport,
|
|
12
|
+
} from "./toast";
|
|
13
|
+
|
|
14
|
+
function Toaster() {
|
|
15
|
+
const { toasts } = useToast();
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<ToastProvider>
|
|
19
|
+
{toasts.map(function ({ id, title, description, action, ...props }: any) {
|
|
20
|
+
return (
|
|
21
|
+
<Toast key={id} {...props}>
|
|
22
|
+
<div className="grid gap-1">
|
|
23
|
+
{title && <ToastTitle>{title}</ToastTitle>}
|
|
24
|
+
{description && (
|
|
25
|
+
<ToastDescription>{description}</ToastDescription>
|
|
26
|
+
)}
|
|
27
|
+
</div>
|
|
28
|
+
{action}
|
|
29
|
+
<ToastClose />
|
|
30
|
+
</Toast>
|
|
31
|
+
);
|
|
32
|
+
})}
|
|
33
|
+
<ToastViewport />
|
|
34
|
+
</ToastProvider>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { Toaster };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as TogglePrimitive from "@radix-ui/react-toggle";
|
|
5
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../../lib/utils";
|
|
8
|
+
|
|
9
|
+
const toggleVariants = cva(
|
|
10
|
+
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
|
|
11
|
+
{
|
|
12
|
+
variants: {
|
|
13
|
+
variant: {
|
|
14
|
+
default: "bg-transparent",
|
|
15
|
+
outline:
|
|
16
|
+
"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",
|
|
17
|
+
},
|
|
18
|
+
size: {
|
|
19
|
+
default: "h-10 px-3",
|
|
20
|
+
sm: "h-9 px-2.5",
|
|
21
|
+
lg: "h-11 px-5",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
defaultVariants: {
|
|
25
|
+
variant: "default",
|
|
26
|
+
size: "default",
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const Toggle = React.forwardRef<
|
|
32
|
+
React.ElementRef<typeof TogglePrimitive.Root>,
|
|
33
|
+
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
|
|
34
|
+
VariantProps<typeof toggleVariants>
|
|
35
|
+
>(({ className, variant, size, ...props }, ref) => (
|
|
36
|
+
<TogglePrimitive.Root
|
|
37
|
+
ref={ref}
|
|
38
|
+
className={cn(toggleVariants({ variant, size, className }), "alq--toggle")}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
));
|
|
42
|
+
|
|
43
|
+
Toggle.displayName = TogglePrimitive.Root.displayName;
|
|
44
|
+
|
|
45
|
+
export { Toggle, toggleVariants };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cn } from "../../../../lib/utils";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
|
|
4
|
+
export interface TypographyProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span";
|
|
6
|
+
typeStyle:
|
|
7
|
+
| "display"
|
|
8
|
+
| "heading1"
|
|
9
|
+
| "heading2"
|
|
10
|
+
| "heading3"
|
|
11
|
+
| "heading4"
|
|
12
|
+
| "small"
|
|
13
|
+
| "tiny";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const Typography = forwardRef<HTMLDivElement, TypographyProps>(
|
|
17
|
+
({ as: Component = "p", typeStyle, ...props }, ref) => {
|
|
18
|
+
return (
|
|
19
|
+
<Component
|
|
20
|
+
{...props}
|
|
21
|
+
className={cn(props.className, `alq--typography-${typeStyle}`)}
|
|
22
|
+
ref={ref}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
Typography.displayName = "Typography";
|
|
29
|
+
|
|
30
|
+
export { Typography };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { ApiError, ActionResponse } from "../../types/type";
|
|
5
|
+
|
|
6
|
+
export const useDocumentReader = (
|
|
7
|
+
url: string,
|
|
8
|
+
getDocument: (id: string) => Promise<ActionResponse<Blob>>,
|
|
9
|
+
) => {
|
|
10
|
+
const [loading, setLoading] = useState<boolean>(true);
|
|
11
|
+
const [error, setError] = useState<string | null>(null);
|
|
12
|
+
const [document, setDocument] = useState<Blob | null>(null);
|
|
13
|
+
|
|
14
|
+
const handleDocumentError = (error: ApiError) => {
|
|
15
|
+
const errorMessage = "Hubo un error al obtener el documento. Por favor ponganse en contacto con el administrador.";
|
|
16
|
+
setError(errorMessage);
|
|
17
|
+
throw new Error(error?.message || 'Unknown error');
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const resetDocument = () => {
|
|
21
|
+
setDocument(null);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const fetchDocument = async () => {
|
|
25
|
+
setLoading(true);
|
|
26
|
+
setError(null);
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const res = await getDocument(url);
|
|
30
|
+
if (!res.success) {
|
|
31
|
+
handleDocumentError(res.error as ApiError || new Error('Unknown error'));
|
|
32
|
+
setLoading(false);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
res.data && setDocument(res.data);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
handleDocumentError(error as ApiError);
|
|
38
|
+
} finally {
|
|
39
|
+
setLoading(false);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return { document, loading, fetchDocument, resetDocument, error };
|
|
44
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
type ResizeObserverOptions = {
|
|
4
|
+
box?: 'content-box' | 'border-box';
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type ResizeObserverCallback = (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;
|
|
8
|
+
|
|
9
|
+
export default function useResizeObserver(
|
|
10
|
+
element: Element | null,
|
|
11
|
+
options: ResizeObserverOptions | undefined,
|
|
12
|
+
observerCallback: ResizeObserverCallback
|
|
13
|
+
): void {
|
|
14
|
+
const observerRef = useRef<ResizeObserver | null>(null);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!element) return;
|
|
18
|
+
|
|
19
|
+
observerRef.current = new ResizeObserver(observerCallback);
|
|
20
|
+
observerRef.current.observe(element, options);
|
|
21
|
+
|
|
22
|
+
return () => {
|
|
23
|
+
if (observerRef.current) {
|
|
24
|
+
observerRef.current.disconnect();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}, [element, options, observerCallback]);
|
|
28
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
const CHAR_DELAY = 25;
|
|
3
|
+
const PUNCTUATION_DELAY = 200;
|
|
4
|
+
const PUNCTUATION_MARKS = [".", "!", "?", ";", ":"];
|
|
5
|
+
|
|
6
|
+
function useTextStreaming(
|
|
7
|
+
content: string,
|
|
8
|
+
shouldStream: boolean,
|
|
9
|
+
handleIsTextStreaming?: (isStreaming: boolean) => void
|
|
10
|
+
) {
|
|
11
|
+
const [displayedContent, setDisplayedContent] = useState<string>("");
|
|
12
|
+
const timeoutId = useRef<NodeJS.Timeout | null>(null);
|
|
13
|
+
const hasStartedStreaming = useRef<boolean>(false);
|
|
14
|
+
|
|
15
|
+
const getDelayForChar = (text: string, position: number): number => {
|
|
16
|
+
if (position === 0) return CHAR_DELAY;
|
|
17
|
+
|
|
18
|
+
const previousChar = text[position - 1] || '';
|
|
19
|
+
const isEllipsis = text.slice(position - 1, position + 2) === "...";
|
|
20
|
+
|
|
21
|
+
if (isEllipsis) {
|
|
22
|
+
return CHAR_DELAY;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return PUNCTUATION_MARKS.includes(previousChar)
|
|
26
|
+
? PUNCTUATION_DELAY
|
|
27
|
+
: CHAR_DELAY;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!shouldStream && !hasStartedStreaming.current) {
|
|
32
|
+
setDisplayedContent(content);
|
|
33
|
+
handleIsTextStreaming?.(false);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
handleIsTextStreaming?.(true);
|
|
38
|
+
hasStartedStreaming.current = true;
|
|
39
|
+
|
|
40
|
+
if (displayedContent.length < content.length) {
|
|
41
|
+
const delay = getDelayForChar(content, displayedContent.length);
|
|
42
|
+
timeoutId.current = setTimeout(() => {
|
|
43
|
+
setDisplayedContent((prev) => prev + content[prev.length]);
|
|
44
|
+
}, delay);
|
|
45
|
+
} else {
|
|
46
|
+
handleIsTextStreaming?.(false);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return () => {
|
|
50
|
+
if (timeoutId.current) clearTimeout(timeoutId.current);
|
|
51
|
+
};
|
|
52
|
+
}, [
|
|
53
|
+
content,
|
|
54
|
+
displayedContent,
|
|
55
|
+
shouldStream,
|
|
56
|
+
getDelayForChar,
|
|
57
|
+
handleIsTextStreaming,
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
return displayedContent;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { useTextStreaming };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// Inspired by react-hot-toast library
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
ToastActionElement,
|
|
8
|
+
ToastProps,
|
|
9
|
+
} from "../../components/atoms/ui/toast";
|
|
10
|
+
|
|
11
|
+
const TOAST_LIMIT = 1;
|
|
12
|
+
const TOAST_REMOVE_DELAY = 1000000;
|
|
13
|
+
|
|
14
|
+
type ToasterToast = ToastProps & {
|
|
15
|
+
id: string;
|
|
16
|
+
title?: React.ReactNode;
|
|
17
|
+
description?: React.ReactNode;
|
|
18
|
+
action?: ToastActionElement;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const actionTypes = {
|
|
22
|
+
ADD_TOAST: "ADD_TOAST",
|
|
23
|
+
UPDATE_TOAST: "UPDATE_TOAST",
|
|
24
|
+
DISMISS_TOAST: "DISMISS_TOAST",
|
|
25
|
+
REMOVE_TOAST: "REMOVE_TOAST",
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
let count = 0;
|
|
29
|
+
|
|
30
|
+
function genId() {
|
|
31
|
+
count = (count + 1) % Number.MAX_SAFE_INTEGER;
|
|
32
|
+
return count.toString();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type ActionType = typeof actionTypes;
|
|
36
|
+
|
|
37
|
+
type Action =
|
|
38
|
+
| {
|
|
39
|
+
type: ActionType["ADD_TOAST"];
|
|
40
|
+
toast: ToasterToast;
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
type: ActionType["UPDATE_TOAST"];
|
|
44
|
+
toast: Partial<ToasterToast>;
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
type: ActionType["DISMISS_TOAST"];
|
|
48
|
+
toastId?: ToasterToast["id"];
|
|
49
|
+
}
|
|
50
|
+
| {
|
|
51
|
+
type: ActionType["REMOVE_TOAST"];
|
|
52
|
+
toastId?: ToasterToast["id"];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
interface State {
|
|
56
|
+
toasts: ToasterToast[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
|
60
|
+
|
|
61
|
+
const addToRemoveQueue = (toastId: string) => {
|
|
62
|
+
if (toastTimeouts.has(toastId)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const timeout = setTimeout(() => {
|
|
67
|
+
toastTimeouts.delete(toastId);
|
|
68
|
+
dispatch({
|
|
69
|
+
type: "REMOVE_TOAST",
|
|
70
|
+
toastId: toastId,
|
|
71
|
+
});
|
|
72
|
+
}, TOAST_REMOVE_DELAY);
|
|
73
|
+
|
|
74
|
+
toastTimeouts.set(toastId, timeout);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const reducer = (state: State, action: Action): State => {
|
|
78
|
+
switch (action.type) {
|
|
79
|
+
case "ADD_TOAST":
|
|
80
|
+
return {
|
|
81
|
+
...state,
|
|
82
|
+
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
case "UPDATE_TOAST":
|
|
86
|
+
return {
|
|
87
|
+
...state,
|
|
88
|
+
toasts: state.toasts.map((t) =>
|
|
89
|
+
t.id === action.toast.id ? { ...t, ...action.toast } : t
|
|
90
|
+
),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
case "DISMISS_TOAST": {
|
|
94
|
+
const { toastId } = action;
|
|
95
|
+
|
|
96
|
+
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
|
97
|
+
// but I'll keep it here for simplicity
|
|
98
|
+
if (toastId) {
|
|
99
|
+
addToRemoveQueue(toastId);
|
|
100
|
+
} else {
|
|
101
|
+
state.toasts.forEach((toast) => {
|
|
102
|
+
addToRemoveQueue(toast.id);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
...state,
|
|
108
|
+
toasts: state.toasts.map((t) =>
|
|
109
|
+
t.id === toastId || toastId === undefined
|
|
110
|
+
? {
|
|
111
|
+
...t,
|
|
112
|
+
open: false,
|
|
113
|
+
}
|
|
114
|
+
: t
|
|
115
|
+
),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
case "REMOVE_TOAST":
|
|
119
|
+
if (action.toastId === undefined) {
|
|
120
|
+
return {
|
|
121
|
+
...state,
|
|
122
|
+
toasts: [],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
...state,
|
|
127
|
+
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const listeners: Array<(state: State) => void> = [];
|
|
133
|
+
|
|
134
|
+
let memoryState: State = { toasts: [] };
|
|
135
|
+
|
|
136
|
+
function dispatch(action: Action) {
|
|
137
|
+
memoryState = reducer(memoryState, action);
|
|
138
|
+
listeners.forEach((listener) => {
|
|
139
|
+
listener(memoryState);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
type Toast = Omit<ToasterToast, "id">;
|
|
144
|
+
|
|
145
|
+
function toast({ ...props }: Toast) {
|
|
146
|
+
const id = genId();
|
|
147
|
+
|
|
148
|
+
const update = (props: ToasterToast) =>
|
|
149
|
+
dispatch({
|
|
150
|
+
type: "UPDATE_TOAST",
|
|
151
|
+
toast: { ...props, id },
|
|
152
|
+
});
|
|
153
|
+
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
|
|
154
|
+
|
|
155
|
+
dispatch({
|
|
156
|
+
type: "ADD_TOAST",
|
|
157
|
+
toast: {
|
|
158
|
+
...props,
|
|
159
|
+
id,
|
|
160
|
+
open: true,
|
|
161
|
+
onOpenChange: (open) => {
|
|
162
|
+
if (!open) dismiss();
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
id: id,
|
|
169
|
+
dismiss,
|
|
170
|
+
update,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function useToast() {
|
|
175
|
+
const [state, setState] = React.useState<State>(memoryState);
|
|
176
|
+
|
|
177
|
+
React.useEffect(() => {
|
|
178
|
+
listeners.push(setState);
|
|
179
|
+
return () => {
|
|
180
|
+
const index = listeners.indexOf(setState);
|
|
181
|
+
if (index > -1) {
|
|
182
|
+
listeners.splice(index, 1);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}, [state]);
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
...state,
|
|
189
|
+
toast,
|
|
190
|
+
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { useToast, toast };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./atoms";
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
import { buttonVariants } from "../atoms/ui/button";
|
|
8
|
+
|
|
9
|
+
const AlertDialog = AlertDialogPrimitive.Root;
|
|
10
|
+
|
|
11
|
+
const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
|
|
12
|
+
|
|
13
|
+
const AlertDialogPortal = AlertDialogPrimitive.Portal;
|
|
14
|
+
|
|
15
|
+
const AlertDialogOverlay = React.forwardRef<
|
|
16
|
+
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
|
|
17
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
|
|
18
|
+
>(({ className, ...props }, ref) => (
|
|
19
|
+
<AlertDialogPrimitive.Overlay
|
|
20
|
+
className={cn(
|
|
21
|
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
22
|
+
className
|
|
23
|
+
)}
|
|
24
|
+
{...props}
|
|
25
|
+
ref={ref}
|
|
26
|
+
/>
|
|
27
|
+
));
|
|
28
|
+
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
|
|
29
|
+
|
|
30
|
+
const AlertDialogContent = React.forwardRef<
|
|
31
|
+
React.ElementRef<typeof AlertDialogPrimitive.Content>,
|
|
32
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
|
|
33
|
+
>(({ className, ...props }, ref) => (
|
|
34
|
+
<AlertDialogPortal>
|
|
35
|
+
<AlertDialogOverlay />
|
|
36
|
+
<AlertDialogPrimitive.Content
|
|
37
|
+
ref={ref}
|
|
38
|
+
className={cn(
|
|
39
|
+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
|
40
|
+
className
|
|
41
|
+
)}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
</AlertDialogPortal>
|
|
45
|
+
));
|
|
46
|
+
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;
|
|
47
|
+
|
|
48
|
+
const AlertDialogHeader = ({
|
|
49
|
+
className,
|
|
50
|
+
...props
|
|
51
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
52
|
+
<div
|
|
53
|
+
className={cn(
|
|
54
|
+
"flex flex-col space-y-2 text-center sm:text-left",
|
|
55
|
+
className
|
|
56
|
+
)}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
AlertDialogHeader.displayName = "AlertDialogHeader";
|
|
61
|
+
|
|
62
|
+
const AlertDialogFooter = ({
|
|
63
|
+
className,
|
|
64
|
+
...props
|
|
65
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
66
|
+
<div
|
|
67
|
+
className={cn(
|
|
68
|
+
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
|
69
|
+
className
|
|
70
|
+
)}
|
|
71
|
+
{...props}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
AlertDialogFooter.displayName = "AlertDialogFooter";
|
|
75
|
+
|
|
76
|
+
const AlertDialogTitle = React.forwardRef<
|
|
77
|
+
React.ElementRef<typeof AlertDialogPrimitive.Title>,
|
|
78
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
|
|
79
|
+
>(({ className, ...props }, ref) => (
|
|
80
|
+
<AlertDialogPrimitive.Title
|
|
81
|
+
ref={ref}
|
|
82
|
+
className={cn("text-lg font-semibold", className)}
|
|
83
|
+
{...props}
|
|
84
|
+
/>
|
|
85
|
+
));
|
|
86
|
+
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;
|
|
87
|
+
|
|
88
|
+
const AlertDialogDescription = React.forwardRef<
|
|
89
|
+
React.ElementRef<typeof AlertDialogPrimitive.Description>,
|
|
90
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
|
|
91
|
+
>(({ className, ...props }, ref) => (
|
|
92
|
+
<AlertDialogPrimitive.Description
|
|
93
|
+
ref={ref}
|
|
94
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
95
|
+
{...props}
|
|
96
|
+
/>
|
|
97
|
+
));
|
|
98
|
+
AlertDialogDescription.displayName =
|
|
99
|
+
AlertDialogPrimitive.Description.displayName;
|
|
100
|
+
|
|
101
|
+
const AlertDialogAction = React.forwardRef<
|
|
102
|
+
React.ElementRef<typeof AlertDialogPrimitive.Action>,
|
|
103
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
|
|
104
|
+
>(({ className, ...props }, ref) => (
|
|
105
|
+
<AlertDialogPrimitive.Action
|
|
106
|
+
ref={ref}
|
|
107
|
+
className={cn(buttonVariants(), className)}
|
|
108
|
+
{...props}
|
|
109
|
+
/>
|
|
110
|
+
));
|
|
111
|
+
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
|
|
112
|
+
|
|
113
|
+
const AlertDialogCancel = React.forwardRef<
|
|
114
|
+
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
|
|
115
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
|
|
116
|
+
>(({ className, ...props }, ref) => (
|
|
117
|
+
<AlertDialogPrimitive.Cancel
|
|
118
|
+
ref={ref}
|
|
119
|
+
className={cn(
|
|
120
|
+
buttonVariants({ variant: "outline" }),
|
|
121
|
+
"mt-2 sm:mt-0",
|
|
122
|
+
className
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
/>
|
|
126
|
+
));
|
|
127
|
+
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
AlertDialog,
|
|
131
|
+
AlertDialogPortal,
|
|
132
|
+
AlertDialogOverlay,
|
|
133
|
+
AlertDialogTrigger,
|
|
134
|
+
AlertDialogContent,
|
|
135
|
+
AlertDialogHeader,
|
|
136
|
+
AlertDialogFooter,
|
|
137
|
+
AlertDialogTitle,
|
|
138
|
+
AlertDialogDescription,
|
|
139
|
+
AlertDialogAction,
|
|
140
|
+
AlertDialogCancel,
|
|
141
|
+
};
|