From f15d97fcef6eecd8bd4b0c4482fc3cac1f3b18b6 Mon Sep 17 00:00:00 2001 From: zernonia Date: Thu, 2 Nov 2023 19:37:06 +0800 Subject: [PATCH] chore: run build registry --- apps/www/__registry__/index.ts | 122 ++++++++++++++---- apps/www/src/public/registry/index.json | 22 ++++ .../registry/styles/default/switch.json | 2 +- .../public/registry/styles/default/toast.json | 47 +++++-- .../registry/styles/new-york/toast.json | 47 +++++-- 5 files changed, 197 insertions(+), 43 deletions(-) diff --git a/apps/www/__registry__/index.ts b/apps/www/__registry__/index.ts index 0251b406..61fbc8ca 100644 --- a/apps/www/__registry__/index.ts +++ b/apps/www/__registry__/index.ts @@ -103,14 +103,14 @@ export const Index = { CheckboxFormMultiple: { name: 'CheckboxFormMultiple', type: 'components:example', - registryDependencies: ['button', 'form', 'checkbox'], + registryDependencies: ['button', 'form', 'checkbox', 'toast'], component: () => import('../src/lib/registry/default/example/CheckboxFormMultiple.vue').then(m => m.default), files: ['../src/lib/registry/default/example/CheckboxFormMultiple.vue'], }, CheckboxFormSingle: { name: 'CheckboxFormSingle', type: 'components:example', - registryDependencies: ['button', 'form', 'checkbox'], + registryDependencies: ['button', 'form', 'checkbox', 'toast'], component: () => import('../src/lib/registry/default/example/CheckboxFormSingle.vue').then(m => m.default), files: ['../src/lib/registry/default/example/CheckboxFormSingle.vue'], }, @@ -145,7 +145,7 @@ export const Index = { ComboboxForm: { name: 'ComboboxForm', type: 'components:example', - registryDependencies: ['utils', 'button', 'command', 'form', 'popover'], + registryDependencies: ['utils', 'button', 'command', 'form', 'popover', 'toast'], component: () => import('../src/lib/registry/default/example/ComboboxForm.vue').then(m => m.default), files: ['../src/lib/registry/default/example/ComboboxForm.vue'], }, @@ -194,7 +194,7 @@ export const Index = { DatePickerForm: { name: 'DatePickerForm', type: 'components:example', - registryDependencies: ['utils', 'button', 'calendar', 'form', 'popover'], + registryDependencies: ['utils', 'button', 'calendar', 'form', 'popover', 'toast'], component: () => import('../src/lib/registry/default/example/DatePickerForm.vue').then(m => m.default), files: ['../src/lib/registry/default/example/DatePickerForm.vue'], }, @@ -257,14 +257,14 @@ export const Index = { InputForm: { name: 'InputForm', type: 'components:example', - registryDependencies: ['button', 'form', 'input'], + registryDependencies: ['button', 'form', 'input', 'toast'], component: () => import('../src/lib/registry/default/example/InputForm.vue').then(m => m.default), files: ['../src/lib/registry/default/example/InputForm.vue'], }, InputFormAutoAnimate: { name: 'InputFormAutoAnimate', type: 'components:example', - registryDependencies: ['button', 'form', 'input'], + registryDependencies: ['button', 'form', 'input', 'toast'], component: () => import('../src/lib/registry/default/example/InputFormAutoAnimate.vue').then(m => m.default), files: ['../src/lib/registry/default/example/InputFormAutoAnimate.vue'], }, @@ -341,7 +341,7 @@ export const Index = { RadioGroupForm: { name: 'RadioGroupForm', type: 'components:example', - registryDependencies: ['button', 'form', 'radio-group'], + registryDependencies: ['button', 'form', 'radio-group', 'toast'], component: () => import('../src/lib/registry/default/example/RadioGroupForm.vue').then(m => m.default), files: ['../src/lib/registry/default/example/RadioGroupForm.vue'], }, @@ -362,7 +362,7 @@ export const Index = { SelectForm: { name: 'SelectForm', type: 'components:example', - registryDependencies: ['button', 'form', 'select'], + registryDependencies: ['button', 'form', 'select', 'toast'], component: () => import('../src/lib/registry/default/example/SelectForm.vue').then(m => m.default), files: ['../src/lib/registry/default/example/SelectForm.vue'], }, @@ -404,7 +404,7 @@ export const Index = { SwitchForm: { name: 'SwitchForm', type: 'components:example', - registryDependencies: ['button', 'form', 'switch'], + registryDependencies: ['button', 'form', 'switch', 'toast'], component: () => import('../src/lib/registry/default/example/SwitchForm.vue').then(m => m.default), files: ['../src/lib/registry/default/example/SwitchForm.vue'], }, @@ -439,7 +439,7 @@ export const Index = { TextareaForm: { name: 'TextareaForm', type: 'components:example', - registryDependencies: ['button', 'form', 'textarea'], + registryDependencies: ['button', 'form', 'textarea', 'toast'], component: () => import('../src/lib/registry/default/example/TextareaForm.vue').then(m => m.default), files: ['../src/lib/registry/default/example/TextareaForm.vue'], }, @@ -464,6 +464,41 @@ export const Index = { component: () => import('../src/lib/registry/default/example/TextareaWithText.vue').then(m => m.default), files: ['../src/lib/registry/default/example/TextareaWithText.vue'], }, + ToastDemo: { + name: 'ToastDemo', + type: 'components:example', + registryDependencies: ['button', 'use-toast'], + component: () => import('../src/lib/registry/default/example/ToastDemo.vue').then(m => m.default), + files: ['../src/lib/registry/default/example/ToastDemo.vue'], + }, + ToastDestructive: { + name: 'ToastDestructive', + type: 'components:example', + registryDependencies: ['button', 'use-toast', 'toast'], + component: () => import('../src/lib/registry/default/example/ToastDestructive.vue').then(m => m.default), + files: ['../src/lib/registry/default/example/ToastDestructive.vue'], + }, + ToastSimple: { + name: 'ToastSimple', + type: 'components:example', + registryDependencies: ['button', 'use-toast'], + component: () => import('../src/lib/registry/default/example/ToastSimple.vue').then(m => m.default), + files: ['../src/lib/registry/default/example/ToastSimple.vue'], + }, + ToastWithAction: { + name: 'ToastWithAction', + type: 'components:example', + registryDependencies: ['button', 'use-toast', 'toast'], + component: () => import('../src/lib/registry/default/example/ToastWithAction.vue').then(m => m.default), + files: ['../src/lib/registry/default/example/ToastWithAction.vue'], + }, + ToastWithTitle: { + name: 'ToastWithTitle', + type: 'components:example', + registryDependencies: ['button', 'use-toast'], + component: () => import('../src/lib/registry/default/example/ToastWithTitle.vue').then(m => m.default), + files: ['../src/lib/registry/default/example/ToastWithTitle.vue'], + }, ToggleDemo: { name: 'ToggleDemo', type: 'components:example', @@ -581,21 +616,21 @@ export const Index = { type: 'components:example', registryDependencies: ['button', 'card', 'themes', 'config'], component: () => import('../src/lib/registry/default/example/Cards/ActivityGoal.vue').then(m => m.default), - files: ['../src/lib/registry/default/example/ActivityGoal.vue'], + files: ['../src/lib/registry/default/example/Cards/ActivityGoal.vue'], }, DataTable: { name: 'DataTable', type: 'components:example', registryDependencies: ['button', 'checkbox', 'dropdown-menu', 'input', 'table', 'card', 'utils'], component: () => import('../src/lib/registry/default/example/Cards/DataTable.vue').then(m => m.default), - files: ['../src/lib/registry/default/example/DataTable.vue'], + files: ['../src/lib/registry/default/example/Cards/DataTable.vue'], }, Metric: { name: 'Metric', type: 'components:example', registryDependencies: ['card', 'config'], component: () => import('../src/lib/registry/default/example/Cards/Metric.vue').then(m => m.default), - files: ['../src/lib/registry/default/example/Metric.vue'], + files: ['../src/lib/registry/default/example/Cards/Metric.vue'], }, }, 'new-york': { @@ -700,14 +735,14 @@ export const Index = { CheckboxFormMultiple: { name: 'CheckboxFormMultiple', type: 'components:example', - registryDependencies: ['button', 'form', 'checkbox'], + registryDependencies: ['button', 'form', 'checkbox', 'toast'], component: () => import('../src/lib/registry/new-york/example/CheckboxFormMultiple.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/CheckboxFormMultiple.vue'], }, CheckboxFormSingle: { name: 'CheckboxFormSingle', type: 'components:example', - registryDependencies: ['button', 'form', 'checkbox'], + registryDependencies: ['button', 'form', 'checkbox', 'toast'], component: () => import('../src/lib/registry/new-york/example/CheckboxFormSingle.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/CheckboxFormSingle.vue'], }, @@ -742,7 +777,7 @@ export const Index = { ComboboxForm: { name: 'ComboboxForm', type: 'components:example', - registryDependencies: ['utils', 'button', 'command', 'form', 'popover'], + registryDependencies: ['utils', 'button', 'command', 'form', 'popover', 'toast'], component: () => import('../src/lib/registry/new-york/example/ComboboxForm.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/ComboboxForm.vue'], }, @@ -791,7 +826,7 @@ export const Index = { DatePickerForm: { name: 'DatePickerForm', type: 'components:example', - registryDependencies: ['utils', 'button', 'calendar', 'form', 'popover'], + registryDependencies: ['utils', 'button', 'calendar', 'form', 'popover', 'toast'], component: () => import('../src/lib/registry/new-york/example/DatePickerForm.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/DatePickerForm.vue'], }, @@ -854,14 +889,14 @@ export const Index = { InputForm: { name: 'InputForm', type: 'components:example', - registryDependencies: ['button', 'form', 'input'], + registryDependencies: ['button', 'form', 'input', 'toast'], component: () => import('../src/lib/registry/new-york/example/InputForm.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/InputForm.vue'], }, InputFormAutoAnimate: { name: 'InputFormAutoAnimate', type: 'components:example', - registryDependencies: ['button', 'form', 'input'], + registryDependencies: ['button', 'form', 'input', 'toast'], component: () => import('../src/lib/registry/new-york/example/InputFormAutoAnimate.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/InputFormAutoAnimate.vue'], }, @@ -938,7 +973,7 @@ export const Index = { RadioGroupForm: { name: 'RadioGroupForm', type: 'components:example', - registryDependencies: ['button', 'form', 'radio-group'], + registryDependencies: ['button', 'form', 'radio-group', 'toast'], component: () => import('../src/lib/registry/new-york/example/RadioGroupForm.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/RadioGroupForm.vue'], }, @@ -959,7 +994,7 @@ export const Index = { SelectForm: { name: 'SelectForm', type: 'components:example', - registryDependencies: ['button', 'form', 'select'], + registryDependencies: ['button', 'form', 'select', 'toast'], component: () => import('../src/lib/registry/new-york/example/SelectForm.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/SelectForm.vue'], }, @@ -1001,7 +1036,7 @@ export const Index = { SwitchForm: { name: 'SwitchForm', type: 'components:example', - registryDependencies: ['button', 'form', 'switch'], + registryDependencies: ['button', 'form', 'switch', 'toast'], component: () => import('../src/lib/registry/new-york/example/SwitchForm.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/SwitchForm.vue'], }, @@ -1036,7 +1071,7 @@ export const Index = { TextareaForm: { name: 'TextareaForm', type: 'components:example', - registryDependencies: ['button', 'form', 'textarea'], + registryDependencies: ['button', 'form', 'textarea', 'toast'], component: () => import('../src/lib/registry/new-york/example/TextareaForm.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/TextareaForm.vue'], }, @@ -1061,6 +1096,41 @@ export const Index = { component: () => import('../src/lib/registry/new-york/example/TextareaWithText.vue').then(m => m.default), files: ['../src/lib/registry/new-york/example/TextareaWithText.vue'], }, + ToastDemo: { + name: 'ToastDemo', + type: 'components:example', + registryDependencies: ['button', 'use-toast'], + component: () => import('../src/lib/registry/new-york/example/ToastDemo.vue').then(m => m.default), + files: ['../src/lib/registry/new-york/example/ToastDemo.vue'], + }, + ToastDestructive: { + name: 'ToastDestructive', + type: 'components:example', + registryDependencies: ['button', 'use-toast', 'toast'], + component: () => import('../src/lib/registry/new-york/example/ToastDestructive.vue').then(m => m.default), + files: ['../src/lib/registry/new-york/example/ToastDestructive.vue'], + }, + ToastSimple: { + name: 'ToastSimple', + type: 'components:example', + registryDependencies: ['button', 'use-toast'], + component: () => import('../src/lib/registry/new-york/example/ToastSimple.vue').then(m => m.default), + files: ['../src/lib/registry/new-york/example/ToastSimple.vue'], + }, + ToastWithAction: { + name: 'ToastWithAction', + type: 'components:example', + registryDependencies: ['button', 'use-toast', 'toast'], + component: () => import('../src/lib/registry/new-york/example/ToastWithAction.vue').then(m => m.default), + files: ['../src/lib/registry/new-york/example/ToastWithAction.vue'], + }, + ToastWithTitle: { + name: 'ToastWithTitle', + type: 'components:example', + registryDependencies: ['button', 'use-toast'], + component: () => import('../src/lib/registry/new-york/example/ToastWithTitle.vue').then(m => m.default), + files: ['../src/lib/registry/new-york/example/ToastWithTitle.vue'], + }, ToggleDemo: { name: 'ToggleDemo', type: 'components:example', @@ -1178,21 +1248,21 @@ export const Index = { type: 'components:example', registryDependencies: ['button', 'card', 'themes', 'config'], component: () => import('../src/lib/registry/new-york/example/Cards/ActivityGoal.vue').then(m => m.default), - files: ['../src/lib/registry/new-york/example/ActivityGoal.vue'], + files: ['../src/lib/registry/new-york/example/Cards/ActivityGoal.vue'], }, DataTable: { name: 'DataTable', type: 'components:example', registryDependencies: ['button', 'checkbox', 'dropdown-menu', 'input', 'table', 'card', 'utils'], component: () => import('../src/lib/registry/new-york/example/Cards/DataTable.vue').then(m => m.default), - files: ['../src/lib/registry/new-york/example/DataTable.vue'], + files: ['../src/lib/registry/new-york/example/Cards/DataTable.vue'], }, Metric: { name: 'Metric', type: 'components:example', registryDependencies: ['card', 'config'], component: () => import('../src/lib/registry/new-york/example/Cards/Metric.vue').then(m => m.default), - files: ['../src/lib/registry/new-york/example/Metric.vue'], + files: ['../src/lib/registry/new-york/example/Cards/Metric.vue'], }, }, } diff --git a/apps/www/src/public/registry/index.json b/apps/www/src/public/registry/index.json index 0f1b727d..328d58fd 100644 --- a/apps/www/src/public/registry/index.json +++ b/apps/www/src/public/registry/index.json @@ -600,6 +600,28 @@ ], "type": "components:ui" }, + { + "name": "toast", + "dependencies": [ + "radix-vue" + ], + "registryDependencies": [ + "utils" + ], + "files": [ + "ui/toast/Toast.vue", + "ui/toast/ToastAction.vue", + "ui/toast/ToastClose.vue", + "ui/toast/ToastDescription.vue", + "ui/toast/ToastProvider.vue", + "ui/toast/ToastTitle.vue", + "ui/toast/ToastViewport.vue", + "ui/toast/Toaster.vue", + "ui/toast/index.ts", + "ui/toast/use-toast.ts" + ], + "type": "components:ui" + }, { "name": "toggle", "dependencies": [ diff --git a/apps/www/src/public/registry/styles/default/switch.json b/apps/www/src/public/registry/styles/default/switch.json index d0e168cd..3ab1479f 100644 --- a/apps/www/src/public/registry/styles/default/switch.json +++ b/apps/www/src/public/registry/styles/default/switch.json @@ -9,7 +9,7 @@ "files": [ { "name": "Switch.vue", - "content": "\n\n\n" + "content": "\n\n\n" }, { "name": "index.ts", diff --git a/apps/www/src/public/registry/styles/default/toast.json b/apps/www/src/public/registry/styles/default/toast.json index 0a5e62b5..fbb653fc 100644 --- a/apps/www/src/public/registry/styles/default/toast.json +++ b/apps/www/src/public/registry/styles/default/toast.json @@ -1,20 +1,51 @@ { "name": "toast", "dependencies": [ - "@radix-ui/react-toast" + "radix-vue" + ], + "registryDependencies": [ + "utils" ], "files": [ { - "name": "toast.tsx", - "content": "import * as React from \"react\"\nimport * as ToastPrimitives from \"@radix-ui/react-toast\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { X } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst ToastProvider = ToastPrimitives.Provider\n\nconst ToastViewport = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastViewport.displayName = ToastPrimitives.Viewport.displayName\n\nconst toastVariants = cva(\n \"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full\",\n {\n variants: {\n variant: {\n default: \"border bg-background text-foreground\",\n destructive:\n \"destructive group border-destructive bg-destructive text-destructive-foreground\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n },\n }\n)\n\nconst Toast = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef &\n VariantProps\n>(({ class, variant, ...props }, ref) => {\n return (\n \n )\n})\nToast.displayName = ToastPrimitives.Root.displayName\n\nconst ToastAction = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastAction.displayName = ToastPrimitives.Action.displayName\n\nconst ToastClose = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n \n \n))\nToastClose.displayName = ToastPrimitives.Close.displayName\n\nconst ToastTitle = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastTitle.displayName = ToastPrimitives.Title.displayName\n\nconst ToastDescription = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastDescription.displayName = ToastPrimitives.Description.displayName\n\ntype ToastProps = React.ComponentPropsWithoutRef\n\ntype ToastActionElement = React.ReactElement\n\nexport {\n type ToastProps,\n type ToastActionElement,\n ToastProvider,\n ToastViewport,\n Toast,\n ToastTitle,\n ToastDescription,\n ToastClose,\n ToastAction,\n}\n" + "name": "Toast.vue", + "content": "\n\n\n\n\n" + }, + { + "name": "ToastAction.vue", + "content": "\n\n\n" + }, + { + "name": "ToastClose.vue", + "content": "\n\n\n" + }, + { + "name": "ToastDescription.vue", + "content": "\n\n\n" + }, + { + "name": "ToastProvider.vue", + "content": "\n\n\n" + }, + { + "name": "ToastTitle.vue", + "content": "\n\n\n" + }, + { + "name": "ToastViewport.vue", + "content": "\n\n\n" + }, + { + "name": "Toaster.vue", + "content": "\n\n\n" + }, + { + "name": "index.ts", + "content": "export { default as Toaster } from './Toaster.vue'\nexport { default as Toast } from './Toast.vue'\nexport { default as ToastViewport } from './ToastViewport.vue'\nexport { default as ToastAction } from './ToastAction.vue'\nexport { default as ToastClose } from './ToastClose.vue'\nexport { default as ToastTitle } from './ToastTitle.vue'\nexport { default as ToastDescription } from './ToastDescription.vue'\nexport { default as ToastProvider } from './ToastProvider.vue'\nexport { toast, useToast } from './use-toast'\n\nimport { cva } from 'class-variance-authority'\n\nexport const toastVariants = cva(\n 'group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full',\n {\n variants: {\n variant: {\n default: 'border bg-background text-foreground',\n destructive:\n 'destructive group border-destructive bg-destructive text-destructive-foreground',\n },\n },\n defaultVariants: {\n variant: 'default',\n },\n },\n)\n" }, { "name": "use-toast.ts", - "content": "// Inspired by react-hot-toast library\nimport * as React from \"react\"\n\nimport type {\n ToastActionElement,\n ToastProps,\n} from \"@/registry/default/ui/toast\"\n\nconst TOAST_LIMIT = 1\nconst TOAST_REMOVE_DELAY = 1000000\n\ntype ToasterToast = ToastProps & {\n id: string\n title?: React.ReactNode\n description?: React.ReactNode\n action?: ToastActionElement\n}\n\nconst actionTypes = {\n ADD_TOAST: \"ADD_TOAST\",\n UPDATE_TOAST: \"UPDATE_TOAST\",\n DISMISS_TOAST: \"DISMISS_TOAST\",\n REMOVE_TOAST: \"REMOVE_TOAST\",\n} as const\n\nlet count = 0\n\nfunction genId() {\n count = (count + 1) % Number.MAX_VALUE\n return count.toString()\n}\n\ntype ActionType = typeof actionTypes\n\ntype Action =\n | {\n type: ActionType[\"ADD_TOAST\"]\n toast: ToasterToast\n }\n | {\n type: ActionType[\"UPDATE_TOAST\"]\n toast: Partial\n }\n | {\n type: ActionType[\"DISMISS_TOAST\"]\n toastId?: ToasterToast[\"id\"]\n }\n | {\n type: ActionType[\"REMOVE_TOAST\"]\n toastId?: ToasterToast[\"id\"]\n }\n\ninterface State {\n toasts: ToasterToast[]\n}\n\nconst toastTimeouts = new Map>()\n\nconst addToRemoveQueue = (toastId: string) => {\n if (toastTimeouts.has(toastId)) {\n return\n }\n\n const timeout = setTimeout(() => {\n toastTimeouts.delete(toastId)\n dispatch({\n type: \"REMOVE_TOAST\",\n toastId: toastId,\n })\n }, TOAST_REMOVE_DELAY)\n\n toastTimeouts.set(toastId, timeout)\n}\n\nexport const reducer = (state: State, action: Action): State => {\n switch (action.type) {\n case \"ADD_TOAST\":\n return {\n ...state,\n toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),\n }\n\n case \"UPDATE_TOAST\":\n return {\n ...state,\n toasts: state.toasts.map((t) =>\n t.id === action.toast.id ? { ...t, ...action.toast } : t\n ),\n }\n\n case \"DISMISS_TOAST\": {\n const { toastId } = action\n\n // ! Side effects ! - This could be extracted into a dismissToast() action,\n // but I'll keep it here for simplicity\n if (toastId) {\n addToRemoveQueue(toastId)\n } else {\n state.toasts.forEach((toast) => {\n addToRemoveQueue(toast.id)\n })\n }\n\n return {\n ...state,\n toasts: state.toasts.map((t) =>\n t.id === toastId || toastId === undefined\n ? {\n ...t,\n open: false,\n }\n : t\n ),\n }\n }\n case \"REMOVE_TOAST\":\n if (action.toastId === undefined) {\n return {\n ...state,\n toasts: [],\n }\n }\n return {\n ...state,\n toasts: state.toasts.filter((t) => t.id !== action.toastId),\n }\n }\n}\n\nconst listeners: Array<(state: State) => void> = []\n\nlet memoryState: State = { toasts: [] }\n\nfunction dispatch(action: Action) {\n memoryState = reducer(memoryState, action)\n listeners.forEach((listener) => {\n listener(memoryState)\n })\n}\n\ntype Toast = Omit\n\nfunction toast({ ...props }: Toast) {\n const id = genId()\n\n const update = (props: ToasterToast) =>\n dispatch({\n type: \"UPDATE_TOAST\",\n toast: { ...props, id },\n })\n const dismiss = () => dispatch({ type: \"DISMISS_TOAST\", toastId: id })\n\n dispatch({\n type: \"ADD_TOAST\",\n toast: {\n ...props,\n id,\n open: true,\n onOpenChange: (open) => {\n if (!open) dismiss()\n },\n },\n })\n\n return {\n id: id,\n dismiss,\n update,\n }\n}\n\nfunction useToast() {\n const [state, setState] = React.useState(memoryState)\n\n React.useEffect(() => {\n listeners.push(setState)\n return () => {\n const index = listeners.indexOf(setState)\n if (index > -1) {\n listeners.splice(index, 1)\n }\n }\n }, [state])\n\n return {\n ...state,\n toast,\n dismiss: (toastId?: string) => dispatch({ type: \"DISMISS_TOAST\", toastId }),\n }\n}\n\nexport { useToast, toast }\n" - }, - { - "name": "toaster.tsx", - "content": "\"use client\"\n\nimport {\n Toast,\n ToastClose,\n ToastDescription,\n ToastProvider,\n ToastTitle,\n ToastViewport,\n} from \"@/registry/default/ui/toast\"\nimport { useToast } from \"@/registry/default/ui/use-toast\"\n\nexport function Toaster() {\n const { toasts } = useToast()\n\n return (\n \n {toasts.map(function ({ id, title, description, action, ...props }) {\n return (\n \n
\n {title && {title}}\n {description && (\n {description}\n )}\n
\n {action}\n \n
\n )\n })}\n \n
\n )\n}\n" + "content": "import { computed, ref } from 'vue'\nimport type { Component, VNode } from 'vue'\nimport type { ToastProps } from './Toast.vue'\n\nconst TOAST_LIMIT = 1\nconst TOAST_REMOVE_DELAY = 1000000\n\nexport type StringOrVNode =\n | string\n | VNode\n | (() => VNode)\n\ntype ToasterToast = ToastProps & {\n id: string\n title?: string\n description?: StringOrVNode\n action?: Component\n}\n\nconst actionTypes = {\n ADD_TOAST: 'ADD_TOAST',\n UPDATE_TOAST: 'UPDATE_TOAST',\n DISMISS_TOAST: 'DISMISS_TOAST',\n REMOVE_TOAST: 'REMOVE_TOAST',\n} as const\n\nlet count = 0\n\nfunction genId() {\n count = (count + 1) % Number.MAX_VALUE\n return count.toString()\n}\n\ntype ActionType = typeof actionTypes\n\ntype Action =\n | {\n type: ActionType['ADD_TOAST']\n toast: ToasterToast\n }\n | {\n type: ActionType['UPDATE_TOAST']\n toast: Partial\n }\n | {\n type: ActionType['DISMISS_TOAST']\n toastId?: ToasterToast['id']\n }\n | {\n type: ActionType['REMOVE_TOAST']\n toastId?: ToasterToast['id']\n }\n\ninterface State {\n toasts: ToasterToast[]\n}\n\nconst toastTimeouts = new Map>()\n\nfunction addToRemoveQueue(toastId: string) {\n if (toastTimeouts.has(toastId))\n return\n\n const timeout = setTimeout(() => {\n toastTimeouts.delete(toastId)\n dispatch({\n type: actionTypes.REMOVE_TOAST,\n toastId,\n })\n }, TOAST_REMOVE_DELAY)\n\n toastTimeouts.set(toastId, timeout)\n}\n\nconst state = ref({\n toasts: [],\n})\n\nfunction dispatch(action: Action) {\n switch (action.type) {\n case actionTypes.ADD_TOAST:\n state.value.toasts = [action.toast, ...state.value.toasts].slice(0, TOAST_LIMIT)\n break\n\n case actionTypes.UPDATE_TOAST:\n state.value.toasts = state.value.toasts.map(t =>\n t.id === action.toast.id ? { ...t, ...action.toast } : t,\n )\n break\n\n case actionTypes.DISMISS_TOAST: {\n const { toastId } = action\n\n if (toastId) {\n addToRemoveQueue(toastId)\n }\n else {\n state.value.toasts.forEach((toast) => {\n addToRemoveQueue(toast.id)\n })\n }\n\n state.value.toasts = state.value.toasts.map(t =>\n t.id === toastId || toastId === undefined\n ? {\n ...t,\n open: false,\n }\n : t,\n )\n break\n }\n\n case actionTypes.REMOVE_TOAST:\n if (action.toastId === undefined)\n state.value.toasts = []\n else\n state.value.toasts = state.value.toasts.filter(t => t.id !== action.toastId)\n\n break\n }\n}\n\nfunction useToast() {\n return {\n toasts: computed(() => state.value.toasts),\n toast,\n dismiss: (toastId?: string) => dispatch({ type: actionTypes.DISMISS_TOAST, toastId }),\n }\n}\n\ntype Toast = Omit\n\nfunction toast(props: Toast) {\n const id = genId()\n\n const update = (props: ToasterToast) =>\n dispatch({\n type: actionTypes.UPDATE_TOAST,\n toast: { ...props, id },\n })\n\n const dismiss = () => dispatch({ type: actionTypes.DISMISS_TOAST, toastId: id })\n\n dispatch({\n type: actionTypes.ADD_TOAST,\n toast: {\n ...props,\n id,\n 'open': true,\n 'onUpdate:open': (open: boolean) => {\n if (!open)\n dismiss()\n },\n },\n })\n\n return {\n id,\n dismiss,\n update,\n }\n}\n\nexport { toast, useToast }\n" } ], "type": "components:ui" diff --git a/apps/www/src/public/registry/styles/new-york/toast.json b/apps/www/src/public/registry/styles/new-york/toast.json index a3b074b1..69a43a93 100644 --- a/apps/www/src/public/registry/styles/new-york/toast.json +++ b/apps/www/src/public/registry/styles/new-york/toast.json @@ -1,20 +1,51 @@ { "name": "toast", "dependencies": [ - "@radix-ui/react-toast" + "radix-vue" + ], + "registryDependencies": [ + "utils" ], "files": [ { - "name": "toast.tsx", - "content": "import * as React from \"react\"\nimport { Cross2Icon } from \"@radix-ui/react-icons\"\nimport * as ToastPrimitives from \"@radix-ui/react-toast\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst ToastProvider = ToastPrimitives.Provider\n\nconst ToastViewport = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastViewport.displayName = ToastPrimitives.Viewport.displayName\n\nconst toastVariants = cva(\n \"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full\",\n {\n variants: {\n variant: {\n default: \"border bg-background text-foreground\",\n destructive:\n \"destructive group border-destructive bg-destructive text-destructive-foreground\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n },\n }\n)\n\nconst Toast = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef &\n VariantProps\n>(({ class, variant, ...props }, ref) => {\n return (\n \n )\n})\nToast.displayName = ToastPrimitives.Root.displayName\n\nconst ToastAction = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastAction.displayName = ToastPrimitives.Action.displayName\n\nconst ToastClose = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n \n \n))\nToastClose.displayName = ToastPrimitives.Close.displayName\n\nconst ToastTitle = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastTitle.displayName = ToastPrimitives.Title.displayName\n\nconst ToastDescription = React.forwardRef<\n React.ElementRef,\n React.ComponentPropsWithoutRef\n>(({ class, ...props }, ref) => (\n \n))\nToastDescription.displayName = ToastPrimitives.Description.displayName\n\ntype ToastProps = React.ComponentPropsWithoutRef\n\ntype ToastActionElement = React.ReactElement\n\nexport {\n type ToastProps,\n type ToastActionElement,\n ToastProvider,\n ToastViewport,\n Toast,\n ToastTitle,\n ToastDescription,\n ToastClose,\n ToastAction,\n}\n" + "name": "Toast.vue", + "content": "\n\n\n\n\n" + }, + { + "name": "ToastAction.vue", + "content": "\n\n\n" + }, + { + "name": "ToastClose.vue", + "content": "\n\n\n" + }, + { + "name": "ToastDescription.vue", + "content": "\n\n\n" + }, + { + "name": "ToastProvider.vue", + "content": "\n\n\n" + }, + { + "name": "ToastTitle.vue", + "content": "\n\n\n" + }, + { + "name": "ToastViewport.vue", + "content": "\n\n\n" + }, + { + "name": "Toaster.vue", + "content": "\n\n\n" + }, + { + "name": "index.ts", + "content": "export { default as Toaster } from './Toaster.vue'\nexport { default as Toast } from './Toast.vue'\nexport { default as ToastViewport } from './ToastViewport.vue'\nexport { default as ToastAction } from './ToastAction.vue'\nexport { default as ToastClose } from './ToastClose.vue'\nexport { default as ToastTitle } from './ToastTitle.vue'\nexport { default as ToastDescription } from './ToastDescription.vue'\nexport { default as ToastProvider } from './ToastProvider.vue'\nexport { toast, useToast } from './use-toast'\n\nimport { cva } from 'class-variance-authority'\n\nexport const toastVariants = cva(\n 'group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full',\n {\n variants: {\n variant: {\n default: 'border bg-background text-foreground',\n destructive:\n 'destructive group border-destructive bg-destructive text-destructive-foreground',\n },\n },\n defaultVariants: {\n variant: 'default',\n },\n },\n)\n" }, { "name": "use-toast.ts", - "content": "// Inspired by react-hot-toast library\nimport * as React from \"react\"\n\nimport type {\n ToastActionElement,\n ToastProps,\n} from \"@/registry/default/ui/toast\"\n\nconst TOAST_LIMIT = 1\nconst TOAST_REMOVE_DELAY = 1000000\n\ntype ToasterToast = ToastProps & {\n id: string\n title?: React.ReactNode\n description?: React.ReactNode\n action?: ToastActionElement\n}\n\nconst actionTypes = {\n ADD_TOAST: \"ADD_TOAST\",\n UPDATE_TOAST: \"UPDATE_TOAST\",\n DISMISS_TOAST: \"DISMISS_TOAST\",\n REMOVE_TOAST: \"REMOVE_TOAST\",\n} as const\n\nlet count = 0\n\nfunction genId() {\n count = (count + 1) % Number.MAX_VALUE\n return count.toString()\n}\n\ntype ActionType = typeof actionTypes\n\ntype Action =\n | {\n type: ActionType[\"ADD_TOAST\"]\n toast: ToasterToast\n }\n | {\n type: ActionType[\"UPDATE_TOAST\"]\n toast: Partial\n }\n | {\n type: ActionType[\"DISMISS_TOAST\"]\n toastId?: ToasterToast[\"id\"]\n }\n | {\n type: ActionType[\"REMOVE_TOAST\"]\n toastId?: ToasterToast[\"id\"]\n }\n\ninterface State {\n toasts: ToasterToast[]\n}\n\nconst toastTimeouts = new Map>()\n\nconst addToRemoveQueue = (toastId: string) => {\n if (toastTimeouts.has(toastId)) {\n return\n }\n\n const timeout = setTimeout(() => {\n toastTimeouts.delete(toastId)\n dispatch({\n type: \"REMOVE_TOAST\",\n toastId: toastId,\n })\n }, TOAST_REMOVE_DELAY)\n\n toastTimeouts.set(toastId, timeout)\n}\n\nexport const reducer = (state: State, action: Action): State => {\n switch (action.type) {\n case \"ADD_TOAST\":\n return {\n ...state,\n toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),\n }\n\n case \"UPDATE_TOAST\":\n return {\n ...state,\n toasts: state.toasts.map((t) =>\n t.id === action.toast.id ? { ...t, ...action.toast } : t\n ),\n }\n\n case \"DISMISS_TOAST\": {\n const { toastId } = action\n\n // ! Side effects ! - This could be extracted into a dismissToast() action,\n // but I'll keep it here for simplicity\n if (toastId) {\n addToRemoveQueue(toastId)\n } else {\n state.toasts.forEach((toast) => {\n addToRemoveQueue(toast.id)\n })\n }\n\n return {\n ...state,\n toasts: state.toasts.map((t) =>\n t.id === toastId || toastId === undefined\n ? {\n ...t,\n open: false,\n }\n : t\n ),\n }\n }\n case \"REMOVE_TOAST\":\n if (action.toastId === undefined) {\n return {\n ...state,\n toasts: [],\n }\n }\n return {\n ...state,\n toasts: state.toasts.filter((t) => t.id !== action.toastId),\n }\n }\n}\n\nconst listeners: Array<(state: State) => void> = []\n\nlet memoryState: State = { toasts: [] }\n\nfunction dispatch(action: Action) {\n memoryState = reducer(memoryState, action)\n listeners.forEach((listener) => {\n listener(memoryState)\n })\n}\n\ntype Toast = Omit\n\nfunction toast({ ...props }: Toast) {\n const id = genId()\n\n const update = (props: ToasterToast) =>\n dispatch({\n type: \"UPDATE_TOAST\",\n toast: { ...props, id },\n })\n const dismiss = () => dispatch({ type: \"DISMISS_TOAST\", toastId: id })\n\n dispatch({\n type: \"ADD_TOAST\",\n toast: {\n ...props,\n id,\n open: true,\n onOpenChange: (open) => {\n if (!open) dismiss()\n },\n },\n })\n\n return {\n id: id,\n dismiss,\n update,\n }\n}\n\nfunction useToast() {\n const [state, setState] = React.useState(memoryState)\n\n React.useEffect(() => {\n listeners.push(setState)\n return () => {\n const index = listeners.indexOf(setState)\n if (index > -1) {\n listeners.splice(index, 1)\n }\n }\n }, [state])\n\n return {\n ...state,\n toast,\n dismiss: (toastId?: string) => dispatch({ type: \"DISMISS_TOAST\", toastId }),\n }\n}\n\nexport { useToast, toast }\n" - }, - { - "name": "toaster.tsx", - "content": "\"use client\"\n\nimport {\n Toast,\n ToastClose,\n ToastDescription,\n ToastProvider,\n ToastTitle,\n ToastViewport,\n} from \"@/registry/new-york/ui/toast\"\nimport { useToast } from \"@/registry/new-york/ui/use-toast\"\n\nexport function Toaster() {\n const { toasts } = useToast()\n\n return (\n \n {toasts.map(function ({ id, title, description, action, ...props }) {\n return (\n \n
\n {title && {title}}\n {description && (\n {description}\n )}\n
\n {action}\n \n
\n )\n })}\n \n
\n )\n}\n" + "content": "import { computed, ref } from 'vue'\nimport type { Component, VNode } from 'vue'\nimport type { ToastProps } from './Toast.vue'\n\nconst TOAST_LIMIT = 1\nconst TOAST_REMOVE_DELAY = 1000000\n\nexport type StringOrVNode =\n | string\n | VNode\n | (() => VNode)\n\ntype ToasterToast = ToastProps & {\n id: string\n title?: string\n description?: StringOrVNode\n action?: Component\n}\n\nconst actionTypes = {\n ADD_TOAST: 'ADD_TOAST',\n UPDATE_TOAST: 'UPDATE_TOAST',\n DISMISS_TOAST: 'DISMISS_TOAST',\n REMOVE_TOAST: 'REMOVE_TOAST',\n} as const\n\nlet count = 0\n\nfunction genId() {\n count = (count + 1) % Number.MAX_VALUE\n return count.toString()\n}\n\ntype ActionType = typeof actionTypes\n\ntype Action =\n | {\n type: ActionType['ADD_TOAST']\n toast: ToasterToast\n }\n | {\n type: ActionType['UPDATE_TOAST']\n toast: Partial\n }\n | {\n type: ActionType['DISMISS_TOAST']\n toastId?: ToasterToast['id']\n }\n | {\n type: ActionType['REMOVE_TOAST']\n toastId?: ToasterToast['id']\n }\n\ninterface State {\n toasts: ToasterToast[]\n}\n\nconst toastTimeouts = new Map>()\n\nfunction addToRemoveQueue(toastId: string) {\n if (toastTimeouts.has(toastId))\n return\n\n const timeout = setTimeout(() => {\n toastTimeouts.delete(toastId)\n dispatch({\n type: actionTypes.REMOVE_TOAST,\n toastId,\n })\n }, TOAST_REMOVE_DELAY)\n\n toastTimeouts.set(toastId, timeout)\n}\n\nconst state = ref({\n toasts: [],\n})\n\nfunction dispatch(action: Action) {\n switch (action.type) {\n case actionTypes.ADD_TOAST:\n state.value.toasts = [action.toast, ...state.value.toasts].slice(0, TOAST_LIMIT)\n break\n\n case actionTypes.UPDATE_TOAST:\n state.value.toasts = state.value.toasts.map(t =>\n t.id === action.toast.id ? { ...t, ...action.toast } : t,\n )\n break\n\n case actionTypes.DISMISS_TOAST: {\n const { toastId } = action\n\n if (toastId) {\n addToRemoveQueue(toastId)\n }\n else {\n state.value.toasts.forEach((toast) => {\n addToRemoveQueue(toast.id)\n })\n }\n\n state.value.toasts = state.value.toasts.map(t =>\n t.id === toastId || toastId === undefined\n ? {\n ...t,\n open: false,\n }\n : t,\n )\n break\n }\n\n case actionTypes.REMOVE_TOAST:\n if (action.toastId === undefined)\n state.value.toasts = []\n else\n state.value.toasts = state.value.toasts.filter(t => t.id !== action.toastId)\n\n break\n }\n}\n\nfunction useToast() {\n return {\n toasts: computed(() => state.value.toasts),\n toast,\n dismiss: (toastId?: string) => dispatch({ type: actionTypes.DISMISS_TOAST, toastId }),\n }\n}\n\ntype Toast = Omit\n\nfunction toast(props: Toast) {\n const id = genId()\n\n const update = (props: ToasterToast) =>\n dispatch({\n type: actionTypes.UPDATE_TOAST,\n toast: { ...props, id },\n })\n\n const dismiss = () => dispatch({ type: actionTypes.DISMISS_TOAST, toastId: id })\n\n dispatch({\n type: actionTypes.ADD_TOAST,\n toast: {\n ...props,\n id,\n 'open': true,\n 'onUpdate:open': (open: boolean) => {\n if (!open)\n dismiss()\n },\n },\n })\n\n return {\n id,\n dismiss,\n update,\n }\n}\n\nexport { toast, useToast }\n" } ], "type": "components:ui"