@zhin.js/console-ui 1.0.0 → 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 +45 -0
- package/README.md +118 -11
- 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/components/BrandMark.d.ts +16 -0
- package/dist/components/BrandMark.js +21 -0
- package/dist/components/InfoHint.js +2 -1
- package/dist/components/PageHeader.d.ts +9 -2
- package/dist/components/PageHeader.js +6 -3
- package/dist/components/PageShell.d.ts +18 -3
- package/dist/components/PageShell.js +5 -3
- package/dist/components/RefreshControl.d.ts +6 -1
- package/dist/components/RefreshControl.js +9 -6
- package/dist/components/StatCard.d.ts +19 -5
- package/dist/components/StatCard.js +36 -10
- 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.js +3 -2
- 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 +23 -3
- package/dist/components/empty-state.js +36 -8
- package/dist/components/error-alert.js +2 -1
- 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 +12 -0
- package/dist/components/page-chrome.js +6 -5
- package/dist/components/ui/accordion.js +3 -2
- package/dist/components/ui/alert.js +5 -5
- package/dist/components/ui/badge.js +10 -9
- package/dist/components/ui/button.d.ts +10 -1
- package/dist/components/ui/button.js +26 -11
- package/dist/components/ui/card.d.ts +6 -0
- package/dist/components/ui/card.js +5 -4
- package/dist/components/ui/checkbox.js +2 -1
- 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.js +7 -6
- package/dist/components/ui/dropdown-menu.js +6 -5
- package/dist/components/ui/input.d.ts +6 -1
- package/dist/components/ui/input.js +3 -2
- package/dist/components/ui/list-item-button.js +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/radio-group.js +1 -1
- package/dist/components/ui/scroll-area.js +1 -1
- package/dist/components/ui/searchable-select.d.ts +3 -0
- package/dist/components/ui/searchable-select.js +4 -3
- package/dist/components/ui/select.d.ts +7 -1
- package/dist/components/ui/select.js +7 -5
- package/dist/components/ui/sheet.js +4 -3
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/table.d.ts +11 -0
- package/dist/components/ui/table.js +37 -6
- package/dist/components/ui/tabs.js +3 -3
- package/dist/components/ui/textarea.d.ts +6 -1
- package/dist/components/ui/textarea.js +3 -2
- package/dist/components/ui/tooltip.js +1 -1
- 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 +41 -1
- package/dist/i18n/messages.d.ts +20 -1
- package/dist/i18n/messages.js +40 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +11 -0
- package/dist/scale.json +643 -0
- package/dist/styles.css +1919 -836
- package/dist/theme.css +469 -0
- package/dist/tokens.css +434 -123
- package/dist/version.js +1 -1
- 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 +33 -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
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { createContext, useContext, useEffect, useMemo, useSyncExternalStore } from 'react';
|
|
3
3
|
import { cn } from '../cn.js';
|
|
4
4
|
import { RefreshControl } from './RefreshControl.js';
|
|
5
|
+
import { PageActions } from './actions.js';
|
|
5
6
|
/** One store per mounted page slot; the shell creates it and passes it to {@link PageChromeProvider}. */
|
|
6
7
|
export function createPageChromeStore() {
|
|
7
8
|
let current;
|
|
@@ -40,12 +41,12 @@ export function PageChromeProvider({ store, children }) {
|
|
|
40
41
|
*/
|
|
41
42
|
export function usePageChrome(chrome) {
|
|
42
43
|
const store = useContext(PageChromeContext);
|
|
43
|
-
const { actions, refresh } = chrome;
|
|
44
|
+
const { title, description, actions, refresh, menuActions, moreActions } = chrome;
|
|
44
45
|
useEffect(() => {
|
|
45
46
|
if (!store)
|
|
46
47
|
return;
|
|
47
|
-
return store.set({ actions, refresh });
|
|
48
|
-
}, [store, actions, refresh]);
|
|
48
|
+
return store.set({ title, description, actions, refresh, menuActions, moreActions });
|
|
49
|
+
}, [store, title, description, actions, refresh, menuActions, moreActions]);
|
|
49
50
|
return store !== null;
|
|
50
51
|
}
|
|
51
52
|
/** The chrome the current page registered; for the shell. */
|
|
@@ -59,7 +60,7 @@ const noopGet = () => undefined;
|
|
|
59
60
|
/** Renders the registered refresh control and actions; the shell puts it into `PageHeader.actions`. */
|
|
60
61
|
export function PageChromeActions({ store, className }) {
|
|
61
62
|
const chrome = usePageChromeState(store);
|
|
62
|
-
if (!chrome || (chrome.actions == null && !chrome.refresh))
|
|
63
|
+
if (!chrome || (chrome.actions == null && !chrome.refresh && !chrome.menuActions?.length && !chrome.moreActions?.length))
|
|
63
64
|
return null;
|
|
64
|
-
return (_jsxs(
|
|
65
|
+
return (_jsxs(PageActions, { className: cn('console-page-chrome-actions', className), actions: chrome.menuActions, moreActions: chrome.moreActions, children: [chrome.refresh ? _jsx(RefreshControl, { ...chrome.refresh }) : null, chrome.actions] }));
|
|
65
66
|
}
|
|
@@ -4,11 +4,12 @@ import * as Radix from "radix-ui";
|
|
|
4
4
|
const AccordionPrimitive = Radix.Accordion;
|
|
5
5
|
import { cn } from '../../cn.js';
|
|
6
6
|
import { ChevronDown } from "lucide-react";
|
|
7
|
+
import { CONSOLE_ICON_STROKE_WIDTH } from '../icon.js';
|
|
7
8
|
const Accordion = AccordionPrimitive.Root;
|
|
8
9
|
const AccordionItem = forwardRef(({ className, value, ...props }, ref) => (_jsx(AccordionPrimitive.Item, { ref: ref, value: value, className: cn("border-b", className), ...props })));
|
|
9
10
|
AccordionItem.displayName = "AccordionItem";
|
|
10
|
-
const AccordionTrigger = forwardRef(({ className, children, ...props }, ref) => (_jsx(AccordionPrimitive.Header, { className: "flex", children: _jsxs(AccordionPrimitive.Trigger, { ref: ref, className: cn("flex flex-1 items-center justify-between py-
|
|
11
|
+
const AccordionTrigger = forwardRef(({ className, children, ...props }, ref) => (_jsx(AccordionPrimitive.Header, { className: "flex", children: _jsxs(AccordionPrimitive.Trigger, { ref: ref, className: cn("flex min-h-control flex-1 items-center justify-between py-3 text-body font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180", className), ...props, children: [children, _jsx(ChevronDown, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, className: "h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200" })] }) })));
|
|
11
12
|
AccordionTrigger.displayName = "AccordionTrigger";
|
|
12
|
-
const AccordionContent = forwardRef(({ className, children, ...props }, ref) => (_jsx(AccordionPrimitive.Content, { ref: ref, className: "overflow-hidden text-
|
|
13
|
+
const AccordionContent = forwardRef(({ className, children, ...props }, ref) => (_jsx(AccordionPrimitive.Content, { ref: ref, className: "overflow-hidden text-body data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down", ...props, children: _jsx("div", { className: cn("pb-4 pt-0", className), children: children }) })));
|
|
13
14
|
AccordionContent.displayName = "AccordionContent";
|
|
14
15
|
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
|
|
@@ -2,13 +2,13 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import { cva } from "class-variance-authority";
|
|
4
4
|
import { cn } from '../../cn.js';
|
|
5
|
-
const alertVariants = cva("relative w-full rounded-
|
|
5
|
+
const alertVariants = cva("console-alert relative w-full rounded-card border px-4 py-3 text-body leading-relaxed [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:size-4 [&>svg]:text-foreground [&>svg~*]:pl-6", {
|
|
6
6
|
variants: {
|
|
7
7
|
variant: {
|
|
8
8
|
default: "border-transparent bg-secondary text-foreground",
|
|
9
9
|
destructive: "border-destructive/30 bg-destructive/5 text-destructive dark:border-destructive/40 [&>svg]:text-destructive",
|
|
10
|
-
success: "console-badge-success [&>svg]:text-
|
|
11
|
-
warning: "console-badge-warning [&>svg]:text-
|
|
10
|
+
success: "console-badge-success [&>svg]:text-success",
|
|
11
|
+
warning: "console-badge-warning [&>svg]:text-warning",
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
14
|
defaultVariants: {
|
|
@@ -17,8 +17,8 @@ const alertVariants = cva("relative w-full rounded-[var(--console-radius-lg)] bo
|
|
|
17
17
|
});
|
|
18
18
|
const Alert = forwardRef(({ className, variant, ...props }, ref) => (_jsx("div", { ref: ref, role: "alert", className: cn(alertVariants({ variant }), className), ...props })));
|
|
19
19
|
Alert.displayName = "Alert";
|
|
20
|
-
const AlertTitle = forwardRef(({ className, ...props }, ref) => (_jsx("h5", { ref: ref, className: cn("mb-1 font-
|
|
20
|
+
const AlertTitle = forwardRef(({ className, ...props }, ref) => (_jsx("h5", { ref: ref, className: cn("mb-1 font-strong leading-normal", className), ...props })));
|
|
21
21
|
AlertTitle.displayName = "AlertTitle";
|
|
22
|
-
const AlertDescription = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("text-
|
|
22
|
+
const AlertDescription = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("text-body [&_p]:leading-relaxed", className), ...props })));
|
|
23
23
|
AlertDescription.displayName = "AlertDescription";
|
|
24
24
|
export { Alert, AlertTitle, AlertDescription };
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { cva } from "class-variance-authority";
|
|
3
3
|
import { cn } from '../../cn.js';
|
|
4
|
-
const badgeVariants = cva("
|
|
4
|
+
const badgeVariants = cva("console-badge transition-colors", {
|
|
5
5
|
variants: {
|
|
6
6
|
variant: {
|
|
7
|
-
default: "border-
|
|
8
|
-
secondary: "border-transparent bg-
|
|
9
|
-
destructive: "
|
|
7
|
+
default: "border-primary-action-border bg-primary-action text-primary-action-foreground",
|
|
8
|
+
secondary: "border-transparent bg-foreground/6 text-secondary-foreground",
|
|
9
|
+
destructive: "console-badge-danger",
|
|
10
10
|
outline: "border-[color:var(--console-border-strong)] text-foreground",
|
|
11
|
-
|
|
11
|
+
// 「正常」 is not a colored badge (ADR 0063 D15 第 1 条): success renders as muted text.
|
|
12
|
+
success: "console-status-quiet border-transparent px-0",
|
|
12
13
|
warning: "console-badge-warning",
|
|
13
14
|
info: "console-badge-info",
|
|
14
15
|
},
|
|
15
|
-
//
|
|
16
|
+
// One badge implementation (D16): `sm` is kept for compatibility and renders the same.
|
|
16
17
|
size: {
|
|
17
|
-
default: "
|
|
18
|
-
sm: "
|
|
18
|
+
default: "",
|
|
19
|
+
sm: "",
|
|
19
20
|
},
|
|
20
21
|
},
|
|
21
22
|
defaultVariants: {
|
|
@@ -24,6 +25,6 @@ const badgeVariants = cva("inline-flex items-center whitespace-nowrap rounded-fu
|
|
|
24
25
|
},
|
|
25
26
|
});
|
|
26
27
|
function Badge({ className, variant, size, ...props }) {
|
|
27
|
-
return _jsx("span", { className: cn(badgeVariants({ variant, size }), className), ...props });
|
|
28
|
+
return _jsx("span", { "data-slot": "badge", className: cn(badgeVariants({ variant, size }), className), ...props });
|
|
28
29
|
}
|
|
29
30
|
export { Badge, badgeVariants };
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type * as React from "react";
|
|
2
2
|
import { type VariantProps } from "class-variance-authority";
|
|
3
|
+
/**
|
|
4
|
+
* Button variants (ADR 0063 「色板角色与信号色」, zhinjs/console#125):
|
|
5
|
+
* primary solid brand, dark text — at most one per view (the next step: 登录, 保存, 发送, 筛选)
|
|
6
|
+
* soft palette tint, the former `default`; `default` is its deprecated alias until P4
|
|
7
|
+
* outline / secondary / ghost / link
|
|
8
|
+
* destructive ghost: destructive text, no fill — every dangerous entry point on a page
|
|
9
|
+
* destructive-outline outline button with destructive text (ADR 0063 决策 5)
|
|
10
|
+
* destructive-solid solid red — only the confirm button of a confirmation dialog
|
|
11
|
+
*/
|
|
3
12
|
declare const buttonVariants: (props?: ({
|
|
4
|
-
variant?: "link" | "default" | "destructive" | "secondary" | "outline" | "destructive-outline" | "ghost" | null | undefined;
|
|
13
|
+
variant?: "link" | "default" | "destructive" | "secondary" | "outline" | "primary" | "soft" | "destructive-outline" | "destructive-solid" | "ghost" | null | undefined;
|
|
5
14
|
size?: "default" | "sm" | "lg" | "icon" | null | undefined;
|
|
6
15
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
16
|
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
@@ -3,35 +3,50 @@ import { forwardRef } from "react";
|
|
|
3
3
|
import * as Radix from "radix-ui";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { cn } from '../../cn.js';
|
|
6
|
-
const
|
|
6
|
+
const SOFT = "border-primary-action-border bg-primary-action text-primary-action-foreground hover:border-primary hover:bg-primary-action/72";
|
|
7
|
+
/**
|
|
8
|
+
* Button variants (ADR 0063 「色板角色与信号色」, zhinjs/console#125):
|
|
9
|
+
* primary solid brand, dark text — at most one per view (the next step: 登录, 保存, 发送, 筛选)
|
|
10
|
+
* soft palette tint, the former `default`; `default` is its deprecated alias until P4
|
|
11
|
+
* outline / secondary / ghost / link
|
|
12
|
+
* destructive ghost: destructive text, no fill — every dangerous entry point on a page
|
|
13
|
+
* destructive-outline outline button with destructive text (ADR 0063 决策 5)
|
|
14
|
+
* destructive-solid solid red — only the confirm button of a confirmation dialog
|
|
15
|
+
*/
|
|
16
|
+
const buttonVariants = cva("console-control inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-control border border-transparent text-body font-medium transition-[background-color,border-color,color,box-shadow] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", {
|
|
7
17
|
variants: {
|
|
8
18
|
variant: {
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
// The light-theme brand (#76EEC6) is close to white, so the brand-text hairline gives the button its edge.
|
|
20
|
+
primary: "border-brand-text/70 bg-brand text-brand-foreground hover:bg-brand/85 dark:border-transparent",
|
|
21
|
+
soft: SOFT,
|
|
22
|
+
/** @deprecated Renamed to `soft` (zhinjs/console#125); same look, kept until ADR 0063 P4. */
|
|
23
|
+
default: SOFT,
|
|
24
|
+
destructive: "text-destructive hover:bg-destructive/8",
|
|
11
25
|
outline: "border-[color:var(--console-border-strong)] bg-card text-foreground hover:bg-[var(--console-surface-hover)]",
|
|
12
26
|
// Page-level entry to a dangerous action (ADR 0063 决策 5): the outline button with destructive text.
|
|
13
|
-
// The solid `destructive` variant is only for the confirm button inside the confirmation dialog.
|
|
14
27
|
"destructive-outline": "border-[color:var(--console-border-strong)] bg-card text-destructive hover:bg-[var(--console-surface-hover)]",
|
|
28
|
+
// Only for the confirm button inside a confirmation dialog (ConfirmDialog variant="destructive").
|
|
29
|
+
"destructive-solid": "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
15
30
|
secondary: "bg-secondary text-secondary-foreground hover:bg-accent",
|
|
16
31
|
ghost: "text-foreground hover:bg-[var(--console-surface-hover)]",
|
|
17
|
-
link: "text-
|
|
32
|
+
link: "text-brand-text underline-offset-4 hover:underline",
|
|
18
33
|
},
|
|
19
34
|
size: {
|
|
20
|
-
default: "h-
|
|
21
|
-
sm: "h-
|
|
22
|
-
lg: "h-
|
|
23
|
-
icon: "
|
|
35
|
+
default: "h-control px-3",
|
|
36
|
+
sm: "h-control-compact px-3 text-label",
|
|
37
|
+
lg: "h-control px-4",
|
|
38
|
+
icon: "size-control shrink-0",
|
|
24
39
|
},
|
|
25
40
|
},
|
|
26
41
|
defaultVariants: {
|
|
27
|
-
variant: "
|
|
42
|
+
variant: "soft",
|
|
28
43
|
size: "default",
|
|
29
44
|
},
|
|
30
45
|
});
|
|
31
46
|
const Slot = Radix.Slot.Root;
|
|
32
47
|
const Button = forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
33
48
|
const Comp = asChild ? Slot : "button";
|
|
34
|
-
return (_jsx(Comp, { className: cn(buttonVariants({ variant, size, className })), ref: ref, ...props }));
|
|
49
|
+
return (_jsx(Comp, { "data-slot": "button", className: cn(buttonVariants({ variant, size, className })), ref: ref, ...props }));
|
|
35
50
|
});
|
|
36
51
|
Button.displayName = "Button";
|
|
37
52
|
export { Button, buttonVariants };
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type * as React from "react";
|
|
2
2
|
export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
3
|
interactive?: boolean;
|
|
4
|
+
/**
|
|
5
|
+
* The card fills the page column edge to edge on phone-width pages (below 40rem it reaches the
|
|
6
|
+
* screen edges and has no radius, ADR 0063 D16). Only for cards placed directly in the page.
|
|
7
|
+
*/
|
|
8
|
+
edge?: boolean;
|
|
4
9
|
}
|
|
10
|
+
/** Card: hairline border, no shadow when static; interactive cards lift (e-1) on wide containers. */
|
|
5
11
|
declare const Card: React.ForwardRefExoticComponent<CardProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
12
|
declare const CardHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
7
13
|
declare const CardTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import { cn } from '../../cn.js';
|
|
4
|
-
|
|
4
|
+
/** Card: hairline border, no shadow when static; interactive cards lift (e-1) on wide containers. */
|
|
5
|
+
const Card = forwardRef(({ className, interactive, edge, ...props }, ref) => (_jsx("div", { ref: ref, "data-slot": "card", "data-interactive": interactive ? "" : undefined, "data-edge": edge ? "" : undefined, className: cn("console-card text-card-foreground", interactive && "console-card--interactive", className), ...props })));
|
|
5
6
|
Card.displayName = "Card";
|
|
6
|
-
const CardHeader = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("
|
|
7
|
+
const CardHeader = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("console-card-header", className), ...props })));
|
|
7
8
|
CardHeader.displayName = "CardHeader";
|
|
8
9
|
const CardTitle = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("console-section-title", className), ...props })));
|
|
9
10
|
CardTitle.displayName = "CardTitle";
|
|
10
11
|
const CardDescription = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("console-text-body text-muted-foreground", className), ...props })));
|
|
11
12
|
CardDescription.displayName = "CardDescription";
|
|
12
|
-
const CardContent = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("
|
|
13
|
+
const CardContent = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("console-card-content", className), ...props })));
|
|
13
14
|
CardContent.displayName = "CardContent";
|
|
14
|
-
const CardFooter = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("
|
|
15
|
+
const CardFooter = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("console-card-footer", className), ...props })));
|
|
15
16
|
CardFooter.displayName = "CardFooter";
|
|
16
17
|
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
|
@@ -4,6 +4,7 @@ import * as Radix from "radix-ui";
|
|
|
4
4
|
const CheckboxPrimitive = Radix.Checkbox;
|
|
5
5
|
import { cn } from '../../cn.js';
|
|
6
6
|
import { Check, Minus } from "lucide-react";
|
|
7
|
-
|
|
7
|
+
import { CONSOLE_ICON_STROKE_WIDTH } from '../icon.js';
|
|
8
|
+
const Checkbox = forwardRef(({ className, ...props }, ref) => (_jsx(CheckboxPrimitive.Root, { ref: ref, className: cn("console-control console-touch peer inline-flex size-4 shrink-0 items-center justify-center rounded-check border border-input bg-card text-background transition-colors disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-brand-text data-[state=checked]:bg-brand-text data-[state=indeterminate]:border-brand-text data-[state=indeterminate]:bg-brand-text", className), ...props, children: _jsxs(CheckboxPrimitive.Indicator, { className: "group/indicator flex items-center justify-center text-current", children: [_jsx(Check, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, className: "hidden h-3.5 w-3.5 group-data-[state=checked]/indicator:block" }), _jsx(Minus, { strokeWidth: CONSOLE_ICON_STROKE_WIDTH, className: "hidden h-3.5 w-3.5 group-data-[state=indeterminate]/indicator:block" })] }) })));
|
|
8
9
|
Checkbox.displayName = "Checkbox";
|
|
9
10
|
export { Checkbox };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Look of the text-like controls (Input, Textarea, SelectTrigger, SearchableSelectField,
|
|
3
|
+
* DateField, DateTimeField), ADR 0063 D29:
|
|
4
|
+
* default hairline border on a card surface
|
|
5
|
+
* ghost no border and no fill until hovered or focused; for secondary fields (fallback
|
|
6
|
+
* models, unset slots) so a long form does not become a wall of boxes
|
|
7
|
+
*/
|
|
8
|
+
export type ControlVariant = 'default' | 'ghost';
|
|
9
|
+
/** Border and surface classes of a control variant (Tailwind utilities, merged with `cn`). */
|
|
10
|
+
export declare function controlVariantClass(variant: ControlVariant | null | undefined): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const DEFAULT = 'border-input bg-card hover:border-foreground/45 focus-visible:border-brand-text disabled:bg-muted';
|
|
2
|
+
const GHOST = 'border-transparent bg-transparent hover:border-input focus-visible:border-brand-text aria-expanded:border-input data-[state=open]:border-input disabled:bg-transparent';
|
|
3
|
+
/** Border and surface classes of a control variant (Tailwind utilities, merged with `cn`). */
|
|
4
|
+
export function controlVariantClass(variant) {
|
|
5
|
+
return variant === 'ghost' ? GHOST : DEFAULT;
|
|
6
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure date logic of `DateField` / `DateTimeField` (no DOM, no time zone surprises): values are
|
|
3
|
+
* ISO 8601 strings in local time — `YYYY-MM-DD` for a date, `YYYY-MM-DDTHH:mm` for a date and time
|
|
4
|
+
* (the value format of the native `date` / `datetime-local` inputs), `''` when empty.
|
|
5
|
+
*/
|
|
6
|
+
export interface CalendarDate {
|
|
7
|
+
readonly year: number;
|
|
8
|
+
/** 1–12 */
|
|
9
|
+
readonly month: number;
|
|
10
|
+
readonly day: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CalendarDateTime extends CalendarDate {
|
|
13
|
+
readonly hour: number;
|
|
14
|
+
readonly minute: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function daysInMonth(year: number, month: number): number;
|
|
17
|
+
/** Reads the date part of a date or date-time value; `null` when empty or invalid. */
|
|
18
|
+
export declare function parseDateValue(value: string | null | undefined): CalendarDate | null;
|
|
19
|
+
/** Reads a date-time value (a bare date counts as 00:00); `null` when empty or invalid. */
|
|
20
|
+
export declare function parseDateTimeValue(value: string | null | undefined): CalendarDateTime | null;
|
|
21
|
+
export declare function formatDateValue(date: CalendarDate): string;
|
|
22
|
+
export declare function formatDateTimeValue(value: CalendarDateTime): string;
|
|
23
|
+
export declare function fromDate(date: Date): CalendarDate;
|
|
24
|
+
export declare function compareDates(a: CalendarDate, b: CalendarDate): number;
|
|
25
|
+
export declare function sameDate(a: CalendarDate | null, b: CalendarDate | null): boolean;
|
|
26
|
+
export declare function addDays(date: CalendarDate, days: number): CalendarDate;
|
|
27
|
+
/** Same day in another month, clamped to that month's last day (Jan 31 + 1 month = Feb 28/29). */
|
|
28
|
+
export declare function addMonths(date: CalendarDate, months: number): CalendarDate;
|
|
29
|
+
/** Whether `date` is inside `[min, max]` (date parts of the bounds; either bound may be empty). */
|
|
30
|
+
export declare function isWithin(date: CalendarDate, min?: string, max?: string): boolean;
|
|
31
|
+
export declare function clampDate(date: CalendarDate, min?: string, max?: string): CalendarDate;
|
|
32
|
+
/** 0 = Sunday … 6 = Saturday */
|
|
33
|
+
export declare function weekday(date: CalendarDate): number;
|
|
34
|
+
/** First day of the week that contains `date`. */
|
|
35
|
+
export declare function startOfWeek(date: CalendarDate, weekStartsOn: 0 | 1): CalendarDate;
|
|
36
|
+
/** Six weeks × seven days covering the month (leading / trailing days of the neighbour months included). */
|
|
37
|
+
export declare function calendarMonth(year: number, month: number, weekStartsOn: 0 | 1): CalendarDate[][];
|
|
38
|
+
/** Hour / minute typed into the time boxes: digits only, clamped into range; `null` when not a number. */
|
|
39
|
+
export declare function clampTimePart(text: string, max: number): number | null;
|
|
@@ -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';
|