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

Octicons

원문 보기 위키 갱신

Octicons (코드 가이드)

GitHub이 직접 만든 확장 가능한(scalable) 아이콘 세트예요. Octicons는 SVG로 제공되지만, React와 Rails 프로젝트에서 더 쉽게 쓰도록 도와주는 헬퍼도 함께 제공돼요.

이 페이지에서는 React와 Rails에서 Octicon 아이콘을 설치하고, 크기를 조절하고, 색상을 채우고, 접근성 있는 이름을 붙이는 방법을 단계별로 설명해요.

출처: 문서

본문

Octicons는 GitHub가 손수 만든 확장 가능한 아이콘 세트예요. SVG로 제공되지만, React와 Rails 프로젝트에서 더 쉽게 사용할 수 있는 헬퍼도 함께 있어요.

React

시작하기 (Getting started)

설치 (Install)

npm install @primer/octicons-react

기본 사용법 (Basic usage)

// Import the component
import {ArrowRightIcon} from '@primer/octicons-react'

// Render the icon component
const MyComponent = () => <ArrowRightIcon />

크기 (Size)

아이콘 컴포넌트에는 픽셀 수를 받는 size prop이 있어요. 기본 아이콘 크기는 16px예요.

<>
  <AlertFillIcon size={12} />
  <AlertFillIcon size={16} />
  <AlertFillIcon size={24} />
</>

채우기 색상 (Fill color)

기본적으로 아이콘 채우기는 currentColor를 사용해서 주변 텍스트(그리고 테마) 색상을 자동으로 따라가요. 커스텀 채우기를 강제하기보다 상속된 색을 활용하는 걸 선호해요.

// in real-world scenarios, use CSS instead of a `style` attribute
<span style={{color: 'var(--fgColor-attention)'}}>
  <AlertFillIcon />
</span>

높은 특이도(specificity)의 오버라이드가 필요하다면 fill에 색상 문자열을 전달할 수 있어요. Primer Primitives의 CSS 변수를 적극 권장하는데, 현재 테마(다크 모드, 고대비 모드 등)에 따라 자동으로 적응하기 때문이에요.

<AlertFillIcon fill="var(--fgColor-attention)" />

접근성 (Accessibility)

기본적으로 장식용이에요. aria-hidden을 추가할 필요 없이, 컴포넌트가 장식용 케이스를 자동으로 처리해요.

아이콘 하나만으로 필수적인 의미를 전달할 때만 aria-label로 접근 가능한 이름을 추가하세요:

<AlertFillIcon aria-label="Build failed" />

아이콘이 설명 텍스트 옆에 나타날 때는 보통 aria-label이 필요 없어요:

<span>
  <AlertFillIcon /> Build failed
</span>

상호작용 가능한 아이콘 전용 버튼에는 IconButton 컴포넌트를 사용하세요.

Rails

시작하기 (Getting started)

설치 (Install)

Primer ViewComponents gem을 추가하세요:

# Gemfile
gem "primer_view_components"

그다음 번들하세요:

bundle install

기본 사용법 (Basic usage)

<%= render(Primer::Beta::Octicon.new(:"arrow-right")) %>

크기 (Size)

미리 정의된 토큰(:xsmall, :small, :medium 등) 중 하나와 함께 size: 키워드를 사용하세요. 기본 아이콘 크기는 16px(:small)예요.

<%= render Primer::Beta::Octicon.new(:"alert-fill", size: :xsmall) %>
<%= render Primer::Beta::Octicon.new(:"alert-fill", size: :small) %>
<%= render Primer::Beta::Octicon.new(:"alert-fill", size: :medium) %>

채우기 색상 (Fill color)

아이콘은 currentColor(컨테이너의 계산된 color)를 상속해요. 아이콘이 테마 변경(다크 모드, 고대비 등)에 자동으로 적응하도록 상속을 선호하세요.

<span class="color-fg-attention">
  <%= render Primer::Beta::Octicon.new(:"alert-fill") %>
</span>

높은 특이도의 오버라이드가 필요하다면 fill 속성에 색상 문자열을 전달하세요. Primer Primitives의 CSS 변수를 적극 권장하는데, 현재 테마(다크 모드, 고대비 모드 등)에 따라 적응하기 때문이에요.

<%= render Primer::Beta::Octicon.new(:"alert-fill", fill: "var(--fgColor-attention)") %>

접근성 (Accessibility)

기본적으로 장식용이에요. 접근 가능한 라벨이 제공되지 않으면 컴포넌트가 aria-hidden="true"를 자동으로 설정해 주니 별도 조치가 필요 없어요.

아이콘 자체가 필수적인 의미를 전달할 때만(“contentful”할 때만) 접근 가능한 이름을 제공하세요:

<%= render Primer::Beta::Octicon.new(:"alert-fill", "aria-label": "Build failed") %>

(또는 aria: 해시 형태 사용)

<%= render Primer::Beta::Octicon.new(:"alert-fill", aria: { label: "Build failed" }) %>

설명 텍스트 옆의 아이콘(라벨 불필요, 중복 라벨링 피하기):

<span>
  <%= render Primer::Beta::Octicon.new(:"alert-fill") %> Build failed
</span>

상호작용 가능한 아이콘 전용 버튼에는 Primer::Beta::IconButton을 사용하세요.

기타 (Other)

primer/octicons에서 SVG를 가져와 애플리케이션에서 직접 렌더링할 수 있어요.

더 알아보기 (Learn more)