feat(design): add Modernist UI primitives (Button, Tag, StatusTag, Field, Card, table styles)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { ButtonHTMLAttributes } from 'react'
|
||||
import { cx } from './cx'
|
||||
|
||||
type Variant = 'primary' | 'secondary' | 'ghost' | 'icon'
|
||||
|
||||
const BASE =
|
||||
'inline-flex items-center gap-1.5 text-left font-extrabold text-sm leading-tight ' +
|
||||
'border border-transparent cursor-pointer transition-colors ' +
|
||||
'disabled:opacity-45 disabled:cursor-not-allowed'
|
||||
|
||||
const VARIANTS: Record<Variant, string> = {
|
||||
primary: 'justify-start bg-accent text-ground px-3.5 py-2 hover:bg-accent-600 active:bg-accent-700',
|
||||
secondary: 'justify-start border-divider text-ink px-3.5 py-2 hover:bg-ink/7 active:bg-ink/15',
|
||||
ghost: 'justify-start text-accent-700 px-1 py-2 hover:bg-accent/10 active:bg-accent/20',
|
||||
icon: 'justify-center w-9 h-9 p-0 text-ink hover:bg-ink/7 active:bg-ink/15',
|
||||
}
|
||||
|
||||
type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
|
||||
variant?: Variant
|
||||
block?: boolean
|
||||
}
|
||||
|
||||
export function Button({ variant = 'primary', block = false, className, type = 'button', ...rest }: Props) {
|
||||
return <button type={type} className={cx(BASE, VARIANTS[variant], block && 'w-full', className)} {...rest} />
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
export function Card({
|
||||
kicker,
|
||||
title,
|
||||
meta,
|
||||
children,
|
||||
}: {
|
||||
kicker?: ReactNode
|
||||
title?: ReactNode
|
||||
meta?: ReactNode
|
||||
children?: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-col gap-2 p-3 bg-surface">
|
||||
{kicker && <span className="text-[10px] tracking-[0.1em] uppercase text-accent-700">{kicker}</span>}
|
||||
{title && <h3 className="text-[17px] leading-tight font-extrabold">{title}</h3>}
|
||||
{children && <div className="flex-1 text-[13px] opacity-80">{children}</div>}
|
||||
{meta && <div className="flex items-center gap-1.5 text-[11px] text-ink/50">{meta}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export const cx = (...parts: Array<string | false | null | undefined>): string =>
|
||||
parts.filter(Boolean).join(' ')
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { InputHTMLAttributes, ReactNode, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react'
|
||||
import { cx } from './cx'
|
||||
|
||||
export const INPUT_CLASS =
|
||||
'w-full min-h-9 px-2.5 py-1.5 text-sm text-ink caret-accent bg-surface border border-divider ' +
|
||||
'hover:border-ink/45 focus-visible:border-accent focus-visible:outline-offset-0 ' +
|
||||
'disabled:opacity-45 disabled:cursor-not-allowed'
|
||||
|
||||
export function Field({ label, htmlFor, children }: { label: string; htmlFor: string; children: ReactNode }) {
|
||||
return (
|
||||
<div>
|
||||
<label htmlFor={htmlFor} className="block text-xs mb-[5px] text-ink/70">
|
||||
{label}
|
||||
</label>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function Input({ className, ...rest }: InputHTMLAttributes<HTMLInputElement>) {
|
||||
return <input className={cx(INPUT_CLASS, className)} {...rest} />
|
||||
}
|
||||
|
||||
export function Textarea({ className, ...rest }: TextareaHTMLAttributes<HTMLTextAreaElement>) {
|
||||
return <textarea className={cx(INPUT_CLASS, 'min-h-[90px] resize-y', className)} {...rest} />
|
||||
}
|
||||
|
||||
export function Select({ className, ...rest }: SelectHTMLAttributes<HTMLSelectElement>) {
|
||||
return <select className={cx(INPUT_CLASS, className)} {...rest} />
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import {
|
||||
AlarmClock,
|
||||
BadgeCheck,
|
||||
Circle,
|
||||
CircleAlert,
|
||||
CircleCheck,
|
||||
ClipboardList,
|
||||
ListChecks,
|
||||
Loader,
|
||||
RotateCcw,
|
||||
Search,
|
||||
type LucideIcon,
|
||||
} from 'lucide-react'
|
||||
import { Tag, type TagVariant } from './tag'
|
||||
|
||||
const TONES: Record<string, TagVariant> = {
|
||||
reported: 'accent',
|
||||
triaged: 'outline',
|
||||
investigating: 'outline',
|
||||
capa_pending: 'outline',
|
||||
verification: 'outline',
|
||||
closed: 'neutral',
|
||||
open: 'accent',
|
||||
in_progress: 'outline',
|
||||
overdue: 'accent',
|
||||
pending_verification: 'outline',
|
||||
verified: 'neutral',
|
||||
reopened: 'accent',
|
||||
}
|
||||
|
||||
const ICONS: Record<string, LucideIcon> = {
|
||||
reported: CircleAlert,
|
||||
triaged: ListChecks,
|
||||
investigating: Search,
|
||||
capa_pending: ClipboardList,
|
||||
verification: BadgeCheck,
|
||||
closed: CircleCheck,
|
||||
open: Circle,
|
||||
in_progress: Loader,
|
||||
overdue: AlarmClock,
|
||||
pending_verification: BadgeCheck,
|
||||
verified: CircleCheck,
|
||||
reopened: RotateCcw,
|
||||
}
|
||||
|
||||
export function statusTone(status: string): TagVariant {
|
||||
return TONES[status] ?? 'neutral'
|
||||
}
|
||||
|
||||
function humanize(value: string): string {
|
||||
return value
|
||||
.split('_')
|
||||
.map(w => (w === 'capa' ? 'CAPA' : w.charAt(0).toUpperCase() + w.slice(1)))
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
export function StatusTag({ status, children }: { status: string; children?: ReactNode }) {
|
||||
const Icon = ICONS[status]
|
||||
return (
|
||||
<Tag variant={statusTone(status)}>
|
||||
{Icon && <Icon size={12} strokeWidth={2} aria-hidden />}
|
||||
{children ?? humanize(status)}
|
||||
</Tag>
|
||||
)
|
||||
}
|
||||
|
||||
const PRIORITY_TONES: Record<string, TagVariant> = { high: 'accent', med: 'outline', low: 'neutral' }
|
||||
|
||||
export function PriorityTag({ priority, children }: { priority: string; children?: ReactNode }) {
|
||||
return <Tag variant={PRIORITY_TONES[priority] ?? 'neutral'}>{children ?? humanize(priority)}</Tag>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export const TABLE = 'w-full border-collapse text-sm'
|
||||
export const TH =
|
||||
'text-left text-[11px] uppercase tracking-[0.08em] text-ink/60 px-2 py-2 border-b-2 border-divider'
|
||||
export const TR = 'hover:bg-ink/4'
|
||||
export const TD = 'px-2 py-2 border-b border-divider'
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { cx } from './cx'
|
||||
|
||||
export type TagVariant = 'accent' | 'neutral' | 'outline'
|
||||
|
||||
const VARIANTS: Record<TagVariant, string> = {
|
||||
accent: 'bg-accent-100 text-accent-800',
|
||||
neutral: 'bg-neutral-100 text-neutral-800',
|
||||
outline: 'border border-accent text-accent-700',
|
||||
}
|
||||
|
||||
export function Tag({ variant, children, className }: { variant: TagVariant; children: ReactNode; className?: string }) {
|
||||
return (
|
||||
<span
|
||||
className={cx(
|
||||
'inline-flex items-center gap-1 text-[11px] font-medium tracking-wide px-2.5 py-[3px] whitespace-nowrap',
|
||||
VARIANTS[variant],
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user