@leitware/composables 1.6.1 → 1.7.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.
@@ -0,0 +1,390 @@
1
+ import { mergeProps } from '@base-ui/react/merge-props'
2
+ import { useRender } from '@base-ui/react/use-render'
3
+ import {
4
+ createContext,
5
+ forwardRef,
6
+ useContext,
7
+ useEffect,
8
+ useId,
9
+ useImperativeHandle,
10
+ useRef,
11
+ useState,
12
+ type ComponentPropsWithoutRef,
13
+ type PointerEvent,
14
+ type CSSProperties,
15
+ } from 'react'
16
+ import { cn, FOCUS_RING } from '../lib/utils'
17
+ import {
18
+ getFlowEdges,
19
+ getFlowPath,
20
+ type FlowTree,
21
+ type FlowOrientation,
22
+ type FlowPoint,
23
+ } from '../lib/flow'
24
+
25
+ export type FlowAlign = 'start' | 'center'
26
+ const FlowContext = createContext<{ orientation: FlowOrientation; align: FlowAlign }>({
27
+ orientation: 'horizontal',
28
+ align: 'start',
29
+ })
30
+ const sequenceClasses = (orientation: FlowOrientation, align: FlowAlign) =>
31
+ cn(
32
+ 'flex w-max list-none gap-(--flow-gap) p-0',
33
+ orientation === 'vertical' ? 'flex-col' : 'flex-row',
34
+ align === 'center' ? 'items-center' : 'items-start',
35
+ )
36
+
37
+ function readTree(element: HTMLElement): FlowTree | undefined {
38
+ const kind = element.dataset.flowKind
39
+ if (kind === 'node') {
40
+ const id = element.querySelector<HTMLElement>('[data-flow-node]')?.dataset.flowNode
41
+ return id ? { kind: 'node', id } : undefined
42
+ }
43
+ if (kind !== 'sequence' && kind !== 'parallel') return
44
+ const items = element.querySelector<HTMLElement>(':scope > [data-flow-items]') ?? element
45
+ const children = Array.from(items.children).flatMap((child) => {
46
+ const tree = child instanceof HTMLElement ? readTree(child) : undefined
47
+ return tree ? [tree] : []
48
+ })
49
+ return { kind, children }
50
+ }
51
+
52
+ export interface FlowRootProps extends ComponentPropsWithoutRef<'div'> {
53
+ orientation?: FlowOrientation
54
+ align?: FlowAlign
55
+ /** Scrollable canvas with mouse dragging and native touch/keyboard scrolling. @default true */
56
+ canvas?: boolean
57
+ onOverflowChange?: (overflow: { x: boolean; y: boolean }) => void
58
+ }
59
+ interface MeasuredFlow {
60
+ width: number
61
+ height: number
62
+ paths: { id: string; d: string; disabled: boolean }[]
63
+ }
64
+
65
+ export const FlowRoot = forwardRef<HTMLDivElement, FlowRootProps>(function FlowRoot(
66
+ {
67
+ orientation = 'horizontal',
68
+ align = 'start',
69
+ canvas = true,
70
+ onOverflowChange,
71
+ className,
72
+ children,
73
+ dir,
74
+ onPointerDown,
75
+ onPointerMove,
76
+ onPointerUp,
77
+ onPointerCancel,
78
+ onLostPointerCapture,
79
+ ...props
80
+ },
81
+ ref,
82
+ ) {
83
+ const viewportRef = useRef<HTMLDivElement>(null)
84
+ const contentRef = useRef<HTMLDivElement>(null)
85
+ const overflowCallback = useRef(onOverflowChange)
86
+ useEffect(() => {
87
+ overflowCallback.current = onOverflowChange
88
+ }, [onOverflowChange])
89
+ const [drawing, setDrawing] = useState<MeasuredFlow>({ width: 0, height: 0, paths: [] })
90
+ const [panning, setPanning] = useState(false)
91
+ const drag = useRef<{ x: number; y: number; left: number; top: number } | null>(null)
92
+ useImperativeHandle(ref, () => viewportRef.current!, [])
93
+ useEffect(() => {
94
+ const viewport = viewportRef.current
95
+ const content = contentRef.current
96
+ if (!viewport || !content) return
97
+ let frame = 0
98
+ let overflowKey = ''
99
+ const measure = () => {
100
+ const list = content.querySelector<HTMLElement>(':scope > [data-flow-items]')
101
+ const tree = list && readTree(list)
102
+ const origin = content.getBoundingClientRect()
103
+ const rtl = getComputedStyle(content).direction === 'rtl'
104
+ const nodes = new Map<string, HTMLElement>()
105
+ for (const node of content.querySelectorAll<HTMLElement>('[data-flow-node]')) {
106
+ if (node.closest('[data-slot="flow"]') === viewport && node.dataset.flowNode)
107
+ nodes.set(node.dataset.flowNode, node)
108
+ }
109
+ const point = (node: HTMLElement, exit: boolean): FlowPoint => {
110
+ const rect = node.getBoundingClientRect()
111
+ const anchor = node.querySelector<HTMLElement>(
112
+ `[data-flow-anchor="${exit ? 'end' : 'start'}"], [data-flow-anchor="both"]`,
113
+ )
114
+ const cross = anchor?.getBoundingClientRect() ?? rect
115
+ return orientation === 'vertical'
116
+ ? {
117
+ x: cross.left + cross.width / 2 - origin.left,
118
+ y: (exit ? rect.bottom : rect.top) - origin.top,
119
+ }
120
+ : {
121
+ x: (exit !== rtl ? rect.right : rect.left) - origin.left,
122
+ y: cross.top + cross.height / 2 - origin.top,
123
+ }
124
+ }
125
+ const paths = (tree ? getFlowEdges(tree) : []).flatMap((edge) => {
126
+ const from = nodes.get(edge.from),
127
+ to = nodes.get(edge.to)
128
+ if (!from || !to) return []
129
+ const disabled = [from, to].some(
130
+ (node) =>
131
+ node.closest('[data-flow-kind="node"]')?.getAttribute('data-disabled') === 'true',
132
+ )
133
+ return [
134
+ {
135
+ id: `${edge.from}-${edge.to}`,
136
+ d: getFlowPath(point(from, true), point(to, false), orientation),
137
+ disabled,
138
+ },
139
+ ]
140
+ })
141
+ const next = { width: content.offsetWidth, height: content.offsetHeight, paths }
142
+ setDrawing((previous) =>
143
+ JSON.stringify(previous) === JSON.stringify(next) ? previous : next,
144
+ )
145
+ const overflow = {
146
+ x: viewport.scrollWidth > viewport.clientWidth,
147
+ y: viewport.scrollHeight > viewport.clientHeight,
148
+ }
149
+ const key = JSON.stringify(overflow)
150
+ if (key !== overflowKey) {
151
+ overflowKey = key
152
+ overflowCallback.current?.(overflow)
153
+ }
154
+ }
155
+ const schedule = () => {
156
+ cancelAnimationFrame(frame)
157
+ frame = requestAnimationFrame(measure)
158
+ }
159
+ const resize = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(schedule)
160
+ const observeSizes = () => {
161
+ resize?.disconnect()
162
+ resize?.observe(content)
163
+ resize?.observe(viewport)
164
+ for (const node of content.querySelectorAll<HTMLElement>(
165
+ '[data-flow-node], [data-flow-anchor]',
166
+ ))
167
+ resize?.observe(node)
168
+ }
169
+ const mutation = new MutationObserver(() => {
170
+ observeSizes()
171
+ schedule()
172
+ })
173
+ mutation.observe(content, {
174
+ subtree: true,
175
+ childList: true,
176
+ characterData: true,
177
+ attributes: true,
178
+ attributeFilter: ['class', 'style', 'data-disabled', 'dir'],
179
+ })
180
+ mutation.observe(viewport, { attributes: true, attributeFilter: ['dir'] })
181
+ observeSizes()
182
+ measure()
183
+ window.addEventListener('resize', schedule)
184
+ return () => {
185
+ cancelAnimationFrame(frame)
186
+ resize?.disconnect()
187
+ mutation.disconnect()
188
+ window.removeEventListener('resize', schedule)
189
+ }
190
+ }, [orientation, align, canvas, dir])
191
+ const stopDrag = (event: PointerEvent<HTMLDivElement>) => {
192
+ drag.current = null
193
+ setPanning(false)
194
+ if (event.currentTarget.hasPointerCapture(event.pointerId))
195
+ event.currentTarget.releasePointerCapture(event.pointerId)
196
+ }
197
+ return (
198
+ <FlowContext.Provider value={{ orientation, align }}>
199
+ <div
200
+ ref={viewportRef}
201
+ data-slot="flow"
202
+ data-orientation={orientation}
203
+ dir={dir}
204
+ role="group"
205
+ aria-label="Flow diagram"
206
+ tabIndex={canvas ? 0 : undefined}
207
+ className={cn(
208
+ 'max-w-full outline-none',
209
+ canvas &&
210
+ 'overflow-auto rounded-(--flow-canvas-radius) border-(length:--flow-border-width) border-stroke bg-muted bg-[image:var(--flow-canvas-background-image)] [background-size:var(--flow-canvas-background-size)_var(--flow-canvas-background-size)]',
211
+ canvas && FOCUS_RING,
212
+ panning && 'cursor-grabbing select-none',
213
+ className,
214
+ )}
215
+ {...props}
216
+ onPointerDown={(event) => {
217
+ onPointerDown?.(event)
218
+ if (
219
+ !canvas ||
220
+ event.defaultPrevented ||
221
+ event.button !== 0 ||
222
+ event.pointerType !== 'mouse' ||
223
+ !(event.target instanceof Element) ||
224
+ event.target.closest('[data-flow-kind="node"], a, button, input, textarea, select')
225
+ )
226
+ return
227
+ const el = event.currentTarget
228
+ if (el.scrollWidth <= el.clientWidth && el.scrollHeight <= el.clientHeight) return
229
+ drag.current = {
230
+ x: event.clientX,
231
+ y: event.clientY,
232
+ left: el.scrollLeft,
233
+ top: el.scrollTop,
234
+ }
235
+ el.setPointerCapture(event.pointerId)
236
+ setPanning(true)
237
+ event.preventDefault()
238
+ }}
239
+ onPointerMove={(event) => {
240
+ onPointerMove?.(event)
241
+ if (event.defaultPrevented || !drag.current) return
242
+ event.currentTarget.scrollLeft = drag.current.left - (event.clientX - drag.current.x)
243
+ event.currentTarget.scrollTop = drag.current.top - (event.clientY - drag.current.y)
244
+ }}
245
+ onPointerUp={(event) => {
246
+ onPointerUp?.(event)
247
+ stopDrag(event)
248
+ }}
249
+ onPointerCancel={(event) => {
250
+ onPointerCancel?.(event)
251
+ stopDrag(event)
252
+ }}
253
+ onLostPointerCapture={(event) => {
254
+ onLostPointerCapture?.(event)
255
+ drag.current = null
256
+ setPanning(false)
257
+ }}
258
+ >
259
+ <div
260
+ ref={contentRef}
261
+ data-slot="flow-content"
262
+ className={cn(
263
+ 'relative w-max min-w-full',
264
+ canvas && 'px-(--flow-canvas-padding-x) py-(--flow-canvas-padding-y)',
265
+ )}
266
+ >
267
+ <svg
268
+ data-slot="flow-connectors"
269
+ aria-hidden="true"
270
+ className="pointer-events-none absolute inset-0 overflow-visible"
271
+ width={drawing.width}
272
+ height={drawing.height}
273
+ fill="none"
274
+ stroke="var(--flow-connector-color,var(--border-tertiary))"
275
+ strokeWidth="1.5"
276
+ strokeLinecap="round"
277
+ strokeLinejoin="round"
278
+ >
279
+ {drawing.paths.map((path) => (
280
+ <path
281
+ key={path.id}
282
+ data-slot="flow-connector"
283
+ data-disabled={path.disabled || undefined}
284
+ d={path.d}
285
+ opacity={path.disabled ? 'var(--opacity-disabled)' : undefined}
286
+ />
287
+ ))}
288
+ </svg>
289
+ <ol
290
+ data-flow-items=""
291
+ data-flow-kind="sequence"
292
+ className={sequenceClasses(orientation, align)}
293
+ >
294
+ {children}
295
+ </ol>
296
+ </div>
297
+ </div>
298
+ </FlowContext.Provider>
299
+ )
300
+ })
301
+
302
+ export type FlowNodeProps = useRender.ComponentProps<'div'> & { disabled?: boolean }
303
+ export const FlowNode = forwardRef<HTMLDivElement, FlowNodeProps>(function FlowNode(
304
+ { disabled = false, render, className, ...props },
305
+ ref,
306
+ ) {
307
+ const nodeId = useId()
308
+ const defaultProps = {
309
+ 'data-slot': 'flow-node',
310
+ 'data-flow-node': nodeId,
311
+ 'aria-disabled': disabled || undefined,
312
+ className: cn(
313
+ 'relative min-w-0 rounded-(--flow-node-radius) border-(length:--flow-border-width) border-stroke-secondary bg-surface-default px-3 py-2 text-sm text-default shadow-(--flow-node-shadow)',
314
+ disabled && 'opacity-disabled',
315
+ className,
316
+ ),
317
+ }
318
+ const node = useRender({
319
+ defaultTagName: 'div',
320
+ render,
321
+ ref,
322
+ props: mergeProps<'div'>(defaultProps, props),
323
+ })
324
+ return (
325
+ <li data-flow-kind="node" data-disabled={disabled} className="relative shrink-0">
326
+ {node}
327
+ </li>
328
+ )
329
+ })
330
+
331
+ export const FlowParallel = forwardRef<HTMLLIElement, ComponentPropsWithoutRef<'li'>>(
332
+ function FlowParallel({ className, children, ...props }, ref) {
333
+ const { orientation } = useContext(FlowContext)
334
+ return (
335
+ <li
336
+ ref={ref}
337
+ data-slot="flow-parallel"
338
+ data-flow-kind="parallel"
339
+ className={cn('shrink-0', className)}
340
+ {...props}
341
+ >
342
+ <ul
343
+ data-flow-items=""
344
+ className={cn(
345
+ 'flex w-max list-none gap-(--flow-branch-gap) p-0',
346
+ orientation === 'horizontal' ? 'flex-col' : 'flex-row',
347
+ )}
348
+ >
349
+ {children}
350
+ </ul>
351
+ </li>
352
+ )
353
+ },
354
+ )
355
+ export const FlowList = forwardRef<HTMLLIElement, ComponentPropsWithoutRef<'li'>>(function FlowList(
356
+ { className, children, ...props },
357
+ ref,
358
+ ) {
359
+ const { orientation, align } = useContext(FlowContext)
360
+ return (
361
+ <li
362
+ ref={ref}
363
+ data-slot="flow-list"
364
+ data-flow-kind="sequence"
365
+ className={cn('shrink-0', className)}
366
+ {...props}
367
+ >
368
+ <ol data-flow-items="" className={sequenceClasses(orientation, align)}>
369
+ {children}
370
+ </ol>
371
+ </li>
372
+ )
373
+ })
374
+ export interface FlowAnchorProps extends ComponentPropsWithoutRef<'span'> {
375
+ type?: 'start' | 'end' | 'both'
376
+ }
377
+ export const FlowAnchor = forwardRef<HTMLSpanElement, FlowAnchorProps>(function FlowAnchor(
378
+ { type = 'both', style, ...props },
379
+ ref,
380
+ ) {
381
+ return (
382
+ <span
383
+ ref={ref}
384
+ data-slot="flow-anchor"
385
+ data-flow-anchor={type}
386
+ style={{ display: 'block', ...style } as CSSProperties}
387
+ {...props}
388
+ />
389
+ )
390
+ })
@@ -0,0 +1,61 @@
1
+ import { mergeProps } from '@base-ui/react/merge-props'
2
+ import { useRender } from '@base-ui/react/use-render'
3
+ import { forwardRef, type ComponentPropsWithoutRef } from 'react'
4
+ import { cn } from '../lib/utils'
5
+
6
+ export type LayerCardRootProps = useRender.ComponentProps<'div'> & { layered?: boolean }
7
+
8
+ export const LayerCardRoot = forwardRef<HTMLDivElement, LayerCardRootProps>(function LayerCardRoot(
9
+ { layered = true, render, className, ...props },
10
+ ref,
11
+ ) {
12
+ const defaultProps = {
13
+ 'data-slot': 'layer-card',
14
+ 'data-layered': layered,
15
+ className: cn(
16
+ 'w-full overflow-hidden rounded-(--layer-card-radius) border border-stroke text-default',
17
+ layered ? 'bg-muted' : 'bg-surface-default shadow-(--layer-card-shadow)',
18
+ className,
19
+ ),
20
+ }
21
+ return useRender({
22
+ defaultTagName: 'div',
23
+ render,
24
+ ref,
25
+ props: mergeProps<'div'>(defaultProps, props),
26
+ })
27
+ })
28
+
29
+ export type LayerCardSectionProps = ComponentPropsWithoutRef<'div'>
30
+
31
+ export const LayerCardPrimary = forwardRef<HTMLDivElement, LayerCardSectionProps>(
32
+ function LayerCardPrimary({ className, ...props }, ref) {
33
+ return (
34
+ <div
35
+ ref={ref}
36
+ data-slot="layer-card-primary"
37
+ className={cn(
38
+ 'relative z-10 flex min-w-0 flex-col gap-2 rounded-(--layer-card-radius) border border-stroke-secondary bg-surface-default p-(--layer-card-padding) shadow-(--layer-card-shadow)',
39
+ className,
40
+ )}
41
+ {...props}
42
+ />
43
+ )
44
+ },
45
+ )
46
+
47
+ export const LayerCardSecondary = forwardRef<HTMLDivElement, LayerCardSectionProps>(
48
+ function LayerCardSecondary({ className, ...props }, ref) {
49
+ return (
50
+ <div
51
+ ref={ref}
52
+ data-slot="layer-card-secondary"
53
+ className={cn(
54
+ 'flex min-w-0 items-center gap-2 px-(--layer-card-padding) py-3 text-sm font-medium text-content-secondary',
55
+ className,
56
+ )}
57
+ {...props}
58
+ />
59
+ )
60
+ },
61
+ )
@@ -0,0 +1,124 @@
1
+ import { mergeProps } from '@base-ui/react/merge-props'
2
+ import { useRender } from '@base-ui/react/use-render'
3
+ import {
4
+ forwardRef,
5
+ type ComponentPropsWithoutRef,
6
+ type ReactNode,
7
+ type MouseEventHandler,
8
+ } from 'react'
9
+ import { cn, FOCUS_RING } from '../lib/utils'
10
+
11
+ export const TableOfContentsRoot = forwardRef<HTMLElement, ComponentPropsWithoutRef<'nav'>>(
12
+ function TableOfContentsRoot(
13
+ { className, 'aria-label': label = 'Table of contents', ...props },
14
+ ref,
15
+ ) {
16
+ return (
17
+ <nav
18
+ ref={ref}
19
+ data-slot="table-of-contents"
20
+ aria-label={label}
21
+ className={cn('min-w-0', className)}
22
+ {...props}
23
+ />
24
+ )
25
+ },
26
+ )
27
+ export const TableOfContentsTitle = forwardRef<HTMLParagraphElement, ComponentPropsWithoutRef<'p'>>(
28
+ function TableOfContentsTitle({ className, ...props }, ref) {
29
+ return (
30
+ <p
31
+ ref={ref}
32
+ data-slot="table-of-contents-title"
33
+ className={cn(
34
+ 'mb-3 text-xs font-semibold tracking-wide text-content-secondary uppercase',
35
+ className,
36
+ )}
37
+ {...props}
38
+ />
39
+ )
40
+ },
41
+ )
42
+ export const TableOfContentsList = forwardRef<HTMLUListElement, ComponentPropsWithoutRef<'ul'>>(
43
+ function TableOfContentsList({ className, ...props }, ref) {
44
+ return (
45
+ <ul
46
+ ref={ref}
47
+ data-slot="table-of-contents-list"
48
+ className={cn('flex list-none flex-col gap-2 border-s-2 border-stroke p-0', className)}
49
+ {...props}
50
+ />
51
+ )
52
+ },
53
+ )
54
+
55
+ export type TableOfContentsItemProps = useRender.ComponentProps<'a'> & { active?: boolean }
56
+ const TableOfContentsLink = forwardRef<HTMLAnchorElement, TableOfContentsItemProps>(
57
+ function TableOfContentsLink({ active = false, render, className, ...props }, ref) {
58
+ const defaultProps = {
59
+ 'data-slot': 'table-of-contents-link',
60
+ 'data-active': active,
61
+ 'aria-current': active ? ('location' as const) : undefined,
62
+ className: cn(
63
+ 'block w-full truncate border-s-2 border-transparent py-0.5 ps-4 text-start text-sm leading-5 no-underline outline-none',
64
+ FOCUS_RING,
65
+ active
66
+ ? 'border-primary font-medium text-default'
67
+ : 'text-content-secondary hover:border-stroke-secondary hover:text-default',
68
+ className,
69
+ ),
70
+ }
71
+ return useRender({
72
+ defaultTagName: 'a',
73
+ render,
74
+ ref,
75
+ props: mergeProps<'a'>(defaultProps, props),
76
+ })
77
+ },
78
+ )
79
+ export const TableOfContentsItem = forwardRef<HTMLAnchorElement, TableOfContentsItemProps>(
80
+ function TableOfContentsItem(props, ref) {
81
+ return (
82
+ <li data-slot="table-of-contents-item" className="-ms-0.5 min-w-0">
83
+ <TableOfContentsLink ref={ref} {...props} />
84
+ </li>
85
+ )
86
+ },
87
+ )
88
+
89
+ export interface TableOfContentsGroupProps extends Omit<
90
+ ComponentPropsWithoutRef<'li'>,
91
+ 'title' | 'onClick'
92
+ > {
93
+ label: ReactNode
94
+ href?: string
95
+ active?: boolean
96
+ /** Called only for the group label link, never for nested item clicks. */
97
+ onLabelClick?: MouseEventHandler<HTMLAnchorElement>
98
+ }
99
+ export const TableOfContentsGroup = forwardRef<HTMLLIElement, TableOfContentsGroupProps>(
100
+ function TableOfContentsGroup(
101
+ { label, href, active, onLabelClick, className, children, ...props },
102
+ ref,
103
+ ) {
104
+ return (
105
+ <li
106
+ ref={ref}
107
+ data-slot="table-of-contents-group"
108
+ className={cn('-ms-0.5 flex min-w-0 flex-col gap-2', className)}
109
+ {...props}
110
+ >
111
+ {href ? (
112
+ <TableOfContentsLink href={href} active={active} onClick={onLabelClick}>
113
+ {label}
114
+ </TableOfContentsLink>
115
+ ) : (
116
+ <p className="py-0.5 ps-4 text-sm font-medium text-content-secondary">{label}</p>
117
+ )}
118
+ <ul className="flex list-none flex-col gap-2 border-s-2 border-stroke p-0 [&_a]:ps-7">
119
+ {children}
120
+ </ul>
121
+ </li>
122
+ )
123
+ },
124
+ )
@@ -8,39 +8,61 @@ function Tabs({ className, orientation = 'horizontal', ...props }: TabsPrimitive
8
8
  <TabsPrimitive.Root
9
9
  data-slot="tabs"
10
10
  data-orientation={orientation}
11
- className={cn('gap-2 group/tabs flex data-[orientation=horizontal]:flex-col', className)}
11
+ orientation={orientation}
12
+ className={cn(
13
+ 'group/tabs flex min-w-0 gap-2 data-[orientation=horizontal]:flex-col',
14
+ className,
15
+ )}
12
16
  {...props}
13
17
  />
14
18
  )
