@sniptide/ui 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/components/toast.tsx +16 -11
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sniptide/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"gitHead": "21b2e47700c1913c032a9f20a0cb7527ff95937e",
|
|
5
5
|
"description": "Sniptide's shared React components and Tailwind theme, used by the app and the website.",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
7
|
+
"homepage": "https://sniptide.com",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
package/src/components/toast.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { cn } from "cn"
|
|
|
5
5
|
import { AlertCircleIcon, XIcon } from "lucide-react"
|
|
6
6
|
import * as React from "react"
|
|
7
7
|
|
|
8
|
-
type ToastKind = "success" | "error"
|
|
8
|
+
type ToastKind = "success" | "error"
|
|
9
9
|
type ToastAction = { label: string; run: () => void | Promise<void> }
|
|
10
10
|
type ToastItem = {
|
|
11
11
|
id: number
|
|
@@ -21,7 +21,7 @@ type ToastOptions = {
|
|
|
21
21
|
duration?: number
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const DURATION: Record<ToastKind, number> = { success: 3000, error: 6000
|
|
24
|
+
const DURATION: Record<ToastKind, number> = { success: 3000, error: 6000 }
|
|
25
25
|
const ACTION_DURATION = 8000
|
|
26
26
|
const MAX_VISIBLE = 3
|
|
27
27
|
const EMPTY: ToastItem[] = []
|
|
@@ -59,12 +59,12 @@ function show(kind: ToastKind, message: string, options: ToastOptions = {}) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// Feedback for actions that have no button or form of their own to report on, like a menu item.
|
|
62
|
-
// `
|
|
62
|
+
// `success` confirms something that happened with a pink check, and `error` says what failed.
|
|
63
|
+
// Pass `action` for something the reader can take back, like Undo; it renders as a blue chip.
|
|
63
64
|
// Mount <Toaster /> once near the root.
|
|
64
65
|
const toast = {
|
|
65
66
|
success: (message: string, options?: ToastOptions) => show("success", message, options),
|
|
66
67
|
error: (message: string, options?: ToastOptions) => show("error", message, options),
|
|
67
|
-
info: (message: string, options?: ToastOptions) => show("info", message, options),
|
|
68
68
|
dismiss,
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -88,28 +88,33 @@ function Toaster({
|
|
|
88
88
|
() => EMPTY,
|
|
89
89
|
)
|
|
90
90
|
|
|
91
|
+
// Phones stack toasts centered under the top bar; from 1024px they sit in the bottom-right
|
|
92
|
+
// corner at one width, so a stack lines up on its right edge. On touch screens the 24px buttons
|
|
93
|
+
// reach 40px through an invisible hit area.
|
|
91
94
|
return (
|
|
92
95
|
<div
|
|
93
96
|
data-slot="toaster"
|
|
94
97
|
className={cn(
|
|
95
|
-
"pointer-events-none fixed inset-x-0
|
|
98
|
+
"pointer-events-none fixed inset-x-0 top-[calc(env(safe-area-inset-top)+3.75rem)] z-100 flex flex-col items-center gap-2 px-4 lg:top-auto lg:right-[calc(env(safe-area-inset-right)+1.5rem)] lg:bottom-6 lg:left-auto lg:w-80 lg:px-0",
|
|
96
99
|
className,
|
|
97
100
|
)}
|
|
98
101
|
>
|
|
99
102
|
{current.map((item) => (
|
|
100
103
|
<div
|
|
101
104
|
key={item.id}
|
|
105
|
+
data-slot="toast"
|
|
106
|
+
data-kind={item.kind}
|
|
102
107
|
role={item.kind === "error" ? "alert" : "status"}
|
|
103
108
|
className={cn(
|
|
104
|
-
"pointer-events-auto flex max-w-sm items-center gap-
|
|
109
|
+
"pointer-events-auto flex w-full max-w-sm min-h-12 items-center gap-3 rounded-lg border bg-popover py-2.5 pr-2.5 pl-4 text-[13px] leading-[18px] text-popover-foreground shadow-(--float-shadow) animate-in fade-in slide-in-from-top-2 duration-200 lg:slide-in-from-bottom-2 motion-reduce:animate-none",
|
|
105
110
|
item.kind === "error" ? "border-destructive/40" : "border-border",
|
|
106
111
|
)}
|
|
107
112
|
>
|
|
108
113
|
{item.kind === "error" ? (
|
|
109
114
|
<AlertCircleIcon className="size-4 shrink-0 text-destructive" aria-hidden="true" />
|
|
110
|
-
) :
|
|
111
|
-
<SuccessCheck className="text-
|
|
112
|
-
)
|
|
115
|
+
) : (
|
|
116
|
+
<SuccessCheck className="text-highlight" />
|
|
117
|
+
)}
|
|
113
118
|
<span className="min-w-0 flex-1">{item.message}</span>
|
|
114
119
|
{item.action ? (
|
|
115
120
|
<button
|
|
@@ -118,7 +123,7 @@ function Toaster({
|
|
|
118
123
|
dismiss(item.id)
|
|
119
124
|
void item.action?.run()
|
|
120
125
|
}}
|
|
121
|
-
className="
|
|
126
|
+
className="relative h-6 shrink-0 rounded-md bg-primary px-2 text-[13px] font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/85 focus-visible:ring-2 focus-visible:ring-ring/40 active:translate-y-px pointer-coarse:after:absolute pointer-coarse:after:-inset-2"
|
|
122
127
|
>
|
|
123
128
|
{item.action.label}
|
|
124
129
|
</button>
|
|
@@ -127,7 +132,7 @@ function Toaster({
|
|
|
127
132
|
type="button"
|
|
128
133
|
aria-label={dismissLabel}
|
|
129
134
|
onClick={() => dismiss(item.id)}
|
|
130
|
-
className="
|
|
135
|
+
className="relative flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 pointer-coarse:after:absolute pointer-coarse:after:-inset-2"
|
|
131
136
|
>
|
|
132
137
|
<XIcon className="size-3.5" />
|
|
133
138
|
</button>
|