@ttt-productions/ui-core 0.11.18 → 0.11.20
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/dist/react/components/date-time-picker.d.ts +43 -0
- package/dist/react/components/date-time-picker.d.ts.map +1 -0
- package/dist/react/components/date-time-picker.js +188 -0
- package/dist/react/components/date-time-picker.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/package.json +4 -6
- package/src/index.ts +0 -3
- package/src/lib/format-numbers.ts +0 -17
- package/src/lib/utils.ts +0 -9
- package/src/react/components/accordion.tsx +0 -53
- package/src/react/components/alert-dialog.tsx +0 -131
- package/src/react/components/alert.tsx +0 -59
- package/src/react/components/avatar.tsx +0 -51
- package/src/react/components/badge.tsx +0 -31
- package/src/react/components/button.tsx +0 -102
- package/src/react/components/card.tsx +0 -54
- package/src/react/components/checkbox.tsx +0 -28
- package/src/react/components/chunk-error-recovery.tsx +0 -57
- package/src/react/components/collapsible.tsx +0 -11
- package/src/react/components/consequence-dialog.tsx +0 -282
- package/src/react/components/date-picker.tsx +0 -567
- package/src/react/components/dialog.tsx +0 -114
- package/src/react/components/dropdown-menu.tsx +0 -200
- package/src/react/components/end-of-list-indicator.tsx +0 -27
- package/src/react/components/form.tsx +0 -174
- package/src/react/components/input.tsx +0 -23
- package/src/react/components/label.tsx +0 -21
- package/src/react/components/layout/screen-adaptive-view.tsx +0 -106
- package/src/react/components/list-pagination.tsx +0 -101
- package/src/react/components/menubar.tsx +0 -220
- package/src/react/components/popover.tsx +0 -31
- package/src/react/components/progress.tsx +0 -27
- package/src/react/components/radio-group.tsx +0 -36
- package/src/react/components/relative-time.tsx +0 -56
- package/src/react/components/scroll-area.tsx +0 -56
- package/src/react/components/scroll-to-top-button.tsx +0 -85
- package/src/react/components/search-dropdown.tsx +0 -233
- package/src/react/components/select.tsx +0 -165
- package/src/react/components/separator.tsx +0 -26
- package/src/react/components/sheet.tsx +0 -140
- package/src/react/components/skeleton.tsx +0 -16
- package/src/react/components/slider.tsx +0 -25
- package/src/react/components/spinner.tsx +0 -49
- package/src/react/components/switch.tsx +0 -41
- package/src/react/components/table.tsx +0 -121
- package/src/react/components/tabs.tsx +0 -59
- package/src/react/components/textarea.tsx +0 -22
- package/src/react/components/toast.tsx +0 -193
- package/src/react/components/toaster.tsx +0 -43
- package/src/react/components/tooltip.tsx +0 -28
- package/src/react/hooks/use-async-action.ts +0 -63
- package/src/react/hooks/use-cursor-page.ts +0 -139
- package/src/react/hooks/use-media-query.tsx +0 -26
- package/src/react/hooks/use-paged-list.ts +0 -106
- package/src/react/hooks/use-return-scroll.ts +0 -149
- package/src/react/hooks/use-toast.tsx +0 -176
- package/src/react/index.ts +0 -85
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useCallback, useId, useState } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
AlertDialog,
|
|
6
|
-
AlertDialogTrigger,
|
|
7
|
-
AlertDialogContent,
|
|
8
|
-
AlertDialogHeader,
|
|
9
|
-
AlertDialogFooter,
|
|
10
|
-
AlertDialogTitle,
|
|
11
|
-
AlertDialogDescription,
|
|
12
|
-
} from './alert-dialog.js';
|
|
13
|
-
import { Button } from './button.js';
|
|
14
|
-
import { Textarea } from './textarea.js';
|
|
15
|
-
import { Input } from './input.js';
|
|
16
|
-
import { Label } from './label.js';
|
|
17
|
-
import { Zap, Clock, RotateCcw } from 'lucide-react';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The inline required-reason config. The caller OWNS the reason value/onChange (draft state lives at
|
|
21
|
-
* the call site). Any `minLength`/`maxLength` the caller supplies MUST come from a caller-owned
|
|
22
|
-
* constant — this component declares no business numbers and no copy; it only derives the gate + the
|
|
23
|
-
* Textarea `maxLength` from the values it is handed.
|
|
24
|
-
*/
|
|
25
|
-
export interface ConsequenceDialogReason {
|
|
26
|
-
required?: boolean;
|
|
27
|
-
minLength?: number;
|
|
28
|
-
maxLength?: number;
|
|
29
|
-
placeholder?: string;
|
|
30
|
-
label?: React.ReactNode;
|
|
31
|
-
value: string;
|
|
32
|
-
onChange: (value: string) => void;
|
|
33
|
-
rows?: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The exact-match typed-confirmation gate. `phrase` is business copy owned by the CALLER; the
|
|
38
|
-
* component only compares the typed value against it.
|
|
39
|
-
*/
|
|
40
|
-
export interface ConsequenceDialogTypedConfirmation {
|
|
41
|
-
phrase: string;
|
|
42
|
-
label?: React.ReactNode;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface ConsequenceDialogProps {
|
|
46
|
-
/** Uncontrolled open model: the element that opens the dialog (rendered `asChild`). */
|
|
47
|
-
trigger?: React.ReactNode;
|
|
48
|
-
/** Controlled open model. Provide with `onOpenChange`. */
|
|
49
|
-
open?: boolean;
|
|
50
|
-
onOpenChange?: (open: boolean) => void;
|
|
51
|
-
|
|
52
|
-
/** Heading — a string or node so callers can interpolate amounts / names. */
|
|
53
|
-
title: React.ReactNode;
|
|
54
|
-
|
|
55
|
-
/** SLOT 1 — what happens right now (e.g. "initiates a Stripe refund of $X now"). */
|
|
56
|
-
immediateEffect?: React.ReactNode;
|
|
57
|
-
/** SLOT 2 — what settles later, out of band (webhook / worker / async confirmation). */
|
|
58
|
-
delayedEffect?: React.ReactNode;
|
|
59
|
-
/** SLOT 3 — whether/how this can be undone or superseded. */
|
|
60
|
-
reversibility?: React.ReactNode;
|
|
61
|
-
|
|
62
|
-
/** Inline required-reason field. Optional. */
|
|
63
|
-
reason?: ConsequenceDialogReason;
|
|
64
|
-
/** Exact-phrase typed-confirmation gate. Optional. */
|
|
65
|
-
typedConfirmation?: ConsequenceDialogTypedConfirmation;
|
|
66
|
-
|
|
67
|
-
confirmLabel: React.ReactNode;
|
|
68
|
-
cancelLabel?: React.ReactNode;
|
|
69
|
-
/** `true` styles the confirm button with `bg-destructive`. */
|
|
70
|
-
destructive?: boolean;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Runs on confirm. May be async — while it is pending the dialog STAYS OPEN, both buttons disable,
|
|
74
|
-
* and the confirm button shows its pending spinner. Closes on resolve. If it rejects the dialog
|
|
75
|
-
* stays open so the caller's own surface (error toast, TOTP step-up) can show and the operator can
|
|
76
|
-
* retry or cancel. This component takes no Sentry/monitoring dependency — every error path
|
|
77
|
-
* belongs to the caller's `onConfirm`.
|
|
78
|
-
*/
|
|
79
|
-
onConfirm: () => void | Promise<void>;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const SLOT_ICON_CLASS = 'icon-xs mt-0.5 shrink-0 text-muted-foreground';
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* One consequence slot: the icon beside a block column whose label sits on its own line above
|
|
86
|
-
* the slot text. Every element is a block: the `stack-*` spacing is a vertical margin, which an
|
|
87
|
-
* inline element ignores.
|
|
88
|
-
*/
|
|
89
|
-
function ConsequenceRow({
|
|
90
|
-
icon: Icon,
|
|
91
|
-
label,
|
|
92
|
-
children,
|
|
93
|
-
}: {
|
|
94
|
-
icon: typeof Zap;
|
|
95
|
-
label: string;
|
|
96
|
-
children: React.ReactNode;
|
|
97
|
-
}) {
|
|
98
|
-
return (
|
|
99
|
-
<div className="flex items-start gap-2">
|
|
100
|
-
<Icon className={SLOT_ICON_CLASS} aria-hidden="true" />
|
|
101
|
-
<div className="stack-1 min-w-0">
|
|
102
|
-
<div className="text-caption font-medium uppercase tracking-wide text-muted-foreground">
|
|
103
|
-
{label}
|
|
104
|
-
</div>
|
|
105
|
-
<div className="text-small text-foreground">{children}</div>
|
|
106
|
-
</div>
|
|
107
|
-
</div>
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* A reusable confirm-before-a-consequential-action dialog. Three optional, consistently-styled
|
|
113
|
-
* consequence slots (immediate / afterward / reversibility), an optional inline required-reason field,
|
|
114
|
-
* and an optional exact-phrase typed-confirmation gate. Composes the ui-core AlertDialog primitives
|
|
115
|
-
* (Radix) — it never re-implements them. Supports BOTH a `trigger` (uncontrolled) and `open` /
|
|
116
|
-
* `onOpenChange` (controlled).
|
|
117
|
-
*
|
|
118
|
-
* Pending model: the confirm button is a plain `Button` (NOT `AlertDialogAction`), so Radix does not
|
|
119
|
-
* auto-close on click; open state is managed here so the dialog stays open with a visible spinner
|
|
120
|
-
* until `onConfirm` resolves.
|
|
121
|
-
*/
|
|
122
|
-
export function ConsequenceDialog({
|
|
123
|
-
trigger,
|
|
124
|
-
open,
|
|
125
|
-
onOpenChange,
|
|
126
|
-
title,
|
|
127
|
-
immediateEffect,
|
|
128
|
-
delayedEffect,
|
|
129
|
-
reversibility,
|
|
130
|
-
reason,
|
|
131
|
-
typedConfirmation,
|
|
132
|
-
confirmLabel,
|
|
133
|
-
cancelLabel = 'Cancel',
|
|
134
|
-
destructive = false,
|
|
135
|
-
onConfirm,
|
|
136
|
-
}: ConsequenceDialogProps) {
|
|
137
|
-
const isControlled = open !== undefined;
|
|
138
|
-
const [internalOpen, setInternalOpen] = useState(false);
|
|
139
|
-
const [typedValue, setTypedValue] = useState('');
|
|
140
|
-
const [pending, setPending] = useState(false);
|
|
141
|
-
|
|
142
|
-
const actualOpen = isControlled ? open : internalOpen;
|
|
143
|
-
|
|
144
|
-
const reasonId = useId();
|
|
145
|
-
const typedId = useId();
|
|
146
|
-
|
|
147
|
-
const setOpenState = useCallback(
|
|
148
|
-
(next: boolean) => {
|
|
149
|
-
if (isControlled) onOpenChange?.(next);
|
|
150
|
-
else setInternalOpen(next);
|
|
151
|
-
},
|
|
152
|
-
[isControlled, onOpenChange],
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
// Never allow an open-state change (Escape, cancel, controlled parent) to fight the pending action.
|
|
156
|
-
const handleOpenChange = useCallback(
|
|
157
|
-
(next: boolean) => {
|
|
158
|
-
if (pending) return;
|
|
159
|
-
setTypedValue(''); // reset the typed gate on every open/close
|
|
160
|
-
setOpenState(next);
|
|
161
|
-
},
|
|
162
|
-
[pending, setOpenState],
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
const handleConfirm = useCallback(async () => {
|
|
166
|
-
if (pending) return;
|
|
167
|
-
setPending(true);
|
|
168
|
-
try {
|
|
169
|
-
await onConfirm();
|
|
170
|
-
setTypedValue('');
|
|
171
|
-
setOpenState(false);
|
|
172
|
-
} catch {
|
|
173
|
-
// Keep the dialog open — the caller's onConfirm surfaced the error (toast / step-up). The
|
|
174
|
-
// operator can retry or cancel. Never rethrow, never monitor here.
|
|
175
|
-
} finally {
|
|
176
|
-
setPending(false);
|
|
177
|
-
}
|
|
178
|
-
}, [pending, onConfirm, setOpenState]);
|
|
179
|
-
|
|
180
|
-
const reasonTrimmedLength = reason ? reason.value.trim().length : 0;
|
|
181
|
-
const reasonProvided = reasonTrimmedLength > 0;
|
|
182
|
-
const reasonOk = !reason
|
|
183
|
-
? true
|
|
184
|
-
: reason.required && !reasonProvided
|
|
185
|
-
? false
|
|
186
|
-
: !reasonProvided
|
|
187
|
-
? true // optional + empty is fine
|
|
188
|
-
: (reason.minLength === undefined || reasonTrimmedLength >= reason.minLength) &&
|
|
189
|
-
(reason.maxLength === undefined || reason.value.length <= reason.maxLength);
|
|
190
|
-
|
|
191
|
-
const typedOk = !typedConfirmation ? true : typedValue === typedConfirmation.phrase;
|
|
192
|
-
|
|
193
|
-
return (
|
|
194
|
-
<AlertDialog open={actualOpen} onOpenChange={handleOpenChange}>
|
|
195
|
-
{trigger ? <AlertDialogTrigger asChild>{trigger}</AlertDialogTrigger> : null}
|
|
196
|
-
<AlertDialogContent
|
|
197
|
-
onEscapeKeyDown={(e) => {
|
|
198
|
-
if (pending) e.preventDefault();
|
|
199
|
-
}}
|
|
200
|
-
>
|
|
201
|
-
<AlertDialogHeader>
|
|
202
|
-
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
203
|
-
{/* A div, not the primitive's default <p>: the rows are blocks, which a <p> cannot hold.
|
|
204
|
-
Left-aligned at every width — the header centres its text on narrow screens, and a
|
|
205
|
-
wrapped consequence line reads as a list, not a caption. */}
|
|
206
|
-
<AlertDialogDescription asChild>
|
|
207
|
-
<div className="stack-3 text-left">
|
|
208
|
-
{immediateEffect ? (
|
|
209
|
-
<ConsequenceRow icon={Zap} label="Immediately">
|
|
210
|
-
{immediateEffect}
|
|
211
|
-
</ConsequenceRow>
|
|
212
|
-
) : null}
|
|
213
|
-
{delayedEffect ? (
|
|
214
|
-
<ConsequenceRow icon={Clock} label="Afterward">
|
|
215
|
-
{delayedEffect}
|
|
216
|
-
</ConsequenceRow>
|
|
217
|
-
) : null}
|
|
218
|
-
{reversibility ? (
|
|
219
|
-
<ConsequenceRow icon={RotateCcw} label="Reversibility">
|
|
220
|
-
{reversibility}
|
|
221
|
-
</ConsequenceRow>
|
|
222
|
-
) : null}
|
|
223
|
-
</div>
|
|
224
|
-
</AlertDialogDescription>
|
|
225
|
-
</AlertDialogHeader>
|
|
226
|
-
|
|
227
|
-
{reason ? (
|
|
228
|
-
<div className="stack-2">
|
|
229
|
-
<Label htmlFor={reasonId}>{reason.label ?? 'Reason'}</Label>
|
|
230
|
-
<Textarea
|
|
231
|
-
id={reasonId}
|
|
232
|
-
value={reason.value}
|
|
233
|
-
onChange={(e) => reason.onChange(e.target.value)}
|
|
234
|
-
placeholder={reason.placeholder}
|
|
235
|
-
maxLength={reason.maxLength}
|
|
236
|
-
rows={reason.rows ?? 3}
|
|
237
|
-
disabled={pending}
|
|
238
|
-
/>
|
|
239
|
-
</div>
|
|
240
|
-
) : null}
|
|
241
|
-
|
|
242
|
-
{typedConfirmation ? (
|
|
243
|
-
<div className="stack-2">
|
|
244
|
-
<Label htmlFor={typedId}>
|
|
245
|
-
{typedConfirmation.label ?? (
|
|
246
|
-
<>
|
|
247
|
-
Type <span className="font-mono">{typedConfirmation.phrase}</span> to confirm
|
|
248
|
-
</>
|
|
249
|
-
)}
|
|
250
|
-
</Label>
|
|
251
|
-
<Input
|
|
252
|
-
id={typedId}
|
|
253
|
-
value={typedValue}
|
|
254
|
-
onChange={(e) => setTypedValue(e.target.value)}
|
|
255
|
-
placeholder={typedConfirmation.phrase}
|
|
256
|
-
disabled={pending}
|
|
257
|
-
autoComplete="off"
|
|
258
|
-
/>
|
|
259
|
-
</div>
|
|
260
|
-
) : null}
|
|
261
|
-
|
|
262
|
-
<AlertDialogFooter>
|
|
263
|
-
<Button
|
|
264
|
-
variant="outline"
|
|
265
|
-
onClick={() => handleOpenChange(false)}
|
|
266
|
-
disabled={pending}
|
|
267
|
-
>
|
|
268
|
-
{cancelLabel}
|
|
269
|
-
</Button>
|
|
270
|
-
<Button
|
|
271
|
-
variant={destructive ? 'destructive' : 'default'}
|
|
272
|
-
onClick={handleConfirm}
|
|
273
|
-
disabled={!reasonOk || !typedOk}
|
|
274
|
-
pending={pending}
|
|
275
|
-
>
|
|
276
|
-
{confirmLabel}
|
|
277
|
-
</Button>
|
|
278
|
-
</AlertDialogFooter>
|
|
279
|
-
</AlertDialogContent>
|
|
280
|
-
</AlertDialog>
|
|
281
|
-
);
|
|
282
|
-
}
|