15
19
  }
16
20
 
21
+ const segmentedList =
22
+ 'rounded-(--tabs-list-radius) bg-muted p-(--tabs-list-padding) shadow-(--tabs-list-shadow)'
23
+ const lineList =
24
+ 'gap-1 border-b border-stroke bg-transparent pb-1 group-data-[orientation=vertical]/tabs:border-b-0 group-data-[orientation=vertical]/tabs:border-e group-data-[orientation=vertical]/tabs:pe-1'
17
25
  const tabsListVariants = cva(
18
- 'rounded-lg p-0.5 group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none group/tabs-list text-muted-foreground inline-flex w-fit items-center justify-center group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col',
26
+ 'relative isolate inline-flex w-fit max-w-full shrink-0 items-stretch overflow-x-auto group/tabs-list group-data-[orientation=vertical]/tabs:flex-col',
19
27
  {
20
28
  variants: {
21
29
  variant: {
22
- default: 'bg-muted',
23
- line: 'gap-1 bg-transparent',
30
+ default: segmentedList,
31
+ segmented: segmentedList,
32
+ line: lineList,
33
+ underline: lineList,
24
34
  },
25
35
  },
26
- defaultVariants: {
27
- variant: 'default',
28
- },
36
+ defaultVariants: { variant: 'segmented' },
29
37
  },
30
38
  )
