본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

프레임워크 (Frameworks)

원문 보기 위키 갱신

HeroUI를 여러분의 프레임워크와 통합하는 방법을 안내해요.

출처: HeroUI Frameworks

본문

Next.js

1. Next.js 프로젝트 만들기

npx heroui-cli@latest init -t app

-t는 템플릿 선택기를 건너뛰어요. 프로젝트 이름과 패키지 매니저는 여전히 묻기 때문에, 직접 전달하면 모든 프롬프트를 건너뛸 수 있어요: npx heroui-cli@latest init my-app -t app -p pnpm. 그런 다음 새 폴더를 열고 의존성을 설치하세요(예: pnpm install).

2. 첫 번째 HeroUI 컴포넌트 사용하기

예: app/page.tsx

import {Button} from "@heroui/react";

export default function HomePage() {
  return (
    <main className="flex min-h-screen items-center justify-center">
      <Button variant="tertiary">Hello HeroUI</Button>
    </main>
  );
}

HeroUI v3는 provider가 필요 없어요. 컴포넌트는 설치와 스타일 임포트 후 바로 동작해요.

3. 로케일 설정 (선택 사항) (Locale Setup - Optional)

Next.js와 통합하려면 서버의 로케일이 클라이언트와 일치하는지 확인해요.

루트 레이아웃에서 사용자의 선호 언어를 결정하고 <html> 요소에 lang과 dir 속성을 설정해요.

// app/layout.tsx
import {headers} from 'next/headers';
import {isRTL} from '@heroui/react';
import {ClientProviders} from './provider';

export default async function RootLayout({children}) {
  // Get the user's preferred language from the Accept-Language header.
  // You could also get this from a database, URL param, etc.
  const acceptLanguage = (await headers()).get('accept-language');
  const lang = acceptLanguage?.split(/[,;]/)[0] || 'en-US';

  return (
    <html lang={lang} dir={isRTL(lang) ? 'rtl' : 'ltr'}>
      <body>
        <ClientProviders lang={lang}>
          {children}
        </ClientProviders>
      </body>
    </html>
  );
}

app/provider.tsx를 만들어 React Aria가 사용하는 로케일을 설정하는 I18nProvider를 렌더링해요.

// app/provider.tsx
"use client";

import {I18nProvider} from '@heroui/react';

export function ClientProviders({lang, children}) {
  return (
    <I18nProvider locale={lang}>
      {children}
    </I18nProvider>
  );
}

nonce가 있는 Content Security Policy(CSP)를 사용한다면, 문서 head에 <meta property="csp-nonce"> 태그를 추가하고 content 속성을 생성된 nonce 값으로 설정해요. React Aria는 이 태그에서 nonce를 자동으로 읽어요.

Vite

1. Vite 프로젝트 만들기

npx heroui-cli@latest init -t vite

-t는 템플릿 선택기를 건너뛰어요. 프로젝트 이름과 패키지 매니저는 여전히 묻기 때문에, 직접 전달하면 모든 프롬프트를 건너뛸 수 있어요: npx heroui-cli@latest init my-app -t vite -p pnpm. 그런 다음 새 폴더를 열고 의존성을 설치하세요(예: pnpm install).

2. 첫 번째 HeroUI 컴포넌트 사용하기

예: src/App.tsx

import {Button} from "@heroui/react";

function App() {
  return (
    <main className="flex min-h-screen items-center justify-center">
      <Button variant="tertiary">Hello HeroUI</Button>
    </main>
  );
}

export default App;

HeroUI v3는 provider가 필요 없어요. 컴포넌트는 설치와 스타일 임포트 후 바로 동작해요.

React Router

1. React Router 프로젝트 만들기

npx heroui-cli@latest init -t react-router

-t는 템플릿 선택기를 건너뛰어요. 프로젝트 이름과 패키지 매니저는 여전히 묻기 때문에, 직접 전달하면 모든 프롬프트를 건너뛸 수 있어요: npx heroui-cli@latest init my-app -t react-router -p pnpm. 그런 다음 새 폴더를 열고 의존성을 설치하세요(예: pnpm install).

2. 첫 번째 HeroUI 컴포넌트 사용하기

예: app/routes/_index.tsx

import {Button} from "@heroui/react";

export default function Index() {
  return (
    <main className="flex min-h-screen items-center justify-center">
      <Button variant="tertiary">Hello HeroUI</Button>
    </main>
  );
}

이 템플릿은 app/root.tsx에서 import "./tailwind.css";로 스타일을 로드해요. HeroUI v3는 provider가 필요 없어요. 컴포넌트는 설치와 스타일 임포트 후 바로 동작해요.

기타 프레임워크 (Other Frameworks)

@heroui/react는 그 동작이 React Aria 위에 구축되기 때문에 React가 필요해요. 디자인 시스템 자체는 React 의존성이 없는 @heroui/styles에 있으며, HeroUI의 BEM 클래스와 프레임워크에 구애받지 않는 변형 함수를 제공해요. Vue, Svelte, Angular 또는 일반 HTML에서 사용할 수 있어요.

경고: 이것은 HeroUI의 시각적 디자인을 제공하지만 동작은 제공하지 않아요. 키보드 내비게이션, 포커스 관리, ARIA 속성은 @heroui/react의 React Aria에서 오므로, 여러분의 컴포넌트에서 이를 직접 관리해야 해요.

1. 스타일 패키지 설치하기

npm i @heroui/styles

2. 스타일 임포트하기

Tailwind CSS v4:

주요 CSS 파일에 추가해요:

@import "tailwindcss";
@import "@heroui/styles";

Tailwind 유틸리티 클래스가 HeroUI 클래스와 함께 동작하는 유일한 옵션이에요.

Prebuilt CSS:

엔트리 파일에서 컴파일된 스타일시트를 임포트해요. Tailwind 빌드가 필요 없어요:

import "@heroui/styles/dist/heroui.min.css";

CDN:

빌드 단계가 전혀 필요 없어요:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@heroui/styles@3/dist/heroui.min.css" />

prebuilt와 CDN 번들은 HeroUI의 컴포넌트 클래스와 테마 토큰을 포함하지만 Tailwind의 유틸리티 클래스는 포함하지 않아요. flex나 gap-4 같은 유틸리티도 원한다면 Tailwind CSS v4 옵션을 사용하세요.

3. 첫 번째 HeroUI 컴포넌트 사용하기

BEM 클래스를 직접 적용하거나, 타입 안전성을 위해 변형 함수로 생성해요.

Vue:

<script setup lang="ts">
import {buttonVariants} from "@heroui/styles";

const buttonClass = buttonVariants({variant: "primary"});
</script>

<template>
  <button :class="buttonClass">Hello HeroUI</button>

  <!-- Or with BEM classes directly -->
  <button class="button button--primary">Hello HeroUI</button>
</template>

Svelte:

<script lang="ts">
  import {buttonVariants} from "@heroui/styles";

  const buttonClass = buttonVariants({variant: "primary"});
</script>

<button class={buttonClass}>Hello HeroUI</button>

<!-- Or with BEM classes directly -->
<button class="button button--primary">Hello HeroUI</button>

Angular:

import {Component} from "@angular/core";
import {buttonVariants} from "@heroui/styles";

@Component({
  selector: "app-example",
  standalone: true,
  template: `
    <button [class]="buttonClass">Hello HeroUI</button>

    <!-- Or with BEM classes directly -->
    <button class="button button--primary">Hello HeroUI</button>
  `,
})
export class ExampleComponent {
  buttonClass = buttonVariants({variant: "primary"});
}

HTML:

<button class="button button--primary">Hello HeroUI</button>
<button class="button button--secondary button--sm">Small</button>
<button class="button button--danger" disabled>Delete</button>

모든 컴포넌트는 동일한 BEM 규칙을 따라요: 블록 클래스, 변형과 크기의 -- 수정자, 하위 부분의 __ 요소. button의 경우 변형은 .button--primary, --secondary, --tertiary, --ghost, --outline, --danger, --danger-soft이고, 크기는 .button--sm, --md, --lg이며, .button--icon-only와 .button--full-width는 수정자예요.

변형 함수와 임의 요소에 HeroUI 스타일을 적용하는 방법은 Composition을 참고하세요.

4. 인터랙티브 상태 (Interactive states)

HeroUI의 CSS는 기본 의사 클래스와 data-* 속성을 모두 대상으로 하므로, 시맨틱 HTML 요소가 JavaScript 없이도 호버, 눌림, 포커스, 비활성 스타일링을 적용받아요:

/* button.css */
.button {
  &:active,
  &[data-pressed="true"] { ... }

  &:disabled,
  &[aria-disabled="true"] { ... }
}

브라우저가 추론할 수 없는 상태는 직접 설정해야 해요. 가장 일반적인 것들은 다음과 같아요:

Attribute Purpose
data-selected="true" Selected items in menus, list boxes, and tabs
data-entering="true" / data-exiting="true" Enter and exit animations for overlays
data-placement="top" Arrow and offset direction for popovers and tooltips
data-invalid="true" Validation styling on form fields
data-slot="..." Marks child parts of compound components

button, chip, card, skeleton 같은 무상태(stateless) 컴포넌트는 그대로 사용할 수 있는 마크업이에요. 오버레이와 컬렉션(select, menu, popover, date picker)은 직접 관리해야 하는 상태에 의존하므로, 이러한 것들은 React에서 유지하거나 컴포넌트의 CSS 파일에서 data-* 선택자를 읽어 무엇이 필요한지 확인해 보세요.

5. 테마 (Theming)

다크 모드는 상위 요소의 .dark 클래스 또는 data-theme="dark" 속성으로 구동돼요:

<html class="dark">...</html>

<!-- or -->
<html data-theme="dark">...</html>

CSS 변수를 재정의해 테마를 재정의할 수 있어요:

:root {
  --accent: oklch(0.62 0.19 253);
  --radius: 0.5rem;
}

다음 단계 (Next steps)

  • 가장 빠른 설정 경로는 Quick Start
  • 색상과 토큰을 커스터마이징하려면 Themes
  • 변형 함수와 다형성 스타일링은 Composition
  • 사용 가능한 모든 컴포넌트는 Components

더 알아보기 (Learn more)

HeroUI Frameworks에 대해 더 알아보려면 공식 문서를 확인해 주세요.