아이콘
인라인 아이콘의 크기는 아이콘을 담는 컴포넌트에서 지정합니다.
이 페이지의 내용
<svg>, <img> 또는 아이콘 컴포넌트 자체에 icon을 지정하세요. 컴포넌트는 자식 요소의 유형을 기준으로 스타일을 지정하지 않습니다. 각 컴포넌트가 --icon-size를 설정하면 아이콘은 그 값을 따릅니다. 따라서 같은 마크업을 사용해도 버튼, 배지, 탭에서 아이콘 크기가 서로 달라집니다.
버튼, 배지, 탭의 동일 아이콘
<button type="button" class="btn btn-sm"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> Small</button><button type="button" class="btn"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> Medium</button><button type="button" class="btn btn-lg"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 10L16 10" /><path d="M10 4L10 16" /> </svg> Large</button>import PlusIcon16 from '@master/icons-react/native/16/soft/plus'import PlusIcon20 from '@master/icons-react/native/20/soft/plus'<> <button type="button" className="btn btn-sm"><PlusIcon16 className="icon" /> Small</button> <button type="button" className="btn"><PlusIcon16 className="icon" /> Medium</button> <button type="button" className="btn btn-lg"><PlusIcon20 className="icon" /> Large</button></><script> import PlusIcon16 from '@master/icons-svelte/native/16/soft/plus' import PlusIcon20 from '@master/icons-svelte/native/20/soft/plus'</script><button type="button" class="btn btn-sm"><PlusIcon16 class="icon" /> Small</button><button type="button" class="btn"><PlusIcon16 class="icon" /> Medium</button><button type="button" class="btn btn-lg"><PlusIcon20 class="icon" /> Large</button><script setup>import PlusIcon16 from '@master/icons-vue/native/16/soft/plus'import PlusIcon20 from '@master/icons-vue/native/20/soft/plus'</script><template> <button type="button" class="btn btn-sm"><PlusIcon16 class="icon" /> Small</button> <button type="button" class="btn"><PlusIcon16 class="icon" /> Medium</button> <button type="button" class="btn btn-lg"><PlusIcon20 class="icon" /> Large</button></template>#텍스트 속 아이콘
컴포넌트 밖에서 아이콘의 크기는 1em이며, 소문자와 자연스럽게 어울리도록 기준선보다 약간 아래에 배치합니다.
텍스트 속 아이콘
<p class="m(0) text-sm fg-text-body"> Press <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="Download"> <path d="M8.5 9L8.4994 1.9755A0.5 0.5 0 0 0 7.5054 1.9266L7.5 2L7.5014 9.0379A0.5007 0.5007 0 0 0 7.5892 9.285A0.7044 0.7044 0 0 0 8.4108 9.285A0.4996 0.4996 0 0 0 8.5 9Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M5 6L7.8586 8.8586A0.2 0.2 0 0 0 8.1414 8.8586L11 6" /><path d="M2.5 10.5L2.5 12.5A1 1 0 0 0 3.5 13.5L12.5 13.5A1 1 0 0 0 13.5 12.5L13.5 10.5" /> </svg> to download the report.</p>import DownloadIcon from '@master/icons-react/native/16/soft/download'<p className="m(0) text-sm fg-text-body"> Press <DownloadIcon className="icon" aria-label="Download" /> to download the report.</p><script> import DownloadIcon from '@master/icons-svelte/native/16/soft/download'</script><p class="m(0) text-sm fg-text-body"> Press <DownloadIcon class="icon" aria-label="Download" /> to download the report.</p><script setup>import DownloadIcon from '@master/icons-vue/native/16/soft/download'</script><template> <p class="m(0) text-sm fg-text-body"> Press <DownloadIcon class="icon" aria-label="Download" /> to download the report. </p></template>#Master Icons
Master UI 자체의 컴포넌트와 예제는 Master Icons를 사용합니다. 각 아이콘은 16, 20, 24px용으로 세 번 그려지며 색은 currentColor를 사용합니다. icon은 모든 SVG, 이미지, 아이콘 컴포넌트를 받으므로 다른 세트도 같은 방식으로 쓸 수 있습니다. Master Icons는 기본값이지 필수 조건이 아닙니다.
npm install @master/icons-react --save-exact프레임워크에 맞는 패키지를 설치하세요. @master/icons-react, -vue, -svelte, -preact, -astro 중 하나이며, SVG 파일과 순수 JavaScript만 필요하면 @master/icons입니다.
컴포넌트가 아이콘에 주는 크기에 따라 그림을 고르고, 그 그림 하나만 가져와 icon을 적용합니다.
| 컴포넌트가 정한 크기 | 그림 | 그림의 선 두께 |
|---|---|---|
| 17px 이하 | 16 | 1 |
| 18~22px | 20 | 1.25 |
| 22px 초과 | 24 | 1.5 |
import SearchIcon from '@master/icons-react/native/16/soft/search'<button type="button" className="btn btn-square" aria-label="Search"> <SearchIcon className="icon" /></button>HTML에서는 컬렉션에서 SVG를 복사해 icon을 적용합니다. 이름이 다른 세트와 다르므로 쓰기 전에 검색하세요.
node node_modules/@master/icons/skills/master-icons/scripts/search.mjs "arrow left"#선 두께
아이콘은 그림이 가진 선 두께를 유지합니다. Master Icons는 모든 크기를 격자의 16분의 1 두께로 그리므로, 16px에서 1px이며 컴포넌트가 정한 크기에 비례해 굵어집니다. Master Icons의 굵기를 바꾸려면 @master/icons-react/16/soft 같은 고정 엔트리에서 strokeWidth를 고르세요. 뚫린 부분과 간격이 그 두께에 맞게 다시 그려집니다.
선 두께
<svg class="icon fg-text-strong" style="--icon-size: 1.5rem" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="12" cy="12" r="9" /><path d="M12 6.5L12 11.8892A0.2 0.2 0 0 0 12.094 12.0588L16 14.5" /></svg><svg class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 1.25" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="12" cy="12" r="9" /><path d="M12 6.5L12 11.8892A0.2 0.2 0 0 0 12.094 12.0588L16 14.5" /></svg><svg class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 2" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="12" cy="12" r="9" /><path d="M12 6.5L12 11.8892A0.2 0.2 0 0 0 12.094 12.0588L16 14.5" /></svg>import ClockIcon from '@master/icons-react/native/24/soft/clock'<> <ClockIcon className="icon fg-text-strong" style={{ '--icon-size': '1.5rem' } as React.CSSProperties} /> <ClockIcon className="icon fg-text-strong" style={{ '--icon-size': '1.5rem', '--icon-stroke': '1.25' } as React.CSSProperties} /> <ClockIcon className="icon fg-text-strong" style={{ '--icon-size': '1.5rem', '--icon-stroke': '2' } as React.CSSProperties} /></><script> import ClockIcon from '@master/icons-svelte/native/24/soft/clock'</script><ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem" /><ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 1.25" /><ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 2" /><script setup>import ClockIcon from '@master/icons-vue/native/24/soft/clock'</script><template> <ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem" /> <ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 1.25" /> <ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 2" /></template>--icon-stroke는 그림의 선 두께를 그림의 viewBox 단위로 대체합니다. 채움형 아이콘에는 영향을 주지 않습니다. 단순한 선 아이콘 세트를 인터페이스의 굵기에 맞출 때 사용하세요. 컨테이너에 설정하면 안의 모든 아이콘이 따릅니다.
#접근성
- 장식용 아이콘은
aria-hidden="true"로 보조 기술에서 숨기세요. - 아이콘만 있는 컨트롤에는 접근 가능한 이름을 컨트롤 자체에 지정합니다. 예를 들어 정사각형 버튼에
aria-label을 지정합니다. - 위의 다운로드 화살표처럼 문장 속에서 단어를 대신하는 아이콘은 그 단어 자체입니다.
role="img"를 지정하고, 생김새가 아니라 무엇을 나타내는지를aria-label로 알려 주세요.
#사용자 지정 속성
| 속성 | 기본값 | 설명 |
|---|---|---|
--icon-size | 아이콘의 너비와 높이입니다. 아이콘을 담는 컴포넌트에서 값을 설정하며, 그런 컴포넌트가 없으면 1em입니다. | |
--icon-stroke | 그림의 선 두께를 그림의 viewBox 단위로 대체합니다. 지정하지 않으면 아이콘은 자체 선 두께를 유지하며, 채움형 아이콘에는 영향을 주지 않습니다. | |
--icon-color | 아이콘 색상입니다. 컴포넌트에서 이 값을 설정해 아이콘 색을 은은하게 하거나 색조를 입힙니다. 값을 설정하지 않으면 아이콘은 텍스트 색상을 따릅니다. |
#클래스
| 클래스 | 설명 |
|---|---|
icon | 기준선보다 약간 아래에 놓이는 인라인 아이콘. 크기는 --icon-size를 따르며 컴포넌트 밖에서는 1em입니다. |