mirror of
https://github.com/temetro/temetro.git
synced 2026-09-03 14:27:58 +00:00
frontend: real COSS Separated Panels in settings frames
Replace the gap-4-on-CardFrame hack with a faithful COSS Frame: a muted tray (bg-muted/72) holding distinct bordered FramePanels spaced by mt-1, matching coss.com/ui/docs/components/frame. Adds components/ui/frame.tsx and switches SettingsFrame/SettingsCard to render Frame/FramePanel when separated (via context), keeping joined frames on CardFrame. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { useState } from "react";
|
import { createContext, useContext, useState } from "react";
|
||||||
import { Check, Copy } from "lucide-react";
|
import { Check, Copy } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@@ -13,9 +13,15 @@ import {
|
|||||||
CardFrameHeader,
|
CardFrameHeader,
|
||||||
CardFrameTitle,
|
CardFrameTitle,
|
||||||
} from "@/components/ui/card";
|
} from "@/components/ui/card";
|
||||||
|
import { Frame, FramePanel } from "@/components/ui/frame";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
// Whether the enclosing frame is a COSS "Separated Panels" tray. When true,
|
||||||
|
// SettingsCard/ToggleRow render as a FramePanel (a distinct bordered card on the
|
||||||
|
// muted tray) instead of a fused CardFrame Card.
|
||||||
|
const SeparatedFrameContext = createContext(false);
|
||||||
|
|
||||||
// A settings section rendered inside the COSS "frame" surface: a titled header
|
// A settings section rendered inside the COSS "frame" surface: a titled header
|
||||||
// above one or more cards.
|
// above one or more cards.
|
||||||
//
|
//
|
||||||
@@ -43,15 +49,36 @@ export function SettingsFrame({
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
/**
|
/**
|
||||||
* COSS "Separated Panels": add a 1rem gap so sibling panels read as distinct
|
* COSS "Separated Panels": render a muted Frame tray whose children are
|
||||||
* cards instead of one flush joined list. The `gap-4` matches CardFrame's
|
* distinct bordered FramePanels spaced apart (the real coss.com/ui/frame
|
||||||
* built-in `--clip-top/--clip-bottom: -1rem`, which keeps each panel's rounded
|
* look), instead of the fused CardFrame surface. Leave off for a joined list.
|
||||||
* corners clipping correctly across the gap. Leave off for a joined list.
|
|
||||||
*/
|
*/
|
||||||
separated?: boolean;
|
separated?: boolean;
|
||||||
}) {
|
}) {
|
||||||
|
if (separated) {
|
||||||
|
return (
|
||||||
|
<Frame className={className}>
|
||||||
|
<div
|
||||||
|
className="flex items-start justify-between gap-4 px-4 py-3"
|
||||||
|
data-slot="frame-header"
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-0.5">
|
||||||
|
<p className="text-base font-semibold">{title}</p>
|
||||||
|
{description ? (
|
||||||
|
<p className="text-sm text-muted-foreground">{description}</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
{action ? <div className="shrink-0">{action}</div> : null}
|
||||||
|
</div>
|
||||||
|
<SeparatedFrameContext.Provider value={true}>
|
||||||
|
{children}
|
||||||
|
</SeparatedFrameContext.Provider>
|
||||||
|
</Frame>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CardFrame className={cn(separated && "gap-4", className)}>
|
<CardFrame className={className}>
|
||||||
<CardFrameHeader className="border-b border-border/60">
|
<CardFrameHeader className="border-b border-border/60">
|
||||||
<CardFrameTitle className="text-base">{title}</CardFrameTitle>
|
<CardFrameTitle className="text-base">{title}</CardFrameTitle>
|
||||||
{description ? (
|
{description ? (
|
||||||
@@ -105,6 +132,16 @@ export function SettingsCard({
|
|||||||
className?: string;
|
className?: string;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) {
|
}) {
|
||||||
|
const separated = useContext(SeparatedFrameContext);
|
||||||
|
if (separated) {
|
||||||
|
// A distinct panel on the Frame tray. `flex flex-col` mirrors Card's default
|
||||||
|
// layout; callers that need a row (ToggleRow) override with `flex-row`.
|
||||||
|
return (
|
||||||
|
<FramePanel className={cn("flex flex-col", className)}>
|
||||||
|
{children}
|
||||||
|
</FramePanel>
|
||||||
|
);
|
||||||
|
}
|
||||||
return <Card className={className}>{children}</Card>;
|
return <Card className={className}>{children}</Card>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import type React from "react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
// COSS "Frame" primitive (coss.com/ui/docs/components/frame). A Frame is a muted
|
||||||
|
// tray that holds one or more FramePanels; multiple panels are "Separated
|
||||||
|
// Panels" — spaced apart with `mt-1` by default (via the adjacent-sibling
|
||||||
|
// selector below), each a self-contained bordered card. This is the opposite of
|
||||||
|
// `CardFrame` in card.tsx, which fuses its cards into one flush surface.
|
||||||
|
|
||||||
|
export function Frame({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">): React.ReactElement {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"relative flex flex-col rounded-2xl bg-muted/72 p-1",
|
||||||
|
"*:[[data-slot=frame-panel]+[data-slot=frame-panel]]:mt-1",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
data-slot="frame"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FramePanel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">): React.ReactElement {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"relative rounded-xl border bg-background bg-clip-padding p-5 shadow-xs/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
data-slot="frame-panel"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FrameHeader({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">): React.ReactElement {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn("flex flex-col px-5 py-4", className)}
|
||||||
|
data-slot="frame-header"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FrameTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">): React.ReactElement {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn("font-semibold text-sm", className)}
|
||||||
|
data-slot="frame-title"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FrameDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">): React.ReactElement {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
data-slot="frame-description"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FrameFooter({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">): React.ReactElement {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn("px-5 py-4", className)}
|
||||||
|
data-slot="frame-footer"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user