디자인 원칙 (Design Principles)
HeroUI v3의 디자인과 개발을 이끄는 핵심 원칙을 소개해요. 명확성, 접근성, 커스터마이징, 개발자 경험을 우선시하는 10가지 원칙을 다룹니다.
본문
HeroUI v3는 명확성, 접근성, 커스터마이징, 개발자 경험을 우선시하는 10가지 핵심 원칙을 따르고 있어요.
핵심 원칙 (Core Principles)
1. 시각적 스타일보다 의미론적 의도 (Semantic Intent Over Visual Style)
시각적 설명(solid, flat, bordered) 대신 의미론적 명명(primary, secondary, tertiary)을 사용해요. Uber의 Base 디자인 시스템에서 영감을 받았으며, 변형(variant)은 명확한 위계를 따릅니다:
// ✅ Semantic variants communicate hierarchy
<Button variant="primary">Save</Button>
<Button variant="secondary">Edit</Button>
<Button variant="tertiary">Cancel</Button>
| Variant | Purpose | Usage |
|---|---|---|
| Primary | Main action to move forward | 1 per context |
| Secondary | Alternative actions | Multiple allowed |
| Tertiary | Dismissive actions (cancel, skip) | Sparingly |
| Danger | Destructive actions | When needed |
2. 접근성을 기반으로 (Accessibility as Foundation)
WCAG 2.1 AA 준수를 위해 React Aria Components를 기반으로 해요. 자동 ARIA 속성, 키보드 탐색, 화면 낭독기 지원이 포함됩니다.
import { Tabs, TabList, Tab, TabPanel } from '@heroui/react';
<Tabs defaultSelectedKey="profile">
<TabList aria-label="Settings">
<Tab id="profile">Profile</Tab>
<Tab id="security">Security</Tab>
</TabList>
<TabPanel id="profile">Content</TabPanel>
<TabPanel id="security">Content</TabPanel>
</Tabs>
3. 설정보다 합성 (Composition Over Configuration)
복합 컴포넌트(compound component)를 사용해 필요에 따라 부분을 재배열, 커스터마이즈, 생략할 수 있어요. 점 표기법(dot notation), 명명된 내보내기(named exports), 또는 둘 다 섞어 사용할 수 있습니다.
// Compose parts to build exactly what you need
import {
Accordion,
AccordionItem,
AccordionHeading,
AccordionTrigger,
AccordionIndicator,
AccordionPanel,
AccordionBody
} from '@heroui/react';
<Accordion>
<AccordionItem id="1">
<AccordionHeading>
<AccordionTrigger>
Question Text
<AccordionIndicator />
</AccordionTrigger>
</AccordionHeading>
<AccordionPanel>
<AccordionBody>Answer content</AccordionBody>
</AccordionPanel>
</AccordionItem>
</Accordion>
4. 점진적 공개 (Progressive Disclosure)
단순하게 시작하고, 필요할 때만 복잡성을 더해요. 컴포넌트는 최소한의 props로 동작하며 요구사항이 커짐에 따라 확장됩니다.
// Level 1: Minimal
<Button>Click me</Button>
// Level 2: Enhanced
<Button variant="primary" size="lg">
<Icon icon="gravity-ui:check" className="mr-2" />
Submit
</Button>
// Level 3: Advanced
<Button variant="primary" isDisabled={isLoading}>
{isLoading ? <><Spinner size="sm" className="mr-2" /> Loading...</> : 'Submit'}
</Button>
5. 예측 가능한 동작 (Predictable Behavior)
모든 컴포넌트에 일관된 패턴을 적용해요: 크기(sm, md, lg), 변형(variant), className 지원, 데이터 속성. 같은 API, 같은 동작이에요.
// All components follow the same patterns
<Button size="lg" variant="primary" className="custom" data-pressed="true" />
<Chip size="lg" variant="success" className="custom" />
<Avatar size="lg" className="custom" />
// Compound components support both named exports and dot notation
import { Alert, AlertIcon, CardHeader, AccordionTrigger } from '@heroui/react';
// Named exports
<Alert>
<AlertIcon />
</Alert>
// Dot notation
<Alert>
<Alert.Icon />
</Alert>
6. 타입 안전성 우선 (Type Safety First)
IntelliSense, 자동 완성, 컴파일 타임 오류 감지를 갖춘 완전한 TypeScript 지원을 제공해요. 사용자 정의 컴포넌트를 위해 타입을 확장할 수 있습니다.
import type { ButtonProps } from '@heroui/react';
// Type-safe props and event handlers
<Button
variant="primary" // Autocomplete: primary | secondary | tertiary | danger | ghost
size="md" // Type checked: sm | md | lg
onPress={(e) => { // e is properly typed as PressEvent
console.log(e.target);
}}
/>
// Extend types for custom components
interface CustomButtonProps extends Omit<ButtonProps, 'variant'> {
intent: 'save' | 'cancel' | 'delete';
}
7. 스타일과 로직의 분리 (Separation of Styles and Logic)
스타일(@heroui/styles)은 로직(@heroui/react)과 분리되어 있어, 어떤 프레임워크나 바닐라 HTML에서도 사용할 수 있어요. Tailwind Play 예제를 참고하세요.
<!-- Use with plain HTML -->
<button class="button button--primary">Click me</button>
또는 React와 함께 사용:
// Apply styles to any component
import { buttonVariants } from '@heroui/styles';
<Link className={buttonVariants({ variant: "primary" })} href="/home">
Home
</Link>
8. 개발자 경험 우수성 (Developer Experience Excellence)
명확한 API, 설명적인 오류, IntelliSense, AI 친화적인 마크다운 문서, 시각적 테스트를 위한 Storybook을 제공해요.
9. 완전한 커스터마이징 (Complete Customization)
기본 제공되는 아름다운 기본값이에요. CSS 변수나 BEM 클래스로 전체적인 모습을 바꿀 수 있어요. 모든 슬롯을 커스터마이즈할 수 있습니다.
/* Theme-wide changes with variables */
:root {
--accent: oklch(0.7 0.25 260);
--radius: 0.375rem;
--spacing: 0.5rem;
}
/* Component-specific customization */
@layer components {
.button {
@apply uppercase tracking-wider;
}
.button--primary {
@apply bg-gradient-to-r from-purple-500 to-pink-500;
}
}
10. 개방적이고 확장 가능 (Open and Extensible)
필요에 맞게 컴포넌트를 감싸고(wrap), 확장하고(extend), 커스터마이즈해요. 변형(variant) 함수, 직접 BEM 클래스 적용, 또는 사용자 정의 래퍼를 만들 수 있습니다.
변형 함수로 스타일 적용:
import { Link } from '@heroui/react';
import { linkVariants } from '@heroui/styles';
import NextLink from 'next/link';
// Use variant functions to style framework-specific components
const slots = linkVariants({ underline: "hover" });
<NextLink className={slots.base()} href="/about">
About Page
<Link.Icon className={slots.icon()} />
</NextLink>
BEM 클래스 직접 적용:
import Link from 'next/link';
// Apply HeroUI's BEM classes directly to any element
<Link className="button button--primary" href="/dashboard">
Dashboard
</Link>
사용자 정의 래퍼 컴포넌트 만들기:
// Custom wrapper component
const CTAButton = ({
intent = 'primary-cta',
children,
ref,
...props
}: CTAButtonProps) => {
const variantMap = {
'primary-cta': 'primary',
'secondary-cta': 'secondary',
'minimal': 'ghost'
};
return (
<Button ref={ref} variant={variantMap[intent]} {...props}>
{children}
</Button>
);
};
Tailwind Variants로 확장:
import { Button } from '@heroui/react';
import { buttonVariants, tv } from '@heroui/styles';
// Extend button styles with custom variants
const myButtonVariants = tv({
extend: buttonVariants,
variants: {
variant: {
'primary-cta': 'bg-gradient-to-r from-blue-500 to-purple-600 text-white shadow-lg',
'secondary-cta': 'border-2 border-blue-500 text-blue-500 hover:bg-blue-50',
}
}
});
// Use the custom variants
function CustomButton({ variant, className, ...props }) {
return <Button className={myButtonVariants({ variant, className })} {...props} />;
}
// Usage
<CustomButton variant="primary-cta">Get Started</CustomButton>
<CustomButton variant="secondary-cta">Learn More</CustomButton>
HeroUI v2와의 비교 (Comparison with HeroUI v2)
| Aspect | HeroUI v2 | HeroUI v3 |
|---|---|---|
| Animations | Framer Motion | CSS + GPU accelerated |
| Component Pattern | Single components with many props | Compound components |
| Variants | Visual-based (solid, bordered, flat) | Semantic (primary, secondary, tertiary) |
| Styling | Tailwind v4 partially supported | Tailwind v4 fully supported |
| Accessibility | Excellent (React Aria powered) | Excellent (React Aria powered) |
| Bundle Size | Larger (Bundle) | Smaller (tree-shakeable) |
| Customization Difficulty | Medium (Props-based) | Simple (Compound components + Native CSS) |