Files
commitea/apps/desktop/src/renderer/src/components/ui/button.tsx
Croissant Le Doux 635025113c feat(desktop): port the 15 design-system primitives (#14)
Verbatim port of the handoff primitives into components/ui/ — Icon,
Button, IconButton, Badge, Tag, Card, Tabs (core); Input, Select,
Checkbox, Radio, Switch (forms); Dialog, Toast, Tooltip (feedback).
Each keeps its injected token-referencing CSS byte-for-byte; the
handoff .d.ts contracts become the exported prop interfaces. Barrel at
components/ui/index.ts.

Adds a PrimitivesGallery (app root for now; real shell is P3-2) that
exercises every primitive with a light/dark toggle. Smoke suite asserts
the gallery, section coverage, theme flip, and dialog open/Escape;
screenshots captured for both themes. typecheck + 5 e2e green.

Closes P3-1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 12:12:00 -04:00

82 lines
2.8 KiB
TypeScript

import React from 'react'
import { Icon } from './icon.js'
/**
* CommiTea button. Plain verbs only ("Approve", "Brew plan", "Defer") — never witty.
*/
export interface ButtonProps {
/** @default 'primary' */
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
/** @default 'md' */
size?: 'sm' | 'md';
/** Lucide icon name rendered before the label */
icon?: string;
/** Lucide icon name rendered after the label */
iconRight?: string;
disabled?: boolean;
onClick?: (e: React.MouseEvent) => void;
children?: React.ReactNode;
style?: React.CSSProperties;
}
const CSS = `
.ct-btn {
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
font: 600 14px/1 var(--font-sans);
border-radius: var(--radius-2);
border: 1px solid transparent;
cursor: pointer;
white-space: nowrap;
transition: background var(--duration-fast) var(--ease-out),
border-color var(--duration-fast) var(--ease-out),
color var(--duration-fast) var(--ease-out);
}
.ct-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ct-btn--md { height: 34px; padding: 0 14px; }
.ct-btn--sm { height: 28px; padding: 0 10px; font-size: 13px; }
.ct-btn--primary { background: var(--accent); color: var(--text-on-accent); }
.ct-btn--primary:hover:not(:disabled) { background: var(--accent-hover); }
.ct-btn--primary:active:not(:disabled) { background: var(--accent-pressed); }
.ct-btn--secondary { background: var(--surface-card); border-color: var(--line-2); color: var(--ink-1); }
.ct-btn--secondary:hover:not(:disabled) { background: var(--paper-2); }
.ct-btn--secondary:active:not(:disabled) { background: var(--paper-3); }
.ct-btn--ghost { background: transparent; color: var(--ink-2); }
.ct-btn--ghost:hover:not(:disabled) { background: var(--paper-2); color: var(--ink-1); }
.ct-btn--ghost:active:not(:disabled) { background: var(--paper-3); }
.ct-btn--danger { background: var(--danger); color: var(--ink-inverse); }
.ct-btn--danger:hover:not(:disabled) { filter: brightness(0.92); }
`;
(function inject() {
if (typeof document !== 'undefined' && !document.getElementById('ct-button-css')) {
const s = document.createElement('style'); s.id = 'ct-button-css'; s.textContent = CSS;
document.head.appendChild(s);
}
})();
export function Button({
variant = 'primary',
size = 'md',
icon,
iconRight,
disabled = false,
children,
style,
...rest
}: ButtonProps) {
const iconSize = size === 'sm' ? 15 : 17;
return (
<button
type="button"
className={`ct-btn ct-btn--${size} ct-btn--${variant}`}
disabled={disabled}
style={style}
{...rest}
>
{icon ? <Icon name={icon} size={iconSize} /> : null}
{children}
{iconRight ? <Icon name={iconRight} size={iconSize} /> : null}
</button>
);
}