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

아이콘 버튼 (Icon Button)

원문 보기 위키 갱신

아이콘만으로 이루어진 간단한 버튼으로, 액션을 수행하거나 툴바에서 쓸 수 있어요. Shoelace에 기본 포함된 아이콘 전체 목록은 icon 컴포넌트 문서를 참고하세요.

_ | SlIconButton, Shoelace 2.0부터 제공되고 있으며 stable 상태예요.

출처: 문서

본문

| SlIconButton — Since 2.0, stable

아이콘 버튼은 아이콘만으로 된 간단한 버튼으로, 액션을 수행하거나 툴바에서 쓸 수 있어요.

Shoelace에 기본 포함된 아이콘 전체 목록은 icon 컴포넌트를 참고하세요.

<sl-icon-button name="gear" label="Settings"></sl-icon-button>
import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';
const App = () => <SlIconButton name="gear" label="Settings" />;

Examples

Sizes

아이콘 버튼은 부모 요소의 font-size를 물려받아요.

<sl-icon-button name="pencil" label="Edit" style="font-size: 1.5rem;"></sl-icon-button>
<sl-icon-button name="pencil" label="Edit" style="font-size: 2rem;"></sl-icon-button>
<sl-icon-button name="pencil" label="Edit" style="font-size: 2.5rem;"></sl-icon-button>
import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';
const App = () => (
  <>
    <SlIconButton name="pencil" label="Edit" style={{ fontSize: '1.5rem' }} />
    <SlIconButton name="pencil" label="Edit" style={{ fontSize: '2rem' }} />
    <SlIconButton name="pencil" label="Edit" style={{ fontSize: '2.5rem' }} />
  </>
);

Colors

아이콘 버튼은 일관된 모양을 가지도록 설계되어서 색이 상속되지 않아요. 하지만 base 파트를 스타일링해서 커스터마이징할 수는 있어요.

<div class="icon-button-color">
  <sl-icon-button name="type-bold" label="Bold"></sl-icon-button>
  <sl-icon-button name="type-italic" label="Italic"></sl-icon-button>
  <sl-icon-button name="type-underline" label="Underline"></sl-icon-button>
</div>
<style>
  .icon-button-color sl-icon-button::part(base) {
    color: #b00091;
  }
  .icon-button-color sl-icon-button::part(base):hover,
  .icon-button-color sl-icon-button::part(base):focus {
    color: #c913aa;
  }
  .icon-button-color sl-icon-button::part(base):active {
    color: #960077;
  }
</style>
import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';
const css = `
  .icon-button-color sl-icon-button::part(base) {
    color: #b00091;
  }
  .icon-button-color sl-icon-button::part(base):hover,
  .icon-button-color sl-icon-button::part(base):focus {
    color: #c913aa;
  }
  .icon-button-color sl-icon-button::part(base):active {
    color: #960077;
  }
`;
const App = () => (
  <>
    <div className="icon-button-color">
      <SlIconButton name="type-bold" label="Bold" />
      <SlIconButton name="type-italic" label="Italic" />
      <SlIconButton name="type-underline" label="Underline" />
    </div>
    <style>{css}</style>
  </>
);

href 속성을 쓰면 버튼을 링크로 바꿀 수 있어요.

<sl-icon-button name="gear" label="Settings" href="https://example.com" target="_blank"></sl-icon-button>
import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';
const App = () => <SlIconButton name="gear" label="Settings" href="https://example.com" target="_blank" />;

Icon Button with Tooltip

아이콘 버튼을 툴팁으로 감싸면 사용자에게 문맥 정보를 제공할 수 있어요.

<sl-tooltip content="Settings">
  <sl-icon-button name="gear" label="Settings"></sl-icon-button>
</sl-tooltip>
import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';
import SlTooltip from '@shoelace-style/shoelace/dist/react/tooltip';
const App = () => (
  <SlTooltip content="Settings">
    <SlIconButton name="gear" label="Settings" />
  </SlTooltip>
);

Disabled

disabled 속성을 쓰면 아이콘 버튼을 비활성화할 수 있어요.

<sl-icon-button name="gear" label="Settings" disabled></sl-icon-button>
import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';
const App = () => <SlIconButton name="gear" label="Settings" disabled />;

Importing

autoloader나 전통적인 loader를 사용하고 있다면 이 부분은 건너뛰어도 돼요. 그 외에는 아래 스니펫 중 원하는 걸 골라 이 컴포넌트만 골라 가져올 수 있어요.

Script / Import / Bundler / React 방식이 준비되어 있어요.

CDN에서 <script> 태그로 이 컴포넌트를 가져오려면:

<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/icon-button/icon-button.js"></script>

CDN에서 JavaScript import로 가져오려면:

import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/icon-button/icon-button.js';

Bundler를 사용해 가져오려면:

import '@shoelace-style/shoelace/dist/components/icon-button/icon-button.js';

React 컴포넌트로 가져오려면:

import SlIconButton from '@shoelace-style/shoelace/dist/react/icon-button';

Properties

Name Description Reflects Type Default
name The name of the icon to draw. Available names depend on the icon library being used. string | undefined -
library The name of a registered custom icon library. string | undefined -
src An external URL of an SVG file. Be sure you trust the content you are including, as it will be
executed as code and can result in XSS attacks. string | undefined -
href When set, the underlying button will be rendered as an `` with this
href instead of a ``. string | undefined -
target Tells the browser where to open the link. Only used when href is set. '_blank' | '_parent' | '_self' | '_top' | undefined -
download Tells the browser to download the linked file as this filename. Only used when href is
set. string | undefined -
label A description that gets read by assistive devices. For optimal accessibility, you should always
include a label that describes what the icon button does. string ''
disabled Disables the button. boolean false
updateComplete A read-only promise that resolves when the component has
finished updating.

속성과 프로퍼티에 대해 더 알아보세요.

Events

Name React Event Description Event Detail
sl-blur onSlBlur Emitted when the icon button loses focus. -
sl-focus onSlFocus Emitted when the icon button gains focus. -

이벤트에 대해 더 알아보세요.

Methods

Name Description Arguments
click() Simulates a click on the icon button. -
focus() Sets focus on the icon button. options: FocusOptions
blur() Removes focus from the icon button. -

메서드에 대해 더 알아보세요.

Parts

Name Description
base The component’s base wrapper.

CSS 파트 커스터마이징에 대해 더 알아보세요.

Dependencies

이 컴포넌트는 다음 의존성들을 자동으로 가져와요.

  • ``

더 알아보기 (Learn more)