31
39
 
32
40
  function TabsList({
33
41
  className,
34
- variant = 'default',
42
+ variant = 'segmented',
43
+ children,
35
44
  ...props
36
45
  }: TabsPrimitive.List.Props & VariantProps<typeof tabsListVariants>) {
46
+ const segmented = variant === 'default' || variant === 'segmented'
37
47
  return (
38
48
  <TabsPrimitive.List
39
49
  data-slot="tabs-list"
40
50
  data-variant={variant}
51
+ data-treatment={segmented ? 'segmented' : 'underline'}
41
52
  className={cn(tabsListVariants({ variant }), className)}
42
53
  {...props}
43
- />
54
+ >
55
+ {children}
56
+ <TabsPrimitive.Indicator
57
+ data-slot="tabs-indicator"
58
+ className={cn(
59
+ 'pointer-events-none absolute left-0 top-0 z-0 w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top) transition-[translate,width,height] duration-(--motion-duration-disclosure) ease-(--motion-ease-standard) motion-reduce:transition-none',
60
+ segmented
61
+ ? 'h-(--active-tab-height) rounded-(--tabs-tab-radius) border-(length:--tabs-indicator-border-width) border-stroke-secondary bg-surface-default shadow-(--tabs-indicator-shadow)'
62
+ : 'h-0.5 bg-fill-primary [translate:var(--active-tab-left)_0] top-auto bottom-0 group-data-[orientation=vertical]/tabs:top-0 group-data-[orientation=vertical]/tabs:bottom-auto group-data-[orientation=vertical]/tabs:left-auto group-data-[orientation=vertical]/tabs:end-0 group-data-[orientation=vertical]/tabs:w-0.5 group-data-[orientation=vertical]/tabs:h-(--active-tab-height) group-data-[orientation=vertical]/tabs:[translate:0_var(--active-tab-top)]',
63
+ )}
64
+ />
65
+ </TabsPrimitive.List>
44
66
  )
45
67
  }
46
68
 
@@ -50,10 +72,8 @@ function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {
50
72
  data-slot="tabs-trigger"
51
73
  className={cn(
52
74
  FOCUS_RING,
53
- "gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-xs font-medium group-data-vertical/tabs:py-[calc(--spacing(1.25))] [&_svg:not([class*='size-'])]:size-3.5 focus-visible:outline-ring text-muted hover:text-foreground relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap transition-[opacity,box-shadow] group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-disabled [&_svg]:pointer-events-none [&_svg]:shrink-0",
54
- 'group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent',
55
- 'data-active:bg-page dark:data-active:text-foreground dark:data-active:border-field dark:data-active:bg-surface-field/30 data-active:text-foreground',
56
- 'after:bg-foreground after:absolute after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100',
75
+ "relative z-10 inline-flex h-(--tabs-tab-height) shrink-0 items-center justify-center gap-1.5 rounded-(--tabs-tab-radius) bg-transparent px-2.5 text-sm font-normal whitespace-nowrap text-default outline-none transition-colors duration-(--motion-duration-color) data-active:font-medium disabled:pointer-events-none disabled:opacity-disabled data-disabled:pointer-events-none data-disabled:opacity-disabled group-data-[orientation=vertical]/tabs:justify-start [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",
76
+ 'group-data-[treatment=underline]/tabs-list:hover:bg-surface-hover',
57
77
  className,
58
78
  )}
59
79
  {...props}
@@ -65,7 +85,7 @@ function TabsContent({ className, ...props }: TabsPrimitive.Panel.Props) {
65
85
  return (
66
86
  <TabsPrimitive.Panel
67
87
  data-slot="tabs-content"
68
- className={cn('text-xs/relaxed flex-1 outline-none', className)}
88
+ className={cn('flex-1 text-xs/relaxed outline-none', className)}
69
89
  {...props}
70
90
  />
71
91
  )