velxio/frontend/src/components/ui/Button.tsx

57 lines
1.3 KiB
TypeScript
Raw Normal View History

feat(design): tokens, webfonts, Lucide icons, board PNG/WebP picture strip Foundation - Add 7 token CSS files in src/tokens/ — semantic colors, 4-pt spacing, Apple-HIG type ramp, radius/elevation/motion/z-index scales. - Refactor src/index.css to import tokens and remap legacy aliases (--accent, --bg, etc.) onto the new --color-* semantics so existing components keep rendering during migration. - Drop the duplicate font-family from src/App.css; body inherits from :root. - Global *:focus-visible ring backed by --color-focus-ring (WCAG 2.4.7). Webfonts (self-hosted) - Add Inter.var.woff2 (variable, OFL) and JetBrainsMono.var.woff2 to public/fonts/. Preloaded in index.html with crossorigin. - Old stack -apple-system kept as fallback so Mac users still get SF Pro. - Fixes cross-OS rendering inconsistency (Win/Linux/Android were falling back to Segoe UI / Roboto, breaking the type grid). Component primitives - New src/components/ui/{Button,Card,Input}.tsx + .css. Built on the semantic tokens, ready for incremental migration of .ap-* CSS classes. Lucide icons - Replace 6 inline SVG icon components in LandingPage (IcoChip / IcoCpu / IcoCode / IcoZap / IcoLayers / IcoMonitor) with lucide-react imports. Aliased so call sites are unchanged. ~80 lines of inline SVG removed. - IcoGitHub kept bespoke (filled glyph, brand-correct). Marketing assets - Convert top 8 boards to transparent PNG + WebP at 1x / 2x: Arduino Uno, Nano, Mega 2560, Pi Pico, Pi Pico W, ESP32-C3, ESP32-DevKit-V1, XIAO ESP32-S3. - Migrate matching cards in LandingPage and Velxio2Page to <picture> with WebP > PNG > SVG fallback. Other 8 boards keep <img src=*.svg> for now (Raspberry Pi 3B, ESP32-CAM, etc.). - Refresh og-image.png — same canonical URL, new content (4 hero boards + branding instead of generic logo card). - Fix latent bug in LandingPage: ESP32 DevKit V1 card was loading esp32-devkit-c-v4.svg; now uses esp32-devkit-v1.{webp,png,svg}. Build verified: npm run build:docker succeeds, 246 SEO pages prerender. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 01:45:44 +07:00
import { forwardRef, type ButtonHTMLAttributes, type ReactNode } from 'react';
import './Button.css';
type Variant = 'primary' | 'secondary' | 'ghost' | 'white';
type Size = 'sm' | 'md' | 'lg';
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: Variant;
size?: Size;
loading?: boolean;
iconLeft?: ReactNode;
iconRight?: ReactNode;
fullWidth?: boolean;
}
export const Button = forwardRef<HTMLButtonElement, Props>(function Button(
{
variant = 'primary',
size = 'md',
loading = false,
iconLeft,
iconRight,
fullWidth = false,
disabled,
className,
children,
...rest
},
ref,
) {
const classes = [
'ui-btn',
`ui-btn--${variant}`,
`ui-btn--${size}`,
fullWidth ? 'ui-btn--full' : '',
loading ? 'ui-btn--loading' : '',
className ?? '',
]
.filter(Boolean)
.join(' ');
return (
<button
ref={ref}
className={classes}
disabled={disabled || loading}
aria-busy={loading || undefined}
{...rest}
>
{loading ? <span className="ui-btn__spinner" aria-hidden="true" /> : null}
{!loading && iconLeft ? <span className="ui-btn__icon">{iconLeft}</span> : null}
<span className="ui-btn__label">{children}</span>
{!loading && iconRight ? <span className="ui-btn__icon">{iconRight}</span> : null}
</button>
);
});