Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
refactor(ok): adopt shadcn alert for the bundle banner (PRD-7912) (#3386)
Andrew Mikofalvy01ad36da4d9c
diff --git a/packages/app/src/components/SkillPluginBundleBanner.tsx b/packages/app/src/components/SkillPluginBundleBanner.tsxindex 12b119381..60adb7d8a 100644--- a/packages/app/src/components/SkillPluginBundleBanner.tsx+++ b/packages/app/src/components/SkillPluginBundleBanner.tsx@@ -6,6 +6,7 @@ import {type SkillBundleDisclosure,SkillPluginBundleDialog,} from '@/components/SkillPluginBundleDialog';+import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';import { Button } from '@/components/ui/button';/**@@ -54,55 +55,58 @@ export function SkillPluginBundleBanner({return (<div className="editor-content-aligned">- <div className="my-3 rounded-lg border border-border bg-muted/40 px-4 py-3">- <div className="flex items-start gap-3">- <PackageIcon className="mt-0.5 size-4 shrink-0 text-muted-foreground" aria-hidden />- <div className="min-w-0 flex-1">- <p className="font-medium text-sm">- {plugin ? (- <Trans>Part of the {plugin} plugin</Trans>- ) : (- // No manifest to name — the source itself is the grouping.- <Trans>{count} skills at this source</Trans>- )}- </p>- <p className="text-muted-foreground text-sm">- {caps.length > 0 ? (- <Trans>- This repo bundles {count} skills, plus {caps.join(', ')}. Install any of them from- the plugin.- </Trans>- ) : plugin ? (- <Trans>- This repo bundles {count} skills. Install any of them from the plugin.- </Trans>- ) : (- <Trans>- {source} publishes {count} skills. Install any of them together.- </Trans>- )}- </p>- <div className="mt-2.5 flex items-center gap-2">- <Button- variant="outline"- size="sm"- data-testid="plugin-bundle-pick"- onClick={() => setPicking(true)}- >- <Trans>Install skills</Trans>- </Button>- {bundle.repositoryUrl ? (- <Button variant="ghost" size="sm" asChild>- <a href={bundle.repositoryUrl} target="_blank" rel="noreferrer">- <Trans>View plugin</Trans>- <ArrowUpRightIcon className="size-3.5" />- </a>- </Button>- ) : null}- </div>- </div>+ {/* Not the live region Alert defaults to: this arrives when the preview+ finishes resolving its source, so announcing it assertively would cut+ across whatever the reader is on for something purely informational. */}+ <Alert role="note" className="my-3 bg-muted/40 px-4 py-3">+ {/* No tint of its own: Alert paints direct svg children `text-current`+ at a specificity a utility class on the icon cannot beat. */}+ <PackageIcon className="size-4" aria-hidden />+ <AlertTitle>+ {plugin ? (+ <Trans>Part of the {plugin} plugin</Trans>+ ) : (+ // No manifest to name — the source itself is the grouping.+ <Trans>{count} skills at this source</Trans>+ )}+ </AlertTitle>+ {/* `source` can be a long unbroken URL; the grid track would otherwise+ size to it and stretch the whole box. */}+ <AlertDescription className="min-w-0">+ {caps.length > 0 ? (+ <Trans>+ This repo bundles {count} skills, plus {caps.join(', ')}. Install any of them from the+ plugin.+ </Trans>+ ) : plugin ? (+ <Trans>This repo bundles {count} skills. Install any of them from the plugin.</Trans>+ ) : (+ <Trans>+ {source} publishes {count} skills. Install any of them together.+ </Trans>+ )}+ </AlertDescription>+ {/* Third content row, so it needs the same column the title claims —+ auto-placement would otherwise drop it under the icon. */}+ <div className="mt-2.5 flex items-center gap-2 group-has-[>svg]/alert:col-start-2">+ <Button+ variant="outline"+ size="sm"+ data-testid="plugin-bundle-pick"+ onClick={() => setPicking(true)}+ >+ <Trans>Install skills</Trans>+ </Button>+ {bundle.repositoryUrl ? (+ <Button variant="ghost" size="sm" asChild>+ <a href={bundle.repositoryUrl} target="_blank" rel="noreferrer">+ <Trans>View plugin</Trans>+ <ArrowUpRightIcon className="size-3.5" />+ </a>+ </Button>+ ) : null}</div>- </div>+ </Alert><SkillPluginBundleDialogbundle={picking ? bundle : null}source={source}diff --git a/packages/app/src/components/ui/alert.dom.test.tsx b/packages/app/src/components/ui/alert.dom.test.tsxnew file mode 100644index 000000000..17153ebaf--- /dev/null+++ b/packages/app/src/components/ui/alert.dom.test.tsx@@ -0,0 +1,101 @@+/**+ * DOM-substrate tests for Alert. The contract that matters to call sites is the+ * live-region default and its escape hatch: this primitive announces+ * assertively unless a caller opts out, and a passive notice that mounts with+ * the surface around it must opt out or it interrupts the screen reader with+ * content nobody asked for.+ *+ * The layout assertions are class-token checks because the icon column is+ * expressed purely in CSS that jsdom does not execute; the slot assertions are+ * real DOM queries, and the destructive variant depends on the description slot+ * attribute being present to tint through.+ */++import { cleanup, render, screen } from '@testing-library/react';+import { afterEach, describe, expect, test } from 'vitest';+import { expectVisualClassTokens } from '@/test-utils/visual-contract';+import { Alert, AlertAction, AlertDescription, AlertTitle } from './alert';++afterEach(cleanup);++describe('Alert', () => {+ test('announces as a live alert by default', () => {+ render(<Alert>Disk is full</Alert>);++ expect(screen.getByRole('alert').textContent).toBe('Disk is full');+ });++ test('a caller-supplied role replaces the assertive default', () => {+ // Passive notice boxes arrive with the surface they belong to rather than+ // in response to the user, so they opt out of the live region entirely.+ render(<Alert role="note">Part of a plugin</Alert>);++ expect(screen.queryByRole('alert')).toBeNull();+ expect(screen.getByRole('note').textContent).toBe('Part of a plugin');+ });++ test('title and description render as addressable slots inside the box', () => {+ render(+ <Alert>+ <AlertTitle>Update available</AlertTitle>+ <AlertDescription>Restart to apply it.</AlertDescription>+ </Alert>,+ );++ const alert = screen.getByRole('alert');+ expect(alert.querySelector('[data-slot="alert-title"]')?.textContent).toBe('Update available');+ expect(alert.querySelector('[data-slot="alert-description"]')?.textContent).toBe(+ 'Restart to apply it.',+ );+ });++ test('the action slot renders inside the box', () => {+ render(+ <Alert>+ <AlertTitle>Heads up</AlertTitle>+ <AlertAction>+ <span>Dismiss</span>+ </AlertAction>+ </Alert>,+ );++ expect(screen.getByRole('alert').querySelector('[data-slot="alert-action"]')?.textContent).toBe(+ 'Dismiss',+ );+ });++ test('gives an icon child its own column so the text block stays aligned', () => {+ // Call sites lead with a lucide glyph; without the icon column the title and+ // description wrap underneath it instead of beside it.+ render(+ <Alert>+ <svg aria-hidden="true" />+ <AlertTitle>Heads up</AlertTitle>+ </Alert>,+ );++ expectVisualClassTokens(screen.getByRole('alert').getAttribute('class'), [+ 'grid',+ 'has-[>svg]:grid-cols-[auto_1fr]',+ ]);+ });++ test('the destructive variant tints the box and its description', () => {+ render(<Alert variant="destructive">Deletion failed</Alert>);++ expectVisualClassTokens(screen.getByRole('alert').getAttribute('class'), [+ 'text-destructive',+ '*:data-[slot=alert-description]:text-destructive/90',+ ]);+ });++ test('caller className composes with the base classes rather than replacing them', () => {+ render(<Alert className="my-3 bg-muted/40">Notice</Alert>);++ const className = screen.getByRole('alert').getAttribute('class');+ expectVisualClassTokens(className, ['grid', 'rounded-lg', 'my-3', 'bg-muted/40']);+ // The default variant's own background loses to the caller's, rather than+ // both landing and leaving the winner to source order.+ expect(className).not.toContain('bg-card');+ });+});diff --git a/packages/app/src/components/ui/alert.tsx b/packages/app/src/components/ui/alert.tsxnew file mode 100644index 000000000..57a48b785--- /dev/null+++ b/packages/app/src/components/ui/alert.tsx@@ -0,0 +1,87 @@+import { cva, type VariantProps } from 'class-variance-authority';+import type * as React from 'react';+import { cn } from '@/lib/utils';++/**+ * Inset notice box: an icon column, a title, a description, and an optional+ * corner action.+ *+ * Vendored from shadcn/ui's `radix-nova` alert. One deliberate divergence from+ * upstream, recorded so a future `shadcn diff` reviewer knows the drift is+ * intentional rather than rot: the two physical-direction utilities that+ * position the action slot (`pr-18` reserving room for it, `right-2` placing+ * it) are written as their logical equivalents `pe-18` / `end-2`, so the corner+ * action follows the reading direction. Enforced for JSX class strings by the+ * no-physical-direction-utility lint rule; applied to the variant string too so+ * the reserved padding and the action stay on the same side.+ *+ * `role="alert"` is an assertive live region: inserting one of these into a+ * live page interrupts the screen reader with its whole contents. That is right+ * for something the user must hear now and wrong for a notice that simply+ * arrives alongside the surface it belongs to. Props spread last, so a passive+ * notice passes `role="note"` to opt out.+ */+const alertVariants = cva(+ "group/alert relative grid w-full gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pe-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4",+ {+ variants: {+ variant: {+ default: 'bg-card text-card-foreground',+ destructive:+ 'bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current',+ },+ },+ defaultVariants: {+ variant: 'default',+ },+ },+);++function Alert({+ className,+ variant,+ ...props+}: React.ComponentProps<'div'> & VariantProps<typeof alertVariants>) {+ return (+ <div+ data-slot="alert"+ role="alert"+ className={cn(alertVariants({ variant }), className)}+ {...props}+ />+ );+}++function AlertTitle({ className, ...props }: React.ComponentProps<'div'>) {+ return (+ <div+ data-slot="alert-title"+ className={cn(+ 'font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground',+ className,+ )}+ {...props}+ />+ );+}++function AlertDescription({ className, ...props }: React.ComponentProps<'div'>) {+ return (+ <div+ data-slot="alert-description"+ className={cn(+ 'text-balance text-muted-foreground text-sm md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4',+ className,+ )}+ {...props}+ />+ );+}++function AlertAction({ className, ...props }: React.ComponentProps<'div'>) {+ return (+ <div data-slot="alert-action" className={cn('absolute top-2 end-2', className)} {...props} />+ );+}++export { Alert, AlertAction, AlertDescription, AlertTitle };