스니펫
한 줄짜리 명령어와 프롬프트, 명령어 복사 버튼으로 구성된 컴포넌트입니다.
이 페이지의 내용
스니펫은 터미널에서 실행할 한 줄짜리 명령어와 프롬프트, 명령어를 복사하는 버튼으로 구성됩니다. 오목한 영역에 코드 블록과 같은 고정폭 글꼴을 사용하며, 버튼과 높이가 같아 나란히 배치할 수 있습니다. 프롬프트는 선택할 수 없고 명령어는 줄바꿈되지 않습니다. 복사 버튼은 끝에서 4px 안쪽에 있으며, 평소에는 눈에 띄지 않다가 포인터를 올리면 강조됩니다.
스니펫
<div class="snippet max-w(360) mx-auto"> <span class="snippet-prompt" aria-hidden="true">$</span> <code class="snippet-command" tabindex="0">npm install @master/ui</code> <button type="button" class="btn btn-quiet btn-square" aria-label="Copy command"> <svg class="icon snippet-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 1.5H9A1.4999 1.4999 0 0 1 10.5 3V4.25H9.5V3A0.5002 0.5002 0 0 0 9 2.5H3A0.5002 0.5002 0 0 0 2.5 3V9A0.5002 0.5002 0 0 0 3 9.5H4.25V10.5H3A1.4999 1.4999 0 0 1 1.5 9V3A1.4999 1.4999 0 0 1 3 1.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><rect x="5.5" y="5.5" width="8.5" height="8.5" rx="1" /> </svg> <svg class="icon snippet-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> <output class="snippet-status"></output></div><script>document.querySelectorAll('.snippet').forEach(function (snippet) {var status = snippet.querySelector('.snippet-status')var timer = 0snippet.querySelector('.btn').addEventListener('click', function () { var command = Array.prototype.find.call(snippet.querySelectorAll('.snippet-command'), function (line) { return line.checkVisibility() }) navigator.clipboard.writeText(command.textContent).then(function () { status.textContent = 'Copied' clearTimeout(timer) timer = setTimeout(function () { status.textContent = '' }, 2000) })})})</script>#명령어 줄 구성
snippet은 세 요소를 각각 한 열에 배치합니다. snippet-prompt는 터미널에서 명령어 앞에 표시하는 $ 또는 > 기호로, 명령어보다 옅은 색으로 표시합니다. 프롬프트는 선택할 수 없으므로 줄을 직접 선택해도 명령어만 선택됩니다. 스크린 리더가 프롬프트를 읽지 않도록 aria-hidden 속성을 지정합니다. snippet-command로 표시하는 명령어는 <code>에 넣습니다. 마지막에는 눈에 띄지 않는 정사각형 버튼이 놓입니다. 스니펫이 버튼의 높이와 모서리 둥글기를 정하며, 버튼 높이는 줄 높이에서 위아래로 4px씩 뺀 값입니다.
명령어가 한 줄의 표시 영역보다 길면 줄바꿈 없이 가로로 스크롤됩니다. 스크롤바는 표시되지 않으며, 명령어가 더 이어지는 쪽 가장자리가 흐려집니다. 가장자리의 흐림 효과는 스크롤 위치에 따라 달라지므로 스크롤하기 전에는 시작 부분이 선명하게 보입니다. 방향키로 스크롤할 수 있도록 명령어에 tabindex="0"를 지정하세요. 명령어에 포커스가 있으면 줄 전체에 포커스 윤곽선이 표시됩니다.
긴 명령어
<div class="snippet max-w(360) mx-auto"> <span class="snippet-prompt" aria-hidden="true">$</span> <code class="snippet-command" tabindex="0"> curl -fsSL https://ui.master.co/install.sh | sh -s -- --yes --prefix ~/.local </code> <button type="button" class="btn btn-quiet btn-square" aria-label="Copy command"> <svg class="icon snippet-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 1.5H9A1.4999 1.4999 0 0 1 10.5 3V4.25H9.5V3A0.5002 0.5002 0 0 0 9 2.5H3A0.5002 0.5002 0 0 0 2.5 3V9A0.5002 0.5002 0 0 0 3 9.5H4.25V10.5H3A1.4999 1.4999 0 0 1 1.5 9V3A1.4999 1.4999 0 0 1 3 1.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><rect x="5.5" y="5.5" width="8.5" height="8.5" rx="1" /> </svg> <svg class="icon snippet-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> <output class="snippet-status"></output></div><script>document.querySelectorAll('.snippet').forEach(function (snippet) {var status = snippet.querySelector('.snippet-status')var timer = 0snippet.querySelector('.btn').addEventListener('click', function () { var command = Array.prototype.find.call(snippet.querySelectorAll('.snippet-command'), function (line) { return line.checkVisibility() }) navigator.clipboard.writeText(command.textContent).then(function () { status.textContent = 'Copied' clearTimeout(timer) timer = setTimeout(function () { status.textContent = '' }, 2000) })})})</script>#복사
복사에는 스크립트가 필요합니다. 명령어 텍스트를 navigator.clipboard에 전달하세요. 복사 상태는 클래스로 표시하지 않습니다. 버튼 옆에는 화면에 표시되지 않는 빈 <output> 요소(snippet-status)가 있습니다. 스크립트가 여기에 ‘복사됨’을 쓰면 스크린 리더가 이를 읽어 주고, 2초 뒤 스크립트가 내용을 비웁니다. 내용이 있는 동안 스타일시트가 복사 아이콘을 체크 표시로 바꾸므로 화면에서도 같은 상태를 확인할 수 있습니다.
미리보기의 스크립트는 화면에 표시된 명령어를 찾아 클립보드에 쓴 뒤 상태 메시지를 채웠다가 비웁니다. 이 스크립트가 전체 구현입니다. 클립보드 기능은 HTTPS로 제공되거나 localhost에서 제공되는 페이지에서만 사용할 수 있습니다. 스크립트가 비활성화되어 있으면 버튼이 표시되지 않으며, 명령어는 텍스트로 남아 직접 선택해 복사할 수 있습니다.
#패키지 관리자
같은 작업을 실행하는 명령어를 npm, pnpm, bun, yarn별로 제공하려면 네이티브 라디오 버튼으로 구성한 세그먼트 컨트롤을 스니펫 맨 앞에 배치하고, 각 옵션에 해당하는 snippet-command를 옵션과 같은 순서로 작성하세요. 컨트롤 자체의 오목한 영역은 사라지고, 컨트롤은 스니펫 상단의 아주 얇은 구분선 위에 놓입니다. 선택한 옵션은 한 층 위에 놓인 표면으로 표시되며, 다른 옵션을 선택하면 그 표면이 새 위치로 부드럽게 이동합니다. 최대 6개 옵션까지 스크립트 없이 선택한 옵션에 해당하는 명령어가 표시됩니다.
패키지 관리자
<div class="snippet max-w(360) mx-auto"> <div class="segmented" role="radiogroup" aria-label="Package manager"> <label class="segmented-item"> <input class="segmented-input" type="radio" name="manager" checked>npm </label> <label class="segmented-item"> <input class="segmented-input" type="radio" name="manager">pnpm </label> <label class="segmented-item"> <input class="segmented-input" type="radio" name="manager">bun </label> <label class="segmented-item"> <input class="segmented-input" type="radio" name="manager">yarn </label> </div> <span class="snippet-prompt" aria-hidden="true">$</span> <code class="snippet-command" tabindex="0">npm install @master/ui</code> <code class="snippet-command" tabindex="0">pnpm add @master/ui</code> <code class="snippet-command" tabindex="0">bun add @master/ui</code> <code class="snippet-command" tabindex="0">yarn add @master/ui</code> <button type="button" class="btn btn-quiet btn-square" aria-label="Copy command"> <svg class="icon snippet-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 1.5H9A1.4999 1.4999 0 0 1 10.5 3V4.25H9.5V3A0.5002 0.5002 0 0 0 9 2.5H3A0.5002 0.5002 0 0 0 2.5 3V9A0.5002 0.5002 0 0 0 3 9.5H4.25V10.5H3A1.4999 1.4999 0 0 1 1.5 9V3A1.4999 1.4999 0 0 1 3 1.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><rect x="5.5" y="5.5" width="8.5" height="8.5" rx="1" /> </svg> <svg class="icon snippet-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> <output class="snippet-status"></output></div><script>document.querySelectorAll('.snippet').forEach(function (snippet) {var status = snippet.querySelector('.snippet-status')var timer = 0snippet.querySelector('.btn').addEventListener('click', function () { var command = Array.prototype.find.call(snippet.querySelectorAll('.snippet-command'), function (line) { return line.checkVisibility() }) navigator.clipboard.writeText(command.textContent).then(function () { status.textContent = 'Copied' clearTimeout(timer) timer = setTimeout(function () { status.textContent = '' }, 2000) })})})</script>#크기
기본 줄 높이는 버튼과 같은 38px입니다. snippet-sm의 줄 높이는 32px, 글자 크기는 12px로, 정보가 촘촘한 페이지나 표에 사용합니다. snippet-lg의 줄 높이는 44px, 글자 크기는 14px로, 페이지 상단에서 큰 버튼과 높이를 맞출 때 사용합니다. 터치 화면에서도 모든 크기가 줄 높이를 유지하며, 복사 버튼의 터치 조작 영역은 버튼을 중심으로 총 44px 크기로 확보됩니다.
크기
<div class="flex flex-col items-center gap-lg"> <div class="snippet snippet-sm"> <span class="snippet-prompt" aria-hidden="true">$</span> <code class="snippet-command" tabindex="0">npx master-ui add button</code> <button type="button" class="btn btn-quiet btn-square" aria-label="Copy command"> <svg class="icon snippet-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 1.5H9A1.4999 1.4999 0 0 1 10.5 3V4.25H9.5V3A0.5002 0.5002 0 0 0 9 2.5H3A0.5002 0.5002 0 0 0 2.5 3V9A0.5002 0.5002 0 0 0 3 9.5H4.25V10.5H3A1.4999 1.4999 0 0 1 1.5 9V3A1.4999 1.4999 0 0 1 3 1.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><rect x="5.5" y="5.5" width="8.5" height="8.5" rx="1" /> </svg> <svg class="icon snippet-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> <output class="snippet-status"></output> </div> <div class="snippet"> <span class="snippet-prompt" aria-hidden="true">$</span> <code class="snippet-command" tabindex="0">npx master-ui add button</code> <button type="button" class="btn btn-quiet btn-square" aria-label="Copy command"> <svg class="icon snippet-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 1.5H9A1.4999 1.4999 0 0 1 10.5 3V4.25H9.5V3A0.5002 0.5002 0 0 0 9 2.5H3A0.5002 0.5002 0 0 0 2.5 3V9A0.5002 0.5002 0 0 0 3 9.5H4.25V10.5H3A1.4999 1.4999 0 0 1 1.5 9V3A1.4999 1.4999 0 0 1 3 1.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><rect x="5.5" y="5.5" width="8.5" height="8.5" rx="1" /> </svg> <svg class="icon snippet-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> <output class="snippet-status"></output> </div> <div class="flex flex-wrap items-center justify-center gap-sm"> <a class="btn btn-primary btn-lg" href="#">Get started</a> <div class="snippet snippet-lg"> <span class="snippet-prompt" aria-hidden="true">$</span> <code class="snippet-command" tabindex="0">npm install @master/ui</code> <button type="button" class="btn btn-quiet btn-square" aria-label="Copy command"> <svg class="icon snippet-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 1.5H9A1.4999 1.4999 0 0 1 10.5 3V4.25H9.5V3A0.5002 0.5002 0 0 0 9 2.5H3A0.5002 0.5002 0 0 0 2.5 3V9A0.5002 0.5002 0 0 0 3 9.5H4.25V10.5H3A1.4999 1.4999 0 0 1 1.5 9V3A1.4999 1.4999 0 0 1 3 1.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><rect x="5.5" y="5.5" width="8.5" height="8.5" rx="1" /> </svg> <svg class="icon snippet-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" /> </svg> </button> <output class="snippet-status"></output> </div> </div></div><script>document.querySelectorAll('.snippet').forEach(function (snippet) {var status = snippet.querySelector('.snippet-status')var timer = 0snippet.querySelector('.btn').addEventListener('click', function () { var command = Array.prototype.find.call(snippet.querySelectorAll('.snippet-command'), function (line) { return line.checkVisibility() }) navigator.clipboard.writeText(command.textContent).then(function () { status.textContent = 'Copied' clearTimeout(timer) timer = setTimeout(function () { status.textContent = '' }, 2000) })})})</script>#스니펫과 코드의 용도
실행할 한 줄짜리 명령어에는 스니펫을 사용합니다. 여러 줄이나 읽어야 할 파일 또는 출력에는 코드 블록을 사용하고, 문장 속에서 언급하는 명령어에는 인라인 코드를 사용합니다. 눌러야 할 키는 kbd로 표시합니다.
#접근성
- 프롬프트는 장식이므로 명령어 줄에서 스크린 리더가 명령어만 읽도록 프롬프트에
aria-hidden="true"를 지정하세요. - 복사 버튼에 ‘명령어 복사’와 같은
aria-label값을 지정하세요. 버튼 아이콘에는aria-hidden속성이 지정되어 있습니다. - 마크업에서
snippet-status를 비워 두고 내부에 공백도 넣지 마세요. 스크립트가 여기에 ‘복사됨’을 쓰면 스크린 리더가 이를 읽어 줍니다.<output>자체가 현재 읽기를 방해하지 않는 라이브 영역입니다. - 한 줄의 표시 영역보다 긴 명령어를 키보드로 스크롤할 수 있도록 명령어에
tabindex="0"를 지정하세요. - 강제 색상 모드에서는 흐림 효과가 사라지고, 오목한 영역에 윤곽선이 표시되며, 프롬프트에는 시스템의 회색 텍스트 색상이 적용됩니다.
#클래스
| 클래스 | 설명 |
|---|---|
snippet | 높이 38px의 오목한 영역입니다. 고정폭 글꼴을 사용하며 프롬프트, 명령, 버튼을 세 열에 배치합니다. |
snippet-sm | 12px 글자를 쓰는 32px 높이의 줄입니다. 기본 높이는 38px입니다.적용할 클래스는 snippet입니다 |
snippet-lg | 페이지 상단에 쓰는 44px 높이의 줄로, 글자 크기는 14px입니다.적용할 클래스는 snippet입니다 |
snippet-prompt | 프롬프트 기호($ 또는 >)는 차분한 전경색으로 표시하며 텍스트로 선택할 수 없습니다. aria-hidden="true"를 지정하세요. |
snippet-command | 명령을 <code> 요소에 넣습니다. 줄바꿈 없이 한 줄로 표시되며, 가로로 스크롤할 수 있고 내용이 이어지는 가장자리에서 서서히 흐려집니다. tabindex="0"을 지정하세요. 세그먼트 컨트롤과 함께 쓸 때는 옵션과 같은 순서로 옵션당 하나씩, 최대 6개까지 작성하세요. |
snippet-icon | 버튼 안의 복사 아이콘입니다. icon을 적용하며, 상태가 명령 복사 완료를 나타내면 자리를 내줍니다. |
snippet-check | 버튼 안에서 복사 아이콘 뒤에 오는 체크 표시입니다. icon을 적용하며, 복사가 완료되면 복사 아이콘을 대신합니다. |
snippet-status | 화면에 보이지 않는 빈 <output>은 스크립트가 기록한 내용을 보조 기술로 알립니다. 내용이 들어오면 복사 아이콘이 체크 표시로 바뀌고, 내용을 비우면 다시 복사 아이콘으로 돌아옵니다. |
#사용자 지정 속성
| 속성 | 기본값 | 설명 |
|---|---|---|
--snippet-height | 2.375rem | 줄 높이입니다. 버튼 높이는 이보다 8px 작으며 위아래에 각각 4px의 여백이 생깁니다.snippet에 설정합니다 |
--snippet-radius | var(--radius-control) | 모서리 배율을 적용하기 전의 오목한 영역의 원형 반경입니다. 버튼과 옵션에는 안쪽 간격인 4px를 이 반경에서 뺀 값을 사용합니다.snippet에 설정합니다 |
--snippet-fade | 1.5rem | 긴 명령이 가장자리 너머로 이어질 때 적용하는 페이드 길이snippet에 설정합니다 |