@gaulatti/bleecker 0.1.47 → 0.1.49
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/components/fader.d.ts +59 -0
- package/dist/components/fader.js +140 -0
- package/dist/components/meter.d.ts +3 -1
- package/dist/components/meter.js +6 -2
- package/dist/components/tabs.d.ts +4 -0
- package/dist/components/tabs.js +36 -3
- package/dist/components/toggle-group.js +14 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/styles.css +1 -1
- package/dist/tokens/source.d.ts +54 -0
- package/dist/tokens/source.js +45 -2
- package/package.json +3 -2
- package/src/styles/tokens.generated.css +36 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type MeterProps } from './meter';
|
|
2
|
+
export type FaderUnit = 'db' | 'percent';
|
|
3
|
+
export interface FaderProps {
|
|
4
|
+
className?: string;
|
|
5
|
+
/** The coarse step, for Shift with an arrow and for Page Up / Page Down. Defaults to ten steps. */
|
|
6
|
+
coarseStep?: number;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** What the fader sets, announced with its value ("Music: −6.0 dB"). */
|
|
9
|
+
label: string;
|
|
10
|
+
/** How the readout and the announcement show a value. Defaults to `formatFaderValue`. */
|
|
11
|
+
format?: (value: number) => string;
|
|
12
|
+
/** The track's length along its axis (a CSS length). Defaults to 12rem. */
|
|
13
|
+
length?: string;
|
|
14
|
+
/** Labelled scale marks along the track, in the value's unit, placed through `taper`. */
|
|
15
|
+
marks?: ReadonlyArray<number | FaderMark>;
|
|
16
|
+
max: number;
|
|
17
|
+
/**
|
|
18
|
+
* A level shown beside the fader on a linear `min`–`max` scale. With a `taper` the
|
|
19
|
+
* fader's travel is not linear, so a consumer with a taper keeps its own meter.
|
|
20
|
+
*/
|
|
21
|
+
meter?: Pick<MeterProps, 'hold' | 'peak' | 'value' | 'warnFrom'>;
|
|
22
|
+
min: number;
|
|
23
|
+
onValueChange: (value: number) => void;
|
|
24
|
+
orientation?: 'horizontal' | 'vertical';
|
|
25
|
+
/** The fine step, for an arrow key. Defaults to 0.5 dB or 1 %. */
|
|
26
|
+
step?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Where a value sits along the travel, for a non-linear fader such as a console taper:
|
|
29
|
+
* `toPosition(value)` gives 0 (bottom or left) to 1, and `fromPosition` is its inverse.
|
|
30
|
+
* The track, cap, unity mark, scale marks and pointer follow it; keys still step in the
|
|
31
|
+
* value's unit. Defaults to linear between `min` and `max`, and `min`–`max` must cover the
|
|
32
|
+
* values the taper maps (its floor and its top).
|
|
33
|
+
*/
|
|
34
|
+
taper?: FaderTaper;
|
|
35
|
+
/** The value the fader returns to on double-click or the 0 key; drawn as a mark on the track. */
|
|
36
|
+
unity?: number;
|
|
37
|
+
unit: FaderUnit;
|
|
38
|
+
value: number;
|
|
39
|
+
}
|
|
40
|
+
export interface FaderTaper {
|
|
41
|
+
fromPosition: (position: number) => number;
|
|
42
|
+
toPosition: (value: number) => number;
|
|
43
|
+
}
|
|
44
|
+
export interface FaderMark {
|
|
45
|
+
/** Shown beside the mark; defaults to the value, rounded. */
|
|
46
|
+
label?: string;
|
|
47
|
+
value: number;
|
|
48
|
+
}
|
|
49
|
+
/** The value as read out and announced: "−6.0 dB", "+3.0 dB", "75 %". */
|
|
50
|
+
export declare function formatFaderValue(value: number, unit: FaderUnit): string;
|
|
51
|
+
/**
|
|
52
|
+
* A console fader: sets a level between `min` and `max` and states it. Vertical by default, with a
|
|
53
|
+
* unity mark, a readout in tabular numerals and an optional level meter on the same scale.
|
|
54
|
+
*
|
|
55
|
+
* Keyboard: arrows step by `step`, Shift with an arrow (or Page Up / Page Down) by `coarseStep`,
|
|
56
|
+
* Home and End go to the limits, and 0 returns to `unity`. A double-click also returns to unity.
|
|
57
|
+
* Mute and solo are separate controls.
|
|
58
|
+
*/
|
|
59
|
+
export declare function Fader({ className, coarseStep, disabled, format, label, length, marks, max, meter, min, onValueChange, orientation, step, taper, unity, unit, value }: FaderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { cn } from '../utils/cn.js';
|
|
4
|
+
import { Meter } from './meter.js';
|
|
5
|
+
const DECIMALS = { db: 1, percent: 0 };
|
|
6
|
+
/** The value as read out and announced: "−6.0 dB", "+3.0 dB", "75 %". */
|
|
7
|
+
export function formatFaderValue(value, unit) {
|
|
8
|
+
const fixed = Math.abs(value).toFixed(DECIMALS[unit]);
|
|
9
|
+
if (unit === 'percent')
|
|
10
|
+
return `${value < 0 ? '−' : ''}${fixed} %`;
|
|
11
|
+
const sign = Number(fixed) === 0 ? '' : value < 0 ? '−' : '+';
|
|
12
|
+
return `${sign}${fixed} dB`;
|
|
13
|
+
}
|
|
14
|
+
function clampToStep(value, min, max, step) {
|
|
15
|
+
const clamped = Math.min(max, Math.max(min, value));
|
|
16
|
+
if (!(step > 0))
|
|
17
|
+
return clamped;
|
|
18
|
+
const snapped = min + Math.round((clamped - min) / step) * step;
|
|
19
|
+
// Keep the decimals of the step (0.5 + 0.1 drift) and stay inside the range.
|
|
20
|
+
const digits = (String(step).split('.')[1] ?? '').length;
|
|
21
|
+
return Math.min(max, Math.max(min, Number(snapped.toFixed(digits))));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A console fader: sets a level between `min` and `max` and states it. Vertical by default, with a
|
|
25
|
+
* unity mark, a readout in tabular numerals and an optional level meter on the same scale.
|
|
26
|
+
*
|
|
27
|
+
* Keyboard: arrows step by `step`, Shift with an arrow (or Page Up / Page Down) by `coarseStep`,
|
|
28
|
+
* Home and End go to the limits, and 0 returns to `unity`. A double-click also returns to unity.
|
|
29
|
+
* Mute and solo are separate controls.
|
|
30
|
+
*/
|
|
31
|
+
export function Fader({ className, coarseStep, disabled = false, format, label, length = '12rem', marks, max, meter, min, onValueChange, orientation = 'vertical', step, taper, unity, unit, value }) {
|
|
32
|
+
const fine = step ?? (unit === 'db' ? 0.5 : 1);
|
|
33
|
+
const coarse = coarseStep ?? fine * 10;
|
|
34
|
+
const vertical = orientation === 'vertical';
|
|
35
|
+
const span = max - min;
|
|
36
|
+
const travel = (reading) => (taper ? taper.toPosition(reading) : span > 0 ? (reading - min) / span : 0);
|
|
37
|
+
// Where a value sits along the track, in percent of its length.
|
|
38
|
+
const at = (reading) => {
|
|
39
|
+
const position = travel(reading);
|
|
40
|
+
return Number.isFinite(position) ? Math.max(0, Math.min(100, position * 100)) : 0;
|
|
41
|
+
};
|
|
42
|
+
const current = Math.min(max, Math.max(min, value));
|
|
43
|
+
const unityInRange = unity !== undefined && unity >= min && unity <= max;
|
|
44
|
+
const readout = format ? format(current) : formatFaderValue(current, unit);
|
|
45
|
+
const dragging = React.useRef(false);
|
|
46
|
+
const commit = (next) => {
|
|
47
|
+
// A taper can answer something that is not a number (NaN); a fader never reports one.
|
|
48
|
+
if (!Number.isFinite(next))
|
|
49
|
+
return;
|
|
50
|
+
const settled = clampToStep(next, min, max, fine);
|
|
51
|
+
if (settled !== current)
|
|
52
|
+
onValueChange(settled);
|
|
53
|
+
};
|
|
54
|
+
const valueAt = (track, clientX, clientY) => {
|
|
55
|
+
const box = track.getBoundingClientRect();
|
|
56
|
+
const fraction = vertical
|
|
57
|
+
? box.height > 0 ? (box.bottom - clientY) / box.height : 0
|
|
58
|
+
: box.width > 0 ? (clientX - box.left) / box.width : 0;
|
|
59
|
+
const position = Math.max(0, Math.min(1, fraction));
|
|
60
|
+
return taper ? taper.fromPosition(position) : min + position * span;
|
|
61
|
+
};
|
|
62
|
+
const onKeyDown = (event) => {
|
|
63
|
+
if (disabled)
|
|
64
|
+
return;
|
|
65
|
+
const amount = event.shiftKey ? coarse : fine;
|
|
66
|
+
// From a value between steps, the first press of any step key (fine or coarse) goes to the
|
|
67
|
+
// nearest fine step in that direction.
|
|
68
|
+
const onGrid = clampToStep(current, min, max, fine);
|
|
69
|
+
const up = (by) => (onGrid > current ? onGrid : onGrid + by);
|
|
70
|
+
const down = (by) => (onGrid < current ? onGrid : onGrid - by);
|
|
71
|
+
let next = null;
|
|
72
|
+
switch (event.key) {
|
|
73
|
+
case 'ArrowUp':
|
|
74
|
+
case 'ArrowRight':
|
|
75
|
+
next = up(amount);
|
|
76
|
+
break;
|
|
77
|
+
case 'ArrowDown':
|
|
78
|
+
case 'ArrowLeft':
|
|
79
|
+
next = down(amount);
|
|
80
|
+
break;
|
|
81
|
+
case 'PageUp':
|
|
82
|
+
next = up(coarse);
|
|
83
|
+
break;
|
|
84
|
+
case 'PageDown':
|
|
85
|
+
next = down(coarse);
|
|
86
|
+
break;
|
|
87
|
+
case 'Home':
|
|
88
|
+
next = min;
|
|
89
|
+
break;
|
|
90
|
+
case 'End':
|
|
91
|
+
next = max;
|
|
92
|
+
break;
|
|
93
|
+
case '0':
|
|
94
|
+
if (unityInRange)
|
|
95
|
+
next = unity;
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
if (next !== null)
|
|
102
|
+
commit(next);
|
|
103
|
+
};
|
|
104
|
+
const onPointerDown = (event) => {
|
|
105
|
+
if (disabled || event.button !== 0)
|
|
106
|
+
return;
|
|
107
|
+
event.currentTarget.focus();
|
|
108
|
+
dragging.current = true;
|
|
109
|
+
try {
|
|
110
|
+
// Keeps the drag when the pointer leaves the track; a pointer the browser
|
|
111
|
+
// does not know (a synthetic one) cannot be captured, and the drag still works on the track.
|
|
112
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Not capturable: the drag follows the track only.
|
|
116
|
+
}
|
|
117
|
+
commit(valueAt(event.currentTarget, event.clientX, event.clientY));
|
|
118
|
+
};
|
|
119
|
+
const onPointerMove = (event) => {
|
|
120
|
+
if (disabled || !dragging.current)
|
|
121
|
+
return;
|
|
122
|
+
commit(valueAt(event.currentTarget, event.clientX, event.clientY));
|
|
123
|
+
};
|
|
124
|
+
const endDrag = () => {
|
|
125
|
+
dragging.current = false;
|
|
126
|
+
};
|
|
127
|
+
const position = at(current);
|
|
128
|
+
const cap = vertical ? { bottom: `calc(${position}% - 0.5rem)` } : { left: `calc(${position}% - 0.5rem)` };
|
|
129
|
+
const fill = vertical ? { height: `${position}%` } : { width: `${position}%` };
|
|
130
|
+
return (_jsxs("div", { "data-fader": orientation, className: cn('inline-flex gap-2 text-text-primary', vertical ? 'flex-col items-center' : 'flex-row items-center', disabled && 'opacity-50', className), children: [_jsx("span", { className: 'text-xs font-medium text-text-secondary dark:text-text-primary', children: label }), _jsxs("div", { className: cn('flex gap-2', vertical ? 'flex-row items-stretch' : 'flex-col',
|
|
131
|
+
// Room for the scale labels, which sit beside or below the track.
|
|
132
|
+
marks?.length ? (vertical ? 'pl-8' : 'pb-5') : undefined), style: vertical ? { height: length } : { width: length }, children: [_jsxs("div", { role: 'slider', tabIndex: disabled ? -1 : 0, "aria-label": label, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": current, "aria-valuetext": readout, "aria-orientation": orientation, "aria-disabled": disabled || undefined, onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: endDrag, onPointerCancel: endDrag, onLostPointerCapture: endDrag, style: vertical ? { height: length } : { width: length }, onDoubleClick: () => {
|
|
133
|
+
if (!disabled && unityInRange)
|
|
134
|
+
commit(unity);
|
|
135
|
+
}, className: cn('relative shrink-0 touch-none select-none rounded-[var(--radius-ui)] bg-text-primary/15', 'focus:outline-none focus-visible:ring-2 focus-visible:ring-sea focus-visible:ring-offset-2 dark:focus-visible:ring-accent-blue', vertical ? 'w-3' : 'h-3', disabled ? 'cursor-not-allowed' : vertical ? 'cursor-ns-resize' : 'cursor-ew-resize'), children: [_jsx("span", { "data-fader": 'fill', className: cn('absolute rounded-[inherit] bg-sea dark:bg-accent-blue', vertical ? 'inset-x-0 bottom-0' : 'inset-y-0 left-0'), style: fill }), unityInRange ? (_jsx("span", { "data-fader": 'unity', "aria-hidden": 'true', className: cn('absolute bg-text-primary/70', vertical ? '-inset-x-1 h-px' : '-inset-y-1 w-px'), style: vertical ? { bottom: `${at(unity)}%` } : { left: `${at(unity)}%` } })) : null, (marks ?? []).map((mark, index) => {
|
|
136
|
+
const { value: markValue, label: markLabel } = typeof mark === 'number' ? { value: mark, label: undefined } : mark;
|
|
137
|
+
const placed = at(markValue);
|
|
138
|
+
return (_jsx("span", { "data-fader": 'mark', "aria-hidden": 'true', className: cn('absolute whitespace-nowrap font-mono text-xs tabular-nums text-text-secondary dark:text-text-primary', vertical ? 'right-full mr-2 translate-y-1/2' : 'top-full mt-2 -translate-x-1/2'), style: vertical ? { bottom: `${placed}%` } : { left: `${placed}%` }, children: markLabel ?? String(Math.round(markValue)) }, `${index}:${markValue}`));
|
|
139
|
+
}), _jsx("span", { "data-fader": 'cap', "aria-hidden": 'true', className: cn('absolute rounded-sm border border-text-primary/40 bg-white shadow-sm transition-shadow duration-[var(--motion-control)] ease-premium dark:bg-dark-sand', vertical ? '-inset-x-1.5 h-4' : '-inset-y-1.5 w-4'), style: cap })] }), meter ? (_jsx(Meter, { label: `${label} level`, min: min, max: max, unit: unit === 'db' ? 'dB' : '%', orientation: orientation, value: meter.value, peak: meter.peak, hold: meter.hold, warnFrom: meter.warnFrom })) : null] }), _jsx("output", { "aria-hidden": 'true', className: 'font-mono text-xs tabular-nums text-text-secondary dark:text-text-primary', children: readout })] }));
|
|
140
|
+
}
|
|
@@ -5,6 +5,8 @@ export interface MeterProps {
|
|
|
5
5
|
label: string;
|
|
6
6
|
max: number;
|
|
7
7
|
min: number;
|
|
8
|
+
/** Horizontal by default. Vertical fills from the bottom, for a meter beside a vertical fader. */
|
|
9
|
+
orientation?: 'horizontal' | 'vertical';
|
|
8
10
|
/** The live peak, in the same scale as `value`. */
|
|
9
11
|
peak?: number | null;
|
|
10
12
|
unit?: string;
|
|
@@ -16,4 +18,4 @@ export interface MeterProps {
|
|
|
16
18
|
* A reading and its scale: a level between `min` and `max` with an optional live peak, a held peak
|
|
17
19
|
* and a warning zone. It does not animate; the page feeds it new values.
|
|
18
20
|
*/
|
|
19
|
-
export declare function Meter({ className, hold, label, max, min, peak, unit, value, warnFrom }: MeterProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function Meter({ className, hold, label, max, min, orientation, peak, unit, value, warnFrom }: MeterProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/components/meter.js
CHANGED
|
@@ -4,8 +4,12 @@ import { cn } from '../utils/cn.js';
|
|
|
4
4
|
* A reading and its scale: a level between `min` and `max` with an optional live peak, a held peak
|
|
5
5
|
* and a warning zone. It does not animate; the page feeds it new values.
|
|
6
6
|
*/
|
|
7
|
-
export function Meter({ className, hold, label, max, min, peak, unit, value, warnFrom }) {
|
|
7
|
+
export function Meter({ className, hold, label, max, min, orientation = 'horizontal', peak, unit, value, warnFrom }) {
|
|
8
8
|
const span = max - min;
|
|
9
9
|
const at = (reading) => (span > 0 ? Math.max(0, Math.min(100, ((reading - min) / span) * 100)) : 0);
|
|
10
|
-
|
|
10
|
+
const vertical = orientation === 'vertical';
|
|
11
|
+
// Along the meter's axis: from the left, or from the bottom when vertical.
|
|
12
|
+
const from = (percent) => (vertical ? { bottom: `${percent}%` } : { left: `${percent}%` });
|
|
13
|
+
const mark = (percent) => (vertical ? { bottom: `calc(${percent}% - 1px)` } : { left: `calc(${percent}% - 1px)` });
|
|
14
|
+
return (_jsxs("div", { role: 'meter', "aria-label": label, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": value ?? min, "aria-valuetext": value === null ? 'No level' : `${value.toFixed(1)}${unit ? ` ${unit}` : ''}`, "data-orientation": vertical ? 'vertical' : undefined, className: cn('relative overflow-hidden rounded-full bg-sand/30 dark:bg-sand/25', vertical ? 'h-full w-1.5' : 'h-1.5', className), children: [warnFrom !== undefined ? (_jsx("span", { "data-meter": 'warn', className: cn('absolute bg-terracotta/35', vertical ? 'inset-x-0 top-0' : 'inset-y-0 right-0'), style: from(at(warnFrom)) })) : null, value !== null ? (_jsx("span", { "data-meter": 'fill', className: cn('absolute bg-sea dark:bg-accent-blue', vertical ? 'inset-x-0 bottom-0' : 'inset-y-0 left-0'), style: vertical ? { height: `${at(value)}%` } : { width: `${at(value)}%` } })) : null, peak !== undefined && peak !== null ? (_jsx("span", { "data-meter": 'peak', className: cn('absolute bg-text-primary/80', vertical ? 'inset-x-0 h-0.5' : 'inset-y-0 w-0.5'), style: mark(at(peak)) })) : null, hold !== undefined && hold !== null ? (_jsx("span", { "data-meter": 'hold', className: cn('absolute', vertical ? 'inset-x-0 h-0.5' : 'inset-y-0 w-0.5', warnFrom !== undefined && hold >= warnFrom ? 'bg-terracotta' : 'bg-accent-text dark:bg-accent-yellow'), style: mark(at(hold)) })) : null] }));
|
|
11
15
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface TabItem {
|
|
3
|
+
/** How many items the tab holds, shown as a quiet pill after the label; `null` or omitted hides it. */
|
|
4
|
+
count?: number | null;
|
|
5
|
+
/** Shows a short skeleton where the count will be, so it does not jump from blank. */
|
|
6
|
+
countLoading?: boolean;
|
|
3
7
|
id: string;
|
|
4
8
|
label: string;
|
|
5
9
|
href?: string;
|
package/dist/components/tabs.js
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { renderDefaultLink } from './nav-menu.js';
|
|
4
|
+
import { Skeleton } from './skeleton.js';
|
|
4
5
|
import { cn } from '../utils/cn.js';
|
|
6
|
+
/** 999 and below as is, then 1.2k, 12k, 1.2M: the pill stays narrow. The full value goes in the accessible name. */
|
|
7
|
+
function abbreviateCount(count) {
|
|
8
|
+
const trim = (value) => value.toFixed(1).replace(/\.0$/, '');
|
|
9
|
+
if (count < 1000)
|
|
10
|
+
return String(count);
|
|
11
|
+
if (count < 10_000)
|
|
12
|
+
return `${trim(Math.floor(count / 100) / 10)}k`;
|
|
13
|
+
if (count < 1_000_000)
|
|
14
|
+
return `${Math.floor(count / 1000)}k`;
|
|
15
|
+
if (count < 10_000_000)
|
|
16
|
+
return `${trim(Math.floor(count / 100_000) / 10)}M`;
|
|
17
|
+
return `${Math.floor(count / 1_000_000)}M`;
|
|
18
|
+
}
|
|
19
|
+
/** The button's name when it carries a count: the full value, or that the count is still loading. */
|
|
20
|
+
function tabAccessibleName(tab) {
|
|
21
|
+
if (tab.countLoading)
|
|
22
|
+
return `${tab.label}, loading count`;
|
|
23
|
+
if (typeof tab.count === 'number' && Number.isFinite(tab.count)) {
|
|
24
|
+
return `${tab.label}, ${tab.count.toLocaleString('en-US')} ${tab.count === 1 ? 'item' : 'items'}`;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function TabLabel({ tab, isActive }) {
|
|
29
|
+
const hasCount = typeof tab.count === 'number' && Number.isFinite(tab.count);
|
|
30
|
+
if (tab.countLoading) {
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { children: [tab.label, _jsx("span", { className: 'sr-only', children: ", loading count" })] }), _jsx(Skeleton, { "aria-hidden": 'true', "data-tab-count-loading": true, className: 'ml-2 h-4 w-6 rounded-full' })] }));
|
|
32
|
+
}
|
|
33
|
+
if (!hasCount)
|
|
34
|
+
return _jsx(_Fragment, { children: tab.label });
|
|
35
|
+
const count = tab.count;
|
|
36
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { children: [tab.label, _jsx("span", { className: 'sr-only', children: `, ${count.toLocaleString('en-US')} ${count === 1 ? 'item' : 'items'}` })] }), _jsx("span", { "aria-hidden": 'true', "data-tab-count": true, className: cn('ml-2 inline-flex min-w-5 items-center justify-center rounded-full px-1.5 text-xs font-medium tabular-nums', isActive ? 'bg-current/10' : 'bg-sand/25 text-text-secondary dark:bg-white/10 dark:text-text-secondary'), children: abbreviateCount(count) })] }));
|
|
37
|
+
}
|
|
5
38
|
export function Tabs({ activeTab, 'aria-label': ariaLabel = 'Tabs', className, onChange, renderLink, size = 'md', stretch = false, tabs, variant = 'underline' }) {
|
|
6
39
|
const isNavigation = tabs.some((tab) => Boolean(tab.href));
|
|
7
40
|
const handleKeyDown = (event, index) => {
|
|
@@ -36,9 +69,9 @@ export function Tabs({ activeTab, 'aria-label': ariaLabel = 'Tabs', className, o
|
|
|
36
69
|
return (_jsx(React.Fragment, { children: linkRenderer({
|
|
37
70
|
item: { ...tab, href: tab.href },
|
|
38
71
|
className: tabClassName,
|
|
39
|
-
children: tab
|
|
72
|
+
children: _jsx(TabLabel, { tab: tab, isActive: isActive })
|
|
40
73
|
}) }, tab.id));
|
|
41
74
|
}
|
|
42
|
-
return (_jsx("button", { type: 'button', role: 'tab', "aria-selected": isActive, "aria-controls": tab.panelId, tabIndex: isActive ? 0 : -1, onClick: () => onChange?.(tab.id), onKeyDown: (event) => handleKeyDown(event, index), className: tabClassName, children: tab
|
|
75
|
+
return (_jsx("button", { type: 'button', role: 'tab', "aria-selected": isActive, "aria-controls": tab.panelId, "aria-label": tabAccessibleName(tab), tabIndex: isActive ? 0 : -1, onClick: () => onChange?.(tab.id), onKeyDown: (event) => handleKeyDown(event, index), className: tabClassName, children: _jsx(TabLabel, { tab: tab, isActive: isActive }) }, tab.id));
|
|
43
76
|
}) }));
|
|
44
77
|
}
|
|
@@ -23,11 +23,23 @@ export function ToggleGroup({ children, className, disabled, size, type, variant
|
|
|
23
23
|
onValueChange?.(arr.includes(itemValue) ? arr.filter((v) => v !== itemValue) : [...arr, itemValue]);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
return (_jsx(ToggleGroupContext.Provider, { value: { type, value: currentValue, onValueChange: handleChange, size, variant, disabled }, children: _jsx("div", { role: 'group',
|
|
26
|
+
return (_jsx(ToggleGroupContext.Provider, { value: { type, value: currentValue, onValueChange: handleChange, size, variant, disabled }, children: _jsx("div", { role: 'group', "data-variant": variant ?? 'default', className: cn(variant === 'outline'
|
|
27
|
+
? // A segmented control (gaulatti/bleecker#557): the group owns the one rounded outline, and
|
|
28
|
+
// each segment after the first draws the single divider on its left (see the item), so
|
|
29
|
+
// hover, focus and selection change nothing but colour and nothing shifts.
|
|
30
|
+
'inline-flex items-stretch overflow-hidden rounded-[9px] border border-sand/30 dark:border-sand/40'
|
|
31
|
+
: 'inline-flex items-center gap-0.5 rounded-[9px] border border-sand/20 bg-light-sand/65 p-1 dark:border-white/[0.07] dark:bg-white/[0.05]', className), children: children }) }));
|
|
27
32
|
}
|
|
28
33
|
export function ToggleGroupItem({ children, className, disabled, size, value, variant, ...props }) {
|
|
29
34
|
const ctx = useToggleGroup();
|
|
30
35
|
const pressed = ctx.type === 'single' ? ctx.value === value : ctx.value.includes(value);
|
|
31
36
|
const isDisabled = disabled ?? ctx.disabled;
|
|
32
|
-
return (_jsx(Toggle, { pressed: pressed, onPressedChange: () => ctx.onValueChange(value), disabled: isDisabled, size: size ?? ctx.size, variant: variant ?? ctx.variant, className: cn(
|
|
37
|
+
return (_jsx(Toggle, { pressed: pressed, onPressedChange: () => ctx.onValueChange(value), disabled: isDisabled, size: size ?? ctx.size, variant: variant ?? ctx.variant, className: cn((variant ?? ctx.variant) === 'outline'
|
|
38
|
+
? // Inside an outline group a segment is square and draws no outline of its own; each segment
|
|
39
|
+
// after the first draws the one divider on its left, in the group's colour in every state
|
|
40
|
+
// (a pressed segment's colour never reaches it). The group's overflow and radius round the
|
|
41
|
+
// first and last, and the focus ring is drawn inside so it isn't clipped. Tailwind's
|
|
42
|
+
// divide-x on the group can't do this: its selector has zero specificity, so border-0 wins.
|
|
43
|
+
'rounded-none border-0 not-first:border-l not-first:border-sand/30 dark:not-first:border-sand/40 focus-visible:ring-inset'
|
|
44
|
+
: 'rounded-lg', className), ...props, children: children }));
|
|
33
45
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export * from './assets/logo';
|
|
|
98
98
|
export * from './components/panel';
|
|
99
99
|
export * from './components/arm-take';
|
|
100
100
|
export * from './components/meter';
|
|
101
|
+
export * from './components/fader';
|
|
101
102
|
export * from './components/on-air-strip';
|
|
102
103
|
export * from './components/segmented-filter';
|
|
103
104
|
export * from './components/transport';
|
package/dist/index.js
CHANGED
|
@@ -98,6 +98,7 @@ export * from './assets/logo.js';
|
|
|
98
98
|
export * from './components/panel.js';
|
|
99
99
|
export * from './components/arm-take.js';
|
|
100
100
|
export * from './components/meter.js';
|
|
101
|
+
export * from './components/fader.js';
|
|
101
102
|
export * from './components/on-air-strip.js';
|
|
102
103
|
export * from './components/segmented-filter.js';
|
|
103
104
|
export * from './components/transport.js';
|