diff --git a/r/card.json b/r/card.json index 4d7cb82e..15312054 100644 --- a/r/card.json +++ b/r/card.json @@ -17,7 +17,7 @@ "path": "src/components/cipher/ui/card.tsx", "type": "registry:file", "target": "src/components/cipher/ui/card.tsx", - "content": "import * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { Checkbox as CheckboxPrimitive, RadioGroup as RadioGroupPrimitive } from \"radix-ui\";\n\nimport { useDescendantFlags } from \"../lib/descendant-flags\";\nimport { FrameScope, useInFrame } from \"../lib/frame-context\";\nimport { CipherLink, type CipherLinkProps } from \"../lib/link\";\nimport { exit, spring } from \"../lib/motion\";\nimport { type PresenceReport, usePresenceCount, useReportPresence } from \"../lib/presence-count\";\nimport { RadioValueContext } from \"../lib/radio-value-context\";\nimport {\n StretchedLinkContext,\n useStretchedLink,\n useStretchedLinkHost\n} from \"../lib/stretched-link\";\nimport { useControllableState } from \"../lib/use-controllable-state\";\nimport { cn } from \"../lib/utils\";\n\nimport { Badge } from \"./badge\";\nimport { Icon } from \"./icon\";\nimport { TooltipText } from \"./tooltip\";\n\nimport controlStyles from \"./controls.module.css\";\nimport frameStyles from \"./frame.module.css\";\nimport linkStyles from \"./row-link.module.css\";\n\nconst FramedContext = React.createContext(false);\nconst CardChoiceContext = React.createContext(null);\n\nconst cardFlags = {\n \"data-has-slots\":\n ':scope > :is([data-slot=\"card-header\"], [data-slot=\"card-content\"], [data-slot=\"card-footer\"])',\n \"data-frame-head\": `:scope > .${frameStyles.frameHead}`,\n \"data-frame-foot\": `:scope > .${frameStyles.frameFoot}`\n};\nconst cardWatch = {\n subtree: false,\n marks: {\n \"data-before-footer\": `:scope > .${controlStyles.cardBody}:has(+ .${controlStyles.cardFooter}:not([data-placement=\"frame\"]))`\n }\n};\n\nfunction Card({\n className,\n size = \"default\",\n variant: requestedVariant = \"plain\",\n title,\n badges,\n description,\n hint,\n action,\n footer,\n footerPlacement = \"inset\",\n flush = false,\n backdrop,\n selected,\n children,\n ref,\n ...props\n}: Omit, \"title\"> & {\n size?: \"default\" | \"sm\";\n title?: React.ReactNode;\n /** Badges on the title's line, right after its text, such as a plan tier. A DocumentationLink for the card goes here too, so it stays paired with the title. */\n badges?: React.ReactNode;\n /** Controls on the head's end. In a framed card's band a Button takes the 28px band tier (size-control-band) and the 14px icon whatever size it is given, so every action in a band shares one height; leave field sizes unset so they take the same tier. Actions sit space-frame-inline from the corner; badges keep their text height. */\n action?: React.ReactNode;\n footer?: React.ReactNode;\n /** \"frame\" draws the footer in the frame band: its text keeps the title's start inset and its controls take the 28px band tier. */\n footerPlacement?: \"inset\" | \"frame\";\n flush?: boolean;\n /** Decoration such as a Halftone, painted under the surface that holds the title and the card link: the inset of a framed card with a frame footer, otherwise the card itself. That surface becomes the stacking context, so the link overlay and the controls above it stay in one layer. */\n backdrop?: React.ReactNode;\n /** Paints the card as chosen. A CardChoice inside sets it on its own; pass it for a selection the card does not own, and give the link aria-current when a selected card is the current item. */\n selected?: boolean;\n} & (\n | { variant?: \"plain\"; description?: string; hint?: never }\n | {\n variant: \"framed\";\n /** A frame holds a small contained table or list, so its head is a title and actions only. A section that needs a description belongs in a plain Card or a SettingsCard. */\n description?: never;\n /** One short plain-text sentence about the section. The title takes a dotted underline, becomes focusable and shows this in a tooltip on hover and keyboard focus. */\n hint?: string;\n }\n ) & { ref?: React.Ref> }) {\n const convenience =\n title !== undefined ||\n badges !== undefined ||\n description !== undefined ||\n action !== undefined ||\n footer !== undefined;\n const inFrame = useInFrame(\"Card\", requestedVariant);\n const variant = inFrame ? \"plain\" : requestedVariant;\n const [hasLink, reportLink] = useStretchedLinkHost();\n const [choiceChecked, reportChoice] = usePresenceCount();\n const cardRef = useDescendantFlags(cardFlags, cardWatch, ref);\n const titleParts = React.Children.toArray(\n React.isValidElement<{ children?: React.ReactNode }>(title) && title.type === React.Fragment\n ? title.props.children\n : title\n );\n const firstBadge = titleParts.findIndex(\n (part) => React.isValidElement(part) && part.type === Badge\n );\n const hintText = firstBadge > 0 ? titleParts.slice(0, firstBadge) : titleParts;\n const lastText = hintText.at(-1);\n const trailingSpace = typeof lastText === \"string\" && /\\s$/.test(lastText);\n const heading =\n title !== undefined &&\n (hint ? (\n \n \n {trailingSpace ? [...hintText.slice(0, -1), lastText.trimEnd()] : hintText}\n \n {trailingSpace && \" \"}\n {firstBadge > 0 && titleParts.slice(firstBadge)}\n \n ) : (\n {title}\n ));\n const header = (title !== undefined ||\n badges !== undefined ||\n description !== undefined ||\n action) && (\n \n
\n
\n {badges !== undefined ? (\n
\n {heading}\n {badges}\n
\n ) : (\n heading\n )}\n {description !== undefined && {description}}\n
\n
\n {action && {action}}\n
\n );\n return (\n \n \n \n \n \n {convenience &&\n variant !== \"plain\" &&\n footer !== undefined &&\n footerPlacement === \"frame\" ? (\n <>\n \n {backdrop}\n \n {header}\n {children !== undefined && children !== null && (\n {children}\n )}\n \n \n {footer}\n \n ) : convenience ? (\n <>\n {backdrop}\n {header}\n {children}\n {footer !== undefined && (\n {footer}\n )}\n \n ) : (\n <>\n {backdrop}\n {children}\n \n )}\n \n \n \n \n \n );\n}\nCard.displayName = \"Card\";\n\nfunction CardHeader({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n return (\n \n );\n}\nCardHeader.displayName = \"CardHeader\";\n\nfunction CardTitle({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n return (\n \n );\n}\nCardTitle.displayName = \"CardTitle\";\n\nfunction CardBadges({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n return (\n \n );\n}\nCardBadges.displayName = \"CardBadges\";\n\nfunction CardDescription({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n return (\n \n );\n}\nCardDescription.displayName = \"CardDescription\";\n\nfunction CardAction({\n className,\n title,\n children,\n onPointerEnter,\n onFocus,\n ref,\n ...props\n}: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n const [clipped, setClipped] = React.useState();\n const parts: React.ReactNode[] = [];\n let text: (string | number)[] = [];\n const flush = () => {\n if (text.length) parts.push({text.join(\"\")});\n text = [];\n };\n for (const child of React.Children.toArray(children)) {\n if (typeof child === \"string\" || typeof child === \"number\") text.push(child);\n else {\n flush();\n parts.push(child);\n }\n }\n flush();\n const measure = (element: HTMLElement) => {\n if (title !== undefined) return;\n const truncated = [element, ...element.querySelectorAll(\"*\")].some(\n (part) => part.scrollWidth > part.clientWidth\n );\n setClipped(truncated ? element.textContent?.trim() || undefined : undefined);\n };\n return (\n {\n measure(event.currentTarget);\n onPointerEnter?.(event);\n }}\n onFocus={(event) => {\n measure(event.currentTarget);\n onFocus?.(event);\n }}\n {...props}\n >\n {parts}\n \n );\n}\nCardAction.displayName = \"CardAction\";\n\nfunction CardContent({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n return (\n \n );\n}\nCardContent.displayName = \"CardContent\";\n\nfunction CardFooter({\n className,\n placement = \"inset\",\n ref,\n ...props\n}: React.ComponentPropsWithoutRef<\"div\"> & { placement?: \"inset\" | \"frame\" } & {\n ref?: React.Ref>;\n}) {\n const framed = React.useContext(FramedContext);\n const band = framed && placement === \"frame\";\n return (\n \n );\n}\nCardFooter.displayName = \"CardFooter\";\n\nfunction CardLink({\n className,\n disabled,\n title,\n children,\n ref,\n ...props\n}: CipherLinkProps & {\n disabled?: boolean;\n}) {\n const off = disabled ?? (props.link as { disabled?: boolean }).disabled;\n useStretchedLink(!off);\n if (off)\n return (\n \n {children}\n \n );\n return (\n \n {children}\n \n );\n}\n\ntype CardChoiceProps = Omit<\n React.ComponentPropsWithoutRef<\"button\">,\n \"value\" | \"defaultChecked\" | \"onChange\"\n> & {\n /** Makes this a radio inside a RadioGroup, picked by the group's value. Without it the choice is a checkbox. */\n value?: string;\n checked?: boolean;\n defaultChecked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n} & { ref?: React.Ref };\n\n/**\n * Makes the whole Card one checkbox or radio, the way CardLink makes it one link: the label is its\n * accessible name, its overlay covers the card, and the card paints itself selected while it is checked.\n */\nfunction CardChoice({\n className,\n value,\n checked: checkedProp,\n defaultChecked,\n onCheckedChange,\n disabled,\n children,\n ref,\n ...props\n}: CardChoiceProps) {\n const reduced = useReducedMotion();\n const groupValue = React.useContext(RadioValueContext);\n const [toggled, setToggled] = useControllableState({\n value: checkedProp,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange\n });\n const radio = value !== undefined;\n const checked = radio ? groupValue === value : toggled;\n useStretchedLink(!disabled);\n useReportPresence(React.useContext(CardChoiceContext), checked);\n const state = checked ? \"checked\" : \"unchecked\";\n const classes = cn(\n linkStyles.cardLink,\n linkStyles.cardChoice,\n !disabled && linkStyles.stretched,\n className\n );\n const label = (\n <>\n \n {radio ? (\n \n ) : (\n checked && \n )}\n \n {children}\n \n );\n if (radio)\n return (\n \n {label}\n \n );\n return (\n setToggled(next === true)}\n disabled={disabled}\n className={classes}\n {...props}\n >\n {label}\n \n );\n}\nCardChoice.displayName = \"CardChoice\";\n\nexport {\n Card,\n CardAction,\n CardBadges,\n CardChoice,\n CardContent,\n CardDescription,\n CardFooter,\n CardHeader,\n CardLink,\n CardTitle\n};\n" + "content": "import * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { Checkbox as CheckboxPrimitive, RadioGroup as RadioGroupPrimitive } from \"radix-ui\";\n\nimport { useDescendantFlags } from \"../lib/descendant-flags\";\nimport { FrameScope, useInFrame } from \"../lib/frame-context\";\nimport { CipherLink, type CipherLinkProps } from \"../lib/link\";\nimport { exit, spring } from \"../lib/motion\";\nimport { type PresenceReport, usePresenceCount, useReportPresence } from \"../lib/presence-count\";\nimport { RadioValueContext } from \"../lib/radio-value-context\";\nimport {\n StretchedLinkContext,\n useStretchedLink,\n useStretchedLinkHost\n} from \"../lib/stretched-link\";\nimport { useControllableState } from \"../lib/use-controllable-state\";\nimport { cn } from \"../lib/utils\";\n\nimport { Badge } from \"./badge\";\nimport { Icon } from \"./icon\";\nimport { TooltipText } from \"./tooltip\";\n\nimport controlStyles from \"./controls.module.css\";\nimport frameStyles from \"./frame.module.css\";\nimport linkStyles from \"./row-link.module.css\";\n\nconst FramedContext = React.createContext(false);\nconst CardChoiceContext = React.createContext(null);\n\nconst cardFlags = {\n \"data-has-slots\":\n ':scope > :is([data-slot=\"card-header\"], [data-slot=\"card-content\"], [data-slot=\"card-footer\"])',\n \"data-frame-head\": `:scope > .${frameStyles.frameHead}`,\n \"data-frame-foot\": `:scope > .${frameStyles.frameFoot}`\n};\nconst cardWatch = {\n subtree: false,\n marks: {\n \"data-before-footer\": `:scope > .${controlStyles.cardBody}:has(+ .${controlStyles.cardFooter}:not([data-placement=\"frame\"]))`\n }\n};\n\nconst withPanelBackdrop = (children: React.ReactNode, backdrop: React.ReactNode) => {\n let placed = false;\n const walk = (nodes: React.ReactNode): React.ReactNode =>\n React.Children.map(nodes, (child) => {\n if (placed || !React.isValidElement<{ children?: React.ReactNode }>(child)) return child;\n if (child.type === React.Fragment)\n return React.cloneElement(child, undefined, walk(child.props.children));\n if (child.type !== CardContent || \"dangerouslySetInnerHTML\" in child.props) return child;\n placed = true;\n return React.cloneElement(\n child as React.ReactElement<{ children?: React.ReactNode; \"data-backdrop\"?: string }>,\n { \"data-backdrop\": backdrop === undefined ? undefined : \"\" },\n backdrop ?? null,\n child.props.children\n );\n });\n const content = walk(children);\n return { content, placed };\n};\n\nfunction Card({\n className,\n size = \"default\",\n variant: requestedVariant = \"plain\",\n title,\n badges,\n description,\n hint,\n action,\n footer,\n footerPlacement = \"inset\",\n flush = false,\n backdrop,\n selected,\n children,\n ref,\n ...props\n}: Omit, \"title\"> & {\n size?: \"default\" | \"sm\";\n title?: React.ReactNode;\n /** Badges on the title's line, right after its text, such as a plan tier. A DocumentationLink for the card goes here too, so it stays paired with the title. */\n badges?: React.ReactNode;\n /** Controls on the head's end. In a framed card's band a Button takes the 28px band tier (size-control-band) and the 14px icon whatever size it is given, so every action in a band shares one height; leave field sizes unset so they take the same tier. Actions sit space-frame-inline from the corner; badges keep their text height. */\n action?: React.ReactNode;\n footer?: React.ReactNode;\n /** \"frame\" draws the footer in the frame band: its text keeps the title's start inset and its controls take the 28px band tier. */\n footerPlacement?: \"inset\" | \"frame\";\n flush?: boolean;\n /** Decoration such as a Halftone, painted in the content corners and never on a frame's chrome: the inset of a framed card with a frame footer, the first CardContent of any other framed card, otherwise the card itself. That surface becomes the stacking context; on a linked card a content panel holding it rises above the link overlay and passes clicks through to it, so its controls stay clickable. */\n backdrop?: React.ReactNode;\n /** Paints the card as chosen. A CardChoice inside sets it on its own; pass it for a selection the card does not own, and give the link aria-current when a selected card is the current item. */\n selected?: boolean;\n} & (\n | { variant?: \"plain\"; description?: string; hint?: never }\n | {\n variant: \"framed\";\n /** A frame holds a small contained table or list, so its head is a title and actions only. A section that needs a description belongs in a plain Card or a SettingsCard. */\n description?: never;\n /** One short plain-text sentence about the section. The title takes a dotted underline, becomes focusable and shows this in a tooltip on hover and keyboard focus. */\n hint?: string;\n }\n ) & { ref?: React.Ref> }) {\n const convenience =\n title !== undefined ||\n badges !== undefined ||\n description !== undefined ||\n action !== undefined ||\n footer !== undefined;\n const inFrame = useInFrame(\"Card\", requestedVariant);\n const variant = inFrame ? \"plain\" : requestedVariant;\n const panelBackdrop = variant !== \"plain\" && backdrop !== undefined;\n const composed =\n !convenience && variant !== \"plain\" ? withPanelBackdrop(children, backdrop) : null;\n const [hasLink, reportLink] = useStretchedLinkHost();\n const [choiceChecked, reportChoice] = usePresenceCount();\n const cardRef = useDescendantFlags(cardFlags, cardWatch, ref);\n const titleParts = React.Children.toArray(\n React.isValidElement<{ children?: React.ReactNode }>(title) && title.type === React.Fragment\n ? title.props.children\n : title\n );\n const firstBadge = titleParts.findIndex(\n (part) => React.isValidElement(part) && part.type === Badge\n );\n const hintText = firstBadge > 0 ? titleParts.slice(0, firstBadge) : titleParts;\n const lastText = hintText.at(-1);\n const trailingSpace = typeof lastText === \"string\" && /\\s$/.test(lastText);\n const heading =\n title !== undefined &&\n (hint ? (\n \n \n {trailingSpace ? [...hintText.slice(0, -1), lastText.trimEnd()] : hintText}\n \n {trailingSpace && \" \"}\n {firstBadge > 0 && titleParts.slice(firstBadge)}\n \n ) : (\n {title}\n ));\n const header = (title !== undefined ||\n badges !== undefined ||\n description !== undefined ||\n action) && (\n \n
\n
\n {badges !== undefined ? (\n
\n {heading}\n {badges}\n
\n ) : (\n heading\n )}\n {description !== undefined && {description}}\n
\n
\n {action && {action}}\n
\n );\n return (\n \n \n \n \n \n {convenience &&\n variant !== \"plain\" &&\n footer !== undefined &&\n footerPlacement === \"frame\" ? (\n <>\n \n {backdrop}\n \n {header}\n {children !== undefined && children !== null && (\n {children}\n )}\n \n \n {footer}\n \n ) : convenience ? (\n <>\n {!panelBackdrop && backdrop}\n {header}\n \n {panelBackdrop && backdrop}\n {children}\n \n {footer !== undefined && (\n {footer}\n )}\n \n ) : composed ? (\n <>\n {!composed.placed && backdrop}\n {composed.content}\n \n ) : (\n <>\n {backdrop}\n {children}\n \n )}\n \n \n \n \n \n );\n}\nCard.displayName = \"Card\";\n\nfunction CardHeader({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n return (\n \n );\n}\nCardHeader.displayName = \"CardHeader\";\n\nfunction CardTitle({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n return (\n \n );\n}\nCardTitle.displayName = \"CardTitle\";\n\nfunction CardBadges({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n return (\n \n );\n}\nCardBadges.displayName = \"CardBadges\";\n\nfunction CardDescription({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n return (\n \n );\n}\nCardDescription.displayName = \"CardDescription\";\n\nfunction CardAction({\n className,\n title,\n children,\n onPointerEnter,\n onFocus,\n ref,\n ...props\n}: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n const [clipped, setClipped] = React.useState();\n const parts: React.ReactNode[] = [];\n let text: (string | number)[] = [];\n const flush = () => {\n if (text.length) parts.push({text.join(\"\")});\n text = [];\n };\n for (const child of React.Children.toArray(children)) {\n if (typeof child === \"string\" || typeof child === \"number\") text.push(child);\n else {\n flush();\n parts.push(child);\n }\n }\n flush();\n const measure = (element: HTMLElement) => {\n if (title !== undefined) return;\n const truncated = [element, ...element.querySelectorAll(\"*\")].some(\n (part) => part.scrollWidth > part.clientWidth\n );\n setClipped(truncated ? element.textContent?.trim() || undefined : undefined);\n };\n return (\n {\n measure(event.currentTarget);\n onPointerEnter?.(event);\n }}\n onFocus={(event) => {\n measure(event.currentTarget);\n onFocus?.(event);\n }}\n {...props}\n >\n {parts}\n \n );\n}\nCardAction.displayName = \"CardAction\";\n\nfunction CardContent({ className, ref, ...props }: React.ComponentProps<\"div\">) {\n const framed = React.useContext(FramedContext);\n return (\n \n );\n}\nCardContent.displayName = \"CardContent\";\n\nfunction CardFooter({\n className,\n placement = \"inset\",\n ref,\n ...props\n}: React.ComponentPropsWithoutRef<\"div\"> & { placement?: \"inset\" | \"frame\" } & {\n ref?: React.Ref>;\n}) {\n const framed = React.useContext(FramedContext);\n const band = framed && placement === \"frame\";\n return (\n \n );\n}\nCardFooter.displayName = \"CardFooter\";\n\nfunction CardLink({\n className,\n disabled,\n title,\n children,\n ref,\n ...props\n}: CipherLinkProps & {\n disabled?: boolean;\n}) {\n const off = disabled ?? (props.link as { disabled?: boolean }).disabled;\n useStretchedLink(!off);\n if (off)\n return (\n \n {children}\n \n );\n return (\n \n {children}\n \n );\n}\n\ntype CardChoiceProps = Omit<\n React.ComponentPropsWithoutRef<\"button\">,\n \"value\" | \"defaultChecked\" | \"onChange\"\n> & {\n /** Makes this a radio inside a RadioGroup, picked by the group's value. Without it the choice is a checkbox. */\n value?: string;\n checked?: boolean;\n defaultChecked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n} & { ref?: React.Ref };\n\n/**\n * Makes the whole Card one checkbox or radio, the way CardLink makes it one link: the label is its\n * accessible name, its overlay covers the card, and the card paints itself selected while it is checked.\n */\nfunction CardChoice({\n className,\n value,\n checked: checkedProp,\n defaultChecked,\n onCheckedChange,\n disabled,\n children,\n ref,\n ...props\n}: CardChoiceProps) {\n const reduced = useReducedMotion();\n const groupValue = React.useContext(RadioValueContext);\n const [toggled, setToggled] = useControllableState({\n value: checkedProp,\n defaultValue: defaultChecked ?? false,\n onChange: onCheckedChange\n });\n const radio = value !== undefined;\n const checked = radio ? groupValue === value : toggled;\n useStretchedLink(!disabled);\n useReportPresence(React.useContext(CardChoiceContext), checked);\n const state = checked ? \"checked\" : \"unchecked\";\n const classes = cn(\n linkStyles.cardLink,\n linkStyles.cardChoice,\n !disabled && linkStyles.stretched,\n className\n );\n const label = (\n <>\n \n {radio ? (\n \n ) : (\n checked && \n )}\n \n {children}\n \n );\n if (radio)\n return (\n \n {label}\n \n );\n return (\n setToggled(next === true)}\n disabled={disabled}\n className={classes}\n {...props}\n >\n {label}\n \n );\n}\nCardChoice.displayName = \"CardChoice\";\n\nexport {\n Card,\n CardAction,\n CardBadges,\n CardChoice,\n CardContent,\n CardDescription,\n CardFooter,\n CardHeader,\n CardLink,\n CardTitle\n};\n" }, { "path": "src/components/cipher/ui/controls.module.css", @@ -35,7 +35,7 @@ "path": "src/components/cipher/ui/row-link.module.css", "type": "registry:file", "target": "src/components/cipher/ui/row-link.module.css", - "content": ".rowLink {\n display: block;\n min-width: 0;\n overflow: hidden;\n color: inherit;\n text-decoration: none;\n text-overflow: ellipsis;\n white-space: nowrap;\n outline: none;\n}\n.rowLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.rowLink[data-chevron] {\n display: flex;\n flex: 1 1 auto;\n align-items: center;\n gap: var(--cipher-space-8);\n}\n.label {\n flex: 0 1 auto;\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.chevron {\n flex: none;\n width: var(--cipher-size-glyph);\n height: var(--cipher-size-glyph);\n stroke-width: var(--cipher-stroke-icon);\n color: var(--cipher-muted);\n transition: color var(--cipher-duration-fast) var(--cipher-ease-fade);\n}\n.rowLink[data-disabled] .chevron {\n color: var(--cipher-faint);\n}\n:is(:global(tr), :global([data-slot=\"card\"])):is(:hover, :focus-within) .stretched .chevron {\n color: var(--cipher-ink);\n}\n/* Static, so the cover is sized by the cell and not by the stretched-row rule that lifts other links. */\n.cellLink {\n position: static;\n}\n.cellLink::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 2;\n}\n.cellLink:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:where(:global(td)[data-cell-link]) {\n position: relative;\n cursor: pointer;\n}\n:where(:global(td)[data-cell-link]):hover {\n background-image: linear-gradient(var(--cipher-hover), var(--cipher-hover));\n}\n.cardLink {\n color: inherit;\n text-decoration: none;\n outline: none;\n}\n.cardLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoice {\n display: inline-flex;\n align-items: center;\n gap: var(--cipher-space-8);\n max-width: 100%;\n padding: 0;\n border: 0;\n background: none;\n font: inherit;\n letter-spacing: inherit;\n text-align: start;\n cursor: pointer;\n}\n.cardChoice:disabled {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoiceLabel {\n min-width: 0;\n}\n.stretched::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 1;\n}\n.stretched:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:global(tr)[data-stretched-link],\n:global([data-slot=\"card\"])[data-stretched-link],\n:global([data-slot=\"stat-card\"])[data-stretched-link] {\n position: relative;\n cursor: pointer;\n}\n:global([data-slot=\"card\"])[data-stretched-link]:hover {\n background-image: linear-gradient(\n var(--cipher-action-ghost-hover),\n var(--cipher-action-ghost-hover)\n );\n}\n/* :where keeps this at zero specificity, so a control that positions itself absolutely keeps its own layout. */\n:where(\n :global(tr)[data-stretched-link],\n :global([data-slot=\"card\"])[data-stretched-link],\n :global([data-slot=\"stat-card\"])[data-stretched-link]\n )\n :where(\n button:not(.stretched),\n input,\n select,\n textarea,\n label,\n summary,\n a:not(.stretched),\n [role=\"button\"],\n [role=\"checkbox\"]:not(.stretched),\n [role=\"combobox\"],\n [role=\"switch\"],\n [data-slot=\"tooltip-trigger\"],\n [data-row-interactive]\n ) {\n position: relative;\n z-index: 2;\n}\n" + "content": ".rowLink {\n display: block;\n min-width: 0;\n overflow: hidden;\n color: inherit;\n text-decoration: none;\n text-overflow: ellipsis;\n white-space: nowrap;\n outline: none;\n}\n.rowLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.rowLink[data-chevron] {\n display: flex;\n flex: 1 1 auto;\n align-items: center;\n gap: var(--cipher-space-8);\n}\n.label {\n flex: 0 1 auto;\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.chevron {\n flex: none;\n width: var(--cipher-size-glyph);\n height: var(--cipher-size-glyph);\n stroke-width: var(--cipher-stroke-icon);\n color: var(--cipher-muted);\n transition: color var(--cipher-duration-fast) var(--cipher-ease-fade);\n}\n.rowLink[data-disabled] .chevron {\n color: var(--cipher-faint);\n}\n:is(:global(tr), :global([data-slot=\"card\"])):is(:hover, :focus-within) .stretched .chevron {\n color: var(--cipher-ink);\n}\n/* Static, so the cover is sized by the cell and not by the stretched-row rule that lifts other links. */\n.cellLink {\n position: static;\n}\n.cellLink::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 2;\n}\n.cellLink:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:where(:global(td)[data-cell-link]) {\n position: relative;\n cursor: pointer;\n}\n:where(:global(td)[data-cell-link]):hover {\n background-image: linear-gradient(var(--cipher-hover), var(--cipher-hover));\n}\n.cardLink {\n color: inherit;\n text-decoration: none;\n outline: none;\n}\n.cardLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoice {\n display: inline-flex;\n align-items: center;\n gap: var(--cipher-space-8);\n max-width: 100%;\n padding: 0;\n border: 0;\n background: none;\n font: inherit;\n letter-spacing: inherit;\n text-align: start;\n cursor: pointer;\n}\n.cardChoice:disabled {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoiceLabel {\n min-width: 0;\n}\n.stretched::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 1;\n pointer-events: auto;\n}\n.stretched:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:global(tr)[data-stretched-link],\n:global([data-slot=\"card\"])[data-stretched-link],\n:global([data-slot=\"stat-card\"])[data-stretched-link] {\n position: relative;\n cursor: pointer;\n}\n:global([data-slot=\"card\"])[data-stretched-link]:hover {\n background-image: linear-gradient(\n var(--cipher-action-ghost-hover),\n var(--cipher-action-ghost-hover)\n );\n}\n/* :where keeps this at zero specificity, so a control that positions itself absolutely keeps its own layout. */\n:where(\n :global(tr)[data-stretched-link],\n :global([data-slot=\"card\"])[data-stretched-link],\n :global([data-slot=\"stat-card\"])[data-stretched-link]\n )\n :where(\n button:not(.stretched),\n input,\n select,\n textarea,\n label,\n summary,\n a:not(.stretched),\n [role=\"button\"],\n [role=\"checkbox\"]:not(.stretched),\n [role=\"combobox\"],\n [role=\"switch\"],\n [data-slot=\"tooltip-trigger\"],\n [data-row-interactive]\n ) {\n position: relative;\n z-index: 2;\n pointer-events: auto;\n}\n/* A content panel that paints a backdrop is its own stacking context, so it rises above the link\n overlay and lets clicks through to it, keeping its controls (lifted above) clickable. It stays\n unpositioned (z-index applies to it as a flex item) so the overlay still covers the whole card. */\n:is(:global([data-slot=\"card\"]), :global([data-slot=\"stat-card\"]))[data-stretched-link]\n > :global([data-slot=\"card-content\"][data-backdrop]) {\n z-index: 2;\n pointer-events: none;\n}\n" } ] } diff --git a/r/row-link.json b/r/row-link.json index a8e9c9e9..93cdabbc 100644 --- a/r/row-link.json +++ b/r/row-link.json @@ -17,7 +17,7 @@ "path": "src/components/cipher/ui/row-link.module.css", "type": "registry:file", "target": "src/components/cipher/ui/row-link.module.css", - "content": ".rowLink {\n display: block;\n min-width: 0;\n overflow: hidden;\n color: inherit;\n text-decoration: none;\n text-overflow: ellipsis;\n white-space: nowrap;\n outline: none;\n}\n.rowLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.rowLink[data-chevron] {\n display: flex;\n flex: 1 1 auto;\n align-items: center;\n gap: var(--cipher-space-8);\n}\n.label {\n flex: 0 1 auto;\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.chevron {\n flex: none;\n width: var(--cipher-size-glyph);\n height: var(--cipher-size-glyph);\n stroke-width: var(--cipher-stroke-icon);\n color: var(--cipher-muted);\n transition: color var(--cipher-duration-fast) var(--cipher-ease-fade);\n}\n.rowLink[data-disabled] .chevron {\n color: var(--cipher-faint);\n}\n:is(:global(tr), :global([data-slot=\"card\"])):is(:hover, :focus-within) .stretched .chevron {\n color: var(--cipher-ink);\n}\n/* Static, so the cover is sized by the cell and not by the stretched-row rule that lifts other links. */\n.cellLink {\n position: static;\n}\n.cellLink::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 2;\n}\n.cellLink:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:where(:global(td)[data-cell-link]) {\n position: relative;\n cursor: pointer;\n}\n:where(:global(td)[data-cell-link]):hover {\n background-image: linear-gradient(var(--cipher-hover), var(--cipher-hover));\n}\n.cardLink {\n color: inherit;\n text-decoration: none;\n outline: none;\n}\n.cardLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoice {\n display: inline-flex;\n align-items: center;\n gap: var(--cipher-space-8);\n max-width: 100%;\n padding: 0;\n border: 0;\n background: none;\n font: inherit;\n letter-spacing: inherit;\n text-align: start;\n cursor: pointer;\n}\n.cardChoice:disabled {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoiceLabel {\n min-width: 0;\n}\n.stretched::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 1;\n}\n.stretched:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:global(tr)[data-stretched-link],\n:global([data-slot=\"card\"])[data-stretched-link],\n:global([data-slot=\"stat-card\"])[data-stretched-link] {\n position: relative;\n cursor: pointer;\n}\n:global([data-slot=\"card\"])[data-stretched-link]:hover {\n background-image: linear-gradient(\n var(--cipher-action-ghost-hover),\n var(--cipher-action-ghost-hover)\n );\n}\n/* :where keeps this at zero specificity, so a control that positions itself absolutely keeps its own layout. */\n:where(\n :global(tr)[data-stretched-link],\n :global([data-slot=\"card\"])[data-stretched-link],\n :global([data-slot=\"stat-card\"])[data-stretched-link]\n )\n :where(\n button:not(.stretched),\n input,\n select,\n textarea,\n label,\n summary,\n a:not(.stretched),\n [role=\"button\"],\n [role=\"checkbox\"]:not(.stretched),\n [role=\"combobox\"],\n [role=\"switch\"],\n [data-slot=\"tooltip-trigger\"],\n [data-row-interactive]\n ) {\n position: relative;\n z-index: 2;\n}\n" + "content": ".rowLink {\n display: block;\n min-width: 0;\n overflow: hidden;\n color: inherit;\n text-decoration: none;\n text-overflow: ellipsis;\n white-space: nowrap;\n outline: none;\n}\n.rowLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.rowLink[data-chevron] {\n display: flex;\n flex: 1 1 auto;\n align-items: center;\n gap: var(--cipher-space-8);\n}\n.label {\n flex: 0 1 auto;\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.chevron {\n flex: none;\n width: var(--cipher-size-glyph);\n height: var(--cipher-size-glyph);\n stroke-width: var(--cipher-stroke-icon);\n color: var(--cipher-muted);\n transition: color var(--cipher-duration-fast) var(--cipher-ease-fade);\n}\n.rowLink[data-disabled] .chevron {\n color: var(--cipher-faint);\n}\n:is(:global(tr), :global([data-slot=\"card\"])):is(:hover, :focus-within) .stretched .chevron {\n color: var(--cipher-ink);\n}\n/* Static, so the cover is sized by the cell and not by the stretched-row rule that lifts other links. */\n.cellLink {\n position: static;\n}\n.cellLink::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 2;\n}\n.cellLink:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:where(:global(td)[data-cell-link]) {\n position: relative;\n cursor: pointer;\n}\n:where(:global(td)[data-cell-link]):hover {\n background-image: linear-gradient(var(--cipher-hover), var(--cipher-hover));\n}\n.cardLink {\n color: inherit;\n text-decoration: none;\n outline: none;\n}\n.cardLink[data-disabled] {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoice {\n display: inline-flex;\n align-items: center;\n gap: var(--cipher-space-8);\n max-width: 100%;\n padding: 0;\n border: 0;\n background: none;\n font: inherit;\n letter-spacing: inherit;\n text-align: start;\n cursor: pointer;\n}\n.cardChoice:disabled {\n color: var(--cipher-muted);\n cursor: not-allowed;\n}\n.cardChoiceLabel {\n min-width: 0;\n}\n.stretched::after {\n content: \"\";\n position: absolute;\n inset: 0;\n z-index: 1;\n pointer-events: auto;\n}\n.stretched:focus-visible::after {\n outline: var(--cipher-size-focus-ring) solid var(--cipher-ink);\n outline-offset: calc(-1 * var(--cipher-size-focus-ring));\n}\n:global(tr)[data-stretched-link],\n:global([data-slot=\"card\"])[data-stretched-link],\n:global([data-slot=\"stat-card\"])[data-stretched-link] {\n position: relative;\n cursor: pointer;\n}\n:global([data-slot=\"card\"])[data-stretched-link]:hover {\n background-image: linear-gradient(\n var(--cipher-action-ghost-hover),\n var(--cipher-action-ghost-hover)\n );\n}\n/* :where keeps this at zero specificity, so a control that positions itself absolutely keeps its own layout. */\n:where(\n :global(tr)[data-stretched-link],\n :global([data-slot=\"card\"])[data-stretched-link],\n :global([data-slot=\"stat-card\"])[data-stretched-link]\n )\n :where(\n button:not(.stretched),\n input,\n select,\n textarea,\n label,\n summary,\n a:not(.stretched),\n [role=\"button\"],\n [role=\"checkbox\"]:not(.stretched),\n [role=\"combobox\"],\n [role=\"switch\"],\n [data-slot=\"tooltip-trigger\"],\n [data-row-interactive]\n ) {\n position: relative;\n z-index: 2;\n pointer-events: auto;\n}\n/* A content panel that paints a backdrop is its own stacking context, so it rises above the link\n overlay and lets clicks through to it, keeping its controls (lifted above) clickable. It stays\n unpositioned (z-index applies to it as a flex item) so the overlay still covers the whole card. */\n:is(:global([data-slot=\"card\"]), :global([data-slot=\"stat-card\"]))[data-stretched-link]\n > :global([data-slot=\"card-content\"][data-backdrop]) {\n z-index: 2;\n pointer-events: none;\n}\n" } ] } diff --git a/r/stat-card.json b/r/stat-card.json index 5948bb3c..205d719e 100644 --- a/r/stat-card.json +++ b/r/stat-card.json @@ -15,7 +15,7 @@ "path": "src/components/cipher/ui/stat-card.tsx", "type": "registry:file", "target": "src/components/cipher/ui/stat-card.tsx", - "content": "import * as React from \"react\";\n\nimport type { CipherLinkProps } from \"../lib/link\";\nimport { useInFrame } from \"../lib/frame-context\";\nimport { cn } from \"../lib/utils\";\nimport { Card, CardContent, CardLink } from \"./card\";\nimport { Icon, type IconSource } from \"./icon\";\nimport { Media } from \"./item\";\nimport { Skeleton } from \"./skeleton\";\nimport { StatusText } from \"./text\";\n\nimport styles from \"./stat-card.module.css\";\n\nconst trendIcon = {\n up: \"arrow-up\",\n down: \"arrow-down\",\n flat: \"minus\"\n} as const;\nconst trendTone = { up: \"ok\", down: \"bad\", flat: \"neutral\" } as const;\n\nexport type StatCardProps = Omit<\n React.ComponentProps,\n \"title\" | \"badges\" | \"description\" | \"hint\" | \"action\" | \"footer\" | \"footerPlacement\" | \"children\"\n> & {\n label: React.ReactNode;\n value: React.ReactNode;\n icon?: IconSource;\n /** Tone of the icon, for a metric that needs attention. */\n tone?: \"ok\" | \"warn\" | \"bad\" | \"info\";\n /** The change since the last period, such as \"+12%\". Its text carries the direction; the arrow is decoration. */\n delta?: React.ReactNode;\n trend?: \"up\" | \"down\" | \"flat\";\n /** Defaults to ok for up, bad for down and neutral for flat; set it for a metric where up is bad. */\n deltaTone?: \"ok\" | \"bad\" | \"neutral\";\n /** A short line under the value: what the number counts, the comparison period, or a link. */\n note?: React.ReactNode;\n /** Makes the whole card a link, named by the label. */\n link?: CipherLinkProps[\"link\"];\n loading?: boolean;\n /** Replaces the value with this message when the metric failed to load. */\n error?: React.ReactNode;\n};\n\nexport function StatCard({\n label,\n value,\n icon,\n tone,\n delta,\n trend = \"flat\",\n deltaTone,\n note,\n link,\n loading = false,\n error,\n variant = \"framed\",\n backdrop,\n className,\n ...props\n}: StatCardProps) {\n const inFrame = useInFrame(\"StatCard\");\n const panelBackdrop = variant === \"framed\" && !inFrame;\n const id = React.useId();\n const labelId = `${id}-label`;\n const valueId = `${id}-value`;\n const failed = error !== undefined && error !== null && error !== false;\n return (\n \n \n {panelBackdrop && backdrop}\n
\n \n {link ? (\n \n {label}\n \n ) : (\n label\n )}\n \n {icon && }\n
\n {loading ? (\n \n ) : failed ? (\n \n {error}\n \n ) : (\n
\n {value}\n
\n )}\n {!loading && !failed && (delta !== undefined || note !== undefined) && (\n
\n {delta !== undefined && (\n \n \n {delta}\n \n )}\n {note !== undefined && {note}}\n
\n )}\n
\n \n );\n}\n" + "content": "import * as React from \"react\";\n\nimport type { CipherLinkProps } from \"../lib/link\";\nimport { cn } from \"../lib/utils\";\nimport { Card, CardContent, CardLink } from \"./card\";\nimport { Icon, type IconSource } from \"./icon\";\nimport { Media } from \"./item\";\nimport { Skeleton } from \"./skeleton\";\nimport { StatusText } from \"./text\";\n\nimport styles from \"./stat-card.module.css\";\n\nconst trendIcon = {\n up: \"arrow-up\",\n down: \"arrow-down\",\n flat: \"minus\"\n} as const;\nconst trendTone = { up: \"ok\", down: \"bad\", flat: \"neutral\" } as const;\n\nexport type StatCardProps = Omit<\n React.ComponentProps,\n \"title\" | \"badges\" | \"description\" | \"hint\" | \"action\" | \"footer\" | \"footerPlacement\" | \"children\"\n> & {\n label: React.ReactNode;\n value: React.ReactNode;\n icon?: IconSource;\n /** Tone of the icon, for a metric that needs attention. */\n tone?: \"ok\" | \"warn\" | \"bad\" | \"info\";\n /** The change since the last period, such as \"+12%\". Its text carries the direction; the arrow is decoration. */\n delta?: React.ReactNode;\n trend?: \"up\" | \"down\" | \"flat\";\n /** Defaults to ok for up, bad for down and neutral for flat; set it for a metric where up is bad. */\n deltaTone?: \"ok\" | \"bad\" | \"neutral\";\n /** A short line under the value: what the number counts, the comparison period, or a link. */\n note?: React.ReactNode;\n /** Makes the whole card a link, named by the label. */\n link?: CipherLinkProps[\"link\"];\n loading?: boolean;\n /** Replaces the value with this message when the metric failed to load. */\n error?: React.ReactNode;\n};\n\nexport function StatCard({\n label,\n value,\n icon,\n tone,\n delta,\n trend = \"flat\",\n deltaTone,\n note,\n link,\n loading = false,\n error,\n variant = \"framed\",\n className,\n ...props\n}: StatCardProps) {\n const id = React.useId();\n const labelId = `${id}-label`;\n const valueId = `${id}-value`;\n const failed = error !== undefined && error !== null && error !== false;\n return (\n \n \n
\n \n {link ? (\n \n {label}\n \n ) : (\n label\n )}\n \n {icon && }\n
\n {loading ? (\n \n ) : failed ? (\n \n {error}\n \n ) : (\n
\n {value}\n
\n )}\n {!loading && !failed && (delta !== undefined || note !== undefined) && (\n
\n {delta !== undefined && (\n \n \n {delta}\n \n )}\n {note !== undefined && {note}}\n
\n )}\n
\n \n );\n}\n" }, { "path": "src/components/cipher/ui/stat-card.module.css", diff --git a/site/src/catalog.json b/site/src/catalog.json index 65040889..5c55fbd4 100644 --- a/site/src/catalog.json +++ b/site/src/catalog.json @@ -2200,6 +2200,10 @@ { "title": "Bounds, size and reveal (hover a card)", "module": "halftone/bounds" + }, + { + "title": "Framed, without a frame footer", + "module": "halftone/framed" } ] }, diff --git a/site/src/examples/halftone/framed.tsx b/site/src/examples/halftone/framed.tsx new file mode 100644 index 00000000..6ed2b81f --- /dev/null +++ b/site/src/examples/halftone/framed.tsx @@ -0,0 +1,61 @@ +import { Button } from "@infisical/cipher/ui/button"; +import { Card, CardContent, CardHeader, CardLink, CardTitle } from "@infisical/cipher/ui/card"; +import { Halftone } from "@infisical/cipher/ui/halftone"; +import { hueScope } from "@infisical/cipher/lib/hue"; + +export default function Example() { + return ( +
+
+ }> + Card checkout and refunds. + +
+ {"title in the band, no footer"} +
+
+
+ } + > + Card checkout and refunds. + +
{"inset footer"}
+
+
+ }> + + payments-api + + Card checkout and refunds. + +
+ {"composed from CardHeader and CardContent"} +
+
+
+ payments-api} + backdrop={} + > +
+ Card checkout and refunds. + +
+
+
+ {"linked, with a control in the body"} +
+
+
+ ); +} diff --git a/src/ui/card.tsx b/src/ui/card.tsx index f8611c71..9dc10b35 100644 --- a/src/ui/card.tsx +++ b/src/ui/card.tsx @@ -40,6 +40,26 @@ const cardWatch = { } }; +const withPanelBackdrop = (children: React.ReactNode, backdrop: React.ReactNode) => { + let placed = false; + const walk = (nodes: React.ReactNode): React.ReactNode => + React.Children.map(nodes, (child) => { + if (placed || !React.isValidElement<{ children?: React.ReactNode }>(child)) return child; + if (child.type === React.Fragment) + return React.cloneElement(child, undefined, walk(child.props.children)); + if (child.type !== CardContent || "dangerouslySetInnerHTML" in child.props) return child; + placed = true; + return React.cloneElement( + child as React.ReactElement<{ children?: React.ReactNode; "data-backdrop"?: string }>, + { "data-backdrop": backdrop === undefined ? undefined : "" }, + backdrop ?? null, + child.props.children + ); + }); + const content = walk(children); + return { content, placed }; +}; + function Card({ className, size = "default", @@ -68,7 +88,7 @@ function Card({ /** "frame" draws the footer in the frame band: its text keeps the title's start inset and its controls take the 28px band tier. */ footerPlacement?: "inset" | "frame"; flush?: boolean; - /** Decoration such as a Halftone, painted under the surface that holds the title and the card link: the inset of a framed card with a frame footer, otherwise the card itself. That surface becomes the stacking context, so the link overlay and the controls above it stay in one layer. */ + /** Decoration such as a Halftone, painted in the content corners and never on a frame's chrome: the inset of a framed card with a frame footer, the first CardContent of any other framed card, otherwise the card itself. That surface becomes the stacking context; on a linked card a content panel holding it rises above the link overlay and passes clicks through to it, so its controls stay clickable. */ backdrop?: React.ReactNode; /** Paints the card as chosen. A CardChoice inside sets it on its own; pass it for a selection the card does not own, and give the link aria-current when a selected card is the current item. */ selected?: boolean; @@ -90,6 +110,9 @@ function Card({ footer !== undefined; const inFrame = useInFrame("Card", requestedVariant); const variant = inFrame ? "plain" : requestedVariant; + const panelBackdrop = variant !== "plain" && backdrop !== undefined; + const composed = + !convenience && variant !== "plain" ? withPanelBackdrop(children, backdrop) : null; const [hasLink, reportLink] = useStretchedLinkHost(); const [choiceChecked, reportChoice] = usePresenceCount(); const cardRef = useDescendantFlags(cardFlags, cardWatch, ref); @@ -181,13 +204,21 @@ function Card({ ) : convenience ? ( <> - {backdrop} + {!panelBackdrop && backdrop} {header} - {children} + + {panelBackdrop && backdrop} + {children} + {footer !== undefined && ( {footer} )} + ) : composed ? ( + <> + {!composed.placed && backdrop} + {composed.content} + ) : ( <> {backdrop} diff --git a/src/ui/row-link.module.css b/src/ui/row-link.module.css index 1439b4c8..4d8813a8 100644 --- a/src/ui/row-link.module.css +++ b/src/ui/row-link.module.css @@ -94,6 +94,7 @@ position: absolute; inset: 0; z-index: 1; + pointer-events: auto; } .stretched:focus-visible::after { outline: var(--cipher-size-focus-ring) solid var(--cipher-ink); @@ -134,4 +135,13 @@ ) { position: relative; z-index: 2; + pointer-events: auto; +} +/* A content panel that paints a backdrop is its own stacking context, so it rises above the link + overlay and lets clicks through to it, keeping its controls (lifted above) clickable. It stays + unpositioned (z-index applies to it as a flex item) so the overlay still covers the whole card. */ +:is(:global([data-slot="card"]), :global([data-slot="stat-card"]))[data-stretched-link] + > :global([data-slot="card-content"][data-backdrop]) { + z-index: 2; + pointer-events: none; } diff --git a/src/ui/stat-card.tsx b/src/ui/stat-card.tsx index 342123cc..fd38af71 100644 --- a/src/ui/stat-card.tsx +++ b/src/ui/stat-card.tsx @@ -1,7 +1,6 @@ import * as React from "react"; import type { CipherLinkProps } from "../lib/link"; -import { useInFrame } from "../lib/frame-context"; import { cn } from "../lib/utils"; import { Card, CardContent, CardLink } from "./card"; import { Icon, type IconSource } from "./icon"; @@ -54,12 +53,9 @@ export function StatCard({ loading = false, error, variant = "framed", - backdrop, className, ...props }: StatCardProps) { - const inFrame = useInFrame("StatCard"); - const panelBackdrop = variant === "framed" && !inFrame; const id = React.useId(); const labelId = `${id}-label`; const valueId = `${id}-value`; @@ -72,11 +68,9 @@ export function StatCard({ aria-busy={loading || undefined} variant={variant} className={cn(styles.statCard, className)} - backdrop={panelBackdrop ? undefined : backdrop} {...props} > - {panelBackdrop && backdrop}
{link ? ( diff --git a/visual/baselines/desktop/halftone-framed--dark.png b/visual/baselines/desktop/halftone-framed--dark.png new file mode 100644 index 00000000..fe7c4be1 Binary files /dev/null and b/visual/baselines/desktop/halftone-framed--dark.png differ diff --git a/visual/baselines/desktop/halftone-framed--light.png b/visual/baselines/desktop/halftone-framed--light.png new file mode 100644 index 00000000..55af36ae Binary files /dev/null and b/visual/baselines/desktop/halftone-framed--light.png differ diff --git a/visual/baselines/mobile/halftone-framed--dark.png b/visual/baselines/mobile/halftone-framed--dark.png new file mode 100644 index 00000000..db3b7eb0 Binary files /dev/null and b/visual/baselines/mobile/halftone-framed--dark.png differ diff --git a/visual/baselines/mobile/halftone-framed--light.png b/visual/baselines/mobile/halftone-framed--light.png new file mode 100644 index 00000000..46a1c03b Binary files /dev/null and b/visual/baselines/mobile/halftone-framed--light.png differ