@vendure-io/ui 2.1.0 → 3.0.0-next.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 +19 -5
- package/src/components/atoms/accordion.tsx +21 -6
- package/src/components/atoms/alert-dialog.tsx +31 -6
- package/src/components/atoms/alert.tsx +73 -13
- package/src/components/atoms/avatar.tsx +1 -1
- package/src/components/atoms/badge.tsx +7 -2
- package/src/components/atoms/breadcrumb.tsx +137 -4
- package/src/components/atoms/button-group.tsx +30 -6
- package/src/components/atoms/button.tsx +128 -18
- package/src/components/atoms/calendar.tsx +6 -6
- package/src/components/atoms/card.tsx +130 -16
- package/src/components/atoms/carousel.tsx +16 -9
- package/src/components/atoms/chart.tsx +87 -1
- package/src/components/atoms/checkbox.tsx +85 -7
- package/src/components/atoms/collapsible.tsx +2 -1
- package/src/components/atoms/combobox.tsx +147 -21
- package/src/components/atoms/command.tsx +414 -12
- package/src/components/atoms/context-menu.tsx +28 -23
- package/src/components/atoms/dialog.tsx +151 -29
- package/src/components/atoms/direction.tsx +23 -2
- package/src/components/atoms/drawer.tsx +15 -10
- package/src/components/atoms/dropdown-menu.tsx +43 -28
- package/src/components/atoms/empty.tsx +4 -0
- package/src/components/atoms/field.tsx +41 -15
- package/src/components/atoms/hover-card.tsx +61 -8
- package/src/components/atoms/input-group.tsx +17 -9
- package/src/components/atoms/input-otp.tsx +6 -6
- package/src/components/atoms/input.tsx +7 -1
- package/src/components/atoms/item.tsx +3 -3
- package/src/components/atoms/kbd.tsx +32 -3
- package/src/components/atoms/label-swap.tsx +82 -0
- package/src/components/atoms/label.tsx +1 -1
- package/src/components/atoms/menubar.tsx +28 -26
- package/src/components/atoms/native-select.tsx +3 -2
- package/src/components/atoms/navigation-menu.tsx +13 -8
- package/src/components/atoms/pagination.tsx +2 -2
- package/src/components/atoms/popover.tsx +23 -5
- package/src/components/atoms/progress.tsx +46 -33
- package/src/components/atoms/radio-group.tsx +9 -4
- package/src/components/atoms/resizable.tsx +1 -1
- package/src/components/atoms/scroll-area.tsx +2 -2
- package/src/components/atoms/select.tsx +258 -19
- package/src/components/atoms/sheet.tsx +59 -23
- package/src/components/atoms/sidebar.tsx +333 -23
- package/src/components/atoms/skeleton.tsx +1 -1
- package/src/components/atoms/slider.tsx +1 -1
- package/src/components/atoms/sonner.tsx +128 -38
- package/src/components/atoms/spinner.tsx +1 -1
- package/src/components/atoms/switch.tsx +10 -5
- package/src/components/atoms/table.tsx +147 -7
- package/src/components/atoms/tabs.tsx +3 -3
- package/src/components/atoms/textarea.tsx +3 -1
- package/src/components/atoms/toggle-group.tsx +4 -2
- package/src/components/atoms/toggle.tsx +28 -6
- package/src/components/atoms/tooltip.tsx +85 -15
- package/src/components/molecules/anonymized-token.tsx +24 -8
- package/src/components/molecules/app-shell.tsx +53 -20
- package/src/components/molecules/arrow-link.tsx +40 -0
- package/src/components/molecules/chip.tsx +2 -2
- package/src/components/molecules/code-block.tsx +54 -31
- package/src/components/molecules/collapsible-section.tsx +129 -0
- package/src/components/molecules/confirm-dialog.tsx +113 -9
- package/src/components/molecules/copyable-text.tsx +75 -11
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +32 -4
- package/src/components/molecules/data-table/data-table-column-header.tsx +20 -3
- package/src/components/molecules/data-table/data-table-filters.tsx +1 -1
- package/src/components/molecules/data-table/data-table-helpers.tsx +68 -1
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +115 -0
- package/src/components/molecules/data-table/data-table-types.tsx +138 -4
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
- package/src/components/molecules/data-table/data-table.tsx +916 -84
- package/src/components/molecules/data-table/table-pagination.tsx +2 -2
- package/src/components/molecules/date-picker.tsx +13 -7
- package/src/components/molecules/date-range-picker.tsx +13 -6
- package/src/components/molecules/date-time-picker.tsx +13 -7
- package/src/components/molecules/date-time.tsx +8 -1
- package/src/components/molecules/direction-link.tsx +130 -0
- package/src/components/molecules/elapsed-time.tsx +223 -0
- package/src/components/molecules/file-dropzone.tsx +2 -2
- package/src/components/molecules/id-chip.tsx +169 -32
- package/src/components/molecules/inline-code.tsx +4 -0
- package/src/components/molecules/issued-secret.tsx +318 -0
- package/src/components/molecules/list-row.tsx +349 -0
- package/src/components/molecules/live-indicator.tsx +83 -0
- package/src/components/molecules/page-header.tsx +117 -5
- package/src/components/molecules/password-input.tsx +2 -2
- package/src/components/molecules/relative-time.tsx +85 -56
- package/src/components/molecules/search-trigger.tsx +127 -0
- package/src/components/molecules/secret-value.tsx +26 -9
- package/src/components/molecules/skip-link.tsx +1 -1
- package/src/components/molecules/stat-card.tsx +4 -4
- package/src/components/molecules/state-views/empty-state.tsx +35 -17
- package/src/components/molecules/state-views/error-state.tsx +32 -14
- package/src/components/molecules/status-badge.tsx +415 -49
- package/src/components/molecules/time-tooltip.tsx +140 -0
- package/src/components/molecules/timeline.tsx +246 -0
- package/src/components/molecules/visibility-icon.tsx +89 -0
- package/src/hooks/use-active-label-size.ts +32 -0
- package/src/hooks/use-pinned-height.ts +55 -0
- package/src/hooks/use-scrolled.ts +27 -0
- package/src/lib/content-inset.ts +17 -0
- package/src/lib/control-name.ts +55 -0
- package/src/lib/dialog-padding.ts +48 -0
- package/src/lib/field-surface.ts +31 -0
- package/src/lib/format-elapsed.ts +67 -0
- package/src/lib/format-relative.ts +29 -1
- package/src/lib/highlight.ts +3 -3
- package/src/lib/menu-item.tsx +72 -0
- package/src/lib/outline-edge.ts +21 -0
- package/src/lib/popup-align.ts +67 -0
- package/src/lib/popup-direction.ts +22 -0
- package/src/lib/popup-motion.ts +19 -0
- package/src/lib/state-dictionary.ts +42 -6
- package/src/lib/syntax-colors.ts +8 -0
- package/src/lib/tint-recipes.ts +68 -0
- package/src/lib/tone-icons.ts +24 -0
- package/src/lib/trigger-slot.ts +16 -0
- package/src/lib/utils.ts +104 -1
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
2
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
+
import type { Tone } from '@vendure-io/ui/lib/state-dictionary';
|
|
4
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
5
|
+
import type * as React from 'react';
|
|
6
|
+
|
|
7
|
+
// Compound-only, like ListRow: callers assemble the parts, so an entry can
|
|
8
|
+
// hold a plain sentence, an icon, detail content, an actor and a link without
|
|
9
|
+
// an ever-growing prop set.
|
|
10
|
+
//
|
|
11
|
+
// The v3 look: one rail of 1px `input` lines. Each entry is a 14px marker
|
|
12
|
+
// column and the text, 12px apart. The 8px dot sits 6px down, centred on the
|
|
13
|
+
// first 20px line of the sentence. The line under an entry starts 4px below
|
|
14
|
+
// its marker and stops 4px above the next marker, so the rail runs between
|
|
15
|
+
// the dots, never through them. Entries are 16px apart.
|
|
16
|
+
//
|
|
17
|
+
// The rail is the entry's ::after, drawn from the marker of this entry to the
|
|
18
|
+
// marker of the next one, so the last entry draws none. The line ends 2px
|
|
19
|
+
// below the entry (4px above the next dot, which sits 6px down), or 1px above
|
|
20
|
+
// it when the next entry has an icon (an icon sits 3px down).
|
|
21
|
+
const ITEM_RAIL =
|
|
22
|
+
"not-last:after:absolute not-last:after:start-[6.5px] not-last:after:top-[18px] not-last:after:-bottom-0.5 not-last:after:w-px not-last:after:bg-input not-last:after:content-[''] has-[[data-slot=timeline-marker][data-marker=icon]]:after:top-[21px] [&:has(+li_[data-slot=timeline-marker][data-marker=icon])]:after:bottom-px";
|
|
23
|
+
|
|
24
|
+
// Interactive elements inside an entry with a TimelineLink (buttons, links,
|
|
25
|
+
// tooltip triggers) are lifted above the stretched link, so they keep their
|
|
26
|
+
// own click and their own tab stop. The class names stay literal so Tailwind
|
|
27
|
+
// can scan them.
|
|
28
|
+
const LIFT_CONTROLS =
|
|
29
|
+
'[&_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-timeline-control]):not([data-slot=timeline-link])]:relative [&_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-timeline-control]):not([data-slot=timeline-link])]:z-10';
|
|
30
|
+
|
|
31
|
+
// The ListRow entrance: an entry the user just added (`enter="new"`) opens
|
|
32
|
+
// its height on the `height` curve in `row-enter`, so the entries below glide
|
|
33
|
+
// down, then its content fades in from a 3px blur a `fast` beat later.
|
|
34
|
+
// @starting-style runs it on mount only. The 16px gap under the entry opens
|
|
35
|
+
// with it. Reduced motion keeps the fade only.
|
|
36
|
+
const ENTER_NEW =
|
|
37
|
+
'data-[enter=new]:overflow-clip data-[enter=new]:[interpolate-size:allow-keywords] motion-safe:data-[enter=new]:[transition:height_var(--transition-duration-row-enter)_var(--ease-height),padding-bottom_var(--transition-duration-row-enter)_var(--ease-height),opacity_var(--transition-duration-slow)_var(--ease-soft)_var(--transition-duration-fast),filter_var(--transition-duration-slow)_var(--ease-out)_var(--transition-duration-fast)] motion-safe:data-[enter=new]:starting:h-0 motion-safe:data-[enter=new]:starting:pb-0 motion-safe:data-[enter=new]:starting:blur-[3px] data-[enter=new]:starting:opacity-0 motion-reduce:data-[enter=new]:[transition:opacity_var(--transition-duration-normal)_var(--ease-default)]';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A feed of activity entries on one vertical rail, newest first: a crash, a
|
|
41
|
+
* restart, a refund, a note. Renders an `<ol>` of TimelineItems.
|
|
42
|
+
*
|
|
43
|
+
* For entries grouped by day, put a TimelineGroupHeading before each group's
|
|
44
|
+
* own Timeline.
|
|
45
|
+
*/
|
|
46
|
+
function Timeline({ className, ...props }: React.ComponentProps<'ol'>) {
|
|
47
|
+
return <ol data-slot="timeline" className={cn('flex flex-col', className)} {...props} />;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The heading of a group of entries, such as a day ("Today", "Yesterday"):
|
|
52
|
+
* the type of the ListRow day heading, a step above the entry time. Place it
|
|
53
|
+
* before the Timeline of its group. Renders a `div`; pass `render={<h3 />}`
|
|
54
|
+
* when the groups belong in the page outline.
|
|
55
|
+
*/
|
|
56
|
+
function TimelineGroupHeading({ className, render, ...props }: useRender.ComponentProps<'div'>) {
|
|
57
|
+
return useRender({
|
|
58
|
+
defaultTagName: 'div',
|
|
59
|
+
render,
|
|
60
|
+
props: mergeProps<'div'>(
|
|
61
|
+
{
|
|
62
|
+
className: cn(
|
|
63
|
+
'pt-4 pb-2.5 text-xs leading-3 font-semibold text-foreground-secondary first:pt-0',
|
|
64
|
+
className,
|
|
65
|
+
),
|
|
66
|
+
},
|
|
67
|
+
props,
|
|
68
|
+
),
|
|
69
|
+
state: { slot: 'timeline-group-heading' },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface TimelineItemProps extends React.ComponentProps<'li'> {
|
|
74
|
+
/**
|
|
75
|
+
* How an entry added while the page is open enters: `'new'` opens its
|
|
76
|
+
* height, then fades its content in, like a new ListRow. Leave it unset on
|
|
77
|
+
* the entries of the first render, so the feed does not animate on load.
|
|
78
|
+
*/
|
|
79
|
+
enter?: 'new';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* One entry: a TimelineMarker and a TimelineContent. With a TimelineLink
|
|
84
|
+
* inside, the whole entry opens the link; keyboard focus on the link draws a
|
|
85
|
+
* ring around the entry.
|
|
86
|
+
*/
|
|
87
|
+
function TimelineItem({ className, enter, ...props }: TimelineItemProps) {
|
|
88
|
+
return (
|
|
89
|
+
<li
|
|
90
|
+
data-slot="timeline-item"
|
|
91
|
+
data-enter={enter}
|
|
92
|
+
className={cn(
|
|
93
|
+
'group/timeline-item relative grid grid-cols-[14px_minmax(0,1fr)] gap-x-3 not-last:pb-4',
|
|
94
|
+
ITEM_RAIL,
|
|
95
|
+
'has-data-[slot=timeline-link]:cursor-pointer',
|
|
96
|
+
LIFT_CONTROLS,
|
|
97
|
+
ENTER_NEW,
|
|
98
|
+
className,
|
|
99
|
+
)}
|
|
100
|
+
{...props}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The dot fill of each tone, as StatusBadge draws its dot. A dot is a filled
|
|
106
|
+
// shape, so warning takes `warning-indicator`: in `warning-text` it reads
|
|
107
|
+
// brown. Neutral is the `neutral-text` grey.
|
|
108
|
+
const toneDot: Record<Tone, string> = {
|
|
109
|
+
neutral: 'text-neutral-text',
|
|
110
|
+
info: 'text-info-text',
|
|
111
|
+
success: 'text-success-text',
|
|
112
|
+
warning: 'text-warning-indicator',
|
|
113
|
+
critical: 'text-destructive-text',
|
|
114
|
+
progress: 'text-info-text',
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// An icon marker takes the tone's text colour: it is a stroke, as in
|
|
118
|
+
// StatusBadge.
|
|
119
|
+
const toneIcon: Record<Tone, string> = {
|
|
120
|
+
...toneDot,
|
|
121
|
+
warning: 'text-warning-text',
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
interface TimelineMarkerProps extends React.ComponentProps<'span'> {
|
|
125
|
+
/** The tone of the entry, from the state dictionary. Defaults to `neutral`. */
|
|
126
|
+
tone?: Tone;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The mark on the rail. Without children it is an 8px dot in its tone colour.
|
|
131
|
+
* With children (a 14px icon, or a live indicator) they take the place of the
|
|
132
|
+
* dot, centred on the first line of the sentence, in the tone colour.
|
|
133
|
+
* Decorative: the sentence carries the meaning.
|
|
134
|
+
*/
|
|
135
|
+
function TimelineMarker({ className, tone = 'neutral', children, ...props }: TimelineMarkerProps) {
|
|
136
|
+
const icon = children != null && children !== false;
|
|
137
|
+
return (
|
|
138
|
+
<span
|
|
139
|
+
aria-hidden
|
|
140
|
+
data-slot="timeline-marker"
|
|
141
|
+
data-marker={icon ? 'icon' : 'dot'}
|
|
142
|
+
data-tone={tone}
|
|
143
|
+
className={cn(
|
|
144
|
+
'justify-self-center',
|
|
145
|
+
icon
|
|
146
|
+
? cn(
|
|
147
|
+
"mt-0.75 flex size-3.5 items-center justify-center [&_svg:not([class*='size-'])]:size-3.5 [&_svg:not([class*='stroke-'])]:stroke-[1.75]",
|
|
148
|
+
toneIcon[tone],
|
|
149
|
+
)
|
|
150
|
+
: cn('mt-1.5 size-2 rounded-full bg-current', toneDot[tone]),
|
|
151
|
+
className,
|
|
152
|
+
)}
|
|
153
|
+
{...props}
|
|
154
|
+
>
|
|
155
|
+
{icon ? children : null}
|
|
156
|
+
</span>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The text column: the sentence, then the meta line and any detail. */
|
|
161
|
+
function TimelineContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
162
|
+
return <div data-slot="timeline-content" className={cn('min-w-0', className)} {...props} />;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const titleClassName = 'text-sm leading-5 text-foreground text-pretty';
|
|
166
|
+
|
|
167
|
+
/** The sentence of an entry: what happened, in 13px on a 20px line. */
|
|
168
|
+
function TimelineTitle({ className, ...props }: React.ComponentProps<'p'>) {
|
|
169
|
+
return <p data-slot="timeline-title" className={cn(titleClassName, className)} {...props} />;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The sentence of an entry that opens something. Renders a `<button>` for an
|
|
174
|
+
* `onClick` handler; pass `render={<a href="…" />}` (or a router link element)
|
|
175
|
+
* to open a URL. It covers the whole entry, so a click on any point of it
|
|
176
|
+
* opens the link. Its children are the accessible name: keep them to the
|
|
177
|
+
* sentence.
|
|
178
|
+
*/
|
|
179
|
+
function TimelineLink({ className, render, ...props }: useRender.ComponentProps<'button'>) {
|
|
180
|
+
return useRender({
|
|
181
|
+
defaultTagName: 'button',
|
|
182
|
+
render,
|
|
183
|
+
props: mergeProps<'button'>(
|
|
184
|
+
{
|
|
185
|
+
// A native button submits its form by default; a rendered anchor or
|
|
186
|
+
// router link takes no type.
|
|
187
|
+
type: render ? undefined : 'button',
|
|
188
|
+
className: cn(
|
|
189
|
+
titleClassName,
|
|
190
|
+
'block max-w-full cursor-pointer text-start outline-none',
|
|
191
|
+
// The stretched area covers the entry, 6px out to the sides and 4px
|
|
192
|
+
// above and below, but not the 16px gap to the next entry. Keyboard
|
|
193
|
+
// focus draws the ring around it.
|
|
194
|
+
'after:absolute after:-inset-x-1.5 after:-inset-y-1 after:rounded-md group-not-last/timeline-item:after:bottom-3',
|
|
195
|
+
'focus-visible:after:outline-2 focus-visible:after:outline-solid focus-visible:after:outline-ring',
|
|
196
|
+
'decoration-muted-foreground/60 underline-offset-2 group-hover/timeline-item:underline',
|
|
197
|
+
className,
|
|
198
|
+
),
|
|
199
|
+
},
|
|
200
|
+
props,
|
|
201
|
+
),
|
|
202
|
+
state: { slot: 'timeline-link' },
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The 12px muted line under the sentence: the time, as a RelativeTime, and
|
|
208
|
+
* who did it ("Mara Lindqvist · 5 min ago"). Tabular figures keep times
|
|
209
|
+
* steady.
|
|
210
|
+
*/
|
|
211
|
+
function TimelineMeta({ className, ...props }: React.ComponentProps<'p'>) {
|
|
212
|
+
return (
|
|
213
|
+
<p
|
|
214
|
+
data-slot="timeline-meta"
|
|
215
|
+
className={cn('mt-0.5 text-xs leading-4.5 text-muted-foreground tabular-nums', className)}
|
|
216
|
+
{...props}
|
|
217
|
+
/>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Optional content under the meta line: a note, an amount, a state change, a
|
|
223
|
+
* list of the changed lines.
|
|
224
|
+
*/
|
|
225
|
+
function TimelineDetail({ className, ...props }: React.ComponentProps<'div'>) {
|
|
226
|
+
return (
|
|
227
|
+
<div
|
|
228
|
+
data-slot="timeline-detail"
|
|
229
|
+
className={cn('mt-2 text-sm text-foreground-secondary', className)}
|
|
230
|
+
{...props}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export {
|
|
236
|
+
Timeline,
|
|
237
|
+
TimelineContent,
|
|
238
|
+
TimelineDetail,
|
|
239
|
+
TimelineGroupHeading,
|
|
240
|
+
TimelineItem,
|
|
241
|
+
TimelineLink,
|
|
242
|
+
TimelineMarker,
|
|
243
|
+
TimelineMeta,
|
|
244
|
+
TimelineTitle,
|
|
245
|
+
};
|
|
246
|
+
export type { TimelineItemProps, TimelineMarkerProps };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
// lucide's Eye, so the icon lines up with lucide icons at the same size and
|
|
7
|
+
// stroke, and lucide's EyeOff strike line.
|
|
8
|
+
const EYE_OUTLINE =
|
|
9
|
+
'M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0';
|
|
10
|
+
const STRIKE = 'M2 2l20 20';
|
|
11
|
+
|
|
12
|
+
// The line is drawn, not swapped: a path with pathLength 1 and a dash of 1
|
|
13
|
+
// followed by a gap of 2. An offset of 1 puts the whole path in the gap
|
|
14
|
+
// (no round cap peeks out at either end); an offset of 0 shows the whole
|
|
15
|
+
// dash. Between the two the line grows from the top-left corner.
|
|
16
|
+
// A mask cuts the eye along the line, like lucide's EyeOff: the same dash in
|
|
17
|
+
// black, 5 units wide, so 1.5 units of clearance show on each side of the
|
|
18
|
+
// 2-unit line. Its round cap runs a little ahead of the line's tip, so the
|
|
19
|
+
// eye opens just before the line reaches it.
|
|
20
|
+
// Both ways take `normal` on the in-out curve: the icon stays on screen and
|
|
21
|
+
// changes shape. A strong ease-out left the retracting line's round cap as a
|
|
22
|
+
// dot in the corner for most of the time.
|
|
23
|
+
// Transitions only, so a fast toggle reverses from wherever it is. A CSS
|
|
24
|
+
// transition never runs on the first render, so the icon mounts in its
|
|
25
|
+
// state without motion. Reduced motion changes at once.
|
|
26
|
+
const dash =
|
|
27
|
+
'[stroke-dasharray:1_2] [transition:stroke-dashoffset_var(--transition-duration-normal)_var(--ease-in-out)] motion-reduce:transition-none';
|
|
28
|
+
|
|
29
|
+
export interface VisibilityIconProps extends Omit<React.ComponentProps<'svg'>, 'children'> {
|
|
30
|
+
/**
|
|
31
|
+
* `true` (default) draws the open eye. `false` draws the line through it.
|
|
32
|
+
* A change draws the line in or out.
|
|
33
|
+
*/
|
|
34
|
+
visible?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* An eye that shows a visible or hidden state, for show/hide toggles. When
|
|
39
|
+
* `visible` turns false a line draws across the eye and cuts it; when it turns
|
|
40
|
+
* true the line draws back out. It sizes and colours like a lucide icon
|
|
41
|
+
* (24×24 viewBox, `currentColor`, the parent's `[&_svg]` size rules). It is
|
|
42
|
+
* decorative: the control that holds it carries the label.
|
|
43
|
+
*/
|
|
44
|
+
function VisibilityIcon({ visible = true, className, ...props }: VisibilityIconProps) {
|
|
45
|
+
// The mask id must be unique per icon and safe inside `url(#…)`.
|
|
46
|
+
const maskId = `visibility-icon-${React.useId().replace(/[^\w-]/g, '')}`;
|
|
47
|
+
const offset = visible ? '[stroke-dashoffset:1]' : '[stroke-dashoffset:0]';
|
|
48
|
+
return (
|
|
49
|
+
<svg
|
|
50
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
51
|
+
width="24"
|
|
52
|
+
height="24"
|
|
53
|
+
viewBox="0 0 24 24"
|
|
54
|
+
fill="none"
|
|
55
|
+
stroke="currentColor"
|
|
56
|
+
strokeWidth="2"
|
|
57
|
+
strokeLinecap="round"
|
|
58
|
+
strokeLinejoin="round"
|
|
59
|
+
aria-hidden="true"
|
|
60
|
+
data-slot="visibility-icon"
|
|
61
|
+
data-visibility={visible ? 'visible' : 'hidden'}
|
|
62
|
+
// A consumer that dims the hidden state with an opacity class gets the
|
|
63
|
+
// same timing as the line.
|
|
64
|
+
className={cn(
|
|
65
|
+
'[transition:opacity_var(--transition-duration-normal)_var(--ease-soft)] motion-reduce:transition-none',
|
|
66
|
+
className,
|
|
67
|
+
)}
|
|
68
|
+
{...props}
|
|
69
|
+
>
|
|
70
|
+
<mask id={maskId} maskUnits="userSpaceOnUse" x="0" y="0" width="24" height="24">
|
|
71
|
+
<rect width="24" height="24" fill="white" stroke="none" />
|
|
72
|
+
<path
|
|
73
|
+
d={STRIKE}
|
|
74
|
+
pathLength={1}
|
|
75
|
+
stroke="black"
|
|
76
|
+
strokeWidth="5"
|
|
77
|
+
className={cn(dash, offset)}
|
|
78
|
+
/>
|
|
79
|
+
</mask>
|
|
80
|
+
<g mask={`url(#${maskId})`}>
|
|
81
|
+
<path d={EYE_OUTLINE} />
|
|
82
|
+
<circle cx="12" cy="12" r="3" />
|
|
83
|
+
</g>
|
|
84
|
+
<path d={STRIKE} pathLength={1} className={cn(dash, offset)} />
|
|
85
|
+
</svg>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { VisibilityIcon };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The width and height of the active label in a label swap. Put
|
|
5
|
+
* `refs.current[index]` on each label and set `width` and `height` on the
|
|
6
|
+
* swap, so it eases to the active label's size. A ResizeObserver keeps the
|
|
7
|
+
* size current while the label is active: a web font that loads after the
|
|
8
|
+
* first paint, or a label whose text changes, resizes the swap too.
|
|
9
|
+
* `offsetWidth` ignores a scale on an ancestor (a tooltip's entrance, a
|
|
10
|
+
* pressed card), which `getBoundingClientRect` would include.
|
|
11
|
+
*/
|
|
12
|
+
export function useActiveLabelSize(active: number) {
|
|
13
|
+
const refs = React.useRef<(HTMLSpanElement | null)[]>([]);
|
|
14
|
+
const [size, setSize] = React.useState<{ width: number; height: number }>();
|
|
15
|
+
React.useLayoutEffect(() => {
|
|
16
|
+
const label = refs.current[active];
|
|
17
|
+
if (!label) return;
|
|
18
|
+
const measure = () => {
|
|
19
|
+
const width = label.offsetWidth;
|
|
20
|
+
const height = label.offsetHeight;
|
|
21
|
+
setSize((last) =>
|
|
22
|
+
last?.width === width && last.height === height ? last : { width, height },
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
measure();
|
|
26
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
27
|
+
const observer = new ResizeObserver(measure);
|
|
28
|
+
observer.observe(label);
|
|
29
|
+
return () => observer.disconnect();
|
|
30
|
+
}, [active]);
|
|
31
|
+
return { refs, width: size?.width, height: size?.height };
|
|
32
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A ref for a pinned (sticky) header or footer. It writes the element's height
|
|
5
|
+
* to `property` on its scroll container, the closest `[data-slot=<scroller>]`
|
|
6
|
+
* ancestor, and keeps it current with a ResizeObserver: a title that wraps to a
|
|
7
|
+
* second line, or a footer whose buttons wrap, updates it. The container turns
|
|
8
|
+
* the heights into `scroll-padding`, so a field that gets focus (by Tab, a
|
|
9
|
+
* script or form validation) scrolls clear of the header and the footer.
|
|
10
|
+
* `offsetHeight` ignores the entrance scale on the popup.
|
|
11
|
+
*
|
|
12
|
+
* `ref` is the consumer's own ref on the element; the returned ref sets it too.
|
|
13
|
+
*/
|
|
14
|
+
export function usePinnedHeight<T extends HTMLElement>(
|
|
15
|
+
property: string,
|
|
16
|
+
scroller: string,
|
|
17
|
+
ref: React.Ref<T> | undefined,
|
|
18
|
+
) {
|
|
19
|
+
return React.useCallback(
|
|
20
|
+
(node: T | null): (() => void) | undefined => {
|
|
21
|
+
const own = setRef(ref, node);
|
|
22
|
+
const container = node?.closest<HTMLElement>(`[data-slot="${scroller}"]`);
|
|
23
|
+
if (!node || !container) return own;
|
|
24
|
+
const measure = () => container.style.setProperty(property, `${node.offsetHeight}px`);
|
|
25
|
+
measure();
|
|
26
|
+
const observer =
|
|
27
|
+
typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure);
|
|
28
|
+
observer?.observe(node);
|
|
29
|
+
// React 19 calls the returned cleanup instead of the ref with null.
|
|
30
|
+
return () => {
|
|
31
|
+
observer?.disconnect();
|
|
32
|
+
container.style.removeProperty(property);
|
|
33
|
+
own?.();
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
[property, scroller, ref],
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Sets a consumer ref and returns how to clear it: a function ref's own
|
|
41
|
+
// cleanup (React 19), or a call with null.
|
|
42
|
+
function setRef<T>(ref: React.Ref<T> | undefined, node: T | null): (() => void) | undefined {
|
|
43
|
+
if (!ref || !node) return undefined;
|
|
44
|
+
if (typeof ref === 'function') {
|
|
45
|
+
const cleanup = ref(node);
|
|
46
|
+
return () => {
|
|
47
|
+
if (typeof cleanup === 'function') cleanup();
|
|
48
|
+
else ref(null);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
ref.current = node;
|
|
52
|
+
return () => {
|
|
53
|
+
ref.current = null;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A ref for a scroll container. It sets `data-scrolled` on the element while
|
|
5
|
+
* its content is scrolled away from the top, and removes it at the top. A
|
|
6
|
+
* sticky header inside takes the rule with `in-data-scrolled:shadow-scrolled`.
|
|
7
|
+
*
|
|
8
|
+
* `ref` is the consumer's own ref on the element; the returned ref sets it too.
|
|
9
|
+
*/
|
|
10
|
+
export function useScrolled<T extends HTMLElement>(ref?: React.Ref<T>) {
|
|
11
|
+
return React.useCallback(
|
|
12
|
+
(node: T | null): (() => void) | undefined => {
|
|
13
|
+
if (!node) return undefined;
|
|
14
|
+
if (typeof ref === 'function') ref(node);
|
|
15
|
+
else if (ref) ref.current = node;
|
|
16
|
+
const update = () => node.toggleAttribute('data-scrolled', node.scrollTop > 0);
|
|
17
|
+
update();
|
|
18
|
+
node.addEventListener('scroll', update, { passive: true });
|
|
19
|
+
return () => {
|
|
20
|
+
node.removeEventListener('scroll', update);
|
|
21
|
+
if (typeof ref === 'function') ref(null);
|
|
22
|
+
else if (ref) ref.current = null;
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
[ref],
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lines up the text of a styled element (a Badge, a StatusBadge chip, a
|
|
3
|
+
* Button, an IdChip) with the header of its DataTable column.
|
|
4
|
+
*
|
|
5
|
+
* The element sets `--content-inset`: the distance from its box to its first
|
|
6
|
+
* letter (padding, border, and a leading icon with its gap). A DataTable cell
|
|
7
|
+
* pulls its first element back by that distance. This class also pulls the
|
|
8
|
+
* element back when it sits one wrapper deep, as the first child of the
|
|
9
|
+
* cell's first child (for example inside a tooltip trigger).
|
|
10
|
+
*
|
|
11
|
+
* The rule has zero specificity, so a margin the element sets itself wins. It
|
|
12
|
+
* only applies inside a cell marked `data-content-inset-cell`, which only the
|
|
13
|
+
* DataTable sets: it measures the pull-back and indents the column when the
|
|
14
|
+
* pull-back would leave the cell.
|
|
15
|
+
*/
|
|
16
|
+
export const contentInsetPull =
|
|
17
|
+
'[:where([data-content-inset-cell]>:first-child>&:first-child)]:-ms-(--content-inset)';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type NameProps = { 'aria-label'?: string; 'aria-labelledby'?: string };
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The name a popup takes from the control that opens it: the control's
|
|
7
|
+
* `aria-labelledby` (Base UI points it at a Field label), its `aria-label`, or
|
|
8
|
+
* the text of a `<label for>`. With `orSelf`, a control with none of these
|
|
9
|
+
* names the popup by its own content (a trigger that shows its value).
|
|
10
|
+
*/
|
|
11
|
+
function nameFrom(control: HTMLElement | null, { orSelf = false } = {}): NameProps {
|
|
12
|
+
if (!control) return {};
|
|
13
|
+
const labelledBy = control.getAttribute('aria-labelledby');
|
|
14
|
+
if (labelledBy) return { 'aria-labelledby': labelledBy };
|
|
15
|
+
const label = control.getAttribute('aria-label');
|
|
16
|
+
if (label) return { 'aria-label': label };
|
|
17
|
+
const labels = (control as HTMLInputElement).labels;
|
|
18
|
+
const text =
|
|
19
|
+
labels &&
|
|
20
|
+
Array.from(labels, (element) => element.textContent?.trim())
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join(' ');
|
|
23
|
+
if (text) return { 'aria-label': text };
|
|
24
|
+
return orSelf && control.id ? { 'aria-labelledby': control.id } : {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** True when the props already name the element. */
|
|
28
|
+
function hasName(props: NameProps) {
|
|
29
|
+
return Boolean(props['aria-label'] || props['aria-labelledby']);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A ref callback that hands the element to `register` and to the caller's own
|
|
34
|
+
* `ref`, and takes it back from both on unmount.
|
|
35
|
+
*/
|
|
36
|
+
function useRegisteredRef<T extends HTMLElement>(
|
|
37
|
+
ref: React.Ref<T> | undefined,
|
|
38
|
+
register: ((element: T | null) => void) | undefined,
|
|
39
|
+
) {
|
|
40
|
+
return React.useCallback(
|
|
41
|
+
(node: T | null) => {
|
|
42
|
+
register?.(node);
|
|
43
|
+
if (typeof ref === 'function') ref(node);
|
|
44
|
+
else if (ref) ref.current = node;
|
|
45
|
+
return () => {
|
|
46
|
+
register?.(null);
|
|
47
|
+
if (typeof ref === 'function') ref(null);
|
|
48
|
+
else if (ref) ref.current = null;
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
[ref, register],
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { hasName, nameFrom, useRegisteredRef };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The value of the last unconditional `p-*` or `px-*` class in `className`,
|
|
5
|
+
* as CSS: `p-0` → `0px`, `p-4` → `calc(var(--spacing) * 4)`, `p-px` → `1px`,
|
|
6
|
+
* `p-[24px]` → `24px`, `p-(--gap)` → `var(--gap)`. `undefined` when there is
|
|
7
|
+
* none. Classes with a variant (`sm:p-0`) are skipped: an inline style
|
|
8
|
+
* cannot follow a breakpoint.
|
|
9
|
+
*/
|
|
10
|
+
export function paddingFromClassName(className: unknown): string | undefined {
|
|
11
|
+
if (typeof className !== 'string') return undefined;
|
|
12
|
+
let value: string | undefined;
|
|
13
|
+
for (const token of className.split(/\s+/)) {
|
|
14
|
+
const match = /^!?px?-(.+?)!?$/.exec(token);
|
|
15
|
+
if (!match || token.includes(':')) continue;
|
|
16
|
+
const raw = match[1] as string;
|
|
17
|
+
if (raw === 'px') value = '1px';
|
|
18
|
+
else if (/^\d+(\.\d+)?$/.test(raw))
|
|
19
|
+
value = raw === '0' ? '0px' : `calc(var(--spacing) * ${raw})`;
|
|
20
|
+
else if (raw.startsWith('[') && raw.endsWith(']')) value = raw.slice(1, -1).replace(/_/g, ' ');
|
|
21
|
+
else if (raw.startsWith('(--') && raw.endsWith(')')) value = `var(${raw.slice(1, -1)})`;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type StyleProp<State> =
|
|
27
|
+
| React.CSSProperties
|
|
28
|
+
| ((state: State) => React.CSSProperties | undefined)
|
|
29
|
+
| undefined;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sets `--dialog-padding` from a `p-*` or `px-*` class on the dialog, so the
|
|
33
|
+
* pinned header and footer, which reach over the padding with negative
|
|
34
|
+
* margins, stay flush with the dialog's edge. Code written for 2.x sets the
|
|
35
|
+
* dialog's padding with a class (`p-0` around a full-bleed picker); without
|
|
36
|
+
* this, its header and footer would stick out by the default 20px. A
|
|
37
|
+
* `[--dialog-padding:…]` class still works: with no `p-*` class, nothing is set.
|
|
38
|
+
*/
|
|
39
|
+
export function dialogPaddingStyle<State>(
|
|
40
|
+
className: unknown,
|
|
41
|
+
style: StyleProp<State>,
|
|
42
|
+
): StyleProp<State> {
|
|
43
|
+
const padding = paddingFromClassName(className);
|
|
44
|
+
if (padding === undefined) return style;
|
|
45
|
+
const variable = { '--dialog-padding': padding } as React.CSSProperties;
|
|
46
|
+
if (typeof style === 'function') return (state: State) => ({ ...variable, ...style(state) });
|
|
47
|
+
return { ...variable, ...style };
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v3 field surface: the `muted` fill with a 1px inset hairline in the
|
|
3
|
+
* `border` colour, the lg (6px) radius, and a 2px ring drawn inside the field
|
|
4
|
+
* on keyboard focus, over the hairline. An invalid field turns the hairline
|
|
5
|
+
* and the ring destructive. The hairline is a shadow, not a border, so the
|
|
6
|
+
* field keeps its size; forced-colors mode, which drops shadows, gets a real
|
|
7
|
+
* border.
|
|
8
|
+
*
|
|
9
|
+
* Input, Textarea, Select, Combobox, NativeSelect and the date pickers share
|
|
10
|
+
* it. Each field adds its own height, padding and text size.
|
|
11
|
+
*/
|
|
12
|
+
const fieldBase =
|
|
13
|
+
'bg-muted shadow-[inset_0_0_0_1px_var(--border)] rounded-lg outline-none transition-shadow duration-quick ease-soft forced-colors:border';
|
|
14
|
+
|
|
15
|
+
export const fieldSurface = `${fieldBase} focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring aria-invalid:shadow-[inset_0_0_0_1px_var(--destructive)] aria-invalid:focus-visible:outline-destructive`;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The field surface for a field whose focus and invalid state sit on an
|
|
19
|
+
* element inside it: the ring follows `focus-within`, and the hairline turns
|
|
20
|
+
* destructive when a control inside is `aria-invalid`. ComboboxChips and the
|
|
21
|
+
* InputOTP group use it.
|
|
22
|
+
*/
|
|
23
|
+
export const fieldSurfaceWithin = `${fieldBase} focus-within:outline-solid focus-within:outline-2 focus-within:-outline-offset-2 focus-within:outline-ring has-aria-invalid:shadow-[inset_0_0_0_1px_var(--destructive)] has-aria-invalid:focus-within:outline-destructive`;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A ghost Button drawn as a field: the trigger of DatePicker, DateRangePicker
|
|
27
|
+
* and DateTimePicker. It drops the Button's transparent border, so the fill
|
|
28
|
+
* reaches the edge and the field is 34px like an Input, and it starts its
|
|
29
|
+
* icon 10px in with an 8px gap, like an Input's text.
|
|
30
|
+
*/
|
|
31
|
+
export const fieldButton = `${fieldSurface} border-0 bg-clip-border px-2.5 gap-2 min-w-0 flex-1 justify-start font-normal text-foreground hover:text-foreground aria-expanded:text-foreground active:scale-none aria-invalid:ring-0`;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const SECOND = 1000;
|
|
2
|
+
|
|
3
|
+
interface FormatElapsedOptions {
|
|
4
|
+
/** The reader's locale. Default: the runtime's. */
|
|
5
|
+
locale?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type Unit = 'hour' | 'minute' | 'second';
|
|
9
|
+
|
|
10
|
+
// Formatters are cached per locale and unit: a timer formats every second.
|
|
11
|
+
const cache = new Map<string, { number: Intl.NumberFormat; list: Intl.ListFormat }>();
|
|
12
|
+
|
|
13
|
+
function formatters(locale: string | undefined, unit: Unit, padded: boolean) {
|
|
14
|
+
const key = `${locale ?? ''}|${unit}|${padded}`;
|
|
15
|
+
let entry = cache.get(key);
|
|
16
|
+
if (!entry) {
|
|
17
|
+
entry = {
|
|
18
|
+
number: new Intl.NumberFormat(locale, {
|
|
19
|
+
style: 'unit',
|
|
20
|
+
unit,
|
|
21
|
+
unitDisplay: 'narrow',
|
|
22
|
+
minimumIntegerDigits: padded ? 2 : 1,
|
|
23
|
+
}),
|
|
24
|
+
list: new Intl.ListFormat(locale, { type: 'unit', style: 'narrow' }),
|
|
25
|
+
};
|
|
26
|
+
cache.set(key, entry);
|
|
27
|
+
}
|
|
28
|
+
return entry;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Formats a duration in milliseconds as the two largest units, in the reader's
|
|
33
|
+
* locale: `31s`, `1m 15s`, `9m 07s`, `1h 05m` in English, `1 Min., 07 Sek.` or
|
|
34
|
+
* `١ د و٠٧ ث` elsewhere. The smaller unit is zero-padded, so the text keeps
|
|
35
|
+
* its width while it counts (pair it with `tabular-nums`). A negative or
|
|
36
|
+
* invalid duration reads `0s`.
|
|
37
|
+
*
|
|
38
|
+
* The units and the way they join come from `Intl.NumberFormat` (`unit`,
|
|
39
|
+
* `narrow`) and `Intl.ListFormat` (`unit`, `narrow`). `Intl.DurationFormat`
|
|
40
|
+
* cannot zero-pad the smaller unit in this style (`1m 7s`), so the width
|
|
41
|
+
* would jump each time the seconds pass 9.
|
|
42
|
+
*/
|
|
43
|
+
function formatElapsed(ms: number, { locale }: FormatElapsedOptions = {}): string {
|
|
44
|
+
const total = Number.isFinite(ms) ? Math.max(0, Math.floor(ms / SECOND)) : 0;
|
|
45
|
+
const hours = Math.floor(total / 3600);
|
|
46
|
+
const minutes = Math.floor((total % 3600) / 60);
|
|
47
|
+
const seconds = total % 60;
|
|
48
|
+
const pair = (large: Unit, largeValue: number, small: Unit, smallValue: number) => {
|
|
49
|
+
const first = formatters(locale, large, false);
|
|
50
|
+
const second = formatters(locale, small, true);
|
|
51
|
+
return first.list.format([first.number.format(largeValue), second.number.format(smallValue)]);
|
|
52
|
+
};
|
|
53
|
+
if (hours > 0) return pair('hour', hours, 'minute', minutes);
|
|
54
|
+
if (minutes > 0) return pair('minute', minutes, 'second', seconds);
|
|
55
|
+
return formatters(locale, 'second', false).number.format(seconds);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The ISO 8601 duration of `ms` (`PT1M15S`), for a `<time dateTime>`. */
|
|
59
|
+
function isoDuration(ms: number): string {
|
|
60
|
+
const total = Number.isFinite(ms) ? Math.max(0, Math.floor(ms / SECOND)) : 0;
|
|
61
|
+
const hours = Math.floor(total / 3600);
|
|
62
|
+
const minutes = Math.floor((total % 3600) / 60);
|
|
63
|
+
const seconds = total % 60;
|
|
64
|
+
return `PT${hours ? `${hours}H` : ''}${minutes ? `${minutes}M` : ''}${seconds || total === 0 ? `${seconds}S` : ''}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { formatElapsed, isoDuration, type FormatElapsedOptions };
|