@sikka/hawa 0.1.30 → 0.1.32

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": "@sikka/hawa",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "SaaS Oriented UI Kit",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.es.js",
@@ -106,6 +106,8 @@
106
106
  },
107
107
  "dependencies": {
108
108
  "@radix-ui/react-accordion": "^1.1.2",
109
+ "@radix-ui/react-direction": "^1.0.1",
110
+ "@radix-ui/react-toast": "^1.1.4",
109
111
  "@radix-ui/react-dropdown-menu": "^2.0.5",
110
112
  "@radix-ui/react-label": "^2.0.2",
111
113
  "@radix-ui/react-popover": "^1.0.6",
@@ -0,0 +1,163 @@
1
+ import * as React from "react"
2
+ import * as ToastPrimitives from "@radix-ui/react-toast"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+
5
+ import { cn } from "../util"
6
+
7
+ const ToastProvider = ToastPrimitives.Provider
8
+
9
+ const ToastViewport = React.forwardRef<
10
+ React.ElementRef<typeof ToastPrimitives.Viewport>,
11
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
12
+ >(({ className, ...props }, ref) => (
13
+ <ToastPrimitives.Viewport
14
+ ref={ref}
15
+ className={cn(
16
+ "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]",
17
+ className
18
+ )}
19
+ {...props}
20
+ />
21
+ ))
22
+ ToastViewport.displayName = ToastPrimitives.Viewport.displayName
23
+
24
+ const toastVariants = cva(
25
+ "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",
26
+ {
27
+ variants: {
28
+ variant: {
29
+ default: "border bg-background text-foreground",
30
+ destructive:
31
+ "destructive group border-destructive bg-destructive text-destructive-foreground",
32
+ },
33
+ severity: {
34
+ info: "info group text-info-foreground bg-info",
35
+ warning: "warning group text-warning-foreground bg-warning",
36
+ error: "error group border-error bg-error text-error-foreground",
37
+ success: "success group text-success-foreground bg-success",
38
+ none: "bg-red-500 ",
39
+ },
40
+ },
41
+
42
+ defaultVariants: {
43
+ variant: "default",
44
+ },
45
+ }
46
+ )
47
+
48
+ const Toast = React.forwardRef<
49
+ React.ElementRef<typeof ToastPrimitives.Root>,
50
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
51
+ VariantProps<typeof toastVariants> & {
52
+ severity?: "info" | "warning" | "error" | "success" | "none"
53
+ direction?: "rtl" | "ltr"
54
+ }
55
+ >(({ className, variant, severity = "none", ...props }, ref) => {
56
+ return (
57
+ <ToastPrimitives.Root
58
+ ref={ref}
59
+ // dir={'rtl'}
60
+ className={cn(
61
+ toastVariants({ variant, severity }),
62
+ className
63
+ // severity === "error" && "bg-red-500"
64
+ )}
65
+ {...props}
66
+ />
67
+ )
68
+ })
69
+ Toast.displayName = ToastPrimitives.Root.displayName
70
+
71
+ const ToastAction = React.forwardRef<
72
+ React.ElementRef<typeof ToastPrimitives.Action>,
73
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
74
+ >(({ className, ...props }, ref) => (
75
+ <ToastPrimitives.Action
76
+ ref={ref}
77
+ className={cn(
78
+ "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",
79
+ // "group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
80
+
81
+ "group-[.info]:border-muted/40 group-[.info]:hover:border-info/30 group-[.info]:hover:bg-info group-[.info]:hover:text-info-foreground group-[.info]:focus:ring-info",
82
+
83
+ "group-[.error]:border-muted/40 group-[.error]:hover:border-error/30 group-[.error]:hover:bg-error group-[.error]:hover:text-error-foreground group-[.error]:focus:ring-error",
84
+
85
+ "group-[.success]:border-muted/40 group-[.success]:hover:border-success/30 group-[.success]:hover:bg-success group-[.success]:hover:text-success-foreground group-[.success]:focus:ring-success",
86
+
87
+ "group-[.warning]:border-muted/40 group-[.warning]:hover:border-warning/30 group-[.warning]:hover:bg-warning group-[.warning]:hover:text-warning-foreground group-[.warning]:focus:ring-warning",
88
+ className
89
+ )}
90
+ {...props}
91
+ />
92
+ ))
93
+ ToastAction.displayName = ToastPrimitives.Action.displayName
94
+
95
+ const ToastClose = React.forwardRef<
96
+ React.ElementRef<typeof ToastPrimitives.Close>,
97
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
98
+ >(({ className, ...props }, ref) => (
99
+ <ToastPrimitives.Close
100
+ ref={ref}
101
+ className={cn(
102
+ "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",
103
+ className
104
+ )}
105
+ toast-close=""
106
+ {...props}
107
+ >
108
+ <svg
109
+ aria-label="Close Icon"
110
+ aria-hidden="true"
111
+ className="h-4 w-4"
112
+ fill="currentColor"
113
+ viewBox="0 0 20 20"
114
+ >
115
+ <path
116
+ fillRule="evenodd"
117
+ d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
118
+ clipRule="evenodd"
119
+ ></path>
120
+ </svg>
121
+ </ToastPrimitives.Close>
122
+ ))
123
+ ToastClose.displayName = ToastPrimitives.Close.displayName
124
+
125
+ const ToastTitle = React.forwardRef<
126
+ React.ElementRef<typeof ToastPrimitives.Title>,
127
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
128
+ >(({ className, ...props }, ref) => (
129
+ <ToastPrimitives.Title
130
+ ref={ref}
131
+ className={cn("text-sm font-semibold", className)}
132
+ {...props}
133
+ />
134
+ ))
135
+ ToastTitle.displayName = ToastPrimitives.Title.displayName
136
+
137
+ const ToastDescription = React.forwardRef<
138
+ React.ElementRef<typeof ToastPrimitives.Description>,
139
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
140
+ >(({ className, ...props }, ref) => (
141
+ <ToastPrimitives.Description
142
+ ref={ref}
143
+ className={cn("text-sm opacity-90", className)}
144
+ {...props}
145
+ />
146
+ ))
147
+ ToastDescription.displayName = ToastPrimitives.Description.displayName
148
+
149
+ type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
150
+
151
+ type ToastActionElement = React.ReactElement<typeof ToastAction>
152
+
153
+ export {
154
+ type ToastProps,
155
+ type ToastActionElement,
156
+ ToastProvider,
157
+ ToastViewport,
158
+ Toast,
159
+ ToastTitle,
160
+ ToastDescription,
161
+ ToastClose,
162
+ ToastAction,
163
+ }
@@ -0,0 +1,41 @@
1
+ import {
2
+ Toast,
3
+ ToastClose,
4
+ ToastDescription,
5
+ ToastProvider,
6
+ ToastTitle,
7
+ ToastViewport,
8
+ } from "./Toast"
9
+ import { useToast } from "../hooks/useToast"
10
+ import { cn } from "../util"
11
+ import { DirectionProvider } from "@radix-ui/react-direction"
12
+
13
+ export function Toaster(props) {
14
+ const { toasts } = useToast()
15
+
16
+ return (
17
+ <DirectionProvider dir={"rtl"}>
18
+ <ToastProvider
19
+ swipeDirection={props.direction === "rtl" ? "left" : "right"}
20
+ >
21
+ {toasts.map(function ({ id, title, description, action, ...props }) {
22
+ return (
23
+ <Toast direction={props.direction} key={id} {...props}>
24
+ <div className="grid gap-1">
25
+ {title && <ToastTitle>{title}</ToastTitle>}
26
+ {description && (
27
+ <ToastDescription>{description}</ToastDescription>
28
+ )}
29
+ </div>
30
+ {action}
31
+ <ToastClose />
32
+ </Toast>
33
+ )
34
+ })}
35
+ <ToastViewport
36
+ className={cn("gap-2", props.direction === "rtl" && "fixed left-0")}
37
+ />
38
+ </ToastProvider>
39
+ </DirectionProvider>
40
+ )
41
+ }
@@ -25,9 +25,7 @@ const TooltipArrow = React.forwardRef<
25
25
  <TooltipPrimitive.Arrow
26
26
  ref={ref}
27
27
  className={cn(
28
- // "bg-popover",
29
- "bg-red-500 text-blue-500 ",
30
- // "z-50 overflow-hidden rounded-md border bg-popover text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
28
+ // "fill-white",
31
29
  className
32
30
  )}
33
31
  {...props}
@@ -67,3 +67,5 @@ export * from "./Popover"
67
67
  export * from "./Tabs"
68
68
  export * from "./Textarea"
69
69
  export * from "./Separator"
70
+ export * from "./Toast"
71
+ export * from "./Toaster"
@@ -1,2 +1,3 @@
1
1
  export * from "./useDiscloser"
2
2
  export * from "./useHover"
3
+ export * from "./useToast"
@@ -0,0 +1,190 @@
1
+ // Inspired by react-hot-toast library
2
+ import * as React from "react"
3
+
4
+ import type { ToastActionElement, ToastProps } from "../elements/Toast"
5
+
6
+ const TOAST_LIMIT = 5
7
+ const TOAST_REMOVE_DELAY = 1000000
8
+
9
+ type ToasterToast = ToastProps & {
10
+ id: string
11
+ title?: React.ReactNode
12
+ description?: React.ReactNode
13
+ severity?: "info" | "warning" | "error" | "success" | "none"
14
+ action?: ToastActionElement
15
+ }
16
+
17
+ const actionTypes = {
18
+ ADD_TOAST: "ADD_TOAST",
19
+ UPDATE_TOAST: "UPDATE_TOAST",
20
+ DISMISS_TOAST: "DISMISS_TOAST",
21
+ REMOVE_TOAST: "REMOVE_TOAST",
22
+ } as const
23
+
24
+ let count = 0
25
+
26
+ function genId() {
27
+ count = (count + 1) % Number.MAX_VALUE
28
+ return count.toString()
29
+ }
30
+
31
+ type ActionType = typeof actionTypes
32
+
33
+ type Action =
34
+ | {
35
+ type: ActionType["ADD_TOAST"]
36
+ toast: ToasterToast
37
+ }
38
+ | {
39
+ type: ActionType["UPDATE_TOAST"]
40
+ toast: Partial<ToasterToast>
41
+ }
42
+ | {
43
+ type: ActionType["DISMISS_TOAST"]
44
+ toastId?: ToasterToast["id"]
45
+ }
46
+ | {
47
+ type: ActionType["REMOVE_TOAST"]
48
+ toastId?: ToasterToast["id"]
49
+ }
50
+
51
+ interface State {
52
+ toasts: ToasterToast[]
53
+ }
54
+
55
+ const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
56
+
57
+ const addToRemoveQueue = (toastId: string) => {
58
+ if (toastTimeouts.has(toastId)) {
59
+ return
60
+ }
61
+
62
+ const timeout = setTimeout(() => {
63
+ toastTimeouts.delete(toastId)
64
+ dispatch({
65
+ type: "REMOVE_TOAST",
66
+ toastId: toastId,
67
+ })
68
+ }, TOAST_REMOVE_DELAY)
69
+
70
+ toastTimeouts.set(toastId, timeout)
71
+ }
72
+
73
+ export const reducer = (state: State, action: Action): State => {
74
+ switch (action.type) {
75
+ case "ADD_TOAST":
76
+ return {
77
+ ...state,
78
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
79
+ }
80
+
81
+ case "UPDATE_TOAST":
82
+ return {
83
+ ...state,
84
+ toasts: state.toasts.map((t) =>
85
+ t.id === action.toast.id ? { ...t, ...action.toast } : t
86
+ ),
87
+ }
88
+
89
+ case "DISMISS_TOAST": {
90
+ const { toastId } = action
91
+
92
+ // ! Side effects ! - This could be extracted into a dismissToast() action,
93
+ // but I'll keep it here for simplicity
94
+ if (toastId) {
95
+ addToRemoveQueue(toastId)
96
+ } else {
97
+ state.toasts.forEach((toast) => {
98
+ addToRemoveQueue(toast.id)
99
+ })
100
+ }
101
+
102
+ return {
103
+ ...state,
104
+ toasts: state.toasts.map((t) =>
105
+ t.id === toastId || toastId === undefined
106
+ ? {
107
+ ...t,
108
+ open: false,
109
+ }
110
+ : t
111
+ ),
112
+ }
113
+ }
114
+ case "REMOVE_TOAST":
115
+ if (action.toastId === undefined) {
116
+ return {
117
+ ...state,
118
+ toasts: [],
119
+ }
120
+ }
121
+ return {
122
+ ...state,
123
+ toasts: state.toasts.filter((t) => t.id !== action.toastId),
124
+ }
125
+ }
126
+ }
127
+
128
+ const listeners: Array<(state: State) => void> = []
129
+
130
+ let memoryState: State = { toasts: [] }
131
+
132
+ function dispatch(action: Action) {
133
+ memoryState = reducer(memoryState, action)
134
+ listeners.forEach((listener) => {
135
+ listener(memoryState)
136
+ })
137
+ }
138
+
139
+ type Toast = Omit<ToasterToast, "id">
140
+
141
+ function toast({ ...props }: Toast) {
142
+ const id = genId()
143
+
144
+ const update = (props: ToasterToast) =>
145
+ dispatch({
146
+ type: "UPDATE_TOAST",
147
+ toast: { ...props, id },
148
+ })
149
+ const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
150
+
151
+ dispatch({
152
+ type: "ADD_TOAST",
153
+ toast: {
154
+ ...props,
155
+ id,
156
+ open: true,
157
+ onOpenChange: (open) => {
158
+ if (!open) dismiss()
159
+ },
160
+ },
161
+ })
162
+
163
+ return {
164
+ id: id,
165
+ dismiss,
166
+ update,
167
+ }
168
+ }
169
+
170
+ function useToast() {
171
+ const [state, setState] = React.useState<State>(memoryState)
172
+
173
+ React.useEffect(() => {
174
+ listeners.push(setState)
175
+ return () => {
176
+ const index = listeners.indexOf(setState)
177
+ if (index > -1) {
178
+ listeners.splice(index, 1)
179
+ }
180
+ }
181
+ }, [state])
182
+
183
+ return {
184
+ ...state,
185
+ toast,
186
+ dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
187
+ }
188
+ }
189
+
190
+ export { useToast, toast }
@@ -215,7 +215,7 @@ export const AppLayout: React.FunctionComponent<AppLayoutTypes> = ({
215
215
  trigger={
216
216
  <div className="relative h-8 w-8 cursor-pointer overflow-clip rounded ring-1 ring-primary/30 dark:bg-gray-600">
217
217
  <svg
218
- aria-aria-label="Avatar Icon"
218
+ aria-label="Avatar Icon"
219
219
  className="absolute -left-1 h-10 w-10 text-gray-400"
220
220
  fill="currentColor"
221
221
  viewBox="0 0 20 20"