@mgamadeus/ddd-admin-ui 0.1.0-rc.2 → 0.1.0-rc.4
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/.claude/skills/ddd-admin-ui-specialist/SKILL.md +20 -2
- package/CHANGELOG.md +67 -1
- package/README.md +42 -6
- package/STANDARDS.md +132 -58
- package/dist/components.css +63 -3
- package/dist/i18n/hints.json +2 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/store.d.ts +10 -2
- package/dist/i18n/store.d.ts.map +1 -1
- package/dist/i18n/store.js +6 -2
- package/dist/i18n/store.js.map +1 -1
- package/dist/i18n-keys.json +9 -1
- package/dist/list/EntityListBody.d.ts +10 -3
- package/dist/list/EntityListBody.d.ts.map +1 -1
- package/dist/list/EntityListBody.js +9 -3
- package/dist/list/EntityListBody.js.map +1 -1
- package/dist/list/EntityListTable.d.ts +42 -2
- package/dist/list/EntityListTable.d.ts.map +1 -1
- package/dist/list/EntityListTable.js +158 -6
- package/dist/list/EntityListTable.js.map +1 -1
- package/dist/list/StatusBadge.d.ts +1 -1
- package/dist/list/StatusBadge.d.ts.map +1 -1
- package/dist/list/StatusBadge.js +3 -2
- package/dist/list/StatusBadge.js.map +1 -1
- package/dist/logic/index.d.ts +5 -1
- package/dist/logic/index.d.ts.map +1 -1
- package/dist/logic/index.js +2 -0
- package/dist/logic/index.js.map +1 -1
- package/dist/logic/pure/listSort.d.ts +29 -0
- package/dist/logic/pure/listSort.d.ts.map +1 -0
- package/dist/logic/pure/listSort.js +35 -0
- package/dist/logic/pure/listSort.js.map +1 -0
- package/dist/logic/pure/listTracks.d.ts +90 -0
- package/dist/logic/pure/listTracks.d.ts.map +1 -0
- package/dist/logic/pure/listTracks.js +139 -0
- package/dist/logic/pure/listTracks.js.map +1 -0
- package/dist/logic/pure/status.d.ts +23 -2
- package/dist/logic/pure/status.d.ts.map +1 -1
- package/dist/logic/pure/status.js +23 -2
- package/dist/logic/pure/status.js.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/segmented-control.d.ts +57 -0
- package/dist/primitives/segmented-control.d.ts.map +1 -0
- package/dist/primitives/segmented-control.js +206 -0
- package/dist/primitives/segmented-control.js.map +1 -0
- package/dist/primitives/segmentedControlNavigation.d.ts +31 -0
- package/dist/primitives/segmentedControlNavigation.d.ts.map +1 -0
- package/dist/primitives/segmentedControlNavigation.js +65 -0
- package/dist/primitives/segmentedControlNavigation.js.map +1 -0
- package/dist/scripts/build-i18n-manifest.mjs +9 -3
- package/dist/showcase/Showcase.d.ts +35 -0
- package/dist/showcase/Showcase.d.ts.map +1 -0
- package/dist/showcase/Showcase.js +47 -0
- package/dist/showcase/Showcase.js.map +1 -0
- package/dist/showcase/coverage.d.ts +11 -0
- package/dist/showcase/coverage.d.ts.map +1 -0
- package/dist/showcase/coverage.js +77 -0
- package/dist/showcase/coverage.js.map +1 -0
- package/dist/showcase/index.d.ts +6 -0
- package/dist/showcase/index.d.ts.map +1 -0
- package/dist/showcase/index.js +5 -0
- package/dist/showcase/index.js.map +1 -0
- package/dist/showcase/sections/FormShowcase.d.ts +3 -0
- package/dist/showcase/sections/FormShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/FormShowcase.js +26 -0
- package/dist/showcase/sections/FormShowcase.js.map +1 -0
- package/dist/showcase/sections/GlassShowcase.d.ts +3 -0
- package/dist/showcase/sections/GlassShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/GlassShowcase.js +19 -0
- package/dist/showcase/sections/GlassShowcase.js.map +1 -0
- package/dist/showcase/sections/ListShowcase.d.ts +13 -0
- package/dist/showcase/sections/ListShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/ListShowcase.js +67 -0
- package/dist/showcase/sections/ListShowcase.js.map +1 -0
- package/dist/showcase/sections/MediaShowcase.d.ts +3 -0
- package/dist/showcase/sections/MediaShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/MediaShowcase.js +28 -0
- package/dist/showcase/sections/MediaShowcase.js.map +1 -0
- package/dist/showcase/sections/OptionalShowcase.d.ts +14 -0
- package/dist/showcase/sections/OptionalShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/OptionalShowcase.js +32 -0
- package/dist/showcase/sections/OptionalShowcase.js.map +1 -0
- package/dist/showcase/sections/PageShowcase.d.ts +3 -0
- package/dist/showcase/sections/PageShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/PageShowcase.js +37 -0
- package/dist/showcase/sections/PageShowcase.js.map +1 -0
- package/dist/showcase/sections/PrimitivesShowcase.d.ts +13 -0
- package/dist/showcase/sections/PrimitivesShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/PrimitivesShowcase.js +40 -0
- package/dist/showcase/sections/PrimitivesShowcase.js.map +1 -0
- package/dist/showcase/sections/TranslationsShowcase.d.ts +3 -0
- package/dist/showcase/sections/TranslationsShowcase.d.ts.map +1 -0
- package/dist/showcase/sections/TranslationsShowcase.js +30 -0
- package/dist/showcase/sections/TranslationsShowcase.js.map +1 -0
- package/dist/tokens.json +37 -1
- package/package.json +7 -6
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/** One choice of a `SegmentedControl`. Texts are English UI texts (keys), translated by the control. */
|
|
3
|
+
export interface SegmentedControlOption<TValue extends string = string> {
|
|
4
|
+
value: TValue;
|
|
5
|
+
/** The option's name; with `iconOnly` the accessible name and the tooltip. */
|
|
6
|
+
label: string;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
/** A small count or marker after the label; decorative (`aria-hidden`), so say it in `description` when it matters. */
|
|
9
|
+
badge?: ReactNode;
|
|
10
|
+
/** Announced after the label (`aria-describedby`); not shown. */
|
|
11
|
+
description?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Why the option is disabled: announced and shown as the option's tooltip. */
|
|
14
|
+
disabledReason?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SegmentedControlProps<TValue extends string = string> {
|
|
18
|
+
/** The selected option's value; exactly one option is selected, so it must be one of `options`. */
|
|
19
|
+
value: TValue;
|
|
20
|
+
/** Called once per change: on a click, on an arrow key (automatic activation), on Space / Enter, on drag release. */
|
|
21
|
+
onValueChange: (value: TValue) => void;
|
|
22
|
+
options: readonly SegmentedControlOption<TValue>[];
|
|
23
|
+
/** Accessible name of the group (required: the options alone do not say what is chosen). */
|
|
24
|
+
'aria-label': string;
|
|
25
|
+
/** Control height in px (default 32). Touch targets are at least 44 px on a coarse pointer whatever the height. */
|
|
26
|
+
height?: 32 | 36 | 40 | 48;
|
|
27
|
+
/** Icons only; the label stays the accessible name and shows as a tooltip. */
|
|
28
|
+
iconOnly?: boolean;
|
|
29
|
+
/** Stretch over the container's width, options sharing it equally. */
|
|
30
|
+
fullWidth?: boolean;
|
|
31
|
+
/** The selected option's look: the raised card surface (default) or the primary colour. */
|
|
32
|
+
selection?: 'surface' | 'primary';
|
|
33
|
+
/** `onBrand` on a brand-coloured background. */
|
|
34
|
+
tone?: 'default' | 'onBrand';
|
|
35
|
+
/**
|
|
36
|
+
* `automatic` (default): arrow keys, Home and End move and select. `manual`: they move the focus only, Space or Enter
|
|
37
|
+
* selects (an expensive change, e.g. one that loads data).
|
|
38
|
+
*/
|
|
39
|
+
activation?: 'automatic' | 'manual';
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* One value out of a few, side by side (view modes, a period, a scope). A radio group: `role="radiogroup"`, options
|
|
44
|
+
* `role="radio"` with `aria-checked`, one tab stop (the selected option), arrows / Home / End move (selecting at once
|
|
45
|
+
* or, with `activation="manual"`, on Space / Enter), right-to-left aware, disabled options skipped and their reason
|
|
46
|
+
* announced. Not tabs (no panels) and not a toggle group (always exactly one selected).
|
|
47
|
+
*
|
|
48
|
+
* The selected option sits on a sliding indicator, measured after layout (the server render and the hydration render
|
|
49
|
+
* mark the selected option directly). Pressing and dragging across the options moves the indicator as a preview; the
|
|
50
|
+
* value changes once, on release; Escape or a cancelled pointer restores it. A touch drag starts only after a sideways
|
|
51
|
+
* movement, so a vertical swipe keeps scrolling the page.
|
|
52
|
+
*
|
|
53
|
+
* Tooltips (an `iconOnly` option's label, a disabled option's reason) need the tooltip provider of `AdminUiProvider`.
|
|
54
|
+
* Duration and corner come from `--segmented-control-duration` and `--segmented-control-radius`.
|
|
55
|
+
*/
|
|
56
|
+
export declare const SegmentedControl: <TValue extends string = string>({ value, onValueChange, options, "aria-label": ariaLabel, height, iconOnly, fullWidth, selection, tone, activation, className, }: SegmentedControlProps<TValue>) => import("react").JSX.Element;
|
|
57
|
+
//# sourceMappingURL=segmented-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.d.ts","sourceRoot":"","sources":["../../src/primitives/segmented-control.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,SAAS,EAOf,MAAM,OAAO,CAAC;AAYf,wGAAwG;AACxG,MAAM,WAAW,sBAAsB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,uHAAuH;IACvH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACnE,mGAAmG;IACnG,KAAK,EAAE,MAAM,CAAC;IACd,qHAAqH;IACrH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,OAAO,EAAE,SAAS,sBAAsB,CAAC,MAAM,CAAC,EAAE,CAAC;IACnD,4FAA4F;IAC5F,YAAY,EAAE,MAAM,CAAC;IACrB,mHAAmH;IACnH,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAClC,gDAAgD;IAChD,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgCD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,kIAY9D,qBAAqB,CAAC,MAAM,CAAC,gCA+Q/B,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment, useCallback, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
4
|
+
import { useTranslate } from "../i18n/index.js";
|
|
5
|
+
import { cn } from "./cn.js";
|
|
6
|
+
import { isSegmentedKey, segmentedDragDecision, segmentedIndexAtPoint, segmentedIndexForKey, } from "./segmentedControlNavigation.js";
|
|
7
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
|
|
8
|
+
const HEIGHT_CLASS = { 32: 'h-8 text-[13px]', 36: 'h-9 text-[13px]', 40: 'h-10 text-sm', 48: 'h-12 text-sm' };
|
|
9
|
+
const ICON_ONLY_WIDTH_CLASS = { 32: 'w-7', 36: 'w-8', 40: 'w-9', 48: 'w-11' };
|
|
10
|
+
const TRACK_CLASS = { default: 'bg-tint text-muted-foreground', onBrand: 'bg-brand-ink/25 text-brand-light' };
|
|
11
|
+
const INDICATOR_CLASS = {
|
|
12
|
+
surface: { default: 'bg-segment-active shadow-[var(--surface-shadow)]', onBrand: 'bg-brand-light' },
|
|
13
|
+
primary: { default: 'bg-primary', onBrand: 'bg-primary' },
|
|
14
|
+
};
|
|
15
|
+
const HIGHLIGHT_TEXT_CLASS = {
|
|
16
|
+
surface: { default: 'text-foreground', onBrand: 'text-brand-ink' },
|
|
17
|
+
primary: { default: 'text-primary-foreground', onBrand: 'text-primary-foreground' },
|
|
18
|
+
};
|
|
19
|
+
const HOVER_TEXT_CLASS = { default: 'hover:text-foreground', onBrand: 'hover:text-primary-foreground' };
|
|
20
|
+
/**
|
|
21
|
+
* Coarse pointers: an invisible hit area of at least 44 × 44 px around each option, so a 32 px control stays easy to
|
|
22
|
+
* hit on a phone without changing its look.
|
|
23
|
+
*/
|
|
24
|
+
const COARSE_TARGET_CLASS = "pointer-coarse:before:absolute pointer-coarse:before:inset-x-[min(0px,calc((100%_-_44px)/2))] pointer-coarse:before:inset-y-[min(0px,calc((100%_-_44px)/2))] pointer-coarse:before:content-['']";
|
|
25
|
+
/**
|
|
26
|
+
* One value out of a few, side by side (view modes, a period, a scope). A radio group: `role="radiogroup"`, options
|
|
27
|
+
* `role="radio"` with `aria-checked`, one tab stop (the selected option), arrows / Home / End move (selecting at once
|
|
28
|
+
* or, with `activation="manual"`, on Space / Enter), right-to-left aware, disabled options skipped and their reason
|
|
29
|
+
* announced. Not tabs (no panels) and not a toggle group (always exactly one selected).
|
|
30
|
+
*
|
|
31
|
+
* The selected option sits on a sliding indicator, measured after layout (the server render and the hydration render
|
|
32
|
+
* mark the selected option directly). Pressing and dragging across the options moves the indicator as a preview; the
|
|
33
|
+
* value changes once, on release; Escape or a cancelled pointer restores it. A touch drag starts only after a sideways
|
|
34
|
+
* movement, so a vertical swipe keeps scrolling the page.
|
|
35
|
+
*
|
|
36
|
+
* Tooltips (an `iconOnly` option's label, a disabled option's reason) need the tooltip provider of `AdminUiProvider`.
|
|
37
|
+
* Duration and corner come from `--segmented-control-duration` and `--segmented-control-radius`.
|
|
38
|
+
*/
|
|
39
|
+
export const SegmentedControl = ({ value, onValueChange, options, 'aria-label': ariaLabel, height = 32, iconOnly = false, fullWidth = false, selection = 'surface', tone = 'default', activation = 'automatic', className, }) => {
|
|
40
|
+
const { t } = useTranslate();
|
|
41
|
+
const baseId = useId();
|
|
42
|
+
const groupRef = useRef(null);
|
|
43
|
+
const optionRefs = useRef([]);
|
|
44
|
+
const [preview, setPreview] = useState(null);
|
|
45
|
+
const [indicator, setIndicator] = useState(null);
|
|
46
|
+
const drag = useRef(null);
|
|
47
|
+
const suppressClick = useRef(false);
|
|
48
|
+
const disabled = options.map(option => option.disabled === true);
|
|
49
|
+
const selectedIndex = options.findIndex(option => option.value === value);
|
|
50
|
+
const tabStop = selectedIndex !== -1 ? selectedIndex : disabled.indexOf(false);
|
|
51
|
+
const target = preview ?? value;
|
|
52
|
+
const targetIndex = options.findIndex(option => option.value === target);
|
|
53
|
+
const layoutKey = `${options.map(option => option.value).join('|')}:${height}:${iconOnly}:${fullWidth}`;
|
|
54
|
+
// After layout only: place the indicator under the selected (or previewed) option, again on every resize.
|
|
55
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: layoutKey re-measures when the options' boxes may change
|
|
56
|
+
useLayoutEffect(() => {
|
|
57
|
+
const group = groupRef.current;
|
|
58
|
+
if (!group)
|
|
59
|
+
return;
|
|
60
|
+
const place = () => {
|
|
61
|
+
const option = optionRefs.current[targetIndex];
|
|
62
|
+
if (!option || option.offsetWidth === 0) {
|
|
63
|
+
setIndicator(previous => (previous === null ? previous : null));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const next = { left: option.offsetLeft, width: option.offsetWidth };
|
|
67
|
+
setIndicator(previous => (previous && previous.left === next.left && previous.width === next.width ? previous : next));
|
|
68
|
+
};
|
|
69
|
+
place();
|
|
70
|
+
if (typeof ResizeObserver === 'undefined')
|
|
71
|
+
return;
|
|
72
|
+
const observer = new ResizeObserver(place);
|
|
73
|
+
observer.observe(group);
|
|
74
|
+
return () => observer.disconnect();
|
|
75
|
+
}, [targetIndex, layoutKey]);
|
|
76
|
+
const select = useCallback((index) => {
|
|
77
|
+
const option = options[index];
|
|
78
|
+
if (!option || option.disabled || option.value === value)
|
|
79
|
+
return;
|
|
80
|
+
onValueChange(option.value);
|
|
81
|
+
}, [options, value, onValueChange]);
|
|
82
|
+
const endDrag = useCallback(() => {
|
|
83
|
+
const group = groupRef.current;
|
|
84
|
+
const state = drag.current;
|
|
85
|
+
if (group && state && group.hasPointerCapture?.(state.pointerId))
|
|
86
|
+
group.releasePointerCapture(state.pointerId);
|
|
87
|
+
drag.current = null;
|
|
88
|
+
setPreview(null);
|
|
89
|
+
}, []);
|
|
90
|
+
// Escape during a drag restores the value; the release that follows changes nothing.
|
|
91
|
+
const isDragging = preview !== null;
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!isDragging)
|
|
94
|
+
return;
|
|
95
|
+
const onKeyDown = (event) => {
|
|
96
|
+
if (event.key !== 'Escape' || !drag.current)
|
|
97
|
+
return;
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
drag.current.cancelled = true;
|
|
100
|
+
setPreview(null);
|
|
101
|
+
};
|
|
102
|
+
window.addEventListener('keydown', onKeyDown, true);
|
|
103
|
+
return () => window.removeEventListener('keydown', onKeyDown, true);
|
|
104
|
+
}, [isDragging]);
|
|
105
|
+
const onKeyDown = (event) => {
|
|
106
|
+
if (!isSegmentedKey(event.key) || event.altKey || event.ctrlKey || event.metaKey)
|
|
107
|
+
return;
|
|
108
|
+
const current = optionRefs.current.findIndex(option => option === event.target);
|
|
109
|
+
if (current === -1)
|
|
110
|
+
return;
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
const direction = groupRef.current && getComputedStyle(groupRef.current).direction === 'rtl' ? 'rtl' : 'ltr';
|
|
113
|
+
const next = segmentedIndexForKey(disabled, current, event.key, direction);
|
|
114
|
+
optionRefs.current[next]?.focus();
|
|
115
|
+
if (activation === 'automatic')
|
|
116
|
+
select(next);
|
|
117
|
+
};
|
|
118
|
+
const indexAt = (clientX) => segmentedIndexAtPoint(optionRefs.current.map(option => {
|
|
119
|
+
const box = option?.getBoundingClientRect();
|
|
120
|
+
return { left: box?.left ?? 0, right: box?.right ?? 0 };
|
|
121
|
+
}), disabled, clientX);
|
|
122
|
+
const onPointerDown = (event) => {
|
|
123
|
+
if (event.button !== 0 || !event.isPrimary)
|
|
124
|
+
return;
|
|
125
|
+
drag.current = {
|
|
126
|
+
pointerId: event.pointerId,
|
|
127
|
+
pointerType: event.pointerType,
|
|
128
|
+
startX: event.clientX,
|
|
129
|
+
startY: event.clientY,
|
|
130
|
+
active: false,
|
|
131
|
+
cancelled: false,
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
const onPointerMove = (event) => {
|
|
135
|
+
const state = drag.current;
|
|
136
|
+
if (!state || state.pointerId !== event.pointerId || state.cancelled)
|
|
137
|
+
return;
|
|
138
|
+
if (!state.active) {
|
|
139
|
+
const decision = segmentedDragDecision(state.pointerType, event.clientX - state.startX, event.clientY - state.startY);
|
|
140
|
+
if (decision === 'wait')
|
|
141
|
+
return;
|
|
142
|
+
if (decision === 'abandon') {
|
|
143
|
+
drag.current = null;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
state.active = true;
|
|
147
|
+
groupRef.current?.setPointerCapture?.(event.pointerId);
|
|
148
|
+
}
|
|
149
|
+
const index = indexAt(event.clientX);
|
|
150
|
+
const option = options[index];
|
|
151
|
+
if (option)
|
|
152
|
+
setPreview(option.value);
|
|
153
|
+
};
|
|
154
|
+
const onPointerUp = (event) => {
|
|
155
|
+
const state = drag.current;
|
|
156
|
+
if (!state || state.pointerId !== event.pointerId)
|
|
157
|
+
return;
|
|
158
|
+
if (!state.active) {
|
|
159
|
+
// a press without a drag: the option's click selects it
|
|
160
|
+
drag.current = null;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
suppressClick.current = true;
|
|
164
|
+
const next = state.cancelled ? null : preview;
|
|
165
|
+
endDrag();
|
|
166
|
+
if (next !== null && next !== value)
|
|
167
|
+
onValueChange(next);
|
|
168
|
+
};
|
|
169
|
+
const onPointerCancel = (event) => {
|
|
170
|
+
const state = drag.current;
|
|
171
|
+
if (!state || state.pointerId !== event.pointerId)
|
|
172
|
+
return;
|
|
173
|
+
if (state.active)
|
|
174
|
+
suppressClick.current = true;
|
|
175
|
+
endDrag();
|
|
176
|
+
};
|
|
177
|
+
const onOptionClick = (index) => {
|
|
178
|
+
if (suppressClick.current) {
|
|
179
|
+
suppressClick.current = false;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
select(index);
|
|
183
|
+
};
|
|
184
|
+
const indicatorReady = indicator !== null;
|
|
185
|
+
return (_jsxs("div", { ref: groupRef, role: "radiogroup", "aria-label": t(ariaLabel), "data-slot": "segmented-control", onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, onPointerCancel: onPointerCancel, className: cn('relative isolate shrink-0 touch-pan-y items-stretch gap-0.5 rounded-(--segmented-control-radius) p-0.5 select-none', fullWidth ? 'flex w-full' : 'inline-flex', HEIGHT_CLASS[height], TRACK_CLASS[tone], className), children: [indicator && (_jsx("span", { "aria-hidden": true, "data-slot": "segmented-control-indicator", className: cn('pointer-events-none absolute inset-y-0.5 left-0 -z-10 rounded-(--segmented-control-radius) transition-[translate,width] duration-(--segmented-control-duration) ease-out motion-reduce:transition-none', INDICATOR_CLASS[selection][tone]), style: { translate: `${indicator.left}px 0`, width: indicator.width } })), options.map((option, index) => {
|
|
186
|
+
const checked = index === selectedIndex;
|
|
187
|
+
const highlighted = index === targetIndex;
|
|
188
|
+
const descriptionId = option.description ? `${baseId}-description-${index}` : undefined;
|
|
189
|
+
const reasonId = option.disabled && option.disabledReason ? `${baseId}-reason-${index}` : undefined;
|
|
190
|
+
const describedBy = [descriptionId, reasonId].filter(Boolean).join(' ') || undefined;
|
|
191
|
+
const label = t(option.label);
|
|
192
|
+
const button = (_jsxs("button", { ref: element => {
|
|
193
|
+
optionRefs.current[index] = element;
|
|
194
|
+
}, type: "button", role: "radio", "aria-checked": checked, "aria-disabled": option.disabled || undefined, "aria-describedby": describedBy, tabIndex: index === tabStop ? 0 : -1, "data-state": checked ? 'checked' : 'unchecked', onClick: () => onOptionClick(index), className: cn('relative inline-flex min-w-0 cursor-pointer items-center justify-center gap-1.5 rounded-(--segmented-control-radius) px-3 font-bold whitespace-nowrap outline-none transition-colors duration-(--segmented-control-duration) focus-visible:ring-2 focus-visible:ring-ring motion-reduce:transition-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*="size-"])]:size-4', COARSE_TARGET_CLASS, fullWidth && 'flex-1', iconOnly && cn('px-0', ICON_ONLY_WIDTH_CLASS[height]), highlighted ? HIGHLIGHT_TEXT_CLASS[selection][tone] : !option.disabled && HOVER_TEXT_CLASS[tone],
|
|
195
|
+
// before the indicator is measured (server render, hydration) the selected option carries its look
|
|
196
|
+
checked && !indicatorReady && INDICATOR_CLASS[selection][tone], option.disabled && 'cursor-not-allowed opacity-50', option.className), children: [option.icon, _jsx("span", { className: iconOnly ? 'sr-only' : 'truncate', children: label }), option.badge !== undefined && (_jsx("span", { "aria-hidden": true, className: "inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-current/15 px-1 text-[11px] leading-none tabular-nums", children: option.badge }))] }));
|
|
197
|
+
const reason = reasonId ? t(option.disabledReason) : undefined;
|
|
198
|
+
// outside the button: text inside it would join the accessible name; `hidden` text still describes
|
|
199
|
+
const descriptions = (_jsxs(_Fragment, { children: [descriptionId && (_jsx("span", { id: descriptionId, hidden: true, children: t(option.description) })), reasonId && (_jsx("span", { id: reasonId, hidden: true, children: reason }))] }));
|
|
200
|
+
if (!iconOnly && !reason) {
|
|
201
|
+
return (_jsxs(Fragment, { children: [button, descriptions] }, option.value));
|
|
202
|
+
}
|
|
203
|
+
return (_jsxs(Fragment, { children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: button }), _jsx(TooltipContent, { children: iconOnly && reason ? (_jsxs(_Fragment, { children: [label, _jsx("br", {}), reason] })) : ((reason ?? label)) })] }), descriptions] }, option.value));
|
|
204
|
+
})] }));
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=segmented-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.js","sourceRoot":"","sources":["../../src/primitives/segmented-control.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,QAAQ,EAIR,WAAW,EACX,SAAS,EACT,KAAK,EACL,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAe,CAAC;AA4CxE,MAAM,YAAY,GAAG,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,cAAc,EAAW,CAAC;AACvH,MAAM,qBAAqB,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAW,CAAC;AAEvF,MAAM,WAAW,GAA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CACR,IACA,CACJ,CAAC;gBACF,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;oBACzB,OAAO,CACL,MAAC,QAAQ,eACN,MAAM,EACN,YAAY,KAFA,MAAM,CAAC,KAAK,CAGhB,CACZ,CAAC;gBACJ,CAAC;gBACD,OAAO,CACL,MAAC,QAAQ,eACP,MAAC,OAAO,eACN,KAAC,cAAc,IAAC,OAAO,kBAAE,MAAM,GAAkB,EACjD,KAAC,cAAc,cACZ,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,CACpB,8BACG,KAAK,EACN,cAAM,EACL,MAAM,IACN,CACJ,CAAC,CAAC,CAAC,CACF,CAAC,MAAM,IAAI,KAAK,CAAC,CAClB,GACc,IACT,EACT,YAAY,KAfA,MAAM,CAAC,KAAK,CAgBhB,CACZ,CAAC;YACJ,CAAC,CAAC,IACE,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard and pointer mechanics of `SegmentedControl`, as pure functions: which option a key or a pointer position
|
|
3
|
+
* lands on. Disabled options are skipped; arrows wrap around; in a right-to-left control the horizontal arrows swap.
|
|
4
|
+
*/
|
|
5
|
+
/** The keys the control handles; anything else is left to the browser. */
|
|
6
|
+
export type SegmentedKey = 'ArrowLeft' | 'ArrowRight' | 'ArrowUp' | 'ArrowDown' | 'Home' | 'End';
|
|
7
|
+
export declare const isSegmentedKey: (key: string) => key is SegmentedKey;
|
|
8
|
+
/**
|
|
9
|
+
* The index a key moves to from `current` among `disabled.length` options (`disabled[i]` true = skipped). Arrow right /
|
|
10
|
+
* down go forward (left in RTL), arrow left / up go back, Home / End to the first / last enabled option. `current` when
|
|
11
|
+
* no other enabled option exists.
|
|
12
|
+
*/
|
|
13
|
+
export declare const segmentedIndexForKey: (disabled: readonly boolean[], current: number, key: SegmentedKey, direction?: "ltr" | "rtl") => number;
|
|
14
|
+
/** One option's horizontal extent on screen (px, viewport coordinates). */
|
|
15
|
+
export interface SegmentedRect {
|
|
16
|
+
left: number;
|
|
17
|
+
right: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The enabled option under a pointer at `x` during a drag: the option whose extent holds `x`, else the nearest one
|
|
21
|
+
* (a pointer dragged past the ends lands on the first / last). `-1` when every option is disabled.
|
|
22
|
+
*/
|
|
23
|
+
export declare const segmentedIndexAtPoint: (rects: readonly SegmentedRect[], disabled: readonly boolean[], x: number) => number;
|
|
24
|
+
/** A touch drag starts only after this much horizontal movement (px), and only when it is more horizontal than vertical. */
|
|
25
|
+
export declare const SEGMENTED_TOUCH_SLOP = 8;
|
|
26
|
+
/**
|
|
27
|
+
* Does a pointer movement of (`dx`, `dy`) since the press start a drag? Mouse and pen at once; touch only past the slop
|
|
28
|
+
* and mostly sideways, so a vertical swipe keeps scrolling the page. `'abandon'`: a touch that moved vertically first.
|
|
29
|
+
*/
|
|
30
|
+
export declare const segmentedDragDecision: (pointerType: string, dx: number, dy: number) => "drag" | "wait" | "abandon";
|
|
31
|
+
//# sourceMappingURL=segmentedControlNavigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmentedControlNavigation.d.ts","sourceRoot":"","sources":["../../src/primitives/segmentedControlNavigation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;AAIjG,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,GAAG,IAAI,YAA4C,CAAC;AAEjG;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,SAAS,OAAO,EAAE,EAC5B,SAAS,MAAM,EACf,KAAK,YAAY,EACjB,YAAW,KAAK,GAAG,KAAa,KAC/B,MAgBF,CAAC;AAEF,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,SAAS,aAAa,EAAE,EAAE,UAAU,SAAS,OAAO,EAAE,EAAE,GAAG,MAAM,KAAG,MAYhH,CAAC;AAEF,4HAA4H;AAC5H,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,aAAa,MAAM,EACnB,IAAI,MAAM,EACV,IAAI,MAAM,KACT,MAAM,GAAG,MAAM,GAAG,SAMpB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard and pointer mechanics of `SegmentedControl`, as pure functions: which option a key or a pointer position
|
|
3
|
+
* lands on. Disabled options are skipped; arrows wrap around; in a right-to-left control the horizontal arrows swap.
|
|
4
|
+
*/
|
|
5
|
+
const SEGMENTED_KEYS = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'];
|
|
6
|
+
export const isSegmentedKey = (key) => SEGMENTED_KEYS.includes(key);
|
|
7
|
+
/**
|
|
8
|
+
* The index a key moves to from `current` among `disabled.length` options (`disabled[i]` true = skipped). Arrow right /
|
|
9
|
+
* down go forward (left in RTL), arrow left / up go back, Home / End to the first / last enabled option. `current` when
|
|
10
|
+
* no other enabled option exists.
|
|
11
|
+
*/
|
|
12
|
+
export const segmentedIndexForKey = (disabled, current, key, direction = 'ltr') => {
|
|
13
|
+
const count = disabled.length;
|
|
14
|
+
if (count === 0)
|
|
15
|
+
return current;
|
|
16
|
+
const enabled = (index) => !disabled[index];
|
|
17
|
+
if (key === 'Home' || key === 'End') {
|
|
18
|
+
const order = Array.from({ length: count }, (_, index) => index);
|
|
19
|
+
if (key === 'End')
|
|
20
|
+
order.reverse();
|
|
21
|
+
return order.find(enabled) ?? current;
|
|
22
|
+
}
|
|
23
|
+
const forwardKey = direction === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
|
|
24
|
+
const step = key === forwardKey || key === 'ArrowDown' ? 1 : -1;
|
|
25
|
+
for (let offset = 1; offset < count; offset += 1) {
|
|
26
|
+
const index = (((current + step * offset) % count) + count) % count;
|
|
27
|
+
if (enabled(index))
|
|
28
|
+
return index;
|
|
29
|
+
}
|
|
30
|
+
return current;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The enabled option under a pointer at `x` during a drag: the option whose extent holds `x`, else the nearest one
|
|
34
|
+
* (a pointer dragged past the ends lands on the first / last). `-1` when every option is disabled.
|
|
35
|
+
*/
|
|
36
|
+
export const segmentedIndexAtPoint = (rects, disabled, x) => {
|
|
37
|
+
let best = -1;
|
|
38
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
39
|
+
rects.forEach((rect, index) => {
|
|
40
|
+
if (disabled[index])
|
|
41
|
+
return;
|
|
42
|
+
const distance = x < rect.left ? rect.left - x : x > rect.right ? x - rect.right : 0;
|
|
43
|
+
if (distance < bestDistance) {
|
|
44
|
+
best = index;
|
|
45
|
+
bestDistance = distance;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return best;
|
|
49
|
+
};
|
|
50
|
+
/** A touch drag starts only after this much horizontal movement (px), and only when it is more horizontal than vertical. */
|
|
51
|
+
export const SEGMENTED_TOUCH_SLOP = 8;
|
|
52
|
+
/**
|
|
53
|
+
* Does a pointer movement of (`dx`, `dy`) since the press start a drag? Mouse and pen at once; touch only past the slop
|
|
54
|
+
* and mostly sideways, so a vertical swipe keeps scrolling the page. `'abandon'`: a touch that moved vertically first.
|
|
55
|
+
*/
|
|
56
|
+
export const segmentedDragDecision = (pointerType, dx, dy) => {
|
|
57
|
+
if (pointerType !== 'touch')
|
|
58
|
+
return 'drag';
|
|
59
|
+
const horizontal = Math.abs(dx);
|
|
60
|
+
const vertical = Math.abs(dy);
|
|
61
|
+
if (horizontal < SEGMENTED_TOUCH_SLOP && vertical < SEGMENTED_TOUCH_SLOP)
|
|
62
|
+
return 'wait';
|
|
63
|
+
return horizontal > vertical ? 'drag' : 'abandon';
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=segmentedControlNavigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmentedControlNavigation.js","sourceRoot":"","sources":["../../src/primitives/segmentedControlNavigation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,cAAc,GAAsB,CAAC,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAE7G,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAuB,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAEjG;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,QAA4B,EAC5B,OAAe,EACf,GAAiB,EACjB,YAA2B,KAAK,EACxB,EAAE;IACV,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC9B,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAChC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QACjE,IAAI,GAAG,KAAK,KAAK;YAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC;IACxC,CAAC;IACD,MAAM,UAAU,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,C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5H,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,WAAmB,EACnB,EAAU,EACV,EAAU,EACmB,EAAE;IAC/B,IAAI,WAAW,KAAK,OAAO;QAAE,OAAO,MAAM,CAAC;IAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9B,IAAI,UAAU,GAAG,oBAAoB,IAAI,QAAQ,GAAG,oBAAoB;QAAE,OAAO,MAAM,CAAC;IACxF,OAAO,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC,CAAC"}
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
//
|
|
13
13
|
// Scan rules (the same as the host export): string literals passed to `t()`, `translateText()` and `m()` with an
|
|
14
14
|
// optional `{ context }`, and `<Translate context>…</Translate>` elements; a file containing the marker
|
|
15
|
-
// `@translations-ignore-file` is skipped; tests are skipped
|
|
15
|
+
// `@translations-ignore-file` is skipped; tests are skipped; the `showcase` entry (a development page with
|
|
16
|
+
// developer-facing English) is skipped. Key = text, or `${text}__${context}` with a context.
|
|
16
17
|
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
17
18
|
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
18
19
|
import { fileURLToPath } from 'node:url';
|
|
@@ -40,6 +41,9 @@ const CONTEXT = new RegExp(String.raw`context\s*:\s*(${LITERAL})`);
|
|
|
40
41
|
const ELEMENT = /<Translate\b([^>]*)>([^<{}]+)<\/Translate>/g;
|
|
41
42
|
const ELEMENT_CONTEXT = /context=(?:"([^"]*)"|'([^']*)'|\{\s*['"]([^'"]*)['"]\s*\})/;
|
|
42
43
|
const IGNORE_MARKER = '@translations-ignore-file';
|
|
44
|
+
/** Entry folders whose texts are not UI texts of the blocks: the showcase is a development page. */
|
|
45
|
+
const IGNORED_ENTRIES = ['showcase'];
|
|
46
|
+
const inIgnoredEntry = name => IGNORED_ENTRIES.some(entry => name.startsWith(`${entry}/`));
|
|
43
47
|
|
|
44
48
|
const unquote = literal =>
|
|
45
49
|
literal
|
|
@@ -60,7 +64,8 @@ const sourceFiles = () => {
|
|
|
60
64
|
if (sourceMode) {
|
|
61
65
|
return walk(sourceRoot)
|
|
62
66
|
.filter(path => /\.(ts|tsx)$/.test(path) && !/\.test\.tsx?$/.test(path) && !path.endsWith('.d.ts'))
|
|
63
|
-
.map(path => ({ path, name: toPosix(relative(sourceRoot, path)) }))
|
|
67
|
+
.map(path => ({ path, name: toPosix(relative(sourceRoot, path)) }))
|
|
68
|
+
.filter(file => !inIgnoredEntry(file.name));
|
|
64
69
|
}
|
|
65
70
|
// built JS keeps the calls and the comments; the path is the dist path with the source's extension (`.ts` or
|
|
66
71
|
// `.tsx`, read from the file's source map)
|
|
@@ -72,7 +77,8 @@ const sourceFiles = () => {
|
|
|
72
77
|
const map = existsSync(mapPath) ? JSON.parse(readFileSync(mapPath, 'utf8')) : null;
|
|
73
78
|
const extension = /\.tsx?$/.exec(map?.sources?.[0] ?? '')?.[0] ?? '.js';
|
|
74
79
|
return { path, name: toPosix(relative(distRoot, path)).replace(/\.js$/, extension) };
|
|
75
|
-
})
|
|
80
|
+
})
|
|
81
|
+
.filter(file => !inIgnoredEntry(file.name));
|
|
76
82
|
};
|
|
77
83
|
|
|
78
84
|
const scan = ({ path, name }) => {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type NotifySonnerLoader } from './sections/OptionalShowcase.js';
|
|
3
|
+
/** One section of the showcase: a heading and what it draws. Hosts append their own (`Showcase.sections`). */
|
|
4
|
+
export interface ShowcaseSection {
|
|
5
|
+
/** Stable id: the section's anchor (`#showcase-<id>`) and React key. */
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
content: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export type ShowcaseTheme = 'light' | 'dark';
|
|
12
|
+
export interface ShowcaseProps {
|
|
13
|
+
/** The host's own sections, drawn after the package's. */
|
|
14
|
+
sections?: readonly ShowcaseSection[];
|
|
15
|
+
/** Which themes to draw, side by side on wide screens (default both). Dark is a `.dark` ancestor, as in the host. */
|
|
16
|
+
themes?: readonly ShowcaseTheme[];
|
|
17
|
+
/**
|
|
18
|
+
* Loads `./notify-sonner` for its section; only a host with `sonner` passes it:
|
|
19
|
+
* `loadNotifySonner={() => import('@mgamadeus/ddd-admin-ui/notify-sonner')}`. Without it, or when the import fails
|
|
20
|
+
* (the peer is missing), the section says it is skipped.
|
|
21
|
+
*/
|
|
22
|
+
loadNotifySonner?: NotifySonnerLoader;
|
|
23
|
+
/** Leave out package sections by id (`primitives`, `list`, `page`, `form`, `translations`, `media`, `glass`, `notify-sonner`, `next`). */
|
|
24
|
+
omit?: readonly string[];
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Every block of the package in the host's theme, light and dark, one section per entry; the host appends its own
|
|
29
|
+
* sections. A development page: mount it on a route of the host (below `AdminUiProvider`, which brings the tooltip
|
|
30
|
+
* provider) to judge the theme, the tokens and the blocks in one place. Optional peers stay optional: the
|
|
31
|
+
* `./notify-sonner` section loads only through `loadNotifySonner` and is skipped without it; `./next` is described,
|
|
32
|
+
* never imported. Texts are developer-facing English and not part of the text manifest.
|
|
33
|
+
*/
|
|
34
|
+
export declare const Showcase: ({ sections, themes, loadNotifySonner, omit, className }: ShowcaseProps) => import("react").JSX.Element;
|
|
35
|
+
//# sourceMappingURL=Showcase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Showcase.d.ts","sourceRoot":"","sources":["../../src/showcase/Showcase.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AAQjD,OAAO,EAAsC,KAAK,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAK9G,8GAA8G;AAC9G,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,OAAO,EAAE,SAAS,CAAC;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IACtC,qHAAqH;IACrH,MAAM,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IACtC,0IAA0I;IAC1I,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAiDD;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,yDAAuF,aAAa,gCAS5H,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { PortalContainerProvider } from "../primitives/index.js";
|
|
5
|
+
import { cn } from "../primitives/cn.js";
|
|
6
|
+
import { FormShowcase } from "./sections/FormShowcase.js";
|
|
7
|
+
import { GlassShowcase } from "./sections/GlassShowcase.js";
|
|
8
|
+
import { ListShowcase } from "./sections/ListShowcase.js";
|
|
9
|
+
import { MediaShowcase } from "./sections/MediaShowcase.js";
|
|
10
|
+
import { NextShowcase, NotifySonnerShowcase } from "./sections/OptionalShowcase.js";
|
|
11
|
+
import { PageShowcase } from "./sections/PageShowcase.js";
|
|
12
|
+
import { PrimitivesShowcase } from "./sections/PrimitivesShowcase.js";
|
|
13
|
+
import { TranslationsShowcase } from "./sections/TranslationsShowcase.js";
|
|
14
|
+
/** The package's sections, one per entry, in import-matrix order. */
|
|
15
|
+
const packageSections = (loadNotifySonner) => [
|
|
16
|
+
{ id: 'primitives', title: './primitives', description: 'Buttons, fields, overlays, tables, the segmented control.', content: _jsx(PrimitivesShowcase, {}) },
|
|
17
|
+
{ id: 'list', title: './list', description: 'List card, toolbar, filters, table and grid, cells, pickers.', content: _jsx(ListShowcase, {}) },
|
|
18
|
+
{ id: 'page', title: './page', description: 'Page frame and header, detail shell, cards and toolbars.', content: _jsx(PageShowcase, {}) },
|
|
19
|
+
{ id: 'form', title: './form', description: 'Form shell, fields, sections, actions, errors, drawer.', content: _jsx(FormShowcase, {}) },
|
|
20
|
+
{ id: 'translations', title: './translations', description: 'Inputs per content locale and the translation controls.', content: _jsx(TranslationsShowcase, {}) },
|
|
21
|
+
{ id: 'media', title: './media', description: 'Media field, preview and picker.', content: _jsx(MediaShowcase, {}) },
|
|
22
|
+
{ id: 'glass', title: './glass', description: 'Glass pills, quick filters, collapsible cards, groups and rows.', content: _jsx(GlassShowcase, {}) },
|
|
23
|
+
{
|
|
24
|
+
id: 'notify-sonner',
|
|
25
|
+
title: './notify-sonner',
|
|
26
|
+
description: 'Toasts through sonner (optional peer, loaded lazily).',
|
|
27
|
+
content: _jsx(NotifySonnerShowcase, { load: loadNotifySonner }),
|
|
28
|
+
},
|
|
29
|
+
{ id: 'next', title: './next', description: 'Next.js adapters (optional peer): hooks, no markup.', content: _jsx(NextShowcase, {}) },
|
|
30
|
+
];
|
|
31
|
+
const ThemePane = ({ theme, sections }) => {
|
|
32
|
+
// dialogs, menus and tooltips of a pane open inside it, so the dark pane's overlays are dark too
|
|
33
|
+
const [portal, setPortal] = useState(null);
|
|
34
|
+
return (_jsxs("div", { "data-showcase-theme": theme, className: cn('min-w-0 flex-1 rounded-3xl bg-background p-4 text-foreground md:p-6', theme === 'dark' && 'dark'), children: [_jsxs(PortalContainerProvider, { container: portal, children: [_jsx("p", { className: "mb-6 text-[11.5px] font-bold tracking-[0.08em] text-muted-foreground uppercase", children: theme }), _jsx("div", { className: "space-y-12", children: sections.map(section => (_jsxs("section", { id: `showcase-${section.id}-${theme}`, "aria-labelledby": `showcase-${section.id}-${theme}-title`, children: [_jsxs("header", { className: "mb-4 border-b pb-2", children: [_jsx("h2", { id: `showcase-${section.id}-${theme}-title`, className: "text-title-section font-bold", children: section.title }), section.description && _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: section.description })] }), section.content] }, section.id))) })] }), _jsx("div", { ref: setPortal, className: theme === 'dark' ? 'dark' : undefined })] }));
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Every block of the package in the host's theme, light and dark, one section per entry; the host appends its own
|
|
38
|
+
* sections. A development page: mount it on a route of the host (below `AdminUiProvider`, which brings the tooltip
|
|
39
|
+
* provider) to judge the theme, the tokens and the blocks in one place. Optional peers stay optional: the
|
|
40
|
+
* `./notify-sonner` section loads only through `loadNotifySonner` and is skipped without it; `./next` is described,
|
|
41
|
+
* never imported. Texts are developer-facing English and not part of the text manifest.
|
|
42
|
+
*/
|
|
43
|
+
export const Showcase = ({ sections = [], themes = ['light', 'dark'], loadNotifySonner, omit = [], className }) => {
|
|
44
|
+
const all = [...packageSections(loadNotifySonner).filter(section => !omit.includes(section.id)), ...sections];
|
|
45
|
+
return (_jsx("div", { "data-showcase": true, className: cn('flex flex-col gap-6 xl:flex-row', className), children: themes.map(theme => (_jsx(ThemePane, { theme: theme, sections: all }, theme))) }));
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=Showcase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Showcase.js","sourceRoot":"","sources":["../../src/showcase/Showcase.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAkB,QAAQ,EAAE,MAAM,OAAO,CAAC;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AAE,SAAS,EAAC,8BAA8B,YACtF,OAAO,CAAC,KAAK,GACX,EACJ,OAAO,CAAC,WAAW,IAAI,YAAG,SAAS,EAAC,oCAAoC,YAAE,OAAO,CAAC,WAAW,GAAK,IAC5F,EACR,OAAO,CAAC,OAAO,KAPJ,OAAO,CAAC,EAAE,CAQd,CACX,CAAC,GACE,IACkB,EAC1B,cAAK,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,GAAI,IACrE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,EAAE,EAAE,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,gBAAgB,EAAE,IAAI,GAAG,EAAE,EAAE,SAAS,EAAiB,EAAE,EAAE;IAC/H,MAAM,GAAG,GAAG,CAAC,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;IAC9G,OAAO,CACL,qCAAmB,SAAS,EAAE,EAAE,CAAC,iCAAiC,EAAE,SAAS,CAAC,YAC3E,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CACnB,KAAC,SAAS,IAAa,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAlC,KAAK,CAAiC,CACvD,CAAC,GACE,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which exported components of each entry the showcase draws (`shown`), and why the others are not drawn on their own
|
|
3
|
+
* (`notShown`: parts drawn by a shown block, providers, contexts). The package's tests compare it with the entries'
|
|
4
|
+
* exports, so a new block without a showcase sample fails them.
|
|
5
|
+
*/
|
|
6
|
+
export interface ShowcaseEntryCoverage {
|
|
7
|
+
shown: readonly string[];
|
|
8
|
+
notShown: Readonly<Record<string, string>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const SHOWCASE_COVERAGE: Readonly<Record<string, ShowcaseEntryCoverage>>;
|
|
11
|
+
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/showcase/coverage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC5C;AAID,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CA0E7E,CAAC"}
|