From 4fbf7cb0a8dcdea624fcd5277e51857b5b7a31a3 Mon Sep 17 00:00:00 2001 From: GCWing Date: Thu, 29 Oct 2026 11:44:15 +0800 Subject: [PATCH 1/2] feat(ui): unify model settings with shared panel dialogs --- .../design-lab/src/i18n/previewMessages.ts | 3 + .../src/pages/ComponentDetailPage.tsx | 7 +- .../design-tokens/src/system.tokens.json | 4 + .../design-tokens/tests/contract.test.mjs | 1 + design-system/packages/ui/README.md | 40 +++++- .../ui/src/components/Capsule/Capsule.meta.ts | 4 +- .../src/components/Capsule/Capsule.module.css | 41 ++++++ .../ui/src/components/Capsule/Capsule.tsx | 11 +- .../ui/src/components/Dialog/Dialog.meta.ts | 10 +- .../src/components/Dialog/Dialog.module.css | 65 +++++++++ .../ui/src/components/Dialog/Dialog.tsx | 21 ++- .../ui/src/components/Dialog/index.ts | 2 + design-system/packages/ui/src/index.ts | 2 + .../packages/ui/tests/capsule.test.mjs | 29 +++- .../packages/ui/tests/dialog.test.mjs | 15 ++ .../data-tools/ui/generated/design-system.css | 1 + .../pages/ai/ModelDiscoveryPicker.test.tsx | 2 + .../pages/ai/ModelDiscoveryPicker.tsx | 2 +- .../pages/ai/ModelPoolMemberPicker.tsx | 2 +- .../settings/pages/ai/ModelPoolsSection.scss | 8 -- .../settings/pages/ai/ModelPoolsSection.tsx | 2 +- .../ai/ModelSettingsPage.loading.test.tsx | 24 +++- .../settings/pages/ai/ModelSettingsPage.scss | 92 ++---------- .../settings/pages/ai/ModelSettingsPage.tsx | 136 +++++++++--------- .../ai/SubscriptionProviderPicker.module.scss | 7 +- .../pages/ai/SubscriptionProviderPicker.tsx | 23 +-- .../config/components/ModelRouterSettings.tsx | 4 +- .../ModelSettingsDialog.presentation.test.ts | 35 ++++- .../ImageGenerationEditor.tsx | 87 ++++++----- .../ImageGenerationSection.scss | 8 +- .../ImageGenerationSettings.test.tsx | 81 +++++++++++ .../src/locales/en-US/settings/media.json | 2 +- .../src/locales/en-US/settings/models.json | 14 +- .../src/locales/zh-CN/settings/media.json | 2 +- .../src/locales/zh-CN/settings/models.json | 14 +- .../src/locales/zh-TW/settings/media.json | 2 +- .../src/locales/zh-TW/settings/models.json | 14 +- src/web-ui/src/shared/ui/Dialog.test.tsx | 31 ++++ 38 files changed, 582 insertions(+), 266 deletions(-) diff --git a/design-system/apps/design-lab/src/i18n/previewMessages.ts b/design-system/apps/design-lab/src/i18n/previewMessages.ts index ffa1d2e33d..eeb28bf312 100644 --- a/design-system/apps/design-lab/src/i18n/previewMessages.ts +++ b/design-system/apps/design-lab/src/i18n/previewMessages.ts @@ -32,6 +32,7 @@ export const previewEn = { "preview.state.construction": "Engineering drawing", "preview.state.secondary": "Secondary", "preview.state.elevated": "Elevated", "preview.state.floating": "Floating", "preview.state.floating-footer": "Floating footer", "preview.state.alert": "Alert dialog", + "preview.state.panel": "Panel Dialog", "preview.state.disabled-option": "Disabled option", "preview.state.instant": "Immediate tooltip", "preview.state.interactive": "Interactive tooltip", "preview.state.content-only": "Content only", "preview.state.with-heading": "With heading", "preview.state.with-action": "With action", "preview.state.centered": "Centered", "preview.state.with-subtitle": "With subtitle", @@ -74,6 +75,7 @@ export const previewZhCN: Record = { "preview.state.construction": "工程制图", "preview.state.secondary": "次要", "preview.state.elevated": "浮起表面", "preview.state.floating": "悬浮", "preview.state.floating-footer": "悬浮页脚", "preview.state.alert": "提醒弹窗", + "preview.state.panel": "面板弹窗", "preview.state.disabled-option": "禁用选项", "preview.state.instant": "即时提示", "preview.state.interactive": "可交互提示", "preview.state.content-only": "仅内容", "preview.state.with-heading": "附带标题", "preview.state.with-action": "附带操作", "preview.state.centered": "居中", "preview.state.with-subtitle": "附带副标题", @@ -110,6 +112,7 @@ export const previewZhTW: Record = { "preview.state.counter-rotate": "雙六邊形對轉", "preview.state.construction": "工程製圖", "preview.state.floating": "懸浮", "preview.state.floating-footer": "懸浮頁尾", "preview.state.alert": "提醒對話框", + "preview.state.panel": "面板彈窗", "preview.state.disabled-option": "停用選項", "preview.state.instant": "即時提示", "preview.state.interactive": "可互動提示", "preview.state.content-only": "僅內容", "preview.state.with-heading": "附帶標題", "preview.state.with-action": "附帶操作", "preview.state.with-subtitle": "附帶副標題", "preview.state.narrow": "窄螢幕", "preview.state.wide": "寬螢幕", "preview.state.safe-area": "安全區域", diff --git a/design-system/apps/design-lab/src/pages/ComponentDetailPage.tsx b/design-system/apps/design-lab/src/pages/ComponentDetailPage.tsx index 3f076df40e..a8a5fd936a 100644 --- a/design-system/apps/design-lab/src/pages/ComponentDetailPage.tsx +++ b/design-system/apps/design-lab/src/pages/ComponentDetailPage.tsx @@ -257,6 +257,7 @@ const optionLabelKeys: Readonly> = { hidden: "detail.option.hidden", inline: "detail.option.inline", scrolling: "detail.option.scrolling", + panel: "preview.state.panel", "focus-within": "detail.option.focus-within", "with-context": "detail.option.with-context", "with-center": "detail.option.with-center", @@ -647,7 +648,8 @@ export function ComponentDetailPage({ return `import { Icon, Menu, MenuItem, MenuSection, MenuSeparator } from "@openbitfun/ui";\n\n\n \n }>${t("components.preview.menuItemOne")}\n }>${t("components.preview.menuItemTwo")}\n \n \n \n ${t("components.preview.menuDisabledItem")}\n \n`; } if (component.name === "Dialog") { - return `import { Button, Dialog, DialogBody, DialogClose, DialogFooter, DialogHeader, DialogHeading, DialogTitle } from "@openbitfun/ui";\n\n setOpen(false)} open={open} size="xl">\n \n ${t("components.preview.modalTitle")}\n \n \n \n \n \n \n \n`; + const geometry = previewState === "panel" ? 'preset="panel"' : 'size="xl"'; + return `import { Button, Dialog, DialogBody, DialogClose, DialogFooter, DialogHeader, DialogHeading, DialogTitle } from "@openbitfun/ui";\n\n setOpen(false)} open={open} ${geometry}>\n \n ${t("components.preview.modalTitle")}\n \n \n \n \n \n \n \n`; } if (component.name === "Sheet") { return `import { Button, DialogBody, DialogClose, DialogFooter, DialogHeader, DialogHeading, DialogTitle, Sheet } from "@openbitfun/ui";\n\n setOpen(false)} open={open} placement="right" size="lg">\n \n ${t("components.preview.modalTitle")}\n \n \n \n \n \n \n \n`; @@ -872,6 +874,7 @@ export function ComponentDetailPage({ onOpenChange={closePreview} open={overlayOpen} role={state === "alert" ? "alertdialog" : "dialog"} + preset={state === "panel" ? "panel" : "default"} size="xl" > @@ -881,7 +884,7 @@ export function ComponentDetailPage({ {renderDialogConfigurationContent()} - + diff --git a/design-system/packages/design-tokens/src/system.tokens.json b/design-system/packages/design-tokens/src/system.tokens.json index 94b8ef010a..98b522f8c9 100644 --- a/design-system/packages/design-tokens/src/system.tokens.json +++ b/design-system/packages/design-tokens/src/system.tokens.json @@ -995,6 +995,10 @@ "$value": "blur(10px)" }, "footerActionMinWidth": { "$value": "100px" }, + "panelBlockSize": { + "$description": "Fixed Panel Dialog height before viewport clamping; width and content measure reuse the existing xlarge and large dialog scales.", + "$value": "640px" + }, "maxInlineSizeSmall": { "$value": "420px" }, "maxInlineSizeMedium": { "$value": "560px" }, "maxInlineSizeLarge": { "$value": "600px" }, diff --git a/design-system/packages/design-tokens/tests/contract.test.mjs b/design-system/packages/design-tokens/tests/contract.test.mjs index 56886c1a24..7bb5567650 100644 --- a/design-system/packages/design-tokens/tests/contract.test.mjs +++ b/design-system/packages/design-tokens/tests/contract.test.mjs @@ -405,6 +405,7 @@ test("Dialog tokens preserve the reference surface and chrome contract", async ( assert.equal(tokens["overlay.dialog.footerBlur"], "blur(10px)"); assert.equal(tokens["overlay.dialog.footerFadeExtent"], "24px"); assert.equal(tokens["overlay.dialog.footerContentInset"], "104px"); + assert.equal(tokens["overlay.dialog.panelBlockSize"], "640px"); }); test("control heights preserve an eight-pixel size step in every density mode", () => { diff --git a/design-system/packages/ui/README.md b/design-system/packages/ui/README.md index 3cc10abf85..afe86b7308 100644 --- a/design-system/packages/ui/README.md +++ b/design-system/packages/ui/README.md @@ -536,6 +536,15 @@ Leading identity icons stay in their label layout; this contract governs the independent trailing actions. Product CSS owns placement of capsules, not their action offsets, backgrounds, or visibility. +`Capsule layout="split"` joins two direct child controls into equal-width halves +with square inner corners, rounded outer ends, and no mismatched child borders. +Set `splitSizing="content"` to fit the leading control to its content and give the +remaining width to the trailing action. Use a `Select variant="pill"` followed by +a `Button`, with the same explicit size; set the Select's `width="content"` for +content sizing or `width="full"` for equal halves. Each control +keeps its own focus, disabled state, and action; the select popup remains portalled. +Use exactly two controls and omit the floating `action` slot for this layout. + For supplemental label annotations, compose `Tooltip trigger="hover-focus" openOnClick` with `IconButton variant="annotation" size="xs"` and an `info` icon. The annotation uses `color.content.muted` at rest and @@ -838,7 +847,36 @@ Dialog titles use 24px bold type with their own 29px line box and normal trackin Extra-large (`xl`) dialogs have an 800px maximum width and continue shrinking within the viewport gutter. Provider editing uses the floating footer; small workspace creation retains its attached footer and existing button/input sizes. The Lab workspace pattern uses local sample paths and callbacks only. -Keep `Dialog` and `Sheet` mounted and set `open={false}` to close them. They retain the last committed children, size, placement, classes, and styles during the exit animation, with interaction disabled, so clearing an owner selection does not resize the surface. Reopening uses the latest presentation and cancels the pending exit. Owners that conditionally mount an editor can remove it in `onExitComplete`, which runs once after the surface unmounts. +**Panel Dialog** (`Dialog preset="panel"`) is the fixed management-panel layout: +800px wide, 640px high, with a 600px heading and content measure. The heading and +body form one vertically centered group when content is short. Long content uses +the available body height and scrolls; it does not resize the surface. The minimum +top inset and heading-to-body gap share one measure: the header chrome inset plus +16px. Floating footers reserve only their actual action height at the bottom, +with trailing body space for the fade. Plain headings +use the small control height, while a brand mark can grow naturally. Header +actions or a standalone close button stay in the upper-right corner; use +`DialogHeaderLeading` for a fixed upper-left back action. Width and height shrink +within the viewport gutter. `DialogBody` owns scrolling and responsive horizontal +insets. Use direct `DialogHeader` / `DialogHeading`, `DialogBody`, and optional +`DialogFooter` children; group right-side actions in `DialogHeaderActions`. +The preset selects `xl` regardless of `size`; the default preset retains the +existing content-sized behavior. Keep product copy and account logic in consumers. +The only new geometry token is `overlay.dialog.panelBlockSize`: the existing +width and spacing scales cover the other dimensions, but do not define a fixed +panel height. + +```tsx + + + Manage accounts + + + {accountList} + +``` + +Keep `Dialog` and `Sheet` mounted and set `open={false}` to close them. They retain the last committed children, preset, size, placement, classes, and styles during the exit animation, with interaction disabled, so clearing an owner selection does not resize the surface. Reopening uses the latest presentation and cancels the pending exit. Owners that conditionally mount an editor can remove it in `onExitComplete`, which runs once after the surface unmounts. PageHeader `md` uses the settings title with a primary 15px description; `display` uses the welcome heading and medium 17px introduction with a 12px gap. ActionCard uses 12px padding, section-heading typography (15px semibold), and a primary 13px single-line action description. Its inset outline does not inflate the 62px medium minimum height; longer content keeps the independent sibling actions and OverflowText behavior. diff --git a/design-system/packages/ui/src/components/Capsule/Capsule.meta.ts b/design-system/packages/ui/src/components/Capsule/Capsule.meta.ts index 13799d2831..76f3f712e8 100644 --- a/design-system/packages/ui/src/components/Capsule/Capsule.meta.ts +++ b/design-system/packages/ui/src/components/Capsule/Capsule.meta.ts @@ -2,11 +2,13 @@ import type { ComponentMeta } from "../../registry.types"; export const capsuleMeta = { category: "action", - description: "A capsule composition with a circular glass action that overlays the label or occupies reserved space inside its Button surface. Reserved content is centered at rest and shifts aside when the action appears, without changing layout; touch keeps the action available.", + description: "A capsule with joined controls or a circular glass action that overlays the label or occupies reserved space inside its Button surface. Split controls support equal widths or a content-sized leading control. Reserved content is centered at rest and shifts aside when the action appears, without changing layout; touch keeps the action available.", maturity: "stable", name: "Capsule", props: [ { name: "children", type: "ReactNode" }, + { name: "layout", type: "inline | split", defaultValue: "inline" }, + { name: "splitSizing", type: "equal | content", defaultValue: "equal" }, { name: "action", type: "ReactNode" }, { name: "actionPlacement", type: "overlay | reserved", defaultValue: "overlay" }, { name: "size", type: "xs | sm | md | lg", defaultValue: "sm" }, diff --git a/design-system/packages/ui/src/components/Capsule/Capsule.module.css b/design-system/packages/ui/src/components/Capsule/Capsule.module.css index de14824c85..09fedeb5ad 100644 --- a/design-system/packages/ui/src/components/Capsule/Capsule.module.css +++ b/design-system/packages/ui/src/components/Capsule/Capsule.module.css @@ -28,6 +28,47 @@ .root:dir(rtl) { --_capsule-inline-direction: -1; } + .root[data-layout="split"] { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + inline-size: 100%; + } + + .root[data-layout="split"][data-split-sizing="content"] { + grid-template-columns: max-content minmax(0, 1fr); + } + + .root[data-layout="split"] > [data-openbitfun-component="select"], + .root[data-layout="split"] > [data-openbitfun-component="button"] { + min-inline-size: 0; + inline-size: 100%; + } + + .root[data-layout="split"][data-split-sizing="content"] > :first-child { + inline-size: max-content; + max-inline-size: 100%; + } + + /* Match the Select fill to Button's inset fill without changing control size. */ + .root[data-layout="split"] > [data-openbitfun-component="select"] > [data-openbitfun-part="trigger"] { + border-color: transparent; + background-clip: padding-box; + } + + .root[data-layout="split"] > :first-child, + .root[data-layout="split"] > :first-child > [data-openbitfun-part="trigger"] { + border-start-end-radius: 0; + border-end-end-radius: 0; + border-inline-end-width: 0; + } + + .root[data-layout="split"] > :last-child, + .root[data-layout="split"] > :last-child > [data-openbitfun-part="trigger"] { + border-start-start-radius: 0; + border-end-start-radius: 0; + border-inline-start-width: 0; + } + /* Reserve space inside the Button's surface, leaving inter-capsule gaps intact. */ .root[data-action-placement="reserved"] { --_capsule-action-padding: calc( diff --git a/design-system/packages/ui/src/components/Capsule/Capsule.tsx b/design-system/packages/ui/src/components/Capsule/Capsule.tsx index 327142ee2a..b492316815 100644 --- a/design-system/packages/ui/src/components/Capsule/Capsule.tsx +++ b/design-system/packages/ui/src/components/Capsule/Capsule.tsx @@ -5,6 +5,10 @@ import actionStyles from "../../internal/FloatingAction.module.css"; import styles from "./Capsule.module.css"; export interface CapsuleProps extends HTMLAttributes { + /** Join two independent controls into one capsule. */ + layout?: "inline" | "split"; + /** Fit the leading split control to its content, or use equal halves. */ + splitSizing?: "equal" | "content"; /** One IconButton (optionally wrapped in Tooltip), rendered beside the content. */ action?: ReactNode; /** Reserve a fixed action slot inside a Button child's trailing padding. */ @@ -13,18 +17,21 @@ export interface CapsuleProps extends HTMLAttributes { size?: "xs" | "sm" | "md" | "lg"; } -/** Composes content with an independent circular glass action. */ +/** Composes content with a floating action, or joins two independent controls. */ export const Capsule = forwardRef(function Capsule({ action, actionPlacement = "overlay", children, className, + layout = "inline", size = "sm", + splitSizing = "equal", ...props }, ref) { return ( + data-openbitfun-component="capsule" data-layout={layout} data-size={size} data-split-sizing={layout === "split" ? splitSizing : undefined} + data-action-placement={action != null ? actionPlacement : undefined} data-overflow-trigger ref={ref}> {children} {action != null && {action}} diff --git a/design-system/packages/ui/src/components/Dialog/Dialog.meta.ts b/design-system/packages/ui/src/components/Dialog/Dialog.meta.ts index adcbbaa9d6..43e7b56c5f 100644 --- a/design-system/packages/ui/src/components/Dialog/Dialog.meta.ts +++ b/design-system/packages/ui/src/components/Dialog/Dialog.meta.ts @@ -2,7 +2,7 @@ import type { ComponentMeta } from "../../registry.types"; export const dialogMeta = { category: "feedback", - description: "A compound dialog with attached or frosted floating footer anatomy on the shared overlay kernel.", + description: "A compound dialog with attached or floating footers and a fixed Panel Dialog preset on the shared overlay kernel.", maturity: "stable", name: "Dialog", props: [ @@ -12,12 +12,13 @@ export const dialogMeta = { { name: "open", type: "boolean" }, { name: "onOpenChange", type: "(open: false, reason: DialogCloseReason) => void" }, { defaultValue: "md", name: "size", type: "sm | md | lg | xl | 2xl" }, + { defaultValue: "default", name: "preset", type: "default | panel" }, { defaultValue: "false", name: "DialogHeader.separator", type: "boolean" }, { defaultValue: "false", name: "DialogFooter.separator", type: "boolean" }, { defaultValue: "true", name: "closeOnEscape", type: "boolean" }, { defaultValue: "true", name: "closeOnPointerOutside", type: "boolean" }, ], - states: ["default", "open", "alert", "scrolling", "floating-footer"], + states: ["default", "open", "alert", "scrolling", "floating-footer", "panel"], tokens: [ "color.overlay.scrim", "color.surface.raised", @@ -27,6 +28,11 @@ export const dialogMeta = { "color.content.muted", "overlay.dialog.surfaceRadius", "overlay.dialog.viewportGutter", + "overlay.dialog.panelBlockSize", + "overlay.dialog.maxInlineSizeXlarge", + "overlay.dialog.maxInlineSizeLarge", + "space.4", + "control.height.sm", "overlay.dialog.headerPaddingBlockStart", "overlay.dialog.headerPaddingBlockEnd", "overlay.dialog.footerPaddingBlockStart", diff --git a/design-system/packages/ui/src/components/Dialog/Dialog.module.css b/design-system/packages/ui/src/components/Dialog/Dialog.module.css index ab44276461..56efa88dfa 100644 --- a/design-system/packages/ui/src/components/Dialog/Dialog.module.css +++ b/design-system/packages/ui/src/components/Dialog/Dialog.module.css @@ -44,6 +44,70 @@ .surface[data-size="xl"] { max-inline-size: var(--openbitfun-overlay-dialog-max-inline-size-xlarge); } .surface[data-size="2xl"] { max-inline-size: var(--openbitfun-overlay-dialog-max-inline-size-xxlarge); } + .surface[data-preset="panel"] { + --_dialog-panel-title-gap: calc(var(--openbitfun-overlay-dialog-header-padding-block-start) + var(--openbitfun-space-4)); + + display: grid; + grid-template-rows: auto minmax(0, max-content) auto; + align-content: center; + padding-block: var(--_dialog-panel-title-gap); + block-size: min( + var(--openbitfun-overlay-dialog-panel-block-size), + calc(100dvh - 2 * var(--openbitfun-overlay-dialog-viewport-gutter)) + ); + } + + .surface[data-preset="panel"] > .header { + padding-block-start: 0; + padding-block-end: var(--_dialog-panel-title-gap); + } + + .surface[data-preset="panel"] > .header > .heading { + justify-content: center; + min-block-size: var(--openbitfun-control-height-sm); + max-inline-size: var(--openbitfun-overlay-dialog-max-inline-size-large); + margin-inline: auto; + text-align: center; + } + + .surface[data-preset="panel"] > .header > .headerLeading, + .surface[data-preset="panel"] > .header > .headerActions, + .surface[data-preset="panel"] > .header > .close { + position: absolute; + inset-block-start: var(--openbitfun-overlay-dialog-header-padding-block-start); + inset-inline-end: var(--openbitfun-overlay-dialog-header-padding-inline); + } + + .surface[data-preset="panel"] > .header > .headerLeading { + inset-inline-start: var(--openbitfun-overlay-dialog-header-padding-inline); + inset-inline-end: auto; + } + + .surface[data-preset="panel"] > .body { + padding-block: 0; + padding-inline: max( + var(--openbitfun-overlay-dialog-content-padding-lg), + calc((100% - var(--openbitfun-overlay-dialog-max-inline-size-large)) / 2) + ); + } + + .surface[data-preset="panel"] > .footer[data-appearance="attached"] { + justify-content: center; + padding-block: var(--openbitfun-overlay-dialog-header-padding-block-end) 0; + } + + .surface[data-preset="panel"]:has(> .footer[data-appearance="floating"]) { + padding-block-end: max( + var(--_dialog-panel-title-gap), + var(--openbitfun-overlay-dialog-footer-height) + ); + } + + .surface[data-preset="panel"]:has(> .footer[data-appearance="floating"]) > .body { + padding-block-end: var(--openbitfun-overlay-dialog-footer-fade-extent); + scroll-padding-block-end: var(--openbitfun-overlay-dialog-footer-fade-extent); + } + .overlay[data-openbitfun-component="sheet"] { padding: 0; } @@ -113,6 +177,7 @@ letter-spacing: var(--openbitfun-type-support-letter-spacing); } + .headerLeading, .headerActions { display: flex; flex: 0 0 auto; diff --git a/design-system/packages/ui/src/components/Dialog/Dialog.tsx b/design-system/packages/ui/src/components/Dialog/Dialog.tsx index 8dab7eeb3d..79531c56ed 100644 --- a/design-system/packages/ui/src/components/Dialog/Dialog.tsx +++ b/design-system/packages/ui/src/components/Dialog/Dialog.tsx @@ -30,6 +30,7 @@ const EXIT_DURATION_MS = 180; export type DialogCloseReason = "close-button" | "escape-key" | "pointer-outside"; export type DialogFooterAppearance = "attached" | "floating"; +export type DialogPreset = "default" | "panel"; export type DialogSize = "sm" | "md" | "lg" | "xl" | "2xl"; export type SheetPlacement = "left" | "right" | "bottom"; export type SheetSize = "sm" | "md" | "lg"; @@ -73,6 +74,7 @@ interface OverlaySurfaceProps onExitComplete?: () => void; open: boolean; placement?: SheetPlacement; + preset?: DialogPreset; preventScroll?: boolean; role?: "dialog" | "alertdialog"; size: DialogSize | SheetSize; @@ -97,6 +99,7 @@ const OverlaySurface = forwardRef(function onExitComplete, open, placement, + preset, preventScroll = true, role = "dialog", size, @@ -112,15 +115,15 @@ const OverlaySurface = forwardRef(function const titleId = `openbitfun-dialog-title-${useId()}`; const descriptionId = `openbitfun-dialog-description-${useId()}`; const { present, state } = usePresence(open, EXIT_DURATION_MS); - const presentation = { children, className, overlayProps, placement, size, style }; + const presentation = { children, className, overlayProps, placement, preset, size, style }; const lastOpenPresentation = useRef(null); const wasPresent = useRef(present); // Owners often clear selection or form state in the same update as closing. // Retain the content and its geometry together until the exit finishes. useLayoutEffect(() => { - if (open) lastOpenPresentation.current = { children, className, overlayProps, placement, size, style }; + if (open) lastOpenPresentation.current = { children, className, overlayProps, placement, preset, size, style }; else if (!present) lastOpenPresentation.current = null; - }, [children, className, open, overlayProps, placement, present, size, style]); + }, [children, className, open, overlayProps, placement, preset, present, size, style]); useEffect(() => { const completed = wasPresent.current && !present && !open; wasPresent.current = present; @@ -194,6 +197,7 @@ const OverlaySurface = forwardRef(function data-openbitfun-component={kind} data-openbitfun-part="surface" data-placement={rendered.placement} + data-preset={rendered.preset} data-size={rendered.size} data-state={exiting ? "exiting" : "open"} ref={setSurfaceRef} @@ -215,14 +219,15 @@ export interface DialogProps } export const Dialog = forwardRef(function Dialog({ + preset = "default", size = "md", ...props }, ref) { - return ; + return ; }); export interface SheetProps - extends Omit { + extends Omit { placement?: SheetPlacement; size?: SheetSize; } @@ -283,6 +288,12 @@ export const DialogHeaderActions = forwardRef>( + function DialogHeaderLeading({ className, ...props }, ref) { + return
; + }, +); + export interface DialogCloseProps extends Omit { "aria-label"?: string; diff --git a/design-system/packages/ui/src/components/Dialog/index.ts b/design-system/packages/ui/src/components/Dialog/index.ts index 270c54b356..580068281c 100644 --- a/design-system/packages/ui/src/components/Dialog/index.ts +++ b/design-system/packages/ui/src/components/Dialog/index.ts @@ -6,6 +6,7 @@ export { DialogFooter, DialogHeader, DialogHeaderActions, + DialogHeaderLeading, DialogHeading, DialogTitle, Sheet, @@ -15,6 +16,7 @@ export { type DialogFooterAppearance, type DialogFooterProps, type DialogHeaderProps, + type DialogPreset, type DialogProps, type DialogSize, type SheetPlacement, diff --git a/design-system/packages/ui/src/index.ts b/design-system/packages/ui/src/index.ts index 1c794e9afb..c1ad1b6312 100644 --- a/design-system/packages/ui/src/index.ts +++ b/design-system/packages/ui/src/index.ts @@ -186,6 +186,7 @@ export { DialogFooter, DialogHeader, DialogHeaderActions, + DialogHeaderLeading, DialogHeading, DialogTitle, Sheet, @@ -195,6 +196,7 @@ export { type DialogFooterAppearance, type DialogFooterProps, type DialogHeaderProps, + type DialogPreset, type DialogProps, type DialogSize, type SheetPlacement, diff --git a/design-system/packages/ui/tests/capsule.test.mjs b/design-system/packages/ui/tests/capsule.test.mjs index 885c6f2ac0..b4aa401d85 100644 --- a/design-system/packages/ui/tests/capsule.test.mjs +++ b/design-system/packages/ui/tests/capsule.test.mjs @@ -2,7 +2,8 @@ import assert from "node:assert/strict"; import { createElement as h } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import test from "node:test"; -import { Button, Capsule, Icon, IconButton, MultiSelect, TabGroup, Tooltip } from "../dist/index.js"; +import { readFile } from "node:fs/promises"; +import { Button, Capsule, Icon, IconButton, MultiSelect, Select, TabGroup, Tooltip } from "../dist/index.js"; const action = (props = {}) => h(IconButton, { "aria-label": "Remove provider", icon: h(Icon, { name: "delete" }), ...props, @@ -36,6 +37,32 @@ test("capsules without actions preserve ordinary content and do not add a focus assert.doesNotMatch(markup, /tabindex|role=|data-openbitfun-part="action"|data-action-placement/); }); +test("split capsules align filled edges with equal or content-sized leading widths", async () => { + const markup = renderToStaticMarkup(h(Capsule, { layout: "split", splitSizing: "content", size: "sm", role: "group", "aria-label": "Provider" }, + h(Select, { size: "sm", variant: "pill", width: "content", "aria-label": "Region", options: [{ value: "international", label: "International" }] }), + h(Button, { size: "sm", variant: "primary" }, "Sign in"), + )); + assert.match(markup, /data-layout="split"/); + assert.match(markup, /data-split-sizing="content"/); + assert.match(renderToStaticMarkup(h(Capsule, { layout: "split" })), /data-split-sizing="equal"/); + assert.match(markup, /role="combobox"/); + assert.match(markup, /aria-label="Region"/); + assert.match(markup, /Sign in/); + assert.equal((markup.match(/") < markup.lastIndexOf("\[data-openbitfun-part=trigger\]\{border-color:transparent;background-clip:padding-box\}/); + assert.match(splitRules, /border-inline-end-width:0/); + assert.match(splitRules, /border-inline-start-width:0/); + assert.match(splitRules, /border-start-end-radius:0;border-end-end-radius:0/); + assert.match(splitRules, /border-start-start-radius:0;border-end-start-radius:0/); +}); + test("tab actions and removable MultiSelect labels adopt the same glass presentation", () => { const tabs = renderToStaticMarkup(h(TabGroup, { items: [{ value: "a", label: "A long tab", endAction: action({ variant: "outline" }) }] })); assert.match(tabs, /data-openbitfun-variant="glass"/); diff --git a/design-system/packages/ui/tests/dialog.test.mjs b/design-system/packages/ui/tests/dialog.test.mjs index 3ddd17baf8..e7a195d6c1 100644 --- a/design-system/packages/ui/tests/dialog.test.mjs +++ b/design-system/packages/ui/tests/dialog.test.mjs @@ -26,6 +26,7 @@ test("Dialog and Sheet compose the shared overlay kernel and compound anatomy", "title", "description", "header-actions", + "header-leading", "close", "body", "footer", @@ -89,6 +90,20 @@ test("DialogFooter exposes a centered frosted floating action layer", async () = assert.match(styles, /--openbitfun-overlay-dialog-footer-action-min-width/); }); +test("Panel Dialog publishes fixed viewport-safe geometry and centered header spacing", async () => { + const styles = await readFile(new URL("../dist/styles.css", import.meta.url), "utf8"); + const panelRules = styles.match(/\[data-preset=panel\][^{}]*\{[^}]*\}/g)?.join("\n") ?? ""; + + assert.match(panelRules, /\[data-preset=panel\]\{[^}]*grid-template-rows:auto minmax\(0,max-content\) auto;align-content:center/); + assert.match(panelRules, /--_dialog-panel-title-gap:\s*calc\(var\(--openbitfun-overlay-dialog-header-padding-block-start\) \+ var\(--openbitfun-space-4\)\)/); + assert.match(panelRules, /\[data-preset=panel\]\{[^}]*padding-block:var\(--_dialog-panel-title-gap\);block-size:min\(var\(--openbitfun-overlay-dialog-panel-block-size\),calc\(100dvh/); + assert.match(panelRules, /\[data-preset=panel\]>[^{}]+\{padding-block-start:0;padding-block-end:var\(--_dialog-panel-title-gap\)/); + assert.match(panelRules, /\[data-preset=panel\]>[^{}]+\{[^}]*min-block-size:var\(--openbitfun-control-height-sm\);[^}]*text-align:center/); + assert.match(panelRules, /padding-block-end:max\([^}]*var\(--openbitfun-overlay-dialog-footer-height\)/); + assert.doesNotMatch(panelRules, /--openbitfun-overlay-dialog-footer-content-inset/); + assert.match(panelRules, /\[data-preset=panel\]>[^{}]+\{[^}]*padding-inline:max\(var\(--openbitfun-overlay-dialog-content-padding-lg\),calc\(\(100% - var\(--openbitfun-overlay-dialog-max-inline-size-large\)\)\s*\/\s*2\)\)/); +}); + test("dialog separators are explicit and do not leak native attributes", () => { for (const component of [DialogHeader, DialogFooter]) { assert.match(renderToStaticMarkup(createElement(component)), /data-separator="false"/); diff --git a/src/apps/data-tools/ui/generated/design-system.css b/src/apps/data-tools/ui/generated/design-system.css index 4b8b944d71..141bb8159d 100644 --- a/src/apps/data-tools/ui/generated/design-system.css +++ b/src/apps/data-tools/ui/generated/design-system.css @@ -389,6 +389,7 @@ --openbitfun-overlay-dialog-max-inline-size-wide: 1200px; --openbitfun-overlay-dialog-max-inline-size-xlarge: 800px; --openbitfun-overlay-dialog-max-inline-size-xxlarge: 960px; + --openbitfun-overlay-dialog-panel-block-size: 640px; --openbitfun-overlay-dialog-scrollbar-width: var(--openbitfun-scrollbar-width); --openbitfun-overlay-dialog-surface-radius: 28px; --openbitfun-overlay-dialog-viewport-gutter: 24px; diff --git a/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.test.tsx b/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.test.tsx index c11649888f..ce293cf866 100644 --- a/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.test.tsx +++ b/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.test.tsx @@ -73,6 +73,8 @@ describe('model discovery capsules', () => { click(trigger()); expect(popup()!.getAttribute('aria-modal')).toBe('true'); expect(popup()!.getAttribute('data-openbitfun-component')).toBe('dialog'); + expect(popup()!.getAttribute('data-preset')).toBe('panel'); + expect(popup()!.getAttribute('data-size')).toBe('xl'); expect(popup()!.textContent).toContain(copy('providerSelection.fetchedModels', { count: '3' })); expect(capsules().map(button => button.textContent)).toEqual(['alpha', 'beta', 'gamma']); expect(capsules()[0].getAttribute('aria-pressed')).toBe('true'); diff --git a/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.tsx b/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.tsx index e392430739..ebfe941838 100644 --- a/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.tsx +++ b/src/web-ui/src/app/scenes/settings/pages/ai/ModelDiscoveryPicker.tsx @@ -86,7 +86,7 @@ export function ModelDiscoveryPicker({ setOpen(true)}> {t('pools.add')} - {t('pools.add')} diff --git a/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.scss b/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.scss index 7eb9feebe5..7b516eacb5 100644 --- a/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.scss +++ b/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.scss @@ -88,10 +88,6 @@ font-variant-numeric: tabular-nums; } -.openbitfun-model-pools__editor { - block-size: min(640px, calc(100vh - 2 * var(--openbitfun-overlay-dialog-viewport-gutter))); -} - .openbitfun-model-pools__strategies { display: grid; inline-size: 100%; @@ -169,10 +165,6 @@ } } -.openbitfun-model-pools__picker { - block-size: min(420px, calc(100vh - 2 * var(--openbitfun-overlay-dialog-viewport-gutter))); -} - .openbitfun-model-pools__picker-body { gap: var(--openbitfun-space-3); overflow: hidden; diff --git a/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.tsx b/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.tsx index f4f5d311ad..24c07e1544 100644 --- a/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.tsx +++ b/src/web-ui/src/app/scenes/settings/pages/ai/ModelPoolsSection.tsx @@ -253,7 +253,7 @@ export function ModelPoolsSection({ models }: { models: AIModelConfig[] }) { { if (!nextOpen) discardDraft(); }} className="openbitfun-model-pools__editor" data-testid="settings-model-pool-dialog" - size="lg" closeOnPointerOutside={false}> + preset="panel" closeOnPointerOutside={false}> {t(pools.some(pool => pool.id === draft?.id) ? 'pools.editTitle' : 'pools.create')} diff --git a/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.loading.test.tsx b/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.loading.test.tsx index 26b9179eec..2c9efe647b 100644 --- a/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.loading.test.tsx +++ b/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.loading.test.tsx @@ -123,6 +123,10 @@ describe('ModelSettingsPage loading and provider actions', () => { expect(update).not.toHaveBeenCalled(); await act(async () => summary.querySelector('[data-testid="settings-subscription-more"] button')!.click()); const dialog = document.querySelector('[role="dialog"]')!; + expect(dialog.getAttribute('data-preset')).toBe('panel'); + expect(dialog.getAttribute('data-size')).toBe('xl'); + expect(dialog.querySelector('[data-openbitfun-part="header"] [data-openbitfun-part="description"]')).toBeNull(); + expect(dialog.querySelector(`button[aria-label="${copy('subscriptionAuth.rescan')}"]`)).not.toBeNull(); expect(dialog.textContent).toContain('shared@example.invalid'); const quota = dialog.querySelector('[data-account-id="codex"] [data-openbitfun-part="subscriptionQuota"]')!; expect(quota.closest('.openbitfun-config-page-row__description')).not.toBeNull(); @@ -411,8 +415,9 @@ describe('ModelSettingsPage loading and provider actions', () => { vi.spyOn(aiApi, 'cancelSubscriptionLogin').mockResolvedValue(undefined); vi.spyOn(systemAPI, 'openExternal').mockResolvedValue(undefined); await act(async () => root.render()); - await act(async () => button('acquisition.import').click()); + await act(async () => button('acquisition.addSubscription').click()); const dialog = () => document.querySelector('.openbitfun-model-settings__subscription-dialog:not([aria-hidden="true"])')!; + expect(dialog().querySelector(`button[aria-label="${copy('subscriptionAuth.rescan')}"]`)).toBeNull(); const login = (provider: string) => [...dialog().querySelectorAll(`[data-provider="${provider}"] button`)] .find(element => element.textContent === copy('subscriptionAuth.login'))!; expect(dialog().querySelector('[data-testid="settings-subscription-provider"]')).toBeNull(); @@ -429,6 +434,13 @@ describe('ModelSettingsPage loading and provider actions', () => { expect(quota).not.toHaveBeenCalled(); if (loginProvider === 'zcode_cn') { const zcode = dialog().querySelector('[data-provider="zcode"]')!; + const capsule = zcode.querySelector('[data-openbitfun-component="capsule"]')!; + expect(capsule.getAttribute('data-layout')).toBe('split'); + expect(capsule.getAttribute('data-split-sizing')).toBe('content'); + expect(capsule.querySelector('[data-openbitfun-component="select"]')?.getAttribute('data-width')).toBe('content'); + expect(capsule.children).toHaveLength(2); + expect(capsule.querySelector('[role="combobox"]')).not.toBeNull(); + expect(login('zcode').parentElement).toBe(capsule); expect(zcode.querySelector('[role="combobox"]')?.textContent).toBe(copy('subscriptionAuth.regionsShort.zai')); await act(async () => zcode.querySelector('[role="combobox"]')!.click()); await act(async () => [...document.querySelectorAll('[role="option"]')] @@ -464,7 +476,7 @@ describe('ModelSettingsPage loading and provider actions', () => { const start = vi.spyOn(aiApi, 'startSubscriptionAccountLogin').mockRejectedValue(new Error('Authorization unavailable')); vi.spyOn(aiApi, 'cancelSubscriptionLogin').mockResolvedValue(undefined); await act(async () => root.render()); - await act(async () => button('acquisition.import').click()); + await act(async () => button('acquisition.addSubscription').click()); const dialog = document.querySelector('.openbitfun-model-settings__subscription-dialog')!; const action = (key: string) => [...dialog.querySelectorAll('button')] .find(element => element.textContent === copy(key))!; @@ -515,7 +527,7 @@ describe('ModelSettingsPage loading and provider actions', () => { await act(async () => root.render()); await act(async () => inModelEditor ? container.querySelector('[data-testid="settings-subscription-services"] button')!.click() - : button('acquisition.import').click()); + : button('acquisition.addSubscription').click()); const dialog = () => [...document.querySelectorAll('[role="dialog"]')].at(-1)!; const dialogButton = (key: string) => [...dialog().querySelectorAll('button')] .find(element => element.textContent === copy(key))!; @@ -598,7 +610,7 @@ describe('ModelSettingsPage loading and provider actions', () => { expect(selectors().every(element => element.disabled)).toBe(true); expect(button('actions.addModel').disabled).toBe(true); expect(container.querySelector('[data-testid="settings-smart-mode-configure"]')?.disabled).toBe(true); - expect(button('acquisition.import').disabled).toBe(false); + expect(button('acquisition.addSubscription').disabled).toBe(false); await act(async () => { reads.get('ai.models')!.resolve([model]); @@ -803,7 +815,9 @@ describe('ModelSettingsPage loading and provider actions', () => { const editor = document.querySelector('.openbitfun-model-settings__editor-dialog')!; const brand = editor.querySelector('[data-testid="settings-provider-editor-brand"]')!; expect(brand.getAttribute('aria-label')).toBe(model.name); - expect(editor.querySelector('.openbitfun-model-settings__provider-editor-header [data-openbitfun-part="heading"]')?.classList.contains('sr-only')).toBe(true); + expect(editor.getAttribute('data-preset')).toBe('panel'); + expect(editor.querySelector('[data-openbitfun-part="title"]')?.classList.contains('sr-only')).toBe(true); + expect(brand.closest('[data-openbitfun-part="heading"]')).not.toBeNull(); if (kind === 'subscription') expect(brand.querySelector('[data-product-logo="codex"]')?.style.width).toBe('64px'); else { expect(brand.getAttribute('role')).toBe('heading'); diff --git a/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.scss b/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.scss index 807c6bb254..b934fb0c19 100644 --- a/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.scss +++ b/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.scss @@ -1466,10 +1466,6 @@ font-variant-numeric: tabular-nums; } - &__subscription-management { - padding-inline: var(--openbitfun-space-6); - } - &__endpoint-row { > .openbitfun-config-page-row__meta { display: flex; @@ -1680,10 +1676,6 @@ max-width: 100%; } - &__model-discovery-dialog { - block-size: min(420px, calc(100vh - 2 * var(--openbitfun-overlay-dialog-viewport-gutter))); - } - &__model-discovery-body { gap: var(--openbitfun-space-3); overflow: hidden; @@ -1843,75 +1835,17 @@ border-top: 1px dashed var(--openbitfun-color-field-border-hover); } - &__editor-dialog { - block-size: auto; - max-block-size: calc(100dvh - 2 * var(--openbitfun-overlay-dialog-viewport-gutter)); - } - - &__editor-heading-group { - flex: 1 1 auto; - } - - &__provider-editor-header { - display: grid; - grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); - align-items: start; - - > .openbitfun-model-settings__editor-heading-group { - grid-column: 1; - grid-row: 1; - } - - > [data-openbitfun-part='close'] { - grid-column: 3; - grid-row: 1; - justify-self: end; - } - } - &__provider-editor-brand { display: flex; - grid-column: 2; - grid-row: 1; align-items: center; justify-content: center; - min-inline-size: var(--openbitfun-space-16); - min-block-size: var(--openbitfun-space-16); - margin-block-start: var(--openbitfun-space-10); color: var(--openbitfun-color-content-primary); text-align: center; overflow-wrap: anywhere; - font-family: var(--openbitfun-type-heading-page-font-family); - font-size: var(--openbitfun-type-heading-page-font-size); - font-weight: var(--openbitfun-type-heading-page-font-weight); - line-height: var(--openbitfun-type-heading-page-line-height); - } - - &__provider-editor-body > .openbitfun-model-settings__form--modal { - max-inline-size: var(--openbitfun-overlay-dialog-max-inline-size-large); - margin-inline: auto; - } - - &__provider-editor-body .openbitfun-model-settings__form-content { - gap: var(--openbitfun-space-4); - } - - &__model-editor-header { - align-items: center; - - [data-openbitfun-part='heading'] { - justify-content: center; - min-block-size: var(--openbitfun-control-icon-button-xs-size); - } - - [data-openbitfun-part='title'] { - color: var(--openbitfun-color-content-primary); - font-family: var(--openbitfun-type-label-selected-font-family); - font-size: var(--openbitfun-type-label-selected-font-size); - font-weight: var(--openbitfun-type-label-selected-font-weight); - line-height: var(--openbitfun-type-action-row-line-height); - letter-spacing: var(--openbitfun-type-label-selected-letter-spacing); - } + font-family: var(--openbitfun-type-heading-dialog-font-family); + font-size: var(--openbitfun-type-heading-dialog-font-size); + font-weight: var(--openbitfun-type-heading-dialog-font-weight); + line-height: var(--openbitfun-type-heading-dialog-line-height); } &__form--modal { @@ -1928,15 +1862,18 @@ } } + &__single-model-fields .openbitfun-config-page-row { + padding: var(--openbitfun-space-3) var(--openbitfun-space-4); + } + &__advanced-settings-content { padding-inline: 0; } &__form-content { - padding-inline: var(--openbitfun-space-6); display: flex; flex-direction: column; - gap: var(--openbitfun-space-6); + gap: var(--openbitfun-space-4); > * { flex-shrink: 0; @@ -2544,13 +2481,6 @@ } .openbitfun-model-settings { - &__subscription-dialog { - max-block-size: min( - 640px, - calc(100dvh - 2 * var(--openbitfun-overlay-dialog-viewport-gutter)) - ); - } - &__subscription-content { container: config-panel / inline-size; display: grid; @@ -2867,10 +2797,6 @@ } } - .openbitfun-model-settings__form-content { - padding-inline: var(--openbitfun-space-4); - } - .openbitfun-model-settings__connection-section > .openbitfun-config-page-section__body { grid-template-columns: minmax(0, 1fr); } diff --git a/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.tsx b/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.tsx index 946282e891..9833c781c9 100644 --- a/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.tsx +++ b/src/web-ui/src/app/scenes/settings/pages/ai/ModelSettingsPage.tsx @@ -130,10 +130,10 @@ import { Dialog, DialogBody, DialogClose, - DialogDescription, DialogFooter, DialogHeader, DialogHeaderActions, + DialogHeaderLeading, DialogHeading, DialogTitle, Disclosure, @@ -3654,6 +3654,7 @@ const ModelSettingsPage: React.FC = () => { return ( { )}
- )} @@ -4956,7 +4957,7 @@ const ModelSettingsPage: React.FC = () => { ) : (