@hanzo/ui 3.0.5 → 3.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/ui",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Library that contains shared UI primitives, support for a common design system, and other boilerplate support.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -63,6 +63,7 @@
63
63
  "postcss-selector-parser": "^6.0.13",
64
64
  "react-day-picker": "^8.7.1",
65
65
  "react-intersection-observer": "^9.7.0",
66
+ "sonner": "^1.2.3",
66
67
  "tailwind-merge": "^2.2.0",
67
68
  "tailwindcss-animate": "^1.0.6",
68
69
  "tailwindcss-interaction-media": "^0.1.0",
@@ -71,7 +72,7 @@
71
72
  "peerDependencies": {
72
73
  "@hookform/resolvers": "^3.3.2",
73
74
  "lucide-react": "^0.344.0",
74
- "next": "^14.1.0",
75
+ "next": "14.1.3",
75
76
  "next-themes": "^0.2.1",
76
77
  "react": "^18.2.0",
77
78
  "react-dom": "^18.2.0",
@@ -81,18 +81,6 @@ export {
81
81
 
82
82
  export { default as BreakpointIndicator } from './breakpoint-indicator'
83
83
 
84
- export {
85
- type ToastProps,
86
- type ToastActionElement,
87
- ToastProvider,
88
- ToastViewport,
89
- Toast,
90
- ToastTitle,
91
- ToastDescription,
92
- ToastClose,
93
- ToastAction,
94
- } from './toast'
95
-
96
84
  export {
97
85
  Select,
98
86
  SelectGroup,
@@ -163,8 +151,7 @@ export { ToggleGroup, ToggleGroupItem } from './toggle-group'
163
151
 
164
152
  export { ScrollArea, ScrollBar } from './scroll-area'
165
153
 
166
- export { Toaster } from './toaster'
167
- export { useToast, toast } from './use-toast'
154
+ export { Toaster, toast } from './sonner'
168
155
  export { RadioGroup, RadioGroupItem } from './radio-group'
169
156
 
170
157
  export { default as AspectRatio } from './aspect-ratio'
@@ -0,0 +1,35 @@
1
+ "use client"
2
+
3
+ import { useTheme } from "next-themes"
4
+ import { Toaster as Sonner } from "sonner"
5
+ import { toast } from "sonner"
6
+
7
+ type ToasterProps = React.ComponentProps<typeof Sonner>
8
+
9
+ const Toaster = ({ ...props }: ToasterProps) => {
10
+ const { theme = "system" } = useTheme()
11
+
12
+ return (
13
+ <Sonner
14
+ theme={theme as ToasterProps["theme"]}
15
+ className="toaster group"
16
+ toastOptions={{
17
+ classNames: {
18
+ toast:
19
+ "group toast group-[.toaster]:bg-level-2 group-[.toaster]:text-foreground group-[.toaster]:border-muted-3 group-[.toaster]:shadow-lg",
20
+ description: "group-[.toast]:text-foreground",
21
+ actionButton:
22
+ "group-[.toast]:bg-primary group-[.toast]:text-primary-fg",
23
+ cancelButton:
24
+ "group-[.toast]:bg-transparent group-[.toast]:text-foreground",
25
+ },
26
+ }}
27
+ {...props}
28
+ />
29
+ )
30
+ }
31
+
32
+ export {
33
+ toast,
34
+ Toaster
35
+ }
@@ -1,129 +0,0 @@
1
- // @ts-nocheck
2
- 'use client'
3
- import * as React from "react"
4
- import * as ToastPrimitives from "@radix-ui/react-toast"
5
- import { cva, type VariantProps } from "class-variance-authority"
6
- import { X } from "lucide-react"
7
-
8
- import { cn } from "../util"
9
-
10
- const ToastProvider = ToastPrimitives.Provider
11
-
12
- const ToastViewport = React.forwardRef<
13
- React.ElementRef<typeof ToastPrimitives.Viewport>,
14
- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
15
- >(({ className, ...props }, ref) => (
16
- <ToastPrimitives.Viewport
17
- ref={ref}
18
- className={cn(
19
- "fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
20
- className
21
- )}
22
- {...props}
23
- />
24
- ))
25
- ToastViewport.displayName = ToastPrimitives.Viewport.displayName
26
-
27
- const toastVariants = cva(
28
- "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",
29
- {
30
- variants: {
31
- variant: {
32
- default: "border bg-background text-foreground",
33
- destructive:
34
- "destructive group border-destructive bg-destructive text-destructive-fg",
35
- },
36
- },
37
- defaultVariants: {
38
- variant: "default",
39
- },
40
- }
41
- )
42
-
43
- const Toast = React.forwardRef<
44
- React.ElementRef<typeof ToastPrimitives.Root>,
45
- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
46
- VariantProps<typeof toastVariants>
47
- >(({ className, variant, ...props }, ref) => {
48
- return (
49
- <ToastPrimitives.Root
50
- ref={ref}
51
- className={cn(toastVariants({ variant }), className)}
52
- {...props}
53
- />
54
- )
55
- })
56
- Toast.displayName = ToastPrimitives.Root.displayName
57
-
58
- const ToastAction = React.forwardRef<
59
- React.ElementRef<typeof ToastPrimitives.Action>,
60
- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
61
- >(({ className, ...props }, ref) => (
62
- <ToastPrimitives.Action
63
- ref={ref}
64
- className={cn(
65
- "inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted-1/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-fg group-[.destructive]:focus:ring-destructive",
66
- className
67
- )}
68
- {...props}
69
- />
70
- ))
71
- ToastAction.displayName = ToastPrimitives.Action.displayName
72
-
73
- const ToastClose = React.forwardRef<
74
- React.ElementRef<typeof ToastPrimitives.Close>,
75
- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
76
- >(({ className, ...props }, ref) => (
77
- <ToastPrimitives.Close
78
- ref={ref}
79
- className={cn(
80
- "absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
81
- className
82
- )}
83
- toast-close=""
84
- {...props}
85
- >
86
- <X className="h-4 w-4" />
87
- </ToastPrimitives.Close>
88
- ))
89
- ToastClose.displayName = ToastPrimitives.Close.displayName
90
-
91
- const ToastTitle = React.forwardRef<
92
- React.ElementRef<typeof ToastPrimitives.Title>,
93
- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
94
- >(({ className, ...props }, ref) => (
95
- <ToastPrimitives.Title
96
- ref={ref}
97
- className={cn("text-sm font-semibold", className)}
98
- {...props}
99
- />
100
- ))
101
- ToastTitle.displayName = ToastPrimitives.Title.displayName
102
-
103
- const ToastDescription = React.forwardRef<
104
- React.ElementRef<typeof ToastPrimitives.Description>,
105
- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
106
- >(({ className, ...props }, ref) => (
107
- <ToastPrimitives.Description
108
- ref={ref}
109
- className={cn("text-sm opacity-90", className)}
110
- {...props}
111
- />
112
- ))
113
- ToastDescription.displayName = ToastPrimitives.Description.displayName
114
-
115
- type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
116
-
117
- type ToastActionElement = React.ReactElement<typeof ToastAction>
118
-
119
- export {
120
- type ToastProps,
121
- type ToastActionElement,
122
- ToastProvider,
123
- ToastViewport,
124
- Toast,
125
- ToastTitle,
126
- ToastDescription,
127
- ToastClose,
128
- ToastAction,
129
- }
@@ -1,37 +0,0 @@
1
- // @ts-nocheck
2
- "use client"
3
-
4
- import {
5
- Toast,
6
- ToastClose,
7
- ToastDescription,
8
- ToastProvider,
9
- ToastTitle,
10
- ToastViewport,
11
- } from "./toast"
12
-
13
- import { useToast } from "./use-toast"
14
-
15
- export const Toaster: React.FC = () => {
16
- const { toasts } = useToast()
17
-
18
- return (
19
- <ToastProvider>
20
- {toasts.map(function ({ id, title, description, action, ...props }) {
21
- return (
22
- <Toast key={id} {...props}>
23
- <div className="grid gap-1">
24
- {title && <ToastTitle>{title}</ToastTitle>}
25
- {description && (
26
- <ToastDescription>{description}</ToastDescription>
27
- )}
28
- </div>
29
- {action}
30
- <ToastClose />
31
- </Toast>
32
- )
33
- })}
34
- <ToastViewport />
35
- </ToastProvider>
36
- )
37
- }
@@ -1,192 +0,0 @@
1
- // Inspired by react-hot-toast library
2
- import * as React from "react"
3
-
4
- import type {
5
- ToastActionElement,
6
- ToastProps,
7
- } from "./toast"
8
-
9
- const TOAST_LIMIT = 1
10
- const TOAST_REMOVE_DELAY = 1000000
11
-
12
- type ToasterToast = ToastProps & {
13
- id: string
14
- title?: React.ReactNode
15
- description?: React.ReactNode
16
- action?: ToastActionElement
17
- }
18
-
19
- const actionTypes = {
20
- ADD_TOAST: "ADD_TOAST",
21
- UPDATE_TOAST: "UPDATE_TOAST",
22
- DISMISS_TOAST: "DISMISS_TOAST",
23
- REMOVE_TOAST: "REMOVE_TOAST",
24
- } as const
25
-
26
- let count = 0
27
-
28
- function genId() {
29
- count = (count + 1) % Number.MAX_VALUE
30
- return count.toString()
31
- }
32
-
33
- type ActionType = typeof actionTypes
34
-
35
- type Action =
36
- | {
37
- type: ActionType["ADD_TOAST"]
38
- toast: ToasterToast
39
- }
40
- | {
41
- type: ActionType["UPDATE_TOAST"]
42
- toast: Partial<ToasterToast>
43
- }
44
- | {
45
- type: ActionType["DISMISS_TOAST"]
46
- toastId?: ToasterToast["id"]
47
- }
48
- | {
49
- type: ActionType["REMOVE_TOAST"]
50
- toastId?: ToasterToast["id"]
51
- }
52
-
53
- interface State {
54
- toasts: ToasterToast[]
55
- }
56
-
57
- const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
58
-
59
- const addToRemoveQueue = (toastId: string) => {
60
- if (toastTimeouts.has(toastId)) {
61
- return
62
- }
63
-
64
- const timeout = setTimeout(() => {
65
- toastTimeouts.delete(toastId)
66
- dispatch({
67
- type: "REMOVE_TOAST",
68
- toastId: toastId,
69
- })
70
- }, TOAST_REMOVE_DELAY)
71
-
72
- toastTimeouts.set(toastId, timeout)
73
- }
74
-
75
- const reducer = (state: State, action: Action): State => {
76
- switch (action.type) {
77
- case "ADD_TOAST":
78
- return {
79
- ...state,
80
- toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
81
- }
82
-
83
- case "UPDATE_TOAST":
84
- return {
85
- ...state,
86
- toasts: state.toasts.map((t) =>
87
- t.id === action.toast.id ? { ...t, ...action.toast } : t
88
- ),
89
- }
90
-
91
- case "DISMISS_TOAST": {
92
- const { toastId } = action
93
-
94
- // ! Side effects ! - This could be extracted into a dismissToast() action,
95
- // but I'll keep it here for simplicity
96
- if (toastId) {
97
- addToRemoveQueue(toastId)
98
- } else {
99
- state.toasts.forEach((toast) => {
100
- addToRemoveQueue(toast.id)
101
- })
102
- }
103
-
104
- return {
105
- ...state,
106
- toasts: state.toasts.map((t) =>
107
- t.id === toastId || toastId === undefined
108
- ? {
109
- ...t,
110
- open: false,
111
- }
112
- : t
113
- ),
114
- }
115
- }
116
- case "REMOVE_TOAST":
117
- if (action.toastId === undefined) {
118
- return {
119
- ...state,
120
- toasts: [],
121
- }
122
- }
123
- return {
124
- ...state,
125
- toasts: state.toasts.filter((t) => t.id !== action.toastId),
126
- }
127
- }
128
- }
129
-
130
- const listeners: Array<(state: State) => void> = []
131
-
132
- let memoryState: State = { toasts: [] }
133
-
134
- function dispatch(action: Action) {
135
- memoryState = reducer(memoryState, action)
136
- listeners.forEach((listener) => {
137
- listener(memoryState)
138
- })
139
- }
140
-
141
- type Toast = Omit<ToasterToast, "id">
142
-
143
- function toast({ ...props }: Toast) {
144
- const id = genId()
145
-
146
- const update = (props: ToasterToast) =>
147
- dispatch({
148
- type: "UPDATE_TOAST",
149
- toast: { ...props, id },
150
- })
151
- const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
152
-
153
- dispatch({
154
- type: "ADD_TOAST",
155
- toast: {
156
- ...props,
157
- id,
158
- open: true,
159
- onOpenChange: (open: any) => {
160
- if (!open) dismiss()
161
- },
162
- },
163
- })
164
-
165
- return {
166
- id: id,
167
- dismiss,
168
- update,
169
- }
170
- }
171
-
172
- function useToast() {
173
- const [state, setState] = React.useState<State>(memoryState)
174
-
175
- React.useEffect(() => {
176
- listeners.push(setState)
177
- return () => {
178
- const index = listeners.indexOf(setState)
179
- if (index > -1) {
180
- listeners.splice(index, 1)
181
- }
182
- }
183
- }, [state])
184
-
185
- return {
186
- ...state,
187
- toast,
188
- dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
189
- }
190
- }
191
-
192
- export { useToast, toast }