@blankways/ui 0.0.0-stage → 0.1.0-alpha.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/README.md +228 -2
- package/dist/cli/cli.options.d.ts +5 -0
- package/dist/cli/cli.options.js +53 -0
- package/dist/cli/cli.registry.d.ts +6 -0
- package/dist/cli/cli.registry.js +37 -0
- package/dist/cli/cli.types.d.ts +32 -0
- package/dist/cli/cli.types.js +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +47 -0
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +101 -0
- package/dist/commands/doctor.command.d.ts +3 -0
- package/dist/commands/doctor.command.js +92 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/init.command.d.ts +2 -0
- package/dist/commands/init.command.js +38 -0
- package/dist/commands/list.command.d.ts +2 -0
- package/dist/commands/list.command.js +54 -0
- package/dist/commands/meta.command.d.ts +1 -0
- package/dist/commands/meta.command.js +19 -0
- package/dist/commands/styles.command.d.ts +6 -0
- package/dist/commands/styles.command.js +68 -0
- package/dist/config/config.helpers.d.ts +7 -0
- package/dist/config/config.helpers.js +63 -0
- package/dist/config/framework.helpers.d.ts +3 -0
- package/dist/config/framework.helpers.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/constants/cli.constants.d.ts +9 -0
- package/dist/constants/cli.constants.js +15 -0
- package/dist/constants/framework.constants.d.ts +3 -0
- package/dist/constants/framework.constants.js +2 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/doctor/checks/entries.check.d.ts +1 -0
- package/dist/doctor/checks/entries.check.js +21 -0
- package/dist/doctor/checks/icons.check.d.ts +1 -0
- package/dist/doctor/checks/icons.check.js +55 -0
- package/dist/doctor/checks/imports.check.d.ts +1 -0
- package/dist/doctor/checks/imports.check.js +45 -0
- package/dist/doctor/checks/index.d.ts +7 -0
- package/dist/doctor/checks/index.js +7 -0
- package/dist/doctor/checks/motion.check.d.ts +1 -0
- package/dist/doctor/checks/motion.check.js +66 -0
- package/dist/doctor/checks/peers.check.d.ts +1 -0
- package/dist/doctor/checks/peers.check.js +55 -0
- package/dist/doctor/checks/styles.check.d.ts +1 -0
- package/dist/doctor/checks/styles.check.js +45 -0
- package/dist/doctor/checks/themes.check.d.ts +1 -0
- package/dist/doctor/checks/themes.check.js +64 -0
- package/dist/doctor/doctor.helpers.d.ts +6 -0
- package/dist/doctor/doctor.helpers.js +39 -0
- package/dist/doctor/doctor.registry.d.ts +10 -0
- package/dist/doctor/doctor.registry.js +24 -0
- package/dist/doctor/doctor.types.d.ts +27 -0
- package/dist/doctor/doctor.types.js +1 -0
- package/dist/doctor/index.d.ts +3 -0
- package/dist/doctor/index.js +3 -0
- package/dist/errors/cli-error.d.ts +3 -0
- package/dist/errors/cli-error.js +6 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/helpers/args.helpers.d.ts +4 -0
- package/dist/helpers/args.helpers.js +75 -0
- package/dist/helpers/help.helpers.d.ts +1 -0
- package/dist/helpers/help.helpers.js +30 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/package.helpers.d.ts +2 -0
- package/dist/helpers/package.helpers.js +12 -0
- package/dist/helpers/path.helpers.d.ts +3 -0
- package/dist/helpers/path.helpers.js +15 -0
- package/dist/helpers/styles.helpers.d.ts +21 -0
- package/dist/helpers/styles.helpers.js +164 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +1 -0
- package/dist/registry/registry.helpers.d.ts +22 -0
- package/dist/registry/registry.helpers.js +328 -0
- package/dist/registry-data/README.md +71 -0
- package/dist/registry-data/avatar/Avatar.tsx +64 -0
- package/dist/registry-data/avatar/component.json +30 -0
- package/dist/registry-data/avatar/index.ts +1 -0
- package/dist/registry-data/badge/Badge.tsx +76 -0
- package/dist/registry-data/badge/component.json +30 -0
- package/dist/registry-data/badge/index.ts +1 -0
- package/dist/registry-data/brand-logo/BrandLogo.tsx +24 -0
- package/dist/registry-data/brand-logo/component.json +26 -0
- package/dist/registry-data/brand-logo/index.ts +1 -0
- package/dist/registry-data/button/Button.tsx +76 -0
- package/dist/registry-data/button/component.json +33 -0
- package/dist/registry-data/button/index.ts +1 -0
- package/dist/registry-data/button-link/ButtonLink.tsx +83 -0
- package/dist/registry-data/button-link/component.json +33 -0
- package/dist/registry-data/button-link/index.ts +5 -0
- package/dist/registry-data/button-styles/component.json +19 -0
- package/dist/registry-data/button-styles/index.ts +45 -0
- package/dist/registry-data/cn/cn.ts +6 -0
- package/dist/registry-data/cn/component.json +16 -0
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +134 -0
- package/dist/registry-data/confirm-dialog/component.json +34 -0
- package/dist/registry-data/confirm-dialog/index.ts +1 -0
- package/dist/registry-data/container/Container.tsx +22 -0
- package/dist/registry-data/container/component.json +28 -0
- package/dist/registry-data/container/index.ts +1 -0
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +29 -0
- package/dist/registry-data/cursor-glow/component.json +28 -0
- package/dist/registry-data/cursor-glow/index.ts +1 -0
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +157 -0
- package/dist/registry-data/dropdown-menu/component.json +34 -0
- package/dist/registry-data/dropdown-menu/index.ts +5 -0
- package/dist/registry-data/empty-state/EmptyState.tsx +92 -0
- package/dist/registry-data/empty-state/component.json +30 -0
- package/dist/registry-data/empty-state/index.ts +5 -0
- package/dist/registry-data/eyebrow/Eyebrow.tsx +68 -0
- package/dist/registry-data/eyebrow/component.json +30 -0
- package/dist/registry-data/eyebrow/index.ts +1 -0
- package/dist/registry-data/field-styles/component.json +19 -0
- package/dist/registry-data/field-styles/index.ts +42 -0
- package/dist/registry-data/form-dialog/FormDialog.tsx +128 -0
- package/dist/registry-data/form-dialog/component.json +34 -0
- package/dist/registry-data/form-dialog/index.ts +1 -0
- package/dist/registry-data/icons/component.json +22 -0
- package/dist/registry-data/icons/index.ts +21 -0
- package/dist/registry-data/icons-form/component.json +17 -0
- package/dist/registry-data/icons-form/index.ts +1 -0
- package/dist/registry-data/icons-sidebar/component.json +17 -0
- package/dist/registry-data/icons-sidebar/index.ts +1 -0
- package/dist/registry-data/icons-theme/component.json +17 -0
- package/dist/registry-data/icons-theme/index.ts +1 -0
- package/dist/registry-data/icons-toast/component.json +17 -0
- package/dist/registry-data/icons-toast/index.ts +1 -0
- package/dist/registry-data/info-dialog/InfoDialog.tsx +119 -0
- package/dist/registry-data/info-dialog/component.json +36 -0
- package/dist/registry-data/info-dialog/index.ts +1 -0
- package/dist/registry-data/input/Input.tsx +96 -0
- package/dist/registry-data/input/component.json +33 -0
- package/dist/registry-data/input/index.ts +1 -0
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +205 -0
- package/dist/registry-data/multi-combobox/component.json +35 -0
- package/dist/registry-data/multi-combobox/index.ts +5 -0
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +8 -0
- package/dist/registry-data/remote-provider/component.json +25 -0
- package/dist/registry-data/remote-provider/index.ts +3 -0
- package/dist/registry-data/reveal/Reveal.tsx +22 -0
- package/dist/registry-data/reveal/component.json +30 -0
- package/dist/registry-data/reveal/index.ts +1 -0
- package/dist/registry-data/section/Section.tsx +80 -0
- package/dist/registry-data/section/component.json +30 -0
- package/dist/registry-data/section/index.ts +1 -0
- package/dist/registry-data/section-heading/SectionHeading.tsx +105 -0
- package/dist/registry-data/section-heading/component.json +32 -0
- package/dist/registry-data/section-heading/index.ts +1 -0
- package/dist/registry-data/select/Select.tsx +197 -0
- package/dist/registry-data/select/component.json +34 -0
- package/dist/registry-data/select/index.ts +1 -0
- package/dist/registry-data/sidebar/Sidebar.tsx +432 -0
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +77 -0
- package/dist/registry-data/sidebar/SidebarParts.tsx +373 -0
- package/dist/registry-data/sidebar/component.json +47 -0
- package/dist/registry-data/sidebar/index.ts +4 -0
- package/dist/registry-data/sidebar/useSidebar.ts +29 -0
- package/dist/registry-data/styles-base/component.json +19 -0
- package/dist/registry-data/styles-base/index.css +67 -0
- package/dist/registry-data/styles-components/component.json +19 -0
- package/dist/registry-data/styles-components/index.css +30 -0
- package/dist/registry-data/styles-motion/component.json +20 -0
- package/dist/registry-data/styles-motion/index.css +381 -0
- package/dist/registry-data/styles-tokens/component.json +17 -0
- package/dist/registry-data/styles-tokens/index.css +77 -0
- package/dist/registry-data/styles-utilities/component.json +19 -0
- package/dist/registry-data/styles-utilities/index.css +29 -0
- package/dist/registry-data/switch/Switch.tsx +91 -0
- package/dist/registry-data/switch/component.json +34 -0
- package/dist/registry-data/switch/index.ts +1 -0
- package/dist/registry-data/tabs/Tabs.tsx +226 -0
- package/dist/registry-data/tabs/component.json +32 -0
- package/dist/registry-data/tabs/index.ts +1 -0
- package/dist/registry-data/textarea/Textarea.tsx +94 -0
- package/dist/registry-data/textarea/component.json +33 -0
- package/dist/registry-data/textarea/index.ts +1 -0
- package/dist/registry-data/theme-core/component.json +17 -0
- package/dist/registry-data/theme-core/theme.ts +84 -0
- package/dist/registry-data/theme-dark/component.json +19 -0
- package/dist/registry-data/theme-dark/index.ts +7 -0
- package/dist/registry-data/theme-light/component.json +19 -0
- package/dist/registry-data/theme-light/index.ts +7 -0
- package/dist/registry-data/theme-provider/ThemeContext.tsx +177 -0
- package/dist/registry-data/theme-provider/component.json +30 -0
- package/dist/registry-data/theme-provider/index.ts +2 -0
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +269 -0
- package/dist/registry-data/theme-selector/component.json +35 -0
- package/dist/registry-data/theme-selector/selector.ts +1 -0
- package/dist/registry-data/theme-system/component.json +19 -0
- package/dist/registry-data/theme-system/index.ts +7 -0
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +71 -0
- package/dist/registry-data/theme-toggle/component.json +31 -0
- package/dist/registry-data/theme-toggle/toggle.ts +1 -0
- package/dist/registry-data/toast/Toast.tsx +260 -0
- package/dist/registry-data/toast/ToastTypeIcon.tsx +83 -0
- package/dist/registry-data/toast/component.json +43 -0
- package/dist/registry-data/toast/index.ts +3 -0
- package/dist/registry-data/toast/useToast.ts +47 -0
- package/dist/types/cli.types.d.ts +6 -0
- package/dist/types/cli.types.js +1 -0
- package/dist/types/config.types.d.ts +41 -0
- package/dist/types/config.types.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/registry.types.d.ts +37 -0
- package/dist/types/registry.types.js +1 -0
- package/package.json +35 -3
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { State, type StateId } from '@blankways/state'
|
|
2
|
+
import {
|
|
3
|
+
Show,
|
|
4
|
+
Text,
|
|
5
|
+
useAttributes,
|
|
6
|
+
useCompute,
|
|
7
|
+
useState,
|
|
8
|
+
} from '@blankways/state-react'
|
|
9
|
+
import {
|
|
10
|
+
createContext,
|
|
11
|
+
useCallback,
|
|
12
|
+
useContext,
|
|
13
|
+
useEffect,
|
|
14
|
+
useMemo,
|
|
15
|
+
useRef,
|
|
16
|
+
useState as useReactState,
|
|
17
|
+
type CSSProperties,
|
|
18
|
+
type ReactNode,
|
|
19
|
+
} from 'react'
|
|
20
|
+
import { createPortal } from 'react-dom'
|
|
21
|
+
import { cn } from '../../internals/cn.js'
|
|
22
|
+
import { X } from '../../icons/toast.js'
|
|
23
|
+
import { ToastTypeIcon } from './ToastTypeIcon.js'
|
|
24
|
+
import {
|
|
25
|
+
isToastType,
|
|
26
|
+
ToastApiContext,
|
|
27
|
+
type ToastApi,
|
|
28
|
+
type ToastRecord,
|
|
29
|
+
type ToastType,
|
|
30
|
+
} from './useToast.js'
|
|
31
|
+
|
|
32
|
+
const TOAST_LIMIT = 4
|
|
33
|
+
const DEFAULT_TIMEOUT = 5000
|
|
34
|
+
|
|
35
|
+
let nextToastId = 0
|
|
36
|
+
|
|
37
|
+
type ToastManager = {
|
|
38
|
+
toasts: StateId<ToastRecord[]>
|
|
39
|
+
visibleToasts: StateId<ToastRecord[]>
|
|
40
|
+
dismiss: (id?: string) => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ToastManagerContext = createContext<ToastManager | null>(null)
|
|
44
|
+
|
|
45
|
+
type ToastProviderProps = {
|
|
46
|
+
children: ReactNode
|
|
47
|
+
/** Accessible name of the close button, in the app's language. */
|
|
48
|
+
closeLabel?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Adds the toast API to the tree. The manager is a StateId array, with a
|
|
53
|
+
* computed list of visible records and plain `setTimeout` timers.
|
|
54
|
+
*/
|
|
55
|
+
export function ToastProvider({
|
|
56
|
+
children,
|
|
57
|
+
closeLabel = 'Close toast',
|
|
58
|
+
}: ToastProviderProps) {
|
|
59
|
+
const toasts = useState<ToastRecord[]>([])
|
|
60
|
+
const visibleToasts = useCompute<[StateId<ToastRecord[]>], ToastRecord[]>(
|
|
61
|
+
[toasts],
|
|
62
|
+
([records]) => records.filter((record) => State.get(record.visible)),
|
|
63
|
+
)
|
|
64
|
+
const timers = useRef(new Map<string, ReturnType<typeof setTimeout>>())
|
|
65
|
+
|
|
66
|
+
const dismiss = useCallback(
|
|
67
|
+
(id?: string) => {
|
|
68
|
+
const records = State.get(toasts)
|
|
69
|
+
if (id === undefined) {
|
|
70
|
+
for (const record of records) State.set(record.visible, false)
|
|
71
|
+
for (const timer of timers.current.values()) clearTimeout(timer)
|
|
72
|
+
timers.current.clear()
|
|
73
|
+
State.set(toasts, [])
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const target = records.find((record) => record.id === id)
|
|
78
|
+
if (!target) return
|
|
79
|
+
State.set(target.visible, false)
|
|
80
|
+
const timer = timers.current.get(id)
|
|
81
|
+
if (timer !== undefined) {
|
|
82
|
+
clearTimeout(timer)
|
|
83
|
+
timers.current.delete(id)
|
|
84
|
+
}
|
|
85
|
+
State.set(
|
|
86
|
+
toasts,
|
|
87
|
+
records.filter((record) => record.id !== id),
|
|
88
|
+
)
|
|
89
|
+
},
|
|
90
|
+
[toasts],
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
const api = useMemo<ToastApi>(
|
|
94
|
+
() => ({
|
|
95
|
+
toast: (options) => {
|
|
96
|
+
const id = `toast-${++nextToastId}`
|
|
97
|
+
const record: ToastRecord = {
|
|
98
|
+
id,
|
|
99
|
+
title: State.create(options.title),
|
|
100
|
+
description:
|
|
101
|
+
options.description === undefined
|
|
102
|
+
? undefined
|
|
103
|
+
: State.create(options.description),
|
|
104
|
+
type: isToastType(options.type) ? options.type : 'info',
|
|
105
|
+
timeout: options.timeout ?? DEFAULT_TIMEOUT,
|
|
106
|
+
visible: State.create(true),
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const next = [...State.get(toasts), record].slice(-TOAST_LIMIT)
|
|
110
|
+
const keptIds = new Set(next.map((item) => item.id))
|
|
111
|
+
for (const [timerId, timer] of timers.current) {
|
|
112
|
+
if (!keptIds.has(timerId)) {
|
|
113
|
+
clearTimeout(timer)
|
|
114
|
+
timers.current.delete(timerId)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
State.set(toasts, next)
|
|
118
|
+
|
|
119
|
+
if (record.timeout > 0) {
|
|
120
|
+
const timer = setTimeout(() => {
|
|
121
|
+
timers.current.delete(id)
|
|
122
|
+
dismiss(id)
|
|
123
|
+
}, record.timeout)
|
|
124
|
+
timers.current.set(id, timer)
|
|
125
|
+
}
|
|
126
|
+
return id
|
|
127
|
+
},
|
|
128
|
+
dismiss,
|
|
129
|
+
}),
|
|
130
|
+
[dismiss, toasts],
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
const activeTimers = timers.current
|
|
135
|
+
return () => {
|
|
136
|
+
for (const timer of activeTimers.values()) clearTimeout(timer)
|
|
137
|
+
activeTimers.clear()
|
|
138
|
+
}
|
|
139
|
+
}, [])
|
|
140
|
+
|
|
141
|
+
const manager = useMemo<ToastManager>(
|
|
142
|
+
() => ({ toasts, visibleToasts, dismiss }),
|
|
143
|
+
[dismiss, toasts, visibleToasts],
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<ToastApiContext.Provider value={api}>
|
|
148
|
+
<ToastManagerContext.Provider value={manager}>
|
|
149
|
+
{children}
|
|
150
|
+
<ToastViewport closeLabel={closeLabel} />
|
|
151
|
+
</ToastManagerContext.Provider>
|
|
152
|
+
</ToastApiContext.Provider>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
type ToastCardProps = {
|
|
157
|
+
record: ToastRecord
|
|
158
|
+
index: number
|
|
159
|
+
closeLabel: string
|
|
160
|
+
onDismiss: () => void
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function ToastCard({ record, index, closeLabel, onDismiss }: ToastCardProps) {
|
|
164
|
+
const role = useState<HTMLDivElement['role']>('status')
|
|
165
|
+
const live = useState<string>('polite')
|
|
166
|
+
const type = useState<ToastType>(record.type)
|
|
167
|
+
const hasDescription = useState<boolean>(record.description !== undefined)
|
|
168
|
+
const bind = useAttributes<HTMLDivElement>({
|
|
169
|
+
role,
|
|
170
|
+
'aria-live': live,
|
|
171
|
+
'data-type': type,
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<div
|
|
176
|
+
ref={bind}
|
|
177
|
+
data-slot="toast"
|
|
178
|
+
data-state="open"
|
|
179
|
+
style={{ '--index': index } as CSSProperties}
|
|
180
|
+
className="toast-card toast-enter relative overflow-hidden rounded-2xl border border-line bg-paper shadow-xl"
|
|
181
|
+
>
|
|
182
|
+
<div className="flex items-start gap-3 p-3 pr-[1.875rem]">
|
|
183
|
+
<ToastTypeIcon type={type} />
|
|
184
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
185
|
+
<Text
|
|
186
|
+
as="span"
|
|
187
|
+
value={record.title}
|
|
188
|
+
className="text-sm font-semibold text-ink"
|
|
189
|
+
/>
|
|
190
|
+
<Show when={hasDescription}>
|
|
191
|
+
<span className="text-sm leading-relaxed text-ink-soft">
|
|
192
|
+
{record.description ? (
|
|
193
|
+
<Text as="span" value={record.description} />
|
|
194
|
+
) : null}
|
|
195
|
+
</span>
|
|
196
|
+
</Show>
|
|
197
|
+
</div>
|
|
198
|
+
<button
|
|
199
|
+
type="button"
|
|
200
|
+
aria-label={closeLabel}
|
|
201
|
+
onClick={onDismiss}
|
|
202
|
+
className="absolute top-3 right-3 inline-flex size-6 items-center justify-center rounded-2xl text-ink-muted motion-color hover:bg-surface-2 hover:text-ink"
|
|
203
|
+
>
|
|
204
|
+
<X className="size-3.5" aria-hidden="true" />
|
|
205
|
+
</button>
|
|
206
|
+
</div>
|
|
207
|
+
{record.timeout > 0 ? (
|
|
208
|
+
<span
|
|
209
|
+
aria-hidden="true"
|
|
210
|
+
className="progress-life absolute right-0 bottom-0 left-0 h-0.5 bg-brand-500/60"
|
|
211
|
+
style={{ '--life': `${record.timeout}ms` } as CSSProperties}
|
|
212
|
+
/>
|
|
213
|
+
) : null}
|
|
214
|
+
</div>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Portal viewport that renders the visible toasts. Rendered by default. */
|
|
219
|
+
export function ToastViewport({
|
|
220
|
+
closeLabel = 'Close toast',
|
|
221
|
+
className,
|
|
222
|
+
}: { closeLabel?: string; className?: string } = {}) {
|
|
223
|
+
const manager = useContext(ToastManagerContext)
|
|
224
|
+
const [, forceRender] = useReactState(0)
|
|
225
|
+
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
if (!manager) return
|
|
228
|
+
const unwatch = State.watch(manager.visibleToasts, () =>
|
|
229
|
+
forceRender((value) => value + 1),
|
|
230
|
+
)
|
|
231
|
+
return () => State.unwatch(unwatch)
|
|
232
|
+
}, [manager])
|
|
233
|
+
|
|
234
|
+
if (!manager || typeof document === 'undefined') return null
|
|
235
|
+
|
|
236
|
+
const items = State.get(manager.visibleToasts)
|
|
237
|
+
return createPortal(
|
|
238
|
+
<div
|
|
239
|
+
data-slot="toast-viewport"
|
|
240
|
+
className={cn(
|
|
241
|
+
'fixed right-4 bottom-4 z-[80] flex w-[calc(100%-2rem)] max-w-sm flex-col gap-3 outline-none',
|
|
242
|
+
className,
|
|
243
|
+
)}
|
|
244
|
+
>
|
|
245
|
+
{items.map((record, index) => (
|
|
246
|
+
<ToastCard
|
|
247
|
+
key={record.id}
|
|
248
|
+
record={record}
|
|
249
|
+
index={index}
|
|
250
|
+
closeLabel={closeLabel}
|
|
251
|
+
onDismiss={() => manager.dismiss(record.id)}
|
|
252
|
+
/>
|
|
253
|
+
))}
|
|
254
|
+
</div>,
|
|
255
|
+
document.body,
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Alias matching the single-import style of the original component. */
|
|
260
|
+
export { ToastViewport as Toast }
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { State, type StateId } from '@blankways/state'
|
|
2
|
+
import { Show, useMatch, useState } from '@blankways/state-react'
|
|
3
|
+
import { useEffect } from 'react'
|
|
4
|
+
import { cn } from '../../internals/cn.js'
|
|
5
|
+
import { CircleAlert, CircleCheck, Info, TriangleAlert } from '../../icons/toast.js'
|
|
6
|
+
import { isToastType, TOAST_TYPES, type ToastType } from './useToast.js'
|
|
7
|
+
|
|
8
|
+
const TONES: Record<ToastType, string> = {
|
|
9
|
+
info: 'bg-ink/10 text-ink',
|
|
10
|
+
success: 'bg-ink/15 text-ink',
|
|
11
|
+
warning: 'bg-ink/20 text-ink',
|
|
12
|
+
error: 'bg-ink/25 text-ink',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ToastTypeIconProps = {
|
|
16
|
+
type: ToastType | StateId<ToastType>
|
|
17
|
+
className?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The neutral icon bubble of a toast or a notification of the given type. */
|
|
21
|
+
export function ToastTypeIcon({ type, className }: ToastTypeIconProps) {
|
|
22
|
+
const fallback = useState<ToastType>(
|
|
23
|
+
typeof type === 'number' ? State.get(type) : isToastType(type) ? type : 'info',
|
|
24
|
+
)
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (typeof type === 'string') {
|
|
27
|
+
State.set(fallback, isToastType(type) ? type : 'info')
|
|
28
|
+
}
|
|
29
|
+
}, [fallback, type])
|
|
30
|
+
|
|
31
|
+
const typeState = typeof type === 'number' ? type : fallback
|
|
32
|
+
const [isInfo, isSuccess, isWarning, isError] = useMatch(typeState, TOAST_TYPES)
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<span
|
|
36
|
+
className={cn(
|
|
37
|
+
'relative inline-flex size-9 shrink-0 items-center justify-center rounded-2xl',
|
|
38
|
+
className,
|
|
39
|
+
)}
|
|
40
|
+
>
|
|
41
|
+
<Show when={isInfo}>
|
|
42
|
+
<span
|
|
43
|
+
className={cn(
|
|
44
|
+
'absolute inset-0 inline-flex items-center justify-center rounded-2xl',
|
|
45
|
+
TONES.info,
|
|
46
|
+
)}
|
|
47
|
+
>
|
|
48
|
+
<Info className="size-4" aria-hidden="true" />
|
|
49
|
+
</span>
|
|
50
|
+
</Show>
|
|
51
|
+
<Show when={isSuccess}>
|
|
52
|
+
<span
|
|
53
|
+
className={cn(
|
|
54
|
+
'check-draw absolute inset-0 inline-flex items-center justify-center rounded-2xl',
|
|
55
|
+
TONES.success,
|
|
56
|
+
)}
|
|
57
|
+
>
|
|
58
|
+
<CircleCheck className="size-4" aria-hidden="true" />
|
|
59
|
+
</span>
|
|
60
|
+
</Show>
|
|
61
|
+
<Show when={isWarning}>
|
|
62
|
+
<span
|
|
63
|
+
className={cn(
|
|
64
|
+
'absolute inset-0 inline-flex items-center justify-center rounded-2xl',
|
|
65
|
+
TONES.warning,
|
|
66
|
+
)}
|
|
67
|
+
>
|
|
68
|
+
<TriangleAlert className="size-4" aria-hidden="true" />
|
|
69
|
+
</span>
|
|
70
|
+
</Show>
|
|
71
|
+
<Show when={isError}>
|
|
72
|
+
<span
|
|
73
|
+
className={cn(
|
|
74
|
+
'shake absolute inset-0 inline-flex items-center justify-center rounded-2xl',
|
|
75
|
+
TONES.error,
|
|
76
|
+
)}
|
|
77
|
+
>
|
|
78
|
+
<CircleAlert className="size-4" aria-hidden="true" />
|
|
79
|
+
</span>
|
|
80
|
+
</Show>
|
|
81
|
+
</span>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toast",
|
|
3
|
+
"kind": "component",
|
|
4
|
+
"framework": "react",
|
|
5
|
+
"description": "Native React toast provider, portal viewport and typed icons with StateId-backed timers.",
|
|
6
|
+
"dependencies": [
|
|
7
|
+
"cn",
|
|
8
|
+
"icons-toast",
|
|
9
|
+
"styles-motion"
|
|
10
|
+
],
|
|
11
|
+
"peers": [
|
|
12
|
+
"@blankways/state",
|
|
13
|
+
"@blankways/state-react@0.1.0-alpha.1",
|
|
14
|
+
"lucide-react",
|
|
15
|
+
"react",
|
|
16
|
+
"react-dom"
|
|
17
|
+
],
|
|
18
|
+
"suggestions": [
|
|
19
|
+
"styles-tokens",
|
|
20
|
+
"styles-base",
|
|
21
|
+
"styles-components",
|
|
22
|
+
"styles-utilities",
|
|
23
|
+
"styles-motion"
|
|
24
|
+
],
|
|
25
|
+
"files": [
|
|
26
|
+
{
|
|
27
|
+
"source": "Toast.tsx",
|
|
28
|
+
"target": "components/toast/Toast.tsx"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"source": "ToastTypeIcon.tsx",
|
|
32
|
+
"target": "components/toast/ToastTypeIcon.tsx"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"source": "useToast.ts",
|
|
36
|
+
"target": "components/toast/useToast.ts"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"source": "index.ts",
|
|
40
|
+
"target": "components/toast/index.ts"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { StateId } from '@blankways/state'
|
|
2
|
+
import { createContext, useContext } from 'react'
|
|
3
|
+
|
|
4
|
+
export const TOAST_TYPES = ['info', 'success', 'warning', 'error'] as const
|
|
5
|
+
|
|
6
|
+
export type ToastType = (typeof TOAST_TYPES)[number]
|
|
7
|
+
|
|
8
|
+
export function isToastType(value: unknown): value is ToastType {
|
|
9
|
+
return TOAST_TYPES.includes(value as ToastType)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type ToastOptions = {
|
|
13
|
+
title: string
|
|
14
|
+
description?: string
|
|
15
|
+
/** Defaults to `info`. */
|
|
16
|
+
type?: ToastType
|
|
17
|
+
/** Milliseconds on screen. `0` keeps it until it is closed. Defaults to 5000. */
|
|
18
|
+
timeout?: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ToastApi = {
|
|
22
|
+
/** Shows a toast and returns its id. */
|
|
23
|
+
toast: (options: ToastOptions) => string
|
|
24
|
+
/** Closes one toast, or every toast when no id is given. */
|
|
25
|
+
dismiss: (id?: string) => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const ToastApiContext = createContext<ToastApi | null>(null)
|
|
29
|
+
|
|
30
|
+
/** Shows and dismisses toasts from anywhere below a `ToastProvider`. */
|
|
31
|
+
export function useToast(): ToastApi {
|
|
32
|
+
const api = useContext(ToastApiContext)
|
|
33
|
+
if (!api) {
|
|
34
|
+
throw new Error('useToast must be used within a ToastProvider')
|
|
35
|
+
}
|
|
36
|
+
return api
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Internal record kept by `ToastProvider`; text is reactive for `Text`. */
|
|
40
|
+
export type ToastRecord = {
|
|
41
|
+
id: string
|
|
42
|
+
title: StateId<string>
|
|
43
|
+
description?: StateId<string>
|
|
44
|
+
type: ToastType
|
|
45
|
+
timeout: number
|
|
46
|
+
visible: StateId<boolean>
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { SupportedFramework } from '../constants/index.js';
|
|
2
|
+
export type ComponentsConfig = {
|
|
3
|
+
componentsDir: string;
|
|
4
|
+
framework: SupportedFramework;
|
|
5
|
+
overwrite: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type InitOptions = {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
componentsDir?: string;
|
|
10
|
+
framework?: string;
|
|
11
|
+
variant?: string;
|
|
12
|
+
force?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type AddOptions = {
|
|
15
|
+
cwd?: string;
|
|
16
|
+
componentsDir?: string;
|
|
17
|
+
names: string[];
|
|
18
|
+
force?: boolean;
|
|
19
|
+
dryRun?: boolean;
|
|
20
|
+
all?: boolean;
|
|
21
|
+
kind?: string;
|
|
22
|
+
noDeps?: boolean;
|
|
23
|
+
noImport?: boolean;
|
|
24
|
+
globalCss?: string;
|
|
25
|
+
};
|
|
26
|
+
export type ListOptions = {
|
|
27
|
+
cwd?: string;
|
|
28
|
+
kind?: string;
|
|
29
|
+
framework?: SupportedFramework;
|
|
30
|
+
};
|
|
31
|
+
export type StylesOptions = {
|
|
32
|
+
cwd?: string;
|
|
33
|
+
componentsDir?: string;
|
|
34
|
+
globalCss?: string;
|
|
35
|
+
dryRun?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type DoctorOptions = {
|
|
38
|
+
cwd?: string;
|
|
39
|
+
componentsDir?: string;
|
|
40
|
+
globalCss?: string;
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SupportedFramework } from '../constants/index.js';
|
|
2
|
+
export declare const REGISTRY_KINDS: readonly ['component', 'icon', 'theme', 'style', 'utility'];
|
|
3
|
+
export type RegistryKind = (typeof REGISTRY_KINDS)[number];
|
|
4
|
+
export type RegistryFile = {
|
|
5
|
+
source: string;
|
|
6
|
+
target: string;
|
|
7
|
+
};
|
|
8
|
+
export type RegistryManifest = {
|
|
9
|
+
name?: string;
|
|
10
|
+
kind?: RegistryKind;
|
|
11
|
+
framework?: SupportedFramework;
|
|
12
|
+
description?: string;
|
|
13
|
+
hidden?: boolean;
|
|
14
|
+
dependencies?: string[];
|
|
15
|
+
peers?: string[];
|
|
16
|
+
suggestions?: string[];
|
|
17
|
+
files?: RegistryFile[];
|
|
18
|
+
};
|
|
19
|
+
export type RegistryItem = {
|
|
20
|
+
name: string;
|
|
21
|
+
kind: RegistryKind;
|
|
22
|
+
framework: SupportedFramework;
|
|
23
|
+
description: string;
|
|
24
|
+
hidden: boolean;
|
|
25
|
+
dependencies: string[];
|
|
26
|
+
peers: string[];
|
|
27
|
+
suggestions: string[];
|
|
28
|
+
files: RegistryFile[];
|
|
29
|
+
};
|
|
30
|
+
export type ResolvedRegistryItem = RegistryItem & {
|
|
31
|
+
requested: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type CopyResult = {
|
|
34
|
+
copied: string[];
|
|
35
|
+
skipped: string[];
|
|
36
|
+
planned: string[];
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const REGISTRY_KINDS = ['component', 'icon', 'theme', 'style', 'utility'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blankways/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "CLI for copying open UI components into a project.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"ui": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./cli": "./dist/cli.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"tag": "alpha"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^24.0.0",
|
|
29
|
+
"tsc-alias": "^1.9.9",
|
|
30
|
+
"typescript": "^7.0.2",
|
|
31
|
+
"vitest": "^5.0.5"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "node scripts/clean-dist.mjs && tsc && tsc-alias && node scripts/copy-registry.mjs",
|
|
35
|
+
"typecheck": "tsc --noEmit && node scripts/validate-registry.mjs",
|
|
36
|
+
"test": "vitest run --passWithNoTests"
|
|
37
|
+
}
|
|
6
38
|
}
|