From 2a5b9332c71a6a748d7ee9d078389a03c5226de4 Mon Sep 17 00:00:00 2001 From: weeihan Date: Thu, 1 Oct 2026 09:28:34 +0800 Subject: [PATCH] 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 --- components/ui/avatar.tsx | 16 ++ components/ui/button.tsx | 29 ++- components/ui/card.tsx | 10 +- components/ui/checkbox.tsx | 34 +++ components/ui/drawer.tsx | 51 ++++ components/ui/field.tsx | 9 +- components/ui/filter-chip.tsx | 49 ++++ components/ui/modal.tsx | 23 +- components/ui/segmented.tsx | 31 +++ components/ui/status-tag.tsx | 98 ++++--- components/ui/table-styles.ts | 5 - components/ui/tag.tsx | 24 -- .../2026-10-01-ims-admin-refresh-slice-1.md | 4 +- tests/components/ui/modal.test.tsx | 40 +-- tests/components/ui/primitives.test.tsx | 242 +++++++++++------- 15 files changed, 417 insertions(+), 248 deletions(-) create mode 100644 components/ui/avatar.tsx create mode 100644 components/ui/checkbox.tsx create mode 100644 components/ui/drawer.tsx create mode 100644 components/ui/filter-chip.tsx create mode 100644 components/ui/segmented.tsx delete mode 100644 components/ui/table-styles.ts delete mode 100644 components/ui/tag.tsx diff --git a/components/ui/avatar.tsx b/components/ui/avatar.tsx new file mode 100644 index 0000000..0466fe6 --- /dev/null +++ b/components/ui/avatar.tsx @@ -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 ( + + {initials(name)} + + ) +} diff --git a/components/ui/button.tsx b/components/ui/button.tsx index 0947a2b..ecaecf7 100644 --- a/components/ui/button.tsx +++ b/components/ui/button.tsx @@ -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 = { - 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 & { variant?: Variant block?: boolean + mobile?: boolean } -export function Button({ variant = 'primary', block = false, className, type = 'button', ...rest }: Props) { - return + ) +} diff --git a/components/ui/drawer.tsx b/components/ui/drawer.tsx new file mode 100644 index 0000000..3f516e2 --- /dev/null +++ b/components/ui/drawer.tsx @@ -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 ( +
+
+ +
+ ) +} diff --git a/components/ui/field.tsx b/components/ui/field.tsx index 7c85ffa..2815fd1 100644 --- a/components/ui/field.tsx +++ b/components/ui/field.tsx @@ -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 (
-