feat(design): add IMS Admin primitives (Button, StatusTag, Checkbox, FilterChip, Segmented, Avatar, Drawer) and restyle Field, Card, Modal

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 09:28:34 +08:00
co-authored by Claude Haiku 4.5
parent 01343d732e
commit 2a5b9332c7
15 changed files with 417 additions and 248 deletions
+16
View File
@@ -0,0 +1,16 @@
export function initials(name: string): string {
return name
.split(' ')
.map(w => w[0] ?? '')
.join('')
.toUpperCase()
.slice(0, 2)
}
export function Avatar({ name }: { name: string }) {
return (
<span className="inline-grid place-items-center w-6 h-6 rounded-[6px] bg-accent-200 text-accent-700 text-[11px] font-[650]">
{initials(name)}
</span>
)
}
+20 -9
View File
@@ -1,25 +1,36 @@
import type { ButtonHTMLAttributes } from 'react'
import { cx } from './cx'
type Variant = 'primary' | 'secondary' | 'ghost' | 'icon'
type Variant = 'primary' | 'secondary' | '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 ' +
'inline-flex items-center justify-center gap-1.5 whitespace-nowrap transition-colors cursor-pointer ' +
'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',
primary: 'h-8 px-3 rounded-md bg-ink-2 text-white text-[13px] font-semibold shadow-primary hover:bg-ink active:bg-black',
secondary: 'h-8 px-3 rounded-md bg-surface text-ink text-[13px] font-medium shadow-secondary hover:bg-surface-2 active:bg-rule',
icon: 'w-7 h-7 rounded-md text-ink-3 hover:bg-rule',
}
type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: Variant
block?: boolean
mobile?: 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} />
export function Button({ variant = 'primary', block = false, mobile = false, className, type = 'button', ...rest }: Props) {
return (
<button
type={type}
className={cx(
BASE,
VARIANTS[variant],
mobile && variant !== 'icon' && 'h-12 rounded-xl text-sm',
block && 'w-full',
className,
)}
{...rest}
/>
)
}
+5 -5
View File
@@ -12,11 +12,11 @@ export function Card({
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 className="flex flex-col gap-2 p-4 bg-surface rounded-xl shadow-card">
{kicker && <span className="text-[11px] font-semibold tracking-wide uppercase text-muted">{kicker}</span>}
{title && <h3 className="text-base font-[650]">{title}</h3>}
{children && <div className="flex-1 text-[13px] text-ink-3">{children}</div>}
{meta && <div className="flex items-center gap-1.5 text-xs text-faint">{meta}</div>}
</div>
)
}
+34
View File
@@ -0,0 +1,34 @@
import { Check, Minus } from 'lucide-react'
import { cx } from './cx'
export function Checkbox({
checked,
indeterminate = false,
onChange,
label,
}: {
checked: boolean
indeterminate?: boolean
onChange: (next: boolean) => void
label: string
}) {
const on = checked || indeterminate
return (
<button
type="button"
role="checkbox"
aria-checked={indeterminate ? 'mixed' : checked}
aria-label={label}
onClick={e => {
e.stopPropagation()
onChange(!checked)
}}
className={cx(
'inline-grid place-items-center w-4 h-4 rounded-[5px] cursor-pointer',
on ? 'bg-accent text-white' : 'bg-surface shadow-[inset_0_0_0_1.5px_var(--color-faint)]',
)}
>
{indeterminate ? <Minus size={12} strokeWidth={3} aria-hidden /> : checked ? <Check size={12} strokeWidth={3} aria-hidden /> : null}
</button>
)
}
+51
View File
@@ -0,0 +1,51 @@
'use client'
import { useEffect } from 'react'
import { X } from 'lucide-react'
import { Button } from './button'
export function Drawer({
open,
onClose,
title,
actions,
children,
}: {
open: boolean
onClose: () => void
title: string
actions?: React.ReactNode
children: React.ReactNode
}) {
useEffect(() => {
if (!open) return
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() }
document.addEventListener('keydown', onKey)
return () => document.removeEventListener('keydown', onKey)
}, [open, onClose])
if (!open) return null
return (
<div className="fixed inset-0 z-50">
<div className="absolute inset-0 bg-black/30" onClick={onClose} aria-hidden />
<aside
role="dialog"
aria-modal="true"
aria-label={title}
className="absolute top-2 right-2 bottom-2 w-[420px] max-w-[calc(100vw-16px)] flex flex-col overflow-hidden rounded-2xl bg-surface shadow-drawer"
>
<div className="flex items-center justify-between px-4 pt-3.5 pb-2.5">
<h2 className="text-base font-[650]">{title}</h2>
<div className="flex items-center gap-1">
{actions}
<Button variant="icon" aria-label="Close" onClick={onClose}>
<X size={16} strokeWidth={2} aria-hidden />
</Button>
</div>
</div>
<div className="flex-1 overflow-y-auto">{children}</div>
</aside>
</div>
)
}
+4 -5
View File
@@ -2,14 +2,13 @@ import type { InputHTMLAttributes, ReactNode, SelectHTMLAttributes, TextareaHTML
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'
'w-full h-9 px-3 rounded-md bg-surface text-[13px] text-ink caret-accent shadow-input ' +
'placeholder:text-faint 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 htmlFor={htmlFor} className="block text-xs text-muted mb-[5px]">
{label}
</label>
{children}
@@ -22,7 +21,7 @@ export function Input({ className, ...rest }: InputHTMLAttributes<HTMLInputEleme
}
export function Textarea({ className, ...rest }: TextareaHTMLAttributes<HTMLTextAreaElement>) {
return <textarea className={cx(INPUT_CLASS, 'min-h-[90px] resize-y', className)} {...rest} />
return <textarea className={cx(INPUT_CLASS, 'h-auto min-h-[90px] py-2 resize-y', className)} {...rest} />
}
export function Select({ className, ...rest }: SelectHTMLAttributes<HTMLSelectElement>) {
+49
View File
@@ -0,0 +1,49 @@
import { ChevronDown, X } from 'lucide-react'
import { cx } from './cx'
export function FilterChip({
label,
value,
options,
onChange,
}: {
label: string
value: string
options: Array<{ value: string; label: string }>
onChange: (value: string) => void
}) {
const selected = options.find(o => o.value === value)
const set = Boolean(value && selected)
return (
<label
className={cx(
'relative inline-flex items-center gap-1 h-7 px-2.5 rounded-md text-[12.5px] whitespace-nowrap cursor-pointer',
set ? 'bg-accent-tint-2 text-accent-700 shadow-chip-set' : 'bg-surface text-ink-2 shadow-chip',
)}
>
<span>{set ? `${label}: ${selected!.label}` : label}</span>
{!set && <ChevronDown size={12} strokeWidth={2.5} aria-hidden />}
<select
aria-label={label}
value={value}
onChange={e => onChange(e.target.value)}
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
>
<option value="">{label}</option>
{options.map(o => (
<option key={o.value} value={o.value}>{o.label}</option>
))}
</select>
{set && (
<button
type="button"
aria-label={`Clear ${label}`}
onClick={() => onChange('')}
className="relative z-10 inline-grid place-items-center w-4 h-4 cursor-pointer"
>
<X size={12} strokeWidth={2.5} aria-hidden />
</button>
)}
</label>
)
}
+10 -13
View File
@@ -2,6 +2,7 @@
import { useEffect } from 'react'
import { X } from 'lucide-react'
import { Button } from './button'
interface ModalProps {
open: boolean
@@ -26,21 +27,17 @@ export function Modal({ open, onClose, title, children, footer, width = 'md' }:
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" role="dialog" aria-modal="true">
<div className="absolute inset-0 bg-neutral-900/50" onClick={onClose} />
<div className={`relative w-full ${maxW} bg-surface shadow-lg`}>
<div className="flex items-center justify-between px-6 py-4 border-b border-divider">
<h2 className="text-xl font-extrabold text-ink">{title}</h2>
<button
onClick={onClose}
aria-label="Close"
className="inline-flex w-9 h-9 items-center justify-center text-ink cursor-pointer transition-colors hover:bg-ink/7 active:bg-ink/15"
>
<X size={18} strokeWidth={2} aria-hidden />
</button>
<div className="absolute inset-0 bg-black/30" onClick={onClose} />
<div className={`relative w-full ${maxW} bg-surface rounded-xl shadow-float`}>
<div className="flex items-center justify-between px-5 py-3.5 border-b border-rule">
<h2 className="text-base font-[650]">{title}</h2>
<Button variant="icon" aria-label="Close" onClick={onClose}>
<X size={16} strokeWidth={2} aria-hidden />
</Button>
</div>
<div className="px-6 py-5">{children}</div>
<div className="px-5 py-4">{children}</div>
{footer && (
<div className="px-6 py-4 border-t border-divider flex justify-end gap-2">
<div className="px-5 py-3.5 border-t border-rule flex justify-end gap-2">
{footer}
</div>
)}
+31
View File
@@ -0,0 +1,31 @@
import type { ReactNode } from 'react'
import { cx } from './cx'
export function Segmented({
value,
onChange,
options,
}: {
value: string
onChange: (v: string) => void
options: Array<{ value: string; label: ReactNode }>
}) {
return (
<div className="inline-flex p-0.5 rounded-[10px] bg-rule-2">
{options.map(o => (
<button
key={o.value}
type="button"
aria-pressed={o.value === value}
onClick={() => onChange(o.value)}
className={cx(
'inline-flex items-center gap-1.5 px-2.5 py-[5px] rounded-md text-[13px] cursor-pointer whitespace-nowrap',
o.value === value ? 'bg-surface font-semibold shadow-sm' : 'text-ink-3',
)}
>
{o.label}
</button>
))}
</div>
)
}
+43 -55
View File
@@ -1,72 +1,60 @@
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'
import { cx } from './cx'
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',
export type StatusHue = 'amber' | 'blue' | 'violet' | 'orange' | 'indigo' | 'green' | 'grey' | 'red'
const HUES: Record<string, StatusHue> = {
reported: 'amber', triaged: 'blue', investigating: 'violet', capa_pending: 'orange',
verification: 'indigo', closed: 'green',
open: 'grey', in_progress: 'blue', overdue: 'red', pending_verification: 'indigo',
verified: 'green', reopened: 'red',
critical: 'red', high: 'orange', med: 'amber', medium: 'amber', low: 'grey', active: 'green',
}
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,
const LABELS: Record<string, string> = {
capa_pending: 'CAPA pending', pending_verification: 'Verification', in_progress: 'In progress', med: 'Medium',
}
export function statusTone(status: string): TagVariant {
return TONES[status] ?? 'neutral'
// Full literal class strings so Tailwind can see them.
const HUE_CLASS: Record<StatusHue, string> = {
amber: 'bg-st-amber-bg text-st-amber-fg',
blue: 'bg-st-blue-bg text-st-blue-fg',
violet: 'bg-st-violet-bg text-st-violet-fg',
orange: 'bg-st-orange-bg text-st-orange-fg',
indigo: 'bg-st-indigo-bg text-st-indigo-fg',
green: 'bg-st-green-bg text-st-green-fg',
grey: 'bg-st-grey-bg text-st-grey-fg',
red: 'bg-st-red-bg text-st-red-fg',
}
function humanize(value: string): string {
return value
.split('_')
.map(w => (w === 'capa' ? 'CAPA' : w.charAt(0).toUpperCase() + w.slice(1)))
.join(' ')
export function statusHue(key: string): StatusHue {
return HUES[key] ?? 'grey'
}
export function StatusTag({ status, children }: { status: string; children?: ReactNode }) {
const Icon = ICONS[status]
function label(key: string): string {
if (LABELS[key]) return LABELS[key]
const words = key.split('_').join(' ')
return words.charAt(0).toUpperCase() + words.slice(1)
}
function Pill({ hue, className, children }: { hue: StatusHue; className?: string; children: ReactNode }) {
return (
<Tag variant={statusTone(status)}>
{Icon && <Icon size={12} strokeWidth={2} aria-hidden />}
{children ?? humanize(status)}
</Tag>
<span
className={cx(
'inline-flex items-center px-2 py-0.5 rounded-md text-xs font-[550] whitespace-nowrap',
HUE_CLASS[hue],
className,
)}
>
{children}
</span>
)
}
const PRIORITY_TONES: Record<string, TagVariant> = { high: 'accent', med: 'outline', low: 'neutral' }
export function StatusTag({ status, children }: { status: string; children?: ReactNode }) {
return <Pill hue={statusHue(status)}>{children ?? label(status)}</Pill>
}
export function PriorityTag({ priority, children }: { priority: string; children?: ReactNode }) {
return <Tag variant={PRIORITY_TONES[priority] ?? 'neutral'}>{children ?? humanize(priority)}</Tag>
return <Pill hue={statusHue(priority)}>{children ?? label(priority)}</Pill>
}
-5
View File
@@ -1,5 +0,0 @@
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'
-24
View File
@@ -1,24 +0,0 @@
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>
)
}