@zhin.js/console-ui 0.0.0-stage → 1.0.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 +9 -0
- package/LICENSE +21 -0
- package/README.md +88 -2
- package/dist/cn.d.ts +4 -0
- package/dist/cn.js +6 -0
- package/dist/components/InfoHint.d.ts +12 -0
- package/dist/components/InfoHint.js +12 -0
- package/dist/components/PageHeader.d.ts +11 -0
- package/dist/components/PageHeader.js +8 -0
- package/dist/components/PageShell.d.ts +11 -0
- package/dist/components/PageShell.js +8 -0
- package/dist/components/RefreshControl.d.ts +23 -0
- package/dist/components/RefreshControl.js +65 -0
- package/dist/components/StatCard.d.ts +27 -0
- package/dist/components/StatCard.js +27 -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 +71 -0
- package/dist/components/empty-state.d.ts +15 -0
- package/dist/components/empty-state.js +15 -0
- package/dist/components/error-alert.d.ts +15 -0
- package/dist/components/error-alert.js +22 -0
- package/dist/components/page-chrome.d.ts +41 -0
- package/dist/components/page-chrome.js +65 -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 +14 -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 +29 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/button.js +37 -0
- package/dist/components/ui/card.d.ts +11 -0
- package/dist/components/ui/card.js +16 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/checkbox.js +9 -0
- package/dist/components/ui/dialog.d.ts +24 -0
- package/dist/components/ui/dialog.js +26 -0
- package/dist/components/ui/dropdown-menu.d.ts +19 -0
- package/dist/components/ui/dropdown-menu.js +25 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.js +8 -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 +23 -0
- package/dist/components/ui/searchable-select.js +84 -0
- package/dist/components/ui/select.d.ts +23 -0
- package/dist/components/ui/select.js +37 -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 +26 -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 +16 -0
- package/dist/components/ui/table.js +16 -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 +3 -0
- package/dist/components/ui/textarea.js +8 -0
- package/dist/components/ui/tooltip.d.ts +7 -0
- package/dist/components/ui/tooltip.js +11 -0
- package/dist/exports.json +138 -0
- package/dist/i18n/index.d.ts +27 -0
- package/dist/i18n/index.js +33 -0
- package/dist/i18n/messages.d.ts +36 -0
- package/dist/i18n/messages.js +72 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +44 -0
- package/dist/shared-module.d.ts +28 -0
- package/dist/shared-module.js +24 -0
- package/dist/styles.css +2316 -0
- package/dist/tokens.css +341 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +2 -0
- package/package.json +73 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Check, ChevronDown, Search } from 'lucide-react';
|
|
4
|
+
import { cn } from '../../cn.js';
|
|
5
|
+
import { useConsoleUiI18n } from '../../i18n/index.js';
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from './popover.js';
|
|
7
|
+
import { groupSelectOptions, navigableValues } from './searchable-select-model.js';
|
|
8
|
+
/**
|
|
9
|
+
* A select for long lists: a popover with a search box and grouped options (combobox / listbox
|
|
10
|
+
* pattern). Same controlled contract as SelectField (`options` / `value` / `onValueChange`), plus
|
|
11
|
+
* `group`, `description` and `keywords` per option. ↑ / ↓ move, Enter picks, Esc closes.
|
|
12
|
+
*/
|
|
13
|
+
export const SearchableSelectField = forwardRef(({ options, value, onValueChange, disabled, className, id, searchPlaceholder, emptyText, ...aria }, ref) => {
|
|
14
|
+
const i18n = useConsoleUiI18n();
|
|
15
|
+
const listId = useId();
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
const [query, setQuery] = useState('');
|
|
18
|
+
const [active, setActive] = useState(null);
|
|
19
|
+
const listRef = useRef(null);
|
|
20
|
+
const selected = options.find(option => option.value === value);
|
|
21
|
+
const grouped = useMemo(() => groupSelectOptions(options, query), [options, query]);
|
|
22
|
+
const order = useMemo(() => navigableValues(grouped), [grouped]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!open) {
|
|
25
|
+
setQuery('');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setActive(order.includes(value) ? value : order[0] ?? null);
|
|
29
|
+
}, [open]); // only on open / close: active and order are read, not tracked
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (open && (active === null || !order.includes(active)))
|
|
32
|
+
setActive(order[0] ?? null);
|
|
33
|
+
}, [order]); // only when the visible options change
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!open || active === null)
|
|
36
|
+
return;
|
|
37
|
+
// The list mounts with the popover: wait a frame so the chosen option can be scrolled into view.
|
|
38
|
+
const frame = requestAnimationFrame(() => {
|
|
39
|
+
listRef.current?.querySelector(`[data-value="${CSS.escape(active)}"]`)?.scrollIntoView({ block: 'nearest' });
|
|
40
|
+
});
|
|
41
|
+
return () => cancelAnimationFrame(frame);
|
|
42
|
+
}, [active, open]);
|
|
43
|
+
const pick = (next) => {
|
|
44
|
+
onValueChange(next);
|
|
45
|
+
setOpen(false);
|
|
46
|
+
};
|
|
47
|
+
const move = (step) => {
|
|
48
|
+
if (!order.length)
|
|
49
|
+
return;
|
|
50
|
+
const index = active === null ? -1 : order.indexOf(active);
|
|
51
|
+
setActive(order[(index + step + order.length) % order.length]);
|
|
52
|
+
};
|
|
53
|
+
const onKeyDown = (event) => {
|
|
54
|
+
if (event.key === 'ArrowDown') {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
move(1);
|
|
57
|
+
}
|
|
58
|
+
else if (event.key === 'ArrowUp') {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
move(-1);
|
|
61
|
+
}
|
|
62
|
+
else if (event.key === 'Home') {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
setActive(order[0] ?? null);
|
|
65
|
+
}
|
|
66
|
+
else if (event.key === 'End') {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
setActive(order[order.length - 1] ?? null);
|
|
69
|
+
}
|
|
70
|
+
else if (event.key === 'Enter') {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
if (active !== null)
|
|
73
|
+
pick(active);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const optionId = (optionValue) => `${listId}-${order.indexOf(optionValue)}`;
|
|
77
|
+
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, role: "combobox", "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": open ? listId : undefined, disabled: disabled, className: cn('console-control console-searchable-select-trigger', className), ...aria, children: [_jsx("span", { className: "console-searchable-select-value", children: selected ? selected.label : value }), _jsx(ChevronDown, { "aria-hidden": "true", className: "console-searchable-select-chevron" })] }) }), _jsxs(PopoverContent, { className: "console-searchable-select-popover", sideOffset: 4, onOpenAutoFocus: event => event.preventDefault(), children: [_jsxs("div", { className: "console-searchable-select-search", children: [_jsx(Search, { "aria-hidden": "true" }), _jsx("input", { autoFocus: true, value: query, onChange: event => setQuery(event.target.value), onKeyDown: onKeyDown, placeholder: searchPlaceholder ?? i18n.t('select.searchPlaceholder'), "aria-label": searchPlaceholder ?? i18n.t('select.searchPlaceholder'), "aria-controls": listId, "aria-activedescendant": active !== null && order.includes(active) ? optionId(active) : undefined, "aria-autocomplete": "list", role: "combobox", "aria-expanded": "true" })] }), _jsx("div", { ref: listRef, id: listId, role: "listbox", "aria-label": aria['aria-label'], className: "console-searchable-select-list", children: grouped.length ? grouped.map(entry => {
|
|
78
|
+
const items = entry.options.map(option => (_jsxs("div", { id: option.disabled ? undefined : optionId(option.value), role: "option", "data-value": option.value, "aria-selected": option.value === value, "aria-disabled": option.disabled || undefined, className: cn('console-searchable-select-option', option.value === active && 'is-active', option.value === value && 'is-selected'), onMouseMove: () => { if (!option.disabled && active !== option.value)
|
|
79
|
+
setActive(option.value); }, onMouseDown: event => event.preventDefault(), onClick: () => { if (!option.disabled)
|
|
80
|
+
pick(option.value); }, title: typeof option.label === 'string' ? option.label : undefined, children: [_jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "console-searchable-select-label", children: option.label }), option.description ? _jsx("span", { className: "console-searchable-select-description", children: option.description }) : null] }), option.value === value ? _jsx(Check, { "aria-hidden": "true", className: "console-searchable-select-check" }) : null] }, option.value)));
|
|
81
|
+
return entry.group === null ? _jsx("div", { role: "group", children: items }, "__top") : (_jsxs("div", { role: "group", "aria-label": entry.group, className: "console-searchable-select-group", children: [_jsxs("div", { className: "console-searchable-select-group-label", "aria-hidden": "true", children: [entry.group, _jsx("span", { children: entry.options.length })] }), items] }, entry.group));
|
|
82
|
+
}) : _jsx("p", { className: "console-searchable-select-empty", children: emptyText ?? i18n.t('select.noMatch') }) })] })] }));
|
|
83
|
+
});
|
|
84
|
+
SearchableSelectField.displayName = 'SearchableSelectField';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const Select: React.FC<Radix.Select.SelectProps>;
|
|
4
|
+
declare const SelectGroup: React.ForwardRefExoticComponent<Radix.Select.SelectGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
5
|
+
declare const SelectValue: React.ForwardRefExoticComponent<Radix.Select.SelectValueProps & React.RefAttributes<HTMLSpanElement>>;
|
|
6
|
+
declare const SelectTrigger: React.ForwardRefExoticComponent<Omit<Radix.Select.SelectTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
7
|
+
declare const SelectScrollUpButton: React.ForwardRefExoticComponent<Omit<Radix.Select.SelectScrollUpButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
declare const SelectScrollDownButton: React.ForwardRefExoticComponent<Omit<Radix.Select.SelectScrollDownButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
declare const SelectContent: React.ForwardRefExoticComponent<Omit<Radix.Select.SelectContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
declare const SelectItem: React.ForwardRefExoticComponent<Omit<Radix.Select.SelectItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
declare const SelectSeparator: React.ForwardRefExoticComponent<Omit<Radix.Select.SelectSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
+
export interface SelectFieldOption {
|
|
13
|
+
value: string;
|
|
14
|
+
label: React.ReactNode;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface SelectFieldProps extends Omit<React.ComponentPropsWithoutRef<typeof SelectTrigger>, "value" | "defaultValue" | "onChange" | "children" | "asChild" | "name"> {
|
|
18
|
+
options: readonly SelectFieldOption[];
|
|
19
|
+
value: string;
|
|
20
|
+
onValueChange: (value: string) => void;
|
|
21
|
+
}
|
|
22
|
+
declare const SelectField: React.ForwardRefExoticComponent<SelectFieldProps & React.RefAttributes<HTMLButtonElement>>;
|
|
23
|
+
export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton, SelectField, };
|
|
@@ -0,0 +1,37 @@
|
|
|
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 SelectPrimitive = Radix.Select;
|
|
5
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
import { Check, ChevronDown, ChevronUp } from "lucide-react";
|
|
7
|
+
const Select = SelectPrimitive.Root;
|
|
8
|
+
const SelectGroup = SelectPrimitive.Group;
|
|
9
|
+
const SelectValue = SelectPrimitive.Value;
|
|
10
|
+
const SelectTrigger = forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Trigger, { ref: ref, className: cn("console-control flex h-[var(--console-control-height)] w-full items-center justify-between whitespace-nowrap rounded-[var(--console-radius-md)] border-[length:var(--console-border-width)] border-input bg-card hover:border-[hsl(var(--foreground)/0.45)] focus-visible:border-[hsl(var(--primary))] shadow-[var(--console-shadow-xs)] px-3 py-2 text-[length:var(--console-text-body)] ring-offset-background placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60 [&>span]:line-clamp-1", className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(ChevronDown, { className: "h-4 w-4 opacity-50" }) })] })));
|
|
11
|
+
SelectTrigger.displayName = "SelectTrigger";
|
|
12
|
+
const SelectScrollUpButton = forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.ScrollUpButton, { ref: ref, className: cn("flex cursor-default items-center justify-center py-1", className), ...props, children: _jsx(ChevronUp, { className: "h-4 w-4" }) })));
|
|
13
|
+
SelectScrollUpButton.displayName = "SelectScrollUpButton";
|
|
14
|
+
const SelectScrollDownButton = forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.ScrollDownButton, { ref: ref, className: cn("flex cursor-default items-center justify-center py-1", className), ...props, children: _jsx(ChevronDown, { className: "h-4 w-4" }) })));
|
|
15
|
+
SelectScrollDownButton.displayName = "SelectScrollDownButton";
|
|
16
|
+
const SelectContent = forwardRef(({ className, children, position: positionProp, ...props }, ref) => {
|
|
17
|
+
const position = (positionProp ?? "popper");
|
|
18
|
+
return (_jsx(SelectPrimitive.Portal, { children: _jsxs(SelectPrimitive.Content, { ref: ref, className: cn("relative z-50 max-h-[min(24rem,var(--radix-select-content-available-height,calc(100dvh-1rem)))] min-w-[8rem] max-w-[calc(100vw-1rem)] overflow-hidden rounded-[var(--console-radius-lg)] border-[length:var(--console-border-width)] border-border bg-popover text-popover-foreground shadow-[var(--console-shadow-md)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", position === "popper" &&
|
|
19
|
+
"w-[var(--radix-select-trigger-width)]", className), position: position, collisionPadding: 8, sideOffset: 4, ...props, children: [_jsx(SelectScrollUpButton, {}), _jsx(SelectPrimitive.Viewport, { className: cn("min-h-0 w-full min-w-0 overflow-y-auto overscroll-contain p-1"), children: children }), _jsx(SelectScrollDownButton, {})] }) }));
|
|
20
|
+
});
|
|
21
|
+
SelectContent.displayName = "SelectContent";
|
|
22
|
+
const SelectItem = forwardRef(({ className, children, value, ...props }, ref) => (_jsxs(SelectPrimitive.Item, { ref: ref, value: value, className: cn("console-menu-item relative flex w-full min-w-0 cursor-default select-none items-center rounded-[var(--console-radius-sm)] py-1.5 pl-2.5 pr-8 text-[length:var(--console-text-body)] leading-normal outline-none focus:bg-accent focus:text-accent-foreground data-[state=checked]:bg-primary/5 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>span:last-child]:min-w-0 [&>span:last-child]:truncate", className), ...props, children: [_jsx("span", { className: "absolute right-2 flex h-3.5 w-3.5 items-center justify-center text-primary", children: _jsx(SelectPrimitive.ItemIndicator, { children: _jsx(Check, { className: "h-4 w-4" }) }) }), _jsx(SelectPrimitive.ItemText, { children: children })] })));
|
|
23
|
+
SelectItem.displayName = "SelectItem";
|
|
24
|
+
const SelectSeparator = forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.Separator, { ref: ref, className: cn("-mx-1 my-1 h-px bg-muted", className), ...props })));
|
|
25
|
+
SelectSeparator.displayName = "SelectSeparator";
|
|
26
|
+
// Controlled UI only: Radix values are encoded, so native named-form submission is not exposed.
|
|
27
|
+
const SelectField = forwardRef(({ options, value, onValueChange, disabled, ...triggerProps }, ref) => {
|
|
28
|
+
const selected = options.find(option => option.value === value);
|
|
29
|
+
return (_jsxs(Select, { value: JSON.stringify(value), onValueChange: encoded => {
|
|
30
|
+
// Radix's hidden form control emits an empty sentinel for unmatched values.
|
|
31
|
+
const option = options.find(item => JSON.stringify(item.value) === encoded);
|
|
32
|
+
if (option)
|
|
33
|
+
onValueChange(option.value);
|
|
34
|
+
}, disabled: disabled, children: [_jsx(SelectTrigger, { ref: ref, disabled: disabled, ...triggerProps, children: _jsx(SelectValue, { children: selected ? selected.label : value }) }), _jsx(SelectContent, { children: options.map(option => (_jsx(SelectItem, { value: JSON.stringify(option.value), disabled: option.disabled, title: typeof option.label === "string" ? option.label : undefined, children: option.label }, option.value))) })] }));
|
|
35
|
+
});
|
|
36
|
+
SelectField.displayName = "SelectField";
|
|
37
|
+
export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton, SelectField, };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const Separator: React.ForwardRefExoticComponent<Omit<Radix.Separator.SeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
export { Separator };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import * as Radix from "radix-ui";
|
|
4
|
+
const SeparatorPrimitive = Radix.Separator;
|
|
5
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
const Separator = forwardRef(({ className, orientation: orientationProp, decorative = true, ...props }, ref) => {
|
|
7
|
+
const orientation = (orientationProp ?? "horizontal");
|
|
8
|
+
return (_jsx(SeparatorPrimitive.Root, { ref: ref, decorative: decorative, orientation: orientation, className: cn("shrink-0 bg-border", orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]", className), ...props }));
|
|
9
|
+
});
|
|
10
|
+
Separator.displayName = "Separator";
|
|
11
|
+
export { Separator };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const SheetPrimitive: typeof Radix.Dialog;
|
|
4
|
+
declare const Sheet: React.FC<Radix.Dialog.DialogProps>;
|
|
5
|
+
declare const SheetTrigger: React.ForwardRefExoticComponent<Radix.Dialog.DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
6
|
+
declare const SheetPortal: React.FC<Radix.Dialog.DialogPortalProps>;
|
|
7
|
+
declare const SheetClose: React.ForwardRefExoticComponent<Radix.Dialog.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
|
|
8
|
+
declare const SheetOverlay: React.ForwardRefExoticComponent<Omit<Radix.Dialog.DialogOverlayProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
export interface SheetContentProps extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content> {
|
|
10
|
+
side?: "right" | "left" | "bottom";
|
|
11
|
+
}
|
|
12
|
+
declare const SheetContent: React.ForwardRefExoticComponent<SheetContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
13
|
+
declare const SheetHeader: {
|
|
14
|
+
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
17
|
+
declare const SheetBody: {
|
|
18
|
+
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
19
|
+
displayName: string;
|
|
20
|
+
};
|
|
21
|
+
declare const SheetFooter: {
|
|
22
|
+
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
23
|
+
displayName: string;
|
|
24
|
+
};
|
|
25
|
+
declare const SheetTitle: React.ForwardRefExoticComponent<Omit<Radix.Dialog.DialogTitleProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
|
|
26
|
+
declare const SheetDescription: React.ForwardRefExoticComponent<Omit<Radix.Dialog.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>, "ref"> & React.RefAttributes<HTMLParagraphElement>>;
|
|
27
|
+
export { Sheet, SheetPortal, SheetOverlay, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetBody, SheetFooter, SheetTitle, SheetDescription, };
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
import { X } from "lucide-react";
|
|
7
|
+
const SheetPrimitive = Radix.Dialog;
|
|
8
|
+
const Sheet = SheetPrimitive.Root;
|
|
9
|
+
const SheetTrigger = SheetPrimitive.Trigger;
|
|
10
|
+
const SheetPortal = SheetPrimitive.Portal;
|
|
11
|
+
const SheetClose = SheetPrimitive.Close;
|
|
12
|
+
const SheetOverlay = forwardRef(({ className, ...props }, ref) => (_jsx(SheetPrimitive.Overlay, { ref: ref, className: cn("console-sheet-overlay data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", className), ...props })));
|
|
13
|
+
SheetOverlay.displayName = "SheetOverlay";
|
|
14
|
+
const SheetContent = forwardRef(({ side = "right", className, children, ...props }, ref) => (_jsxs(SheetPortal, { children: [_jsx(SheetOverlay, {}), _jsxs(SheetPrimitive.Content, { ref: ref, "data-side": side, className: cn("console-sheet-content outline-none", className), ...props, children: [children, _jsxs(SheetPrimitive.Close, { className: "console-dialog-close disabled:pointer-events-none", children: [_jsx(X, { className: "h-4 w-4" }), _jsx("span", { className: "sr-only", children: _jsx(ConsoleUiText, { id: "dialog.close" }) })] })] })] })));
|
|
15
|
+
SheetContent.displayName = "SheetContent";
|
|
16
|
+
const SheetHeader = ({ className, ...props }) => (_jsx("div", { className: cn("console-sheet-header", className), ...props }));
|
|
17
|
+
SheetHeader.displayName = "SheetHeader";
|
|
18
|
+
const SheetBody = ({ className, ...props }) => (_jsx("div", { className: cn("console-sheet-body", className), ...props }));
|
|
19
|
+
SheetBody.displayName = "SheetBody";
|
|
20
|
+
const SheetFooter = ({ className, ...props }) => (_jsx("div", { className: cn("console-sheet-footer", className), ...props }));
|
|
21
|
+
SheetFooter.displayName = "SheetFooter";
|
|
22
|
+
const SheetTitle = forwardRef(({ className, ...props }, ref) => (_jsx(SheetPrimitive.Title, { ref: ref, className: cn("console-section-title", className), ...props })));
|
|
23
|
+
SheetTitle.displayName = "SheetTitle";
|
|
24
|
+
const SheetDescription = forwardRef(({ className, ...props }, ref) => (_jsx(SheetPrimitive.Description, { ref: ref, className: cn("text-[length:var(--console-text-body)] text-muted-foreground", className), ...props })));
|
|
25
|
+
SheetDescription.displayName = "SheetDescription";
|
|
26
|
+
export { Sheet, SheetPortal, SheetOverlay, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetBody, SheetFooter, SheetTitle, SheetDescription, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import * as Radix from "radix-ui";
|
|
4
|
+
const SwitchPrimitive = Radix.Switch;
|
|
5
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
const Switch = forwardRef(({ className, ...props }, ref) => (_jsx(SwitchPrimitive.Root, { className: cn("console-control peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input", className), ...props, ref: ref, children: _jsx(SwitchPrimitive.Thumb, { className: cn("pointer-events-none block h-4 w-4 rounded-full bg-background transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0") }) })));
|
|
7
|
+
Switch.displayName = "Switch";
|
|
8
|
+
export { Switch };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
declare const Table: React.ForwardRefExoticComponent<React.TableHTMLAttributes<HTMLTableElement> & {
|
|
3
|
+
containerClassName?: string;
|
|
4
|
+
} & React.RefAttributes<HTMLTableElement>>;
|
|
5
|
+
declare const TableHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLTableSectionElement> & {
|
|
6
|
+
sticky?: boolean;
|
|
7
|
+
} & React.RefAttributes<HTMLTableSectionElement>>;
|
|
8
|
+
declare const TableBody: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLTableSectionElement> & React.RefAttributes<HTMLTableSectionElement>>;
|
|
9
|
+
declare const TableRow: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLTableRowElement> & React.RefAttributes<HTMLTableRowElement>>;
|
|
10
|
+
declare const TableHead: React.ForwardRefExoticComponent<React.ThHTMLAttributes<HTMLTableCellElement> & {
|
|
11
|
+
numeric?: boolean;
|
|
12
|
+
} & React.RefAttributes<HTMLTableCellElement>>;
|
|
13
|
+
declare const TableCell: React.ForwardRefExoticComponent<React.TdHTMLAttributes<HTMLTableCellElement> & {
|
|
14
|
+
numeric?: boolean;
|
|
15
|
+
} & React.RefAttributes<HTMLTableCellElement>>;
|
|
16
|
+
export { Table, TableHeader, TableBody, TableRow, TableHead, TableCell };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cn } from '../../cn.js';
|
|
4
|
+
const Table = forwardRef(({ className, containerClassName, ...props }, ref) => (_jsx("div", { className: cn("w-full max-w-full overflow-x-auto", containerClassName), children: _jsx("table", { ref: ref, className: cn("w-full border-collapse text-[length:var(--console-text-body-sm)]", className), ...props }) })));
|
|
5
|
+
Table.displayName = "Table";
|
|
6
|
+
const TableHeader = forwardRef(({ className, sticky, ...props }, ref) => (_jsx("thead", { ref: ref, className: cn(sticky && "sticky top-0 z-10 backdrop-blur-sm", className), ...props })));
|
|
7
|
+
TableHeader.displayName = "TableHeader";
|
|
8
|
+
const TableBody = forwardRef(({ className, ...props }, ref) => (_jsx("tbody", { ref: ref, className: className, ...props })));
|
|
9
|
+
TableBody.displayName = "TableBody";
|
|
10
|
+
const TableRow = forwardRef(({ className, ...props }, ref) => (_jsx("tr", { ref: ref, className: cn("border-b border-border/70 transition-colors last:border-0 hover:bg-[var(--console-surface-hover)]", className), ...props })));
|
|
11
|
+
TableRow.displayName = "TableRow";
|
|
12
|
+
const TableHead = forwardRef(({ className, numeric, scope = "col", ...props }, ref) => (_jsx("th", { ref: ref, scope: scope, className: cn("whitespace-nowrap border-b border-border bg-transparent px-3 py-2.5 align-middle text-[length:var(--console-text-label)] font-medium text-muted-foreground", numeric ? "text-right tabular-nums" : "text-left", className), ...props })));
|
|
13
|
+
TableHead.displayName = "TableHead";
|
|
14
|
+
const TableCell = forwardRef(({ className, numeric, ...props }, ref) => (_jsx("td", { ref: ref, className: cn("px-3 py-2 align-middle", numeric && "text-right tabular-nums", className), ...props })));
|
|
15
|
+
TableCell.displayName = "TableCell";
|
|
16
|
+
export { Table, TableHeader, TableBody, TableRow, TableHead, TableCell };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const Tabs: React.ForwardRefExoticComponent<Radix.Tabs.TabsProps & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
declare const TabsList: React.ForwardRefExoticComponent<Omit<Radix.Tabs.TabsListProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
5
|
+
declare const TabsTrigger: React.ForwardRefExoticComponent<Omit<Radix.Tabs.TabsTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
6
|
+
declare const TabsContent: React.ForwardRefExoticComponent<Omit<Radix.Tabs.TabsContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import * as Radix from "radix-ui";
|
|
4
|
+
const TabsPrimitive = Radix.Tabs;
|
|
5
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
const Tabs = TabsPrimitive.Root;
|
|
7
|
+
const TabsList = forwardRef(({ className, ...props }, ref) => (_jsx(TabsPrimitive.List, { ref: ref, className: cn("inline-flex h-[var(--console-control-height-lg)] items-center justify-center gap-0.5 rounded-[var(--console-radius-lg)] bg-[hsl(var(--foreground)/0.055)] p-1 text-muted-foreground", className), ...props })));
|
|
8
|
+
TabsList.displayName = "TabsList";
|
|
9
|
+
const TabsTrigger = forwardRef(({ className, value, ...props }, ref) => (_jsx(TabsPrimitive.Trigger, { ref: ref, value: value, className: cn("inline-flex items-center justify-center whitespace-nowrap rounded-[var(--console-radius-md)] h-full px-3 py-1 text-[length:var(--console-text-body)] font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:text-foreground data-[state=active]:bg-card data-[state=active]:text-foreground data-[state=active]:shadow-[var(--console-shadow-sm)]", className), ...props })));
|
|
10
|
+
TabsTrigger.displayName = "TabsTrigger";
|
|
11
|
+
const TabsContent = forwardRef(({ className, value, ...props }, ref) => (_jsx(TabsPrimitive.Content, { ref: ref, value: value, className: cn("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", className), ...props })));
|
|
12
|
+
TabsContent.displayName = "TabsContent";
|
|
13
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cn } from '../../cn.js';
|
|
4
|
+
const Textarea = forwardRef(({ className, ...props }, ref) => {
|
|
5
|
+
return (_jsx("textarea", { className: cn("console-control flex min-h-[88px] w-full rounded-[var(--console-radius-md)] border-[length:var(--console-border-width)] border-input bg-card hover:border-[hsl(var(--foreground)/0.45)] focus-visible:border-[hsl(var(--primary))] shadow-[var(--console-shadow-xs)] px-3 py-2 leading-relaxed text-[length:var(--console-text-body)] placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60", className), ref: ref, ...props }));
|
|
6
|
+
});
|
|
7
|
+
Textarea.displayName = "Textarea";
|
|
8
|
+
export { Textarea };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import * as Radix from "radix-ui";
|
|
3
|
+
declare const TooltipProvider: React.FC<Radix.Tooltip.TooltipProviderProps>;
|
|
4
|
+
declare const Tooltip: React.FC<Radix.Tooltip.TooltipProps>;
|
|
5
|
+
declare const TooltipTrigger: React.ForwardRefExoticComponent<Radix.Tooltip.TooltipTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
6
|
+
declare const TooltipContent: React.ForwardRefExoticComponent<Omit<Radix.Tooltip.TooltipContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import * as Radix from "radix-ui";
|
|
4
|
+
const TooltipPrimitive = Radix.Tooltip;
|
|
5
|
+
import { cn } from '../../cn.js';
|
|
6
|
+
const TooltipProvider = TooltipPrimitive.Provider;
|
|
7
|
+
const Tooltip = TooltipPrimitive.Root;
|
|
8
|
+
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
9
|
+
const TooltipContent = forwardRef(({ className, sideOffset = 4, ...props }, ref) => (_jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Content, { ref: ref, sideOffset: sideOffset, className: cn("z-50 overflow-hidden rounded-md bg-foreground px-2.5 py-1.5 text-xs font-medium text-background shadow-console-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props }) })));
|
|
10
|
+
TooltipContent.displayName = "TooltipContent";
|
|
11
|
+
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zhin.js/console-ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"exports": [
|
|
5
|
+
"Accordion",
|
|
6
|
+
"AccordionContent",
|
|
7
|
+
"AccordionItem",
|
|
8
|
+
"AccordionTrigger",
|
|
9
|
+
"Alert",
|
|
10
|
+
"AlertDescription",
|
|
11
|
+
"AlertTitle",
|
|
12
|
+
"Badge",
|
|
13
|
+
"Button",
|
|
14
|
+
"CONSOLE_SHARED_MODULE_ISSUES_KEY",
|
|
15
|
+
"CONSOLE_SHARED_MODULE_ISSUE_EVENT",
|
|
16
|
+
"CONSOLE_SHARED_MODULE_VERSIONS_KEY",
|
|
17
|
+
"CONSOLE_UI_LOCALES",
|
|
18
|
+
"CONSOLE_UI_MESSAGES",
|
|
19
|
+
"CONSOLE_UI_MODULE_ID",
|
|
20
|
+
"CONSOLE_UI_VERSION",
|
|
21
|
+
"Card",
|
|
22
|
+
"CardContent",
|
|
23
|
+
"CardDescription",
|
|
24
|
+
"CardFooter",
|
|
25
|
+
"CardHeader",
|
|
26
|
+
"CardTitle",
|
|
27
|
+
"Checkbox",
|
|
28
|
+
"ConfirmDialog",
|
|
29
|
+
"ConsoleUiI18nProvider",
|
|
30
|
+
"ConsoleUiText",
|
|
31
|
+
"DEFAULT_CONSOLE_UI_LOCALE",
|
|
32
|
+
"DEFAULT_REFRESH_INTERVALS",
|
|
33
|
+
"Dialog",
|
|
34
|
+
"DialogClose",
|
|
35
|
+
"DialogContent",
|
|
36
|
+
"DialogDescription",
|
|
37
|
+
"DialogFooter",
|
|
38
|
+
"DialogHeader",
|
|
39
|
+
"DialogOverlay",
|
|
40
|
+
"DialogPortal",
|
|
41
|
+
"DialogTitle",
|
|
42
|
+
"DialogTrigger",
|
|
43
|
+
"DropdownMenu",
|
|
44
|
+
"DropdownMenuCheckboxItem",
|
|
45
|
+
"DropdownMenuContent",
|
|
46
|
+
"DropdownMenuGroup",
|
|
47
|
+
"DropdownMenuItem",
|
|
48
|
+
"DropdownMenuLabel",
|
|
49
|
+
"DropdownMenuPortal",
|
|
50
|
+
"DropdownMenuRadioGroup",
|
|
51
|
+
"DropdownMenuRadioItem",
|
|
52
|
+
"DropdownMenuSeparator",
|
|
53
|
+
"DropdownMenuSub",
|
|
54
|
+
"DropdownMenuTrigger",
|
|
55
|
+
"EmptyState",
|
|
56
|
+
"ErrorAlert",
|
|
57
|
+
"InfoHint",
|
|
58
|
+
"Input",
|
|
59
|
+
"ListItemButton",
|
|
60
|
+
"MiniRingGauge",
|
|
61
|
+
"PageChromeActions",
|
|
62
|
+
"PageChromeProvider",
|
|
63
|
+
"PageHeader",
|
|
64
|
+
"PageShell",
|
|
65
|
+
"Popover",
|
|
66
|
+
"PopoverAnchor",
|
|
67
|
+
"PopoverContent",
|
|
68
|
+
"PopoverTrigger",
|
|
69
|
+
"RadioGroup",
|
|
70
|
+
"RadioGroupItem",
|
|
71
|
+
"RefreshControl",
|
|
72
|
+
"ScrollArea",
|
|
73
|
+
"ScrollBar",
|
|
74
|
+
"SearchableSelectField",
|
|
75
|
+
"Select",
|
|
76
|
+
"SelectContent",
|
|
77
|
+
"SelectField",
|
|
78
|
+
"SelectGroup",
|
|
79
|
+
"SelectItem",
|
|
80
|
+
"SelectScrollDownButton",
|
|
81
|
+
"SelectScrollUpButton",
|
|
82
|
+
"SelectSeparator",
|
|
83
|
+
"SelectTrigger",
|
|
84
|
+
"SelectValue",
|
|
85
|
+
"Separator",
|
|
86
|
+
"Sheet",
|
|
87
|
+
"SheetBody",
|
|
88
|
+
"SheetClose",
|
|
89
|
+
"SheetContent",
|
|
90
|
+
"SheetDescription",
|
|
91
|
+
"SheetFooter",
|
|
92
|
+
"SheetHeader",
|
|
93
|
+
"SheetOverlay",
|
|
94
|
+
"SheetPortal",
|
|
95
|
+
"SheetTitle",
|
|
96
|
+
"SheetTrigger",
|
|
97
|
+
"Skeleton",
|
|
98
|
+
"StatCard",
|
|
99
|
+
"StatGrid",
|
|
100
|
+
"Switch",
|
|
101
|
+
"Table",
|
|
102
|
+
"TableBody",
|
|
103
|
+
"TableCell",
|
|
104
|
+
"TableHead",
|
|
105
|
+
"TableHeader",
|
|
106
|
+
"TableRow",
|
|
107
|
+
"Tabs",
|
|
108
|
+
"TabsContent",
|
|
109
|
+
"TabsList",
|
|
110
|
+
"TabsTrigger",
|
|
111
|
+
"Textarea",
|
|
112
|
+
"Tooltip",
|
|
113
|
+
"TooltipContent",
|
|
114
|
+
"TooltipProvider",
|
|
115
|
+
"TooltipTrigger",
|
|
116
|
+
"badgeVariants",
|
|
117
|
+
"buttonVariants",
|
|
118
|
+
"canSubmitConfirm",
|
|
119
|
+
"cn",
|
|
120
|
+
"confirmErrorMessage",
|
|
121
|
+
"confirmTextMatches",
|
|
122
|
+
"createConsoleUiI18n",
|
|
123
|
+
"createPageChromeStore",
|
|
124
|
+
"formatConsoleUiMessage",
|
|
125
|
+
"formatRefreshTime",
|
|
126
|
+
"groupSelectOptions",
|
|
127
|
+
"navigableValues",
|
|
128
|
+
"optionMatches",
|
|
129
|
+
"optionSearchText",
|
|
130
|
+
"refreshIntervalOptions",
|
|
131
|
+
"registerConsoleUiSharedModule",
|
|
132
|
+
"resolveConsoleUiLocale",
|
|
133
|
+
"useConfirm",
|
|
134
|
+
"useConsoleUiI18n",
|
|
135
|
+
"usePageChrome",
|
|
136
|
+
"usePageChromeState"
|
|
137
|
+
]
|
|
138
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ConsoleUiLocale, type ConsoleUiMessageKey, type ConsoleUiMessages } from './messages.js';
|
|
3
|
+
export { CONSOLE_UI_LOCALES, CONSOLE_UI_MESSAGES, DEFAULT_CONSOLE_UI_LOCALE, formatConsoleUiMessage, resolveConsoleUiLocale, type ConsoleUiLocale, type ConsoleUiMessageKey, type ConsoleUiMessages, } from './messages.js';
|
|
4
|
+
export interface ConsoleUiI18n {
|
|
5
|
+
readonly locale: ConsoleUiLocale;
|
|
6
|
+
/** Built-in copy for `key` in the current locale (host overrides first), with `{n}` filled from `values`. */
|
|
7
|
+
t(key: ConsoleUiMessageKey, values?: readonly unknown[]): string;
|
|
8
|
+
}
|
|
9
|
+
export declare function createConsoleUiI18n(locale?: string | null, messages?: Partial<ConsoleUiMessages>): ConsoleUiI18n;
|
|
10
|
+
export interface ConsoleUiI18nProviderProps {
|
|
11
|
+
/** Current host locale (any BCP 47 tag; `zh*` → zh-CN, `en*` → en, otherwise zh-CN). */
|
|
12
|
+
readonly locale?: string | null;
|
|
13
|
+
/** Host overrides for the current locale; missing keys fall back to the built-in copy. */
|
|
14
|
+
readonly messages?: Partial<ConsoleUiMessages>;
|
|
15
|
+
readonly children?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Language and copy for every `@zhin.js/console-ui` component. Components never read the host's
|
|
19
|
+
* own i18n; without a provider they render the zh-CN defaults.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ConsoleUiI18nProvider({ locale, messages, children }: ConsoleUiI18nProviderProps): import("react").JSX.Element;
|
|
22
|
+
export declare function useConsoleUiI18n(): ConsoleUiI18n;
|
|
23
|
+
/** Renders one built-in message; for places that cannot call the hook (e.g. inside forwardRef bodies shared with class components). */
|
|
24
|
+
export declare function ConsoleUiText({ id, values }: {
|
|
25
|
+
readonly id: ConsoleUiMessageKey;
|
|
26
|
+
readonly values?: readonly unknown[];
|
|
27
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
+
import { CONSOLE_UI_MESSAGES, DEFAULT_CONSOLE_UI_LOCALE, formatConsoleUiMessage, resolveConsoleUiLocale, } from './messages.js';
|
|
4
|
+
export { CONSOLE_UI_LOCALES, CONSOLE_UI_MESSAGES, DEFAULT_CONSOLE_UI_LOCALE, formatConsoleUiMessage, resolveConsoleUiLocale, } from './messages.js';
|
|
5
|
+
export function createConsoleUiI18n(locale, messages) {
|
|
6
|
+
const resolved = resolveConsoleUiLocale(locale);
|
|
7
|
+
const table = CONSOLE_UI_MESSAGES[resolved];
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
locale: resolved,
|
|
10
|
+
t(key, values) {
|
|
11
|
+
const override = messages?.[key];
|
|
12
|
+
const template = typeof override === 'string' ? override : (table[key] ?? key);
|
|
13
|
+
return formatConsoleUiMessage(template, values);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const ConsoleUiI18nContext = createContext(createConsoleUiI18n(DEFAULT_CONSOLE_UI_LOCALE));
|
|
18
|
+
/**
|
|
19
|
+
* Language and copy for every `@zhin.js/console-ui` component. Components never read the host's
|
|
20
|
+
* own i18n; without a provider they render the zh-CN defaults.
|
|
21
|
+
*/
|
|
22
|
+
export function ConsoleUiI18nProvider({ locale, messages, children }) {
|
|
23
|
+
const value = useMemo(() => createConsoleUiI18n(locale, messages), [locale, messages]);
|
|
24
|
+
return _jsx(ConsoleUiI18nContext.Provider, { value: value, children: children });
|
|
25
|
+
}
|
|
26
|
+
export function useConsoleUiI18n() {
|
|
27
|
+
return useContext(ConsoleUiI18nContext);
|
|
28
|
+
}
|
|
29
|
+
/** Renders one built-in message; for places that cannot call the hook (e.g. inside forwardRef bodies shared with class components). */
|
|
30
|
+
export function ConsoleUiText({ id, values }) {
|
|
31
|
+
const { t } = useConsoleUiI18n();
|
|
32
|
+
return _jsx(_Fragment, { children: t(id, values) });
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in UI copy of `@zhin.js/console-ui` (ADR 0063 决策 1 第 5 条).
|
|
3
|
+
* Keys are stable ids; values use `{0}`, `{1}` … placeholders.
|
|
4
|
+
* The zh-CN / en strings are the ones the Console used before the components moved here.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CONSOLE_UI_LOCALES: readonly ["zh-CN", "en"];
|
|
7
|
+
export type ConsoleUiLocale = (typeof CONSOLE_UI_LOCALES)[number];
|
|
8
|
+
export declare const DEFAULT_CONSOLE_UI_LOCALE: ConsoleUiLocale;
|
|
9
|
+
declare const zhCN: {
|
|
10
|
+
readonly 'dialog.close': "关闭";
|
|
11
|
+
readonly 'confirm.cancel': "取消";
|
|
12
|
+
readonly 'confirm.confirm': "确认";
|
|
13
|
+
readonly 'confirm.processing': "处理中...";
|
|
14
|
+
readonly 'confirm.failed': "操作失败,请重试或取消。";
|
|
15
|
+
readonly 'confirm.notCompleted': "操作未完成:{0}";
|
|
16
|
+
readonly 'confirm.typeToConfirm': "请输入 {0} 以确认:";
|
|
17
|
+
readonly 'empty.noData': "暂无数据";
|
|
18
|
+
readonly 'error.retry': "重试";
|
|
19
|
+
readonly 'error.technicalDetail': "技术详情";
|
|
20
|
+
readonly 'select.searchPlaceholder': "搜索…";
|
|
21
|
+
readonly 'select.noMatch': "没有匹配的选项";
|
|
22
|
+
readonly 'refresh.updatedAt': "更新于 {0}";
|
|
23
|
+
readonly 'refresh.notYet': "尚未更新";
|
|
24
|
+
readonly 'refresh.refresh': "刷新";
|
|
25
|
+
readonly 'refresh.refreshing': "刷新中…";
|
|
26
|
+
readonly 'refresh.interval': "自动刷新间隔";
|
|
27
|
+
readonly 'refresh.manual': "手动刷新";
|
|
28
|
+
readonly 'refresh.auto': "{0}s 自动";
|
|
29
|
+
};
|
|
30
|
+
export type ConsoleUiMessageKey = keyof typeof zhCN;
|
|
31
|
+
export type ConsoleUiMessages = Readonly<Record<ConsoleUiMessageKey, string>>;
|
|
32
|
+
export declare const CONSOLE_UI_MESSAGES: Readonly<Record<ConsoleUiLocale, ConsoleUiMessages>>;
|
|
33
|
+
/** Maps any BCP 47 tag onto a built-in locale: `zh*` → zh-CN, `en*` → en, otherwise the default. */
|
|
34
|
+
export declare function resolveConsoleUiLocale(locale: string | undefined | null): ConsoleUiLocale;
|
|
35
|
+
export declare function formatConsoleUiMessage(template: string, values?: readonly unknown[]): string;
|
|
36
|
+
export {};
|