@zhin.js/console-ui 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README.md +195 -2
- package/audit/index.mjs +21 -0
- package/audit/layout-audit.mjs +492 -0
- package/audit/mount-page.jsx +90 -0
- package/audit/plugin-pages.mjs +186 -0
- package/dist/cn.d.ts +4 -0
- package/dist/cn.js +6 -0
- package/dist/components/BrandMark.d.ts +16 -0
- package/dist/components/BrandMark.js +21 -0
- package/dist/components/InfoHint.d.ts +12 -0
- package/dist/components/InfoHint.js +13 -0
- package/dist/components/PageHeader.d.ts +18 -0
- package/dist/components/PageHeader.js +11 -0
- package/dist/components/PageShell.d.ts +26 -0
- package/dist/components/PageShell.js +10 -0
- package/dist/components/RefreshControl.d.ts +28 -0
- package/dist/components/RefreshControl.js +68 -0
- package/dist/components/StatCard.d.ts +41 -0
- package/dist/components/StatCard.js +53 -0
- package/dist/components/StatusBadge.d.ts +14 -0
- package/dist/components/StatusBadge.js +19 -0
- package/dist/components/actions.d.ts +53 -0
- package/dist/components/actions.js +50 -0
- package/dist/components/code.d.ts +11 -0
- package/dist/components/code.js +10 -0
- package/dist/components/confirm-dialog-model.d.ts +9 -0
- package/dist/components/confirm-dialog-model.js +20 -0
- package/dist/components/confirm-dialog.d.ts +32 -0
- package/dist/components/confirm-dialog.js +72 -0
- package/dist/components/content-blocks.d.ts +141 -0
- package/dist/components/content-blocks.js +77 -0
- package/dist/components/empty-illustrations.d.ts +15 -0
- package/dist/components/empty-illustrations.js +36 -0
- package/dist/components/empty-state.d.ts +35 -0
- package/dist/components/empty-state.js +43 -0
- package/dist/components/error-alert.d.ts +15 -0
- package/dist/components/error-alert.js +23 -0
- package/dist/components/icon.d.ts +11 -0
- package/dist/components/icon.js +8 -0
- package/dist/components/layout.d.ts +38 -0
- package/dist/components/layout.js +28 -0
- package/dist/components/page-chrome.d.ts +53 -0
- package/dist/components/page-chrome.js +66 -0
- package/dist/components/refresh-control-model.d.ts +9 -0
- package/dist/components/refresh-control-model.js +26 -0
- package/dist/components/ui/accordion.d.ts +7 -0
- package/dist/components/ui/accordion.js +15 -0
- package/dist/components/ui/alert.d.ts +8 -0
- package/dist/components/ui/alert.js +24 -0
- package/dist/components/ui/badge.d.ts +9 -0
- package/dist/components/ui/badge.js +30 -0
- package/dist/components/ui/button.d.ts +20 -0
- package/dist/components/ui/button.js +52 -0
- package/dist/components/ui/card.d.ts +17 -0
- package/dist/components/ui/card.js +17 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/checkbox.js +10 -0
- package/dist/components/ui/control-variant.d.ts +10 -0
- package/dist/components/ui/control-variant.js +6 -0
- package/dist/components/ui/date-field-model.d.ts +39 -0
- package/dist/components/ui/date-field-model.js +105 -0
- package/dist/components/ui/date-field.d.ts +33 -0
- package/dist/components/ui/date-field.js +161 -0
- package/dist/components/ui/dialog.d.ts +24 -0
- package/dist/components/ui/dialog.js +27 -0
- package/dist/components/ui/dropdown-menu.d.ts +19 -0
- package/dist/components/ui/dropdown-menu.js +26 -0
- package/dist/components/ui/input.d.ts +8 -0
- package/dist/components/ui/input.js +9 -0
- package/dist/components/ui/list-item-button.d.ts +10 -0
- package/dist/components/ui/list-item-button.js +6 -0
- package/dist/components/ui/popover.d.ts +6 -0
- package/dist/components/ui/popover.js +9 -0
- package/dist/components/ui/radio-group.d.ts +5 -0
- package/dist/components/ui/radio-group.js +10 -0
- package/dist/components/ui/scroll-area.d.ts +5 -0
- package/dist/components/ui/scroll-area.js +13 -0
- package/dist/components/ui/searchable-select-model.d.ts +29 -0
- package/dist/components/ui/searchable-select-model.js +38 -0
- package/dist/components/ui/searchable-select.d.ts +26 -0
- package/dist/components/ui/searchable-select.js +85 -0
- package/dist/components/ui/select.d.ts +29 -0
- package/dist/components/ui/select.js +39 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/separator.js +11 -0
- package/dist/components/ui/sheet.d.ts +27 -0
- package/dist/components/ui/sheet.js +27 -0
- package/dist/components/ui/skeleton.d.ts +3 -0
- package/dist/components/ui/skeleton.js +6 -0
- package/dist/components/ui/switch.d.ts +4 -0
- package/dist/components/ui/switch.js +8 -0
- package/dist/components/ui/table.d.ts +27 -0
- package/dist/components/ui/table.js +47 -0
- package/dist/components/ui/tabs.d.ts +7 -0
- package/dist/components/ui/tabs.js +13 -0
- package/dist/components/ui/textarea.d.ts +8 -0
- package/dist/components/ui/textarea.js +9 -0
- package/dist/components/ui/tooltip.d.ts +7 -0
- package/dist/components/ui/tooltip.js +11 -0
- package/dist/components/use-container-width.d.ts +13 -0
- package/dist/components/use-container-width.js +30 -0
- package/dist/custom-media.css +13 -0
- package/dist/exports.json +178 -0
- package/dist/i18n/index.d.ts +27 -0
- package/dist/i18n/index.js +33 -0
- package/dist/i18n/messages.d.ts +55 -0
- package/dist/i18n/messages.js +110 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +55 -0
- package/dist/scale.json +643 -0
- package/dist/shared-module.d.ts +28 -0
- package/dist/shared-module.js +24 -0
- package/dist/styles.css +3399 -0
- package/dist/theme.css +469 -0
- package/dist/tokens.css +652 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +2 -0
- package/lint/eslint-plugin.mjs +128 -0
- package/lint/stylelint-config.mjs +43 -0
- package/lint/stylelint-plugin.mjs +195 -0
- package/lint/tailwind-classes.mjs +121 -0
- package/package.json +103 -3
- package/tokens/color.mjs +104 -0
- package/tokens/colors.css +220 -0
- package/tokens/generate.mjs +288 -0
- package/tokens/scale.mjs +137 -0
- package/tokens/tokens.mjs +362 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const DATE_VALUE = /^(\d{4})-(\d{2})-(\d{2})$/u;
|
|
2
|
+
const DATE_TIME_VALUE = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::\d{2}(?:\.\d{1,9})?)?$/u;
|
|
3
|
+
/** Values with a zone designator (`Z`, `+08:00`) are read through `Date` and shown in local time. */
|
|
4
|
+
const ZONED_VALUE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/u;
|
|
5
|
+
const pad = (value, length = 2) => String(value).padStart(length, '0');
|
|
6
|
+
export function daysInMonth(year, month) {
|
|
7
|
+
return new Date(year, month, 0).getDate();
|
|
8
|
+
}
|
|
9
|
+
function validDate(year, month, day) {
|
|
10
|
+
if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month))
|
|
11
|
+
return null;
|
|
12
|
+
return { year, month, day };
|
|
13
|
+
}
|
|
14
|
+
/** Reads the date part of a date or date-time value; `null` when empty or invalid. */
|
|
15
|
+
export function parseDateValue(value) {
|
|
16
|
+
if (!value)
|
|
17
|
+
return null;
|
|
18
|
+
const date = DATE_VALUE.exec(value);
|
|
19
|
+
if (date)
|
|
20
|
+
return validDate(Number(date[1]), Number(date[2]), Number(date[3]));
|
|
21
|
+
const dateTime = parseDateTimeValue(value);
|
|
22
|
+
return dateTime ? { year: dateTime.year, month: dateTime.month, day: dateTime.day } : null;
|
|
23
|
+
}
|
|
24
|
+
/** Reads a date-time value (a bare date counts as 00:00); `null` when empty or invalid. */
|
|
25
|
+
export function parseDateTimeValue(value) {
|
|
26
|
+
if (!value)
|
|
27
|
+
return null;
|
|
28
|
+
if (ZONED_VALUE.test(value)) {
|
|
29
|
+
const parsed = new Date(value);
|
|
30
|
+
if (Number.isNaN(parsed.getTime()))
|
|
31
|
+
return null;
|
|
32
|
+
return { ...fromDate(parsed), hour: parsed.getHours(), minute: parsed.getMinutes() };
|
|
33
|
+
}
|
|
34
|
+
const match = DATE_TIME_VALUE.exec(value);
|
|
35
|
+
if (!match) {
|
|
36
|
+
const date = DATE_VALUE.exec(value);
|
|
37
|
+
const day = date ? validDate(Number(date[1]), Number(date[2]), Number(date[3])) : null;
|
|
38
|
+
return day ? { ...day, hour: 0, minute: 0 } : null;
|
|
39
|
+
}
|
|
40
|
+
const day = validDate(Number(match[1]), Number(match[2]), Number(match[3]));
|
|
41
|
+
const hour = Number(match[4]);
|
|
42
|
+
const minute = Number(match[5]);
|
|
43
|
+
if (!day || hour > 23 || minute > 59)
|
|
44
|
+
return null;
|
|
45
|
+
return { ...day, hour, minute };
|
|
46
|
+
}
|
|
47
|
+
export function formatDateValue(date) {
|
|
48
|
+
return `${pad(date.year, 4)}-${pad(date.month)}-${pad(date.day)}`;
|
|
49
|
+
}
|
|
50
|
+
export function formatDateTimeValue(value) {
|
|
51
|
+
return `${formatDateValue(value)}T${pad(value.hour)}:${pad(value.minute)}`;
|
|
52
|
+
}
|
|
53
|
+
export function fromDate(date) {
|
|
54
|
+
return { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };
|
|
55
|
+
}
|
|
56
|
+
export function compareDates(a, b) {
|
|
57
|
+
return (a.year - b.year) || (a.month - b.month) || (a.day - b.day);
|
|
58
|
+
}
|
|
59
|
+
export function sameDate(a, b) {
|
|
60
|
+
return a !== null && b !== null && compareDates(a, b) === 0;
|
|
61
|
+
}
|
|
62
|
+
export function addDays(date, days) {
|
|
63
|
+
return fromDate(new Date(date.year, date.month - 1, date.day + days));
|
|
64
|
+
}
|
|
65
|
+
/** Same day in another month, clamped to that month's last day (Jan 31 + 1 month = Feb 28/29). */
|
|
66
|
+
export function addMonths(date, months) {
|
|
67
|
+
const index = date.year * 12 + (date.month - 1) + months;
|
|
68
|
+
const year = Math.floor(index / 12);
|
|
69
|
+
const month = index - year * 12 + 1;
|
|
70
|
+
return { year, month, day: Math.min(date.day, daysInMonth(year, month)) };
|
|
71
|
+
}
|
|
72
|
+
/** Whether `date` is inside `[min, max]` (date parts of the bounds; either bound may be empty). */
|
|
73
|
+
export function isWithin(date, min, max) {
|
|
74
|
+
const low = parseDateValue(min);
|
|
75
|
+
const high = parseDateValue(max);
|
|
76
|
+
return !(low && compareDates(date, low) < 0) && !(high && compareDates(date, high) > 0);
|
|
77
|
+
}
|
|
78
|
+
export function clampDate(date, min, max) {
|
|
79
|
+
const low = parseDateValue(min);
|
|
80
|
+
const high = parseDateValue(max);
|
|
81
|
+
if (low && compareDates(date, low) < 0)
|
|
82
|
+
return low;
|
|
83
|
+
if (high && compareDates(date, high) > 0)
|
|
84
|
+
return high;
|
|
85
|
+
return date;
|
|
86
|
+
}
|
|
87
|
+
/** 0 = Sunday … 6 = Saturday */
|
|
88
|
+
export function weekday(date) {
|
|
89
|
+
return new Date(date.year, date.month - 1, date.day).getDay();
|
|
90
|
+
}
|
|
91
|
+
/** First day of the week that contains `date`. */
|
|
92
|
+
export function startOfWeek(date, weekStartsOn) {
|
|
93
|
+
return addDays(date, -((weekday(date) - weekStartsOn + 7) % 7));
|
|
94
|
+
}
|
|
95
|
+
/** Six weeks × seven days covering the month (leading / trailing days of the neighbour months included). */
|
|
96
|
+
export function calendarMonth(year, month, weekStartsOn) {
|
|
97
|
+
const first = startOfWeek({ year, month, day: 1 }, weekStartsOn);
|
|
98
|
+
return Array.from({ length: 6 }, (_, week) => Array.from({ length: 7 }, (_, day) => addDays(first, week * 7 + day)));
|
|
99
|
+
}
|
|
100
|
+
/** Hour / minute typed into the time boxes: digits only, clamped into range; `null` when not a number. */
|
|
101
|
+
export function clampTimePart(text, max) {
|
|
102
|
+
if (!/^\d{1,2}$/u.test(text.trim()))
|
|
103
|
+
return null;
|
|
104
|
+
return Math.min(Number(text.trim()), max);
|
|
105
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { ControlVariant } from './control-variant.js';
|
|
3
|
+
export interface DateFieldProps {
|
|
4
|
+
/** ISO value in local time: `YYYY-MM-DD` (DateField) or `YYYY-MM-DDTHH:mm` (DateTimeField); `''` when empty. */
|
|
5
|
+
value: string;
|
|
6
|
+
onValueChange: (value: string) => void;
|
|
7
|
+
/** Earliest / latest selectable day (ISO; only the date part is compared). */
|
|
8
|
+
min?: string;
|
|
9
|
+
max?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Show the clear button and accept Delete / Backspace on the trigger. Default `true`. */
|
|
13
|
+
clearable?: boolean;
|
|
14
|
+
/** `ghost`: no border until hovered, focused or open (ADR 0063 D29). */
|
|
15
|
+
variant?: ControlVariant;
|
|
16
|
+
/** First day of the week: 1 Monday (default for zh-CN), 0 Sunday (default for en). */
|
|
17
|
+
weekStartsOn?: 0 | 1;
|
|
18
|
+
className?: string;
|
|
19
|
+
id?: string;
|
|
20
|
+
'aria-label'?: string;
|
|
21
|
+
'aria-labelledby'?: string;
|
|
22
|
+
'aria-invalid'?: boolean | 'true' | 'false';
|
|
23
|
+
}
|
|
24
|
+
export type DateTimeFieldProps = DateFieldProps;
|
|
25
|
+
/**
|
|
26
|
+
* Date picker (ADR 0063 D29, zhinjs/console#125): replaces `<input type="date">`. A trigger that
|
|
27
|
+
* looks like `SelectTrigger`, and a popover month calendar (grid pattern): ← → ↑ ↓ move by day /
|
|
28
|
+
* week, Home / End to the week's start / end, PageUp / PageDown by month (with Shift by year),
|
|
29
|
+
* Enter or Space picks, Esc closes. Delete / Backspace on the trigger clears the value.
|
|
30
|
+
*/
|
|
31
|
+
export declare const DateField: React.ForwardRefExoticComponent<DateFieldProps & React.RefAttributes<HTMLButtonElement>>;
|
|
32
|
+
/** `DateField` plus hour and minute: replaces `<input type="datetime-local">` (value `YYYY-MM-DDTHH:mm`). */
|
|
33
|
+
export declare const DateTimeField: React.ForwardRefExoticComponent<DateFieldProps & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Calendar, ChevronLeft, ChevronRight, X } from 'lucide-react';
|
|
4
|
+
import { cn } from '../../cn.js';
|
|
5
|
+
import { useConsoleUiI18n } from '../../i18n/index.js';
|
|
6
|
+
import { CONSOLE_ICON_STROKE_WIDTH } from '../icon.js';
|
|
7
|
+
import { Button } from './button.js';
|
|
8
|
+
import { Input } from './input.js';
|
|
9
|
+
import { Popover, PopoverContent, PopoverTrigger } from './popover.js';
|
|
10
|
+
import { addDays, addMonths, calendarMonth, clampDate, clampTimePart, formatDateTimeValue, formatDateValue, fromDate, isWithin, parseDateTimeValue, parseDateValue, sameDate, startOfWeek, } from './date-field-model.js';
|
|
11
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
12
|
+
/**
|
|
13
|
+
* Date picker (ADR 0063 D29, zhinjs/console#125): replaces `<input type="date">`. A trigger that
|
|
14
|
+
* looks like `SelectTrigger`, and a popover month calendar (grid pattern): ← → ↑ ↓ move by day /
|
|
15
|
+
* week, Home / End to the week's start / end, PageUp / PageDown by month (with Shift by year),
|
|
16
|
+
* Enter or Space picks, Esc closes. Delete / Backspace on the trigger clears the value.
|
|
17
|
+
*/
|
|
18
|
+
export const DateField = forwardRef((props, ref) => (_jsx(CalendarField, { ref: ref, mode: "date", ...props })));
|
|
19
|
+
DateField.displayName = 'DateField';
|
|
20
|
+
/** `DateField` plus hour and minute: replaces `<input type="datetime-local">` (value `YYYY-MM-DDTHH:mm`). */
|
|
21
|
+
export const DateTimeField = forwardRef((props, ref) => (_jsx(CalendarField, { ref: ref, mode: "datetime", ...props })));
|
|
22
|
+
DateTimeField.displayName = 'DateTimeField';
|
|
23
|
+
const CalendarField = forwardRef(({ mode, value, onValueChange, min, max, placeholder, disabled, clearable = true, variant, weekStartsOn, className, id, ...aria }, ref) => {
|
|
24
|
+
const i18n = useConsoleUiI18n();
|
|
25
|
+
const locale = i18n.locale;
|
|
26
|
+
const weekStart = weekStartsOn ?? (locale === 'en' ? 0 : 1);
|
|
27
|
+
const time = mode === 'datetime' ? parseDateTimeValue(value) : null;
|
|
28
|
+
const selected = mode === 'datetime' ? time : parseDateValue(value);
|
|
29
|
+
const selectedDate = selected ? { year: selected.year, month: selected.month, day: selected.day } : null;
|
|
30
|
+
const [open, setOpen] = useState(false);
|
|
31
|
+
const [focus, setFocus] = useState(() => clampDate(selectedDate ?? fromDate(new Date()), min, max));
|
|
32
|
+
const [hourText, setHourText] = useState('');
|
|
33
|
+
const [minuteText, setMinuteText] = useState('');
|
|
34
|
+
const gridRef = useRef(null);
|
|
35
|
+
const moveFocus = useRef(false);
|
|
36
|
+
const titleId = useId();
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!open)
|
|
39
|
+
return;
|
|
40
|
+
setFocus(clampDate(selectedDate ?? fromDate(new Date()), min, max));
|
|
41
|
+
setHourText(pad(time?.hour ?? 0));
|
|
42
|
+
setMinuteText(pad(time?.minute ?? 0));
|
|
43
|
+
}, [open]); // only on open: the value is read, not tracked
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!open || !moveFocus.current)
|
|
46
|
+
return;
|
|
47
|
+
moveFocus.current = false;
|
|
48
|
+
gridRef.current?.querySelector(`[data-date="${formatDateValue(focus)}"]`)?.focus();
|
|
49
|
+
}, [focus, open]);
|
|
50
|
+
const weeks = useMemo(() => calendarMonth(focus.year, focus.month, weekStart), [focus.year, focus.month, weekStart]);
|
|
51
|
+
const today = fromDate(new Date());
|
|
52
|
+
const monthTitle = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'long' }).format(new Date(focus.year, focus.month - 1, 1));
|
|
53
|
+
const dayLabel = new Intl.DateTimeFormat(locale, { dateStyle: 'full' });
|
|
54
|
+
const weekdayName = new Intl.DateTimeFormat(locale, { weekday: locale === 'en' ? 'short' : 'narrow' });
|
|
55
|
+
const weekdayFull = new Intl.DateTimeFormat(locale, { weekday: 'long' });
|
|
56
|
+
const emit = (date, hour = time?.hour ?? 0, minute = time?.minute ?? 0) => {
|
|
57
|
+
onValueChange(mode === 'datetime' ? formatDateTimeValue({ ...date, hour, minute }) : formatDateValue(date));
|
|
58
|
+
};
|
|
59
|
+
const pick = (date) => {
|
|
60
|
+
if (!isWithin(date, min, max))
|
|
61
|
+
return;
|
|
62
|
+
if (mode === 'datetime') {
|
|
63
|
+
emit(date, clampTimePart(hourText, 23) ?? 0, clampTimePart(minuteText, 59) ?? 0);
|
|
64
|
+
setFocus(date);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
emit(date);
|
|
68
|
+
setOpen(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const go = (next) => {
|
|
72
|
+
moveFocus.current = true;
|
|
73
|
+
setFocus(clampDate(next, min, max));
|
|
74
|
+
};
|
|
75
|
+
const onGridKeyDown = (event) => {
|
|
76
|
+
const step = {
|
|
77
|
+
ArrowLeft: () => addDays(focus, -1),
|
|
78
|
+
ArrowRight: () => addDays(focus, 1),
|
|
79
|
+
ArrowUp: () => addDays(focus, -7),
|
|
80
|
+
ArrowDown: () => addDays(focus, 7),
|
|
81
|
+
Home: () => startOfWeek(focus, weekStart),
|
|
82
|
+
End: () => addDays(startOfWeek(focus, weekStart), 6),
|
|
83
|
+
PageUp: () => addMonths(focus, event.shiftKey ? -12 : -1),
|
|
84
|
+
PageDown: () => addMonths(focus, event.shiftKey ? 12 : 1),
|
|
85
|
+
};
|
|
86
|
+
const next = step[event.key];
|
|
87
|
+
if (!next)
|
|
88
|
+
return;
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
go(next());
|
|
91
|
+
};
|
|
92
|
+
const commitTime = (hourInput = hourText, minuteInput = minuteText) => {
|
|
93
|
+
const hour = clampTimePart(hourInput, 23);
|
|
94
|
+
const minute = clampTimePart(minuteInput, 59);
|
|
95
|
+
setHourText(pad(hour ?? time?.hour ?? 0));
|
|
96
|
+
setMinuteText(pad(minute ?? time?.minute ?? 0));
|
|
97
|
+
if (hour === null || minute === null)
|
|
98
|
+
return;
|
|
99
|
+
emit(selectedDate ?? focus, hour, minute);
|
|
100
|
+
};
|
|
101
|
+
const timeKeyDown = (part) => (event) => {
|
|
102
|
+
if (event.key === 'Enter') {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
commitTime();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown')
|
|
108
|
+
return;
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
const limit = part === 'hour' ? 24 : 60;
|
|
111
|
+
const current = clampTimePart(part === 'hour' ? hourText : minuteText, limit - 1) ?? 0;
|
|
112
|
+
const next = pad((current + (event.key === 'ArrowUp' ? 1 : -1) + limit) % limit);
|
|
113
|
+
if (part === 'hour') {
|
|
114
|
+
setHourText(next);
|
|
115
|
+
commitTime(next, minuteText);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
setMinuteText(next);
|
|
119
|
+
commitTime(hourText, next);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const setNow = () => {
|
|
123
|
+
const now = new Date();
|
|
124
|
+
const date = clampDate(fromDate(now), min, max);
|
|
125
|
+
if (mode === 'datetime') {
|
|
126
|
+
emit(date, now.getHours(), now.getMinutes());
|
|
127
|
+
setHourText(pad(now.getHours()));
|
|
128
|
+
setMinuteText(pad(now.getMinutes()));
|
|
129
|
+
go(date);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
emit(date);
|
|
133
|
+
setOpen(false);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const clear = () => {
|
|
137
|
+
onValueChange('');
|
|
138
|
+
setOpen(false);
|
|
139
|
+
};
|
|
140
|
+
const display = selectedDate
|
|
141
|
+
? mode === 'datetime' && time ? `${formatDateValue(selectedDate)} ${pad(time.hour)}:${pad(time.minute)}` : formatDateValue(selectedDate)
|
|
142
|
+
: null;
|
|
143
|
+
const canClear = clearable && !disabled && Boolean(value);
|
|
144
|
+
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsxs("div", { className: cn('console-date-field', className), "data-variant": variant === 'ghost' ? 'ghost' : undefined, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, disabled: disabled, "aria-haspopup": "dialog", "data-slot": "input", className: "console-control console-date-field-trigger", onKeyDown: event => {
|
|
145
|
+
if (canClear && (event.key === 'Delete' || event.key === 'Backspace')) {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
clear();
|
|
148
|
+
}
|
|
149
|
+
else if (event.key === 'ArrowDown' && !open) {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
setOpen(true);
|
|
152
|
+
}
|
|
153
|
+
}, ...aria, children: [_jsx(Calendar, { "aria-hidden": "true", strokeWidth: CONSOLE_ICON_STROKE_WIDTH, className: "console-date-field-icon" }), _jsx("span", { className: cn('console-date-field-value', !display && 'is-placeholder'), children: display ?? placeholder ?? i18n.t(mode === 'datetime' ? 'date.placeholderDateTime' : 'date.placeholder') }), canClear ? _jsx("span", { "aria-hidden": "true", className: "console-date-field-spacer" }) : null] }) }), canClear ? (_jsx("button", { type: "button", className: "console-date-field-clear console-touch", "aria-label": i18n.t('date.clear'), onClick: clear, children: _jsx(X, { "aria-hidden": "true", strokeWidth: CONSOLE_ICON_STROKE_WIDTH }) })) : null] }), _jsxs(PopoverContent, { className: "console-date-popover", sideOffset: 4, "aria-labelledby": titleId, onOpenAutoFocus: event => { event.preventDefault(); moveFocus.current = true; setFocus(current => ({ ...current })); }, children: [_jsxs("div", { className: "console-date-header", children: [_jsx(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": i18n.t('date.prevMonth'), onClick: () => setFocus(clampDate(addMonths(focus, -1), min, max)), children: _jsx(ChevronLeft, { "aria-hidden": "true", strokeWidth: CONSOLE_ICON_STROKE_WIDTH }) }), _jsx("p", { id: titleId, className: "console-date-title", "aria-live": "polite", children: monthTitle }), _jsx(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": i18n.t('date.nextMonth'), onClick: () => setFocus(clampDate(addMonths(focus, 1), min, max)), children: _jsx(ChevronRight, { "aria-hidden": "true", strokeWidth: CONSOLE_ICON_STROKE_WIDTH }) })] }), _jsxs("div", { ref: gridRef, role: "grid", "aria-labelledby": titleId, className: "console-date-grid", onKeyDown: onGridKeyDown, children: [_jsx("div", { role: "row", className: "console-date-row", children: weeks[0].map(day => (_jsx("span", { role: "columnheader", className: "console-date-weekday", "aria-label": weekdayFull.format(new Date(day.year, day.month - 1, day.day)), children: weekdayName.format(new Date(day.year, day.month - 1, day.day)) }, formatDateValue(day)))) }), weeks.map(week => (_jsx("div", { role: "row", className: "console-date-row", children: week.map(day => {
|
|
154
|
+
const iso = formatDateValue(day);
|
|
155
|
+
const inMonth = day.month === focus.month;
|
|
156
|
+
const enabled = isWithin(day, min, max);
|
|
157
|
+
const isSelected = sameDate(day, selectedDate);
|
|
158
|
+
return (_jsx("span", { role: "gridcell", "aria-selected": isSelected, children: _jsx("button", { type: "button", "data-date": iso, tabIndex: sameDate(day, focus) ? 0 : -1, disabled: !enabled, "aria-label": dayLabel.format(new Date(day.year, day.month - 1, day.day)), "aria-current": sameDate(day, today) ? 'date' : undefined, className: cn('console-date-day', !inMonth && 'is-outside', isSelected && 'is-selected', sameDate(day, today) && 'is-today'), onClick: () => pick(day), children: day.day }) }, iso));
|
|
159
|
+
}) }, formatDateValue(week[0]))))] }), mode === 'datetime' ? (_jsxs("div", { className: "console-date-time", children: [_jsx("span", { className: "console-date-time-label", children: i18n.t('date.time') }), _jsx(Input, { inputMode: "numeric", maxLength: 2, "aria-label": i18n.t('date.hour'), value: hourText, onChange: event => setHourText(event.target.value), onBlur: () => commitTime(), onKeyDown: timeKeyDown('hour'), className: "console-date-time-input" }), _jsx("span", { "aria-hidden": "true", children: ":" }), _jsx(Input, { inputMode: "numeric", maxLength: 2, "aria-label": i18n.t('date.minute'), value: minuteText, onChange: event => setMinuteText(event.target.value), onBlur: () => commitTime(), onKeyDown: timeKeyDown('minute'), className: "console-date-time-input" })] })) : null, _jsxs("div", { className: "console-date-footer", children: [_jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: setNow, children: i18n.t(mode === 'datetime' ? 'date.now' : 'date.today') }), _jsxs("span", { className: "console-date-footer-end", children: [canClear ? _jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: clear, children: i18n.t('date.clear') }) : null, mode === 'datetime' ? _jsx(Button, { type: "button", variant: "soft", size: "sm", onClick: () => { commitTime(); setOpen(false); }, children: i18n.t('date.done') }) : null] })] })] })] }));
|
|
160
|
+
});
|
|
161
|
+
CalendarField.displayName = 'CalendarField';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const DialogPrimitive: typeof Radix.Dialog;
|
|
4
|
+
declare const Dialog: React.FC<Radix.Dialog.DialogProps>;
|
|
5
|
+
declare const DialogTrigger: React.ForwardRefExoticComponent<Radix.Dialog.DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
6
|
+
declare const DialogPortal: React.FC<Radix.Dialog.DialogPortalProps>;
|
|
7
|
+
declare const DialogClose: React.ForwardRefExoticComponent<Radix.Dialog.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
|
|
8
|
+
declare const DialogOverlay: React.ForwardRefExoticComponent<Omit<Radix.Dialog.DialogOverlayProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
export interface DialogContentProps extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
|
|
10
|
+
variant?: "modal" | "drawer";
|
|
11
|
+
side?: "right" | "left" | "bottom";
|
|
12
|
+
}
|
|
13
|
+
declare const DialogContent: React.ForwardRefExoticComponent<DialogContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
declare const DialogHeader: {
|
|
15
|
+
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
16
|
+
displayName: string;
|
|
17
|
+
};
|
|
18
|
+
declare const DialogFooter: {
|
|
19
|
+
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
20
|
+
displayName: string;
|
|
21
|
+
};
|
|
22
|
+
declare const DialogTitle: React.ForwardRefExoticComponent<Omit<Radix.Dialog.DialogTitleProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
|
|
23
|
+
declare const DialogDescription: React.ForwardRefExoticComponent<Omit<Radix.Dialog.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>, "ref"> & React.RefAttributes<HTMLParagraphElement>>;
|
|
24
|
+
export { Dialog, DialogPortal, DialogOverlay, DialogTrigger, DialogClose, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ConsoleUiText } from '../../i18n/index.js';
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import * as Radix from "radix-ui";
|
|
5
|
+
const DialogPrimitive = Radix.Dialog;
|
|
6
|
+
import { cn } from '../../cn.js';
|
|
7
|
+
import { X } from "lucide-react";
|
|
8
|
+
import { CONSOLE_ICON_STROKE_WIDTH } from '../icon.js';
|
|
9
|
+
const Dialog = DialogPrimitive.Root;
|
|
10
|
+
const DialogTrigger = DialogPrimitive.Trigger;
|
|
11
|
+
const DialogPortal = DialogPrimitive.Portal;
|
|
12
|
+
const DialogClose = DialogPrimitive.Close;
|
|
13
|
+
const DialogOverlay = forwardRef(({ className, ...props }, ref) => (_jsx(DialogPrimitive.Overlay, { ref: ref, className: cn("console-dialog-overlay", className), ...props })));
|
|
14
|
+
DialogOverlay.displayName = "DialogOverlay";
|
|
15
|
+
const DialogContent = forwardRef(({ className, children, variant = "modal", side = "right", ...props }, ref) => (_jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsxs(DialogPrimitive.Content, { ref: ref, "data-side": variant === "drawer" ? side : undefined, "data-slot": variant === "drawer" ? "sheet" : "dialog", className: cn(variant === "drawer"
|
|
16
|
+
? "console-sheet-content outline-none"
|
|
17
|
+
: "console-dialog", className), ...props, children: [children, _jsxs(DialogPrimitive.Close, { className: "console-dialog-close disabled:pointer-events-none", children: [_jsx(X, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, className: "size-4" }), _jsx("span", { className: "sr-only", children: _jsx(ConsoleUiText, { id: "dialog.close" }) })] })] })] })));
|
|
18
|
+
DialogContent.displayName = "DialogContent";
|
|
19
|
+
const DialogHeader = ({ className, ...props }) => (_jsx("div", { className: cn("console-dialog-header", className), ...props }));
|
|
20
|
+
DialogHeader.displayName = "DialogHeader";
|
|
21
|
+
const DialogFooter = ({ className, ...props }) => (_jsx("div", { className: cn("console-dialog-footer", className), ...props }));
|
|
22
|
+
DialogFooter.displayName = "DialogFooter";
|
|
23
|
+
const DialogTitle = forwardRef(({ className, ...props }, ref) => (_jsx(DialogPrimitive.Title, { ref: ref, className: cn("console-section-title", className), ...props })));
|
|
24
|
+
DialogTitle.displayName = "DialogTitle";
|
|
25
|
+
const DialogDescription = forwardRef(({ className, ...props }, ref) => (_jsx(DialogPrimitive.Description, { ref: ref, className: cn("text-body text-muted-foreground", className), ...props })));
|
|
26
|
+
DialogDescription.displayName = "DialogDescription";
|
|
27
|
+
export { Dialog, DialogPortal, DialogOverlay, DialogTrigger, DialogClose, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const DropdownMenu: React.FC<Radix.DropdownMenu.DropdownMenuProps>;
|
|
4
|
+
declare const DropdownMenuTrigger: React.ForwardRefExoticComponent<Radix.DropdownMenu.DropdownMenuTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
+
declare const DropdownMenuGroup: React.ForwardRefExoticComponent<Radix.DropdownMenu.DropdownMenuGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
declare const DropdownMenuPortal: React.FC<Radix.DropdownMenu.DropdownMenuPortalProps>;
|
|
7
|
+
declare const DropdownMenuSub: React.FC<Radix.DropdownMenu.DropdownMenuSubProps>;
|
|
8
|
+
declare const DropdownMenuRadioGroup: React.ForwardRefExoticComponent<Radix.DropdownMenu.DropdownMenuRadioGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
declare const DropdownMenuContent: React.ForwardRefExoticComponent<Omit<Radix.DropdownMenu.DropdownMenuContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
declare const DropdownMenuItem: React.ForwardRefExoticComponent<Omit<Radix.DropdownMenu.DropdownMenuItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
|
|
11
|
+
inset?: boolean;
|
|
12
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
13
|
+
declare const DropdownMenuCheckboxItem: React.ForwardRefExoticComponent<Omit<Radix.DropdownMenu.DropdownMenuCheckboxItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
declare const DropdownMenuRadioItem: React.ForwardRefExoticComponent<Omit<Radix.DropdownMenu.DropdownMenuRadioItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
declare const DropdownMenuLabel: React.ForwardRefExoticComponent<Omit<Radix.DropdownMenu.DropdownMenuLabelProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
|
|
16
|
+
inset?: boolean;
|
|
17
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
18
|
+
declare const DropdownMenuSeparator: React.ForwardRefExoticComponent<Omit<Radix.DropdownMenu.DropdownMenuSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
19
|
+
export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuRadioGroup, DropdownMenuRadioItem, };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import * as Radix from "radix-ui";
|
|
4
|
+
const DropdownMenuPrimitive = Radix.DropdownMenu;
|
|
5
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
import { Check, Circle } from "lucide-react";
|
|
7
|
+
import { CONSOLE_ICON_STROKE_WIDTH } from '../icon.js';
|
|
8
|
+
const DropdownMenu = DropdownMenuPrimitive.Root;
|
|
9
|
+
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
|
10
|
+
const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
|
11
|
+
const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
|
12
|
+
const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
|
13
|
+
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
14
|
+
const DropdownMenuContent = forwardRef(({ className, sideOffset = 4, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Portal, { children: _jsx(DropdownMenuPrimitive.Content, { ref: ref, "data-slot": "popover", sideOffset: sideOffset, className: cn("console-popover min-w-40", className), ...props }) })));
|
|
15
|
+
DropdownMenuContent.displayName = "DropdownMenuContent";
|
|
16
|
+
const DropdownMenuItem = forwardRef(({ className, inset, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Item, { ref: ref, className: cn("console-menu-item relative flex cursor-default select-none items-center gap-2 px-3 py-1 text-body outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0", inset && "pl-8", className), ...props })));
|
|
17
|
+
DropdownMenuItem.displayName = "DropdownMenuItem";
|
|
18
|
+
const DropdownMenuCheckboxItem = forwardRef(({ className, children, checked, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.CheckboxItem, { ref: ref, className: cn("console-menu-item relative flex cursor-default select-none items-center py-1 pl-8 pr-3 text-body outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className), checked: checked, ...props, children: [_jsx("span", { className: "absolute left-2 flex size-4 items-center justify-center", children: _jsx(DropdownMenuPrimitive.ItemIndicator, { children: _jsx(Check, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, className: "size-4" }) }) }), children] })));
|
|
19
|
+
DropdownMenuCheckboxItem.displayName = "DropdownMenuCheckboxItem";
|
|
20
|
+
const DropdownMenuRadioItem = forwardRef(({ className, children, ...props }, ref) => (_jsxs(DropdownMenuPrimitive.RadioItem, { ref: ref, className: cn("console-menu-item relative flex cursor-default select-none items-center gap-2 py-1 pl-8 pr-3 text-body outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0", className), ...props, children: [_jsx("span", { className: "absolute left-2 flex size-4 items-center justify-center", children: _jsx(DropdownMenuPrimitive.ItemIndicator, { children: _jsx(Circle, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, className: "size-2 fill-current" }) }) }), children] })));
|
|
21
|
+
DropdownMenuRadioItem.displayName = "DropdownMenuRadioItem";
|
|
22
|
+
const DropdownMenuLabel = forwardRef(({ className, inset, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Label, { ref: ref, className: cn("px-3 py-1 text-label font-strong text-muted-foreground", inset && "pl-8", className), ...props })));
|
|
23
|
+
DropdownMenuLabel.displayName = "DropdownMenuLabel";
|
|
24
|
+
const DropdownMenuSeparator = forwardRef(({ className, ...props }, ref) => (_jsx(DropdownMenuPrimitive.Separator, { ref: ref, className: cn("-mx-1 my-1 h-px bg-muted", className), ...props })));
|
|
25
|
+
DropdownMenuSeparator.displayName = "DropdownMenuSeparator";
|
|
26
|
+
export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuRadioGroup, DropdownMenuRadioItem, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { type ControlVariant } from './control-variant.js';
|
|
3
|
+
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
4
|
+
/** `ghost`: no border until hovered or focused, for secondary fields (ADR 0063 D29). */
|
|
5
|
+
variant?: ControlVariant;
|
|
6
|
+
}
|
|
7
|
+
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
8
|
+
export { Input };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cn } from '../../cn.js';
|
|
4
|
+
import { controlVariantClass } from './control-variant.js';
|
|
5
|
+
const Input = forwardRef(({ className, type, variant, ...props }, ref) => {
|
|
6
|
+
return (_jsx("input", { type: type, "data-slot": "input", "data-variant": variant === 'ghost' ? 'ghost' : undefined, className: cn("console-control flex h-control w-full rounded-control border px-3 py-1 text-body transition-colors file:border-0 file:bg-transparent file:text-body file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-60", controlVariantClass(variant), className), ref: ref, ...props }));
|
|
7
|
+
});
|
|
8
|
+
Input.displayName = "Input";
|
|
9
|
+
export { Input };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Internal building block for list rows, side-nav items and selectable cards that are
|
|
4
|
+
* buttons but not "actions" (use `Button` for those). It supplies the shared behaviours
|
|
5
|
+
* every such row needs - `type="button"`, a visible focus ring and a 44px tap target
|
|
6
|
+
* below 768px - while the caller's own class owns the visual layout.
|
|
7
|
+
*/
|
|
8
|
+
export type ListItemButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
9
|
+
declare const ListItemButton: React.ForwardRefExoticComponent<ListItemButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
10
|
+
export { ListItemButton };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cn } from '../../cn.js';
|
|
4
|
+
const ListItemButton = forwardRef(({ className, type = "button", ...props }, ref) => (_jsx("button", { ref: ref, type: type, className: cn("cursor-pointer text-left min-h-touch-min disabled:cursor-not-allowed disabled:opacity-50", className), ...props })));
|
|
5
|
+
ListItemButton.displayName = "ListItemButton";
|
|
6
|
+
export { ListItemButton };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { Popover as Primitive } from 'radix-ui';
|
|
3
|
+
export declare const Popover: React.FC<Primitive.PopoverProps>;
|
|
4
|
+
export declare const PopoverTrigger: React.ForwardRefExoticComponent<Primitive.PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
+
export declare const PopoverAnchor: React.ForwardRefExoticComponent<Primitive.PopoverAnchorProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export declare const PopoverContent: React.ForwardRefExoticComponent<Omit<Primitive.PopoverContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { Popover as Primitive } from 'radix-ui';
|
|
4
|
+
import { cn } from '../../cn.js';
|
|
5
|
+
export const Popover = Primitive.Root;
|
|
6
|
+
export const PopoverTrigger = Primitive.Trigger;
|
|
7
|
+
export const PopoverAnchor = Primitive.Anchor;
|
|
8
|
+
export const PopoverContent = forwardRef(({ className, align = 'start', sideOffset = 8, ...props }, ref) => _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { ref: ref, "data-slot": "popover", align: align, sideOffset: sideOffset, collisionPadding: 12, className: cn('console-popover console-popover--panel', className), ...props }) }));
|
|
9
|
+
PopoverContent.displayName = 'PopoverContent';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<Omit<Radix.RadioGroup.RadioGroupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
declare const RadioGroupItem: React.ForwardRefExoticComponent<Omit<Radix.RadioGroup.RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
+
export { RadioGroup, RadioGroupItem };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import * as Radix from "radix-ui";
|
|
4
|
+
import { cn } from '../../cn.js';
|
|
5
|
+
const RadioGroupPrimitive = Radix.RadioGroup;
|
|
6
|
+
const RadioGroup = forwardRef(({ className, ...props }, ref) => (_jsx(RadioGroupPrimitive.Root, { className: cn("grid gap-2", className), ...props, ref: ref })));
|
|
7
|
+
RadioGroup.displayName = "RadioGroup";
|
|
8
|
+
const RadioGroupItem = forwardRef(({ className, ...props }, ref) => (_jsx(RadioGroupPrimitive.Item, { ref: ref, className: cn("console-control console-touch aspect-square size-4 shrink-0 rounded-full border border-input bg-card text-brand-text transition-colors disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-brand-text", className), ...props, children: _jsx(RadioGroupPrimitive.Indicator, { className: "flex items-center justify-center", children: _jsx("span", { className: "h-2 w-2 rounded-full bg-current" }) }) })));
|
|
9
|
+
RadioGroupItem.displayName = "RadioGroupItem";
|
|
10
|
+
export { RadioGroup, RadioGroupItem };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const ScrollArea: React.ForwardRefExoticComponent<Omit<Radix.ScrollArea.ScrollAreaProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
declare const ScrollBar: React.ForwardRefExoticComponent<Omit<Radix.ScrollArea.ScrollAreaScrollbarProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
5
|
+
export { ScrollArea, ScrollBar };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import * as Radix from "radix-ui";
|
|
4
|
+
const ScrollAreaPrimitive = Radix.ScrollArea;
|
|
5
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
const ScrollArea = forwardRef(({ className, children, ...props }, ref) => (_jsxs(ScrollAreaPrimitive.Root, { ref: ref, className: cn("relative overflow-hidden", className), ...props, children: [_jsx(ScrollAreaPrimitive.Viewport, { className: "h-full w-full rounded-[inherit]", children: children }), _jsx(ScrollBar, {}), _jsx(ScrollAreaPrimitive.Corner, {})] })));
|
|
7
|
+
ScrollArea.displayName = "ScrollArea";
|
|
8
|
+
const ScrollBar = forwardRef(({ className, orientation: orientationProp, ...props }, ref) => {
|
|
9
|
+
const orientation = (orientationProp ?? "vertical");
|
|
10
|
+
return (_jsx(ScrollAreaPrimitive.Scrollbar, { ref: ref, orientation: orientation, className: cn("flex touch-none select-none transition-colors", orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-px", orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-px", className), ...props, children: _jsx(ScrollAreaPrimitive.Thumb, { className: "relative flex-1 rounded-full bg-border" }) }));
|
|
11
|
+
});
|
|
12
|
+
ScrollBar.displayName = "ScrollBar";
|
|
13
|
+
export { ScrollArea, ScrollBar };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Pure part of SearchableSelectField: which options a query keeps and how they are grouped.
|
|
4
|
+
* Groups appear in the order their first option appears; ungrouped options (such as 「未设置」)
|
|
5
|
+
* come first and are never filtered out, so clearing a choice stays one click away.
|
|
6
|
+
*/
|
|
7
|
+
export interface SearchableSelectOption {
|
|
8
|
+
value: string;
|
|
9
|
+
label: ReactNode;
|
|
10
|
+
/** Heading the option is listed under; omitted for top-level choices such as 「未设置」. */
|
|
11
|
+
group?: string;
|
|
12
|
+
/** Secondary line under the label (e.g. `model · account`). */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** Extra text the search box matches (the label is used when it is a string). */
|
|
15
|
+
keywords?: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface SearchableSelectGroup<T extends SearchableSelectOption = SearchableSelectOption> {
|
|
19
|
+
group: string | null;
|
|
20
|
+
options: T[];
|
|
21
|
+
}
|
|
22
|
+
/** Text a query is matched against: explicit keywords, else a string label, plus value, description and group. */
|
|
23
|
+
export declare function optionSearchText(option: SearchableSelectOption): string;
|
|
24
|
+
/** Every whitespace-separated term must appear somewhere in the option's search text. */
|
|
25
|
+
export declare function optionMatches(option: SearchableSelectOption, query: string): boolean;
|
|
26
|
+
/** `[{ group: string | null, options }]` for the options matching `query`; empty groups are dropped. */
|
|
27
|
+
export declare function groupSelectOptions<T extends SearchableSelectOption>(options: readonly T[], query?: string): SearchableSelectGroup<T>[];
|
|
28
|
+
/** Values in display order, for arrow-key movement (disabled options are skipped). */
|
|
29
|
+
export declare function navigableValues(grouped: readonly SearchableSelectGroup[]): string[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const normalize = (value) => String(value ?? '').normalize('NFKC').toLocaleLowerCase();
|
|
2
|
+
/** Text a query is matched against: explicit keywords, else a string label, plus value, description and group. */
|
|
3
|
+
export function optionSearchText(option) {
|
|
4
|
+
const label = typeof option.label === 'string' ? option.label : '';
|
|
5
|
+
return normalize([option.keywords ?? '', label, option.value, option.description ?? '', option.group ?? ''].join(' '));
|
|
6
|
+
}
|
|
7
|
+
/** Every whitespace-separated term must appear somewhere in the option's search text. */
|
|
8
|
+
export function optionMatches(option, query) {
|
|
9
|
+
const terms = normalize(query).split(/\s+/u).filter(Boolean);
|
|
10
|
+
if (!terms.length)
|
|
11
|
+
return true;
|
|
12
|
+
const text = optionSearchText(option);
|
|
13
|
+
return terms.every(term => text.includes(term));
|
|
14
|
+
}
|
|
15
|
+
/** `[{ group: string | null, options }]` for the options matching `query`; empty groups are dropped. */
|
|
16
|
+
export function groupSelectOptions(options, query = '') {
|
|
17
|
+
const groups = new Map();
|
|
18
|
+
const loose = [];
|
|
19
|
+
for (const option of options) {
|
|
20
|
+
if (!option.group) {
|
|
21
|
+
if (!query || option.value === '' || optionMatches(option, query))
|
|
22
|
+
loose.push(option);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (!groups.has(option.group))
|
|
26
|
+
groups.set(option.group, []);
|
|
27
|
+
if (optionMatches(option, query))
|
|
28
|
+
groups.get(option.group).push(option);
|
|
29
|
+
}
|
|
30
|
+
return [
|
|
31
|
+
...(loose.length ? [{ group: null, options: loose }] : []),
|
|
32
|
+
...[...groups].filter(([, items]) => items.length).map(([group, items]) => ({ group, options: items })),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
/** Values in display order, for arrow-key movement (disabled options are skipped). */
|
|
36
|
+
export function navigableValues(grouped) {
|
|
37
|
+
return grouped.flatMap(entry => entry.options.filter(option => !option.disabled).map(option => option.value));
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { ControlVariant } from './control-variant.js';
|
|
3
|
+
import { type SearchableSelectOption } from './searchable-select-model.js';
|
|
4
|
+
export type { SearchableSelectOption };
|
|
5
|
+
export interface SearchableSelectFieldProps {
|
|
6
|
+
options: readonly SearchableSelectOption[];
|
|
7
|
+
value: string;
|
|
8
|
+
onValueChange: (value: string) => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
'aria-label'?: string;
|
|
13
|
+
'aria-labelledby'?: string;
|
|
14
|
+
/** Placeholder of the search box. */
|
|
15
|
+
searchPlaceholder?: string;
|
|
16
|
+
/** Shown when nothing matches the search. */
|
|
17
|
+
emptyText?: string;
|
|
18
|
+
/** `ghost`: no border until hovered, focused or open, for secondary fields (ADR 0063 D29). */
|
|
19
|
+
variant?: ControlVariant;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A select for long lists: a popover with a search box and grouped options (combobox / listbox
|
|
23
|
+
* pattern). Same controlled contract as SelectField (`options` / `value` / `onValueChange`), plus
|
|
24
|
+
* `group`, `description` and `keywords` per option. ↑ / ↓ move, Enter picks, Esc closes.
|
|
25
|
+
*/
|
|
26
|
+
export declare const SearchableSelectField: React.ForwardRefExoticComponent<SearchableSelectFieldProps & React.RefAttributes<HTMLButtonElement>>;
|