|
| 1 | +// @unocss-include |
| 2 | +// Co-located devframe -> @antfu/design class helpers: framework-neutral builders |
| 3 | +// returning @antfu/design's semantic shortcut classes, so this surface looks |
| 4 | +// identical to the antfu Vue components. The `@unocss-include` marker makes |
| 5 | +// UnoCSS emit the runtime-assembled class chains below. |
| 6 | +// Tag palette kept literal for extraction: badge-color-blue badge-color-amber |
| 7 | +// badge-color-green badge-color-red badge-color-sky badge-color-violet |
| 8 | +// badge-color-rose badge-color-teal badge-color-orange badge-color-emerald |
| 9 | + |
| 10 | +export function cx(...parts: Array<string | false | null | undefined>): string { |
| 11 | + return parts.filter(Boolean).join(' ') |
| 12 | +} |
| 13 | + |
| 14 | +export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'destructive' | 'link' |
| 15 | +export type ButtonSize = 'md' | 'sm' | 'lg' |
| 16 | +export interface ButtonProps { variant?: ButtonVariant, size?: ButtonSize, class?: string } |
| 17 | + |
| 18 | +export function button({ variant = 'primary', size = 'md', class: extra }: ButtonProps = {}): string { |
| 19 | + const variantClass: Record<ButtonVariant, string> = { |
| 20 | + primary: 'btn-primary', |
| 21 | + secondary: 'btn-action', |
| 22 | + outline: 'btn-action', |
| 23 | + ghost: 'inline-flex items-center justify-center gap-1.5 rounded px2 py1 op75 hover:op100 hover:bg-active transition disabled:pointer-events-none disabled:op30!', |
| 24 | + destructive: 'btn-action text-error border-error/30!', |
| 25 | + link: 'inline-flex items-center gap-1.5 color-active hover:underline underline-offset-2', |
| 26 | + } |
| 27 | + const sizeClass = size === 'sm' |
| 28 | + ? (variant === 'primary' ? 'text-sm px-2.5! py-1!' : 'text-sm') |
| 29 | + : size === 'lg' ? 'text-base px-4! py-2!' : '' |
| 30 | + return cx(variantClass[variant], sizeClass, extra) |
| 31 | +} |
| 32 | + |
| 33 | +export type IconButtonVariant = 'outline' | 'ghost' |
| 34 | +export type IconButtonSize = 'md' | 'sm' |
| 35 | +export interface IconButtonProps { variant?: IconButtonVariant, size?: IconButtonSize, class?: string } |
| 36 | + |
| 37 | +export function iconButton({ variant = 'outline', size = 'md', class: extra }: IconButtonProps = {}): string { |
| 38 | + const base = variant === 'ghost' ? 'btn-icon' : 'btn-icon-square' |
| 39 | + const sizeClass = size === 'sm' ? 'w-7! h-7! text-sm' : '' |
| 40 | + return cx(base, sizeClass, extra) |
| 41 | +} |
| 42 | + |
| 43 | +export type BadgeVariant = 'primary' | 'secondary' | 'success' | 'warning' | 'destructive' | 'outline' |
| 44 | +export interface BadgeProps { variant?: BadgeVariant, class?: string } |
| 45 | + |
| 46 | +export function badge({ variant = 'secondary', class: extra }: BadgeProps = {}): string { |
| 47 | + const variantClass: Record<BadgeVariant, string> = { |
| 48 | + primary: 'badge-active', |
| 49 | + secondary: 'badge-muted', |
| 50 | + success: 'badge badge-color-green', |
| 51 | + warning: 'badge badge-color-amber', |
| 52 | + destructive: 'badge badge-color-red', |
| 53 | + outline: 'badge border border-base', |
| 54 | + } |
| 55 | + return cx(variantClass[variant], extra) |
| 56 | +} |
| 57 | + |
| 58 | +export function tag(color: string, extra?: string): string { |
| 59 | + return cx('badge', `badge-color-${color}`, extra) |
| 60 | +} |
| 61 | + |
| 62 | +export function tabsList(extra?: string): string { |
| 63 | + return cx('inline-flex items-center gap-1 p-1 rounded-lg bg-secondary w-max', extra) |
| 64 | +} |
| 65 | + |
| 66 | +export function tab(extra?: string): string { |
| 67 | + return cx( |
| 68 | + 'px-3 py-1 rounded-md text-sm color-muted inline-flex gap-1.5 items-center whitespace-nowrap select-none cursor-pointer transition outline-none hover:color-base focus-visible:ring-2 focus-visible:ring-primary-500/40 data-[state=active]:bg-base data-[state=active]:color-base data-[state=active]:shadow-sm', |
| 69 | + extra, |
| 70 | + ) |
| 71 | +} |
| 72 | + |
| 73 | +export interface NavTabProps { active?: boolean, class?: string } |
| 74 | +export function navTab({ active = false, class: extra }: NavTabProps = {}): string { |
| 75 | + return cx( |
| 76 | + 'relative inline-flex items-center gap-1.5 max-w-52 px-2 py-1 rounded-md border border-transparent text-sm op-fade select-none cursor-pointer transition hover:op100 hover:bg-active', |
| 77 | + active && 'op100! bg-active border-base! color-base', |
| 78 | + extra, |
| 79 | + ) |
| 80 | +} |
| 81 | + |
| 82 | +export function nav(extra?: string): string { |
| 83 | + return cx('flex items-center gap-2 shrink-0 h-10 px-3 border-b border-base bg-base z-nav', extra) |
| 84 | +} |
| 85 | + |
| 86 | +export function navBrand(extra?: string): string { |
| 87 | + return cx('flex items-center gap-1.5 shrink-0 font-semibold text-sm select-none', extra) |
| 88 | +} |
| 89 | + |
| 90 | +export function toolbar(extra?: string): string { |
| 91 | + return cx('flex items-center gap-2 shrink-0 h-8 px-2.5 border-b border-base bg-secondary text-sm', extra) |
| 92 | +} |
| 93 | + |
| 94 | +export function card(extra?: string): string { |
| 95 | + return cx('flex flex-col rounded-xl border border-base bg-base shadow-sm', extra) |
| 96 | +} |
| 97 | + |
| 98 | +export function panel(extra?: string): string { |
| 99 | + return cx('rounded-lg border border-base bg-base', extra) |
| 100 | +} |
| 101 | + |
| 102 | +export function input(extra?: string): string { |
| 103 | + return cx('w-full min-w-0 rounded border border-base bg-base px-2.5 py-1 text-sm outline-none transition placeholder:color-faint focus-visible:border-active focus-visible:ring-2 focus-visible:ring-primary-500/40', extra) |
| 104 | +} |
| 105 | + |
| 106 | +export function link(extra?: string): string { |
| 107 | + return cx('color-active hover:underline underline-offset-2', extra) |
| 108 | +} |
| 109 | + |
| 110 | +export type DotState = 'running' | 'idle' | 'error' |
| 111 | +export function dot(state: DotState, extra?: string): string { |
| 112 | + const stateClass: Record<DotState, string> = { |
| 113 | + running: 'bg-success', |
| 114 | + idle: 'bg-neutral-400', |
| 115 | + error: 'bg-error', |
| 116 | + } |
| 117 | + return cx('inline-block size-1.5 rounded-full shrink-0', stateClass[state], extra) |
| 118 | +} |
| 119 | + |
| 120 | +export function spinner(extra?: string): string { |
| 121 | + return cx('inline-block size-4 rounded-full border-2 border-current border-t-transparent animate-spin', extra) |
| 122 | +} |
0 commit comments