탐색

v2.1.0
구조

스와이프

옆으로 밀면 해당 행에서 수행할 수 있는 작업이 나타나는 행입니다.

이 페이지의 내용

스와이프는 행을 옆으로 밀면 해당 행에서 수행할 수 있는 작업이 나타나는 컴포넌트입니다. 행은 두 위치에 멈추는 스크롤 영역입니다. 한쪽에는 행 전체 너비를 차지하는 콘텐츠가 있고, 다른 쪽에는 행의 끝 가장자리 뒤에 숨은 작업이 있습니다. 브라우저의 기본 스크롤을 사용하므로 손가락이나 트랙패드로 밀거나 Tab 키를 눌러 작업을 표시할 수 있으며, 스크립트가 필요하지 않습니다.

스와이프

<div class="sheet sheet-raised overflow-hidden w-full max-w(360)">  <div class="swipe">    <div class="swipe-content flex items-center gap-sm p(12)">      <span class="avatar">AL</span>      <div class="min-w(0)">        <p class="m(0) fg-text-strong font-medium">Ada Lovelace</p>        <p class="m(0) fg-text-muted">The notes on the engine are ready.</p>      </div>    </div>    <div class="swipe-actions">      <button class="swipe-action" type="button">        Archive<span class="sr-only">Ada Lovelace</span>      </button>      <button class="swipe-action swipe-action-danger" type="button">        Delete<span class="sr-only">Ada Lovelace</span>      </button>    </div>  </div>  <div class="swipe bt(1) bt-solid b-line-hair">    <div class="swipe-content flex items-center gap-sm p(12)">      <span class="avatar">AT</span>      <div class="min-w(0)">        <p class="m(0) fg-text-strong font-medium">Alan Turing</p>        <p class="m(0) fg-text-muted">Can machines think? A short reply.</p>      </div>    </div>    <div class="swipe-actions">      <button class="swipe-action" type="button">        Archive<span class="sr-only">Alan Turing</span>      </button>      <button class="swipe-action swipe-action-danger" type="button">        Delete<span class="sr-only">Alan Turing</span>      </button>    </div>  </div>  <div class="swipe bt(1) bt-solid b-line-hair">    <div class="swipe-content flex items-center gap-sm p(12)">      <span class="avatar">GH</span>      <div class="min-w(0)">        <p class="m(0) fg-text-strong font-medium">Grace Hopper</p>        <p class="m(0) fg-text-muted">The compiler passes every test.</p>      </div>    </div>    <div class="swipe-actions">      <button class="swipe-action" type="button">        Archive<span class="sr-only">Grace Hopper</span>      </button>      <button class="swipe-action swipe-action-danger" type="button">        Delete<span class="sr-only">Grace Hopper</span>      </button>    </div>  </div></div>
<div className="sheet sheet-raised overflow-hidden w-full max-w(360)">  <div className="swipe">    <div className="swipe-content flex items-center gap-sm p(12)">      <span className="avatar">AL</span>      <div className="min-w(0)">        <p className="m(0) fg-text-strong font-medium">Ada Lovelace</p>        <p className="m(0) fg-text-muted">The notes on the engine are ready.</p>      </div>    </div>    <div className="swipe-actions">      <button className="swipe-action" type="button">        Archive<span className="sr-only">Ada Lovelace</span>      </button>      <button className="swipe-action swipe-action-danger" type="button">        Delete<span className="sr-only">Ada Lovelace</span>      </button>    </div>  </div>  <div className="swipe bt(1) bt-solid b-line-hair">    <div className="swipe-content flex items-center gap-sm p(12)">      <span className="avatar">AT</span>      <div className="min-w(0)">        <p className="m(0) fg-text-strong font-medium">Alan Turing</p>        <p className="m(0) fg-text-muted">Can machines think? A short reply.</p>      </div>    </div>    <div className="swipe-actions">      <button className="swipe-action" type="button">        Archive<span className="sr-only">Alan Turing</span>      </button>      <button className="swipe-action swipe-action-danger" type="button">        Delete<span className="sr-only">Alan Turing</span>      </button>    </div>  </div>  <div className="swipe bt(1) bt-solid b-line-hair">    <div className="swipe-content flex items-center gap-sm p(12)">      <span className="avatar">GH</span>      <div className="min-w(0)">        <p className="m(0) fg-text-strong font-medium">Grace Hopper</p>        <p className="m(0) fg-text-muted">The compiler passes every test.</p>      </div>    </div>    <div className="swipe-actions">      <button className="swipe-action" type="button">        Archive<span className="sr-only">Grace Hopper</span>      </button>      <button className="swipe-action swipe-action-danger" type="button">        Delete<span className="sr-only">Grace Hopper</span>      </button>    </div>  </div></div>
<div class="sheet sheet-raised overflow-hidden w-full max-w(360)">  <div class="swipe">    <div class="swipe-content flex items-center gap-sm p(12)">      <span class="avatar">AL</span>      <div class="min-w(0)">        <p class="m(0) fg-text-strong font-medium">Ada Lovelace</p>        <p class="m(0) fg-text-muted">The notes on the engine are ready.</p>      </div>    </div>    <div class="swipe-actions">      <button class="swipe-action" type="button">        Archive<span class="sr-only">Ada Lovelace</span>      </button>      <button class="swipe-action swipe-action-danger" type="button">        Delete<span class="sr-only">Ada Lovelace</span>      </button>    </div>  </div>  <div class="swipe bt(1) bt-solid b-line-hair">    <div class="swipe-content flex items-center gap-sm p(12)">      <span class="avatar">AT</span>      <div class="min-w(0)">        <p class="m(0) fg-text-strong font-medium">Alan Turing</p>        <p class="m(0) fg-text-muted">Can machines think? A short reply.</p>      </div>    </div>    <div class="swipe-actions">      <button class="swipe-action" type="button">        Archive<span class="sr-only">Alan Turing</span>      </button>      <button class="swipe-action swipe-action-danger" type="button">        Delete<span class="sr-only">Alan Turing</span>      </button>    </div>  </div>  <div class="swipe bt(1) bt-solid b-line-hair">    <div class="swipe-content flex items-center gap-sm p(12)">      <span class="avatar">GH</span>      <div class="min-w(0)">        <p class="m(0) fg-text-strong font-medium">Grace Hopper</p>        <p class="m(0) fg-text-muted">The compiler passes every test.</p>      </div>    </div>    <div class="swipe-actions">      <button class="swipe-action" type="button">        Archive<span class="sr-only">Grace Hopper</span>      </button>      <button class="swipe-action swipe-action-danger" type="button">        Delete<span class="sr-only">Grace Hopper</span>      </button>    </div>  </div></div>
<template>  <div class="sheet sheet-raised overflow-hidden w-full max-w(360)">    <div class="swipe">      <div class="swipe-content flex items-center gap-sm p(12)">        <span class="avatar">AL</span>        <div class="min-w(0)">          <p class="m(0) fg-text-strong font-medium">Ada Lovelace</p>          <p class="m(0) fg-text-muted">The notes on the engine are ready.</p>        </div>      </div>      <div class="swipe-actions">        <button class="swipe-action" type="button">          Archive<span class="sr-only">Ada Lovelace</span>        </button>        <button class="swipe-action swipe-action-danger" type="button">          Delete<span class="sr-only">Ada Lovelace</span>        </button>      </div>    </div>    <div class="swipe bt(1) bt-solid b-line-hair">      <div class="swipe-content flex items-center gap-sm p(12)">        <span class="avatar">AT</span>        <div class="min-w(0)">          <p class="m(0) fg-text-strong font-medium">Alan Turing</p>          <p class="m(0) fg-text-muted">Can machines think? A short reply.</p>        </div>      </div>      <div class="swipe-actions">        <button class="swipe-action" type="button">          Archive<span class="sr-only">Alan Turing</span>        </button>        <button class="swipe-action swipe-action-danger" type="button">          Delete<span class="sr-only">Alan Turing</span>        </button>      </div>    </div>    <div class="swipe bt(1) bt-solid b-line-hair">      <div class="swipe-content flex items-center gap-sm p(12)">        <span class="avatar">GH</span>        <div class="min-w(0)">          <p class="m(0) fg-text-strong font-medium">Grace Hopper</p>          <p class="m(0) fg-text-muted">The compiler passes every test.</p>        </div>      </div>      <div class="swipe-actions">        <button class="swipe-action" type="button">          Archive<span class="sr-only">Grace Hopper</span>        </button>        <button class="swipe-action swipe-action-danger" type="button">          Delete<span class="sr-only">Grace Hopper</span>        </button>      </div>    </div>  </div></template>
행을 옆으로 드래그하거나 트랙패드로 가로 스크롤하거나 Tab 키를 누르세요.

#동작 방식

swipe는 스크롤바가 없는 가로 스크롤 영역이며, 스크롤 스냅이 반드시 적용됩니다. swipe-content는 행 전체 너비를 차지하며 시작 가장자리에 스냅됩니다. 그 뒤에 오는 swipe-actions는 끝 가장자리에 스냅됩니다. 두 위치 사이에서 놓으면 더 가까운 위치에 멈추고, 반대 방향으로 스크롤하면 행이 닫힙니다.

콘텐츠는 불투명합니다. 볼록한 표면과 카드가 제공하는 --surface-color에서 바탕 표면의 색을 가져오고, 드러난 오목한 영역에 짧은 그림자를 드리웁니다. 스크롤 기반 애니메이션을 지원하는 환경에서는 작업이 드러날 때 서서히 나타납니다. 그 외 환경에서는 애니메이션 없이 표시됩니다.

다른 행을 열어도 기존 행이 자동으로 닫히지 않으며, 작업을 눌러도 해당 행이 자동으로 제거되지 않습니다. 두 동작은 페이지에서 처리합니다. 스크립트로 행을 닫으려면 해당 행의 scrollLeft 값을 0으로 설정하세요.

#작업

작업은 버튼이나 링크로 표시하며, 단어 하나를 쓰거나 단어 위에 아이콘을 배치합니다. 각 셀은 너비가 최소 72px이고 높이는 행과 같아, 행 높이에 관계없이 충분한 크기의 터치 대상을 제공합니다. swipe-action-danger는 되돌릴 수 없는 작업으로, 전용 배경색 위에 위험을 나타내는 전경색으로 표시됩니다. 작업은 한두 개로 제한하고, 파괴적 작업은 맨 마지막에 배치하세요.

아이콘을 포함한 작업

<div class="sheet sheet-raised overflow-hidden w-full max-w(360)">  <div class="swipe" id="swipe-open">    <div class="swipe-content flex items-center gap-sm p(16)">      <div class="min-w(0)">        <p class="m(0) fg-text-strong font-medium">Quarterly report.pdf</p>        <p class="m(0) fg-text-muted">2.4 MB · Edited yesterday</p>      </div>    </div>    <div class="swipe-actions">      <button class="swipe-action" type="button">        <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="M10.625 11L10.6242 2.4693A0.625 0.625 0 0 0 9.3818 2.4083L9.375 2.5L9.377 11.05A0.6255 0.6255 0 0 0 9.4989 11.3735Q9.7145 11.5422 10 11.5422Q10.2855 11.5422 10.5011 11.3735A0.625 0.625 0 0 0 10.625 11Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M6.5 7.5L9.8586 10.8586A0.2 0.2 0 0 0 10.1414 10.8586L13.5 7.5" /><path d="M3 13.5L3 15.75A1.25 1.25 0 0 0 4.25 17L15.75 17A1.25 1.25 0 0 0 17 15.75L17 13.5" />        </svg> Save      </button>      <button class="swipe-action swipe-action-danger" type="button">        <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="M3 5.5L17 5.5" /><path d="M5 5.5L5.4501 16.302A1.25 1.25 0 0 0 6.699 17.5L13.301 17.5A1.25 1.25 0 0 0 14.5499 16.302L15 5.5" /><path d="M7.5 5.5L7.5 3.5A1 1 0 0 1 8.5 2.5L11.5 2.5A1 1 0 0 1 12.5 3.5L12.5 5.5" /><path d="M8.5 9L8.5 14" /><path d="M11.5 9L11.5 14" />        </svg> Delete      </button>    </div>  </div></div><script>document.getElementById('swipe-open').scrollLeft = 999</script>
스크립트에서 행을 열거나 닫을 때처럼, 이 예제에서는 scrollLeft를 설정해 행을 엽니다.

#접근성

  • 스와이프는 빠른 접근 수단이며, 같은 작업을 수행할 다른 방법도 반드시 제공해야 합니다. 트랙패드 없이 마우스를 사용하는 사용자는 행을 가로로 스크롤할 수 없습니다. 포인터로도 같은 작업을 찾을 수 있게 하세요. 예를 들어 행에 메뉴를 두거나, 항목을 열었을 때 같은 작업을 제공할 수 있습니다.
  • 작업에는 기본 버튼 요소를 사용하며, 각 버튼은 Tab 키 탐색 순서에 포함됩니다. 버튼이 포커스를 받으면 브라우저가 버튼이 보이도록 스크롤하므로 별도의 키보드 처리가 필요하지 않습니다. 포커스 윤곽선은 스크롤 영역에 잘리지 않도록 셀 안쪽에 그려집니다.
  • 아이콘만 표시하는 작업에는 접근 가능한 이름이 필요합니다. 사용자가 텍스트를 읽고 작업을 찾으므로 아이콘 아래에 단어를 표시하는 편이 좋습니다.
  • 파괴적 작업을 실행하기 전에 확인을 받거나, 실행한 뒤 토스트에서 실행을 취소할 수 있게 하세요.

#클래스

클래스설명
swipe스크롤바 없이 가로로 스크롤되는 행입니다. 콘텐츠나 동작 항목이 표시되는 위치에서 멈춥니다.
swipe-content기본 상태에서 행에 표시되는 내용입니다. 행 전체 너비를 차지하며 배경색은 행이 놓인 표면의 색상과 같습니다.
swipe-actions행의 끝쪽 가장자리 뒤에 있는 오목한 영역에 동작 항목을 배치합니다.
swipe-action버튼이나 링크 하나에 동작 하나를 배치합니다. 셀은 너비가 최소 72px이고 높이는 행과 같으며, 단어 하나를 표시하거나 그 위에 아이콘을 배치합니다.
swipe-action-danger되돌릴 수 없는 작업에 위험 상태 전경색과 그 색을 옅게 깐 배경을 적용합니다.적용할 클래스는 swipe-action입니다

#소스

@master/ui/components/swipe.css
/* * Swipe: a row that slides aside to show what can be done to it. * The row is a scroller with two places to rest: its content, as wide as the row, and the actions that wait * behind its end edge. A finger, a trackpad or the Tab key brings the actions in. The browser's own scrolling * does the work, so there is no script, and letting go between the two settles on the nearer one. * The content keeps the color of the surface it lies on and casts a short shade on what it uncovers; the * actions lie in a well, each at least 72px wide and as tall as the row. Where scroll-driven animations are * supported the actions come forward as they are uncovered. * Swiping is a shortcut and is never the only way: offer the same actions in a menu or on the opened item. */@layer components.ui {  .swipe {    --swipe-surface: var(--surface-color, var(--color-surface-base));    position: relative;    /* The content stands over the actions inside the row, not over a sticky header that scrolls past it. */    isolation: isolate;    display: flex;    min-width: 0;    overflow: auto hidden;    overscroll-behavior-x: contain;    scroll-snap-type: x mandatory;    scrollbar-width: none;    /* The well the actions lie in shows where the content has left. */    background: var(--color-surface-inset);    &::-webkit-scrollbar {      display: none;    }    @media (forced-colors: active) {      background: Canvas;    }  }  /* What the row shows at rest. It is opaque, so nothing of the well shows through it. */  .swipe-content {    position: relative;    z-index: 1;    flex: none;    width: 100%;    min-width: 0;    background: var(--swipe-surface);    /* A contour and a short shade on both edges; the scroller cuts the one that is not uncovered. */    box-shadow: 0 0 0 .5px var(--color-line-contour), 0 0 6px -1px var(--color-shade-1), 0 0 12px -2px var(--color-shade-2);    scroll-snap-align: start;    /* A row that opens its item is a link or a button: its ring stays inside, where the scroller does not cut it. */    &:focus-visible {      outline: 2px solid var(--color-focus);      outline-offset: -2px;    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      &:focus-visible {        outline: 2px solid Highlight;        outline-offset: -2px;      }    }  }  /* The actions, behind the end edge. */  .swipe-actions {    display: flex;    flex: none;    /* The shade the row's upper edge casts into the well. */    box-shadow: inset 0 1px 2px -1px var(--color-shade-2);    scroll-snap-align: end;    @supports (animation-timeline: scroll()) {      @media (prefers-reduced-motion: no-preference) {        /* Longhands: tools that fold the timeline into the shorthand write a value no browser reads. */        animation-name: swipe-arrive;        animation-timing-function: linear;        animation-fill-mode: both;        animation-timeline: scroll(inline nearest);      }    }  }  /* One action: a word, or an icon over a word. The whole cell is the target. */  .swipe-action {    --icon-size: 1.125rem;    display: inline-flex;    flex: none;    flex-direction: column;    align-items: center;    justify-content: center;    gap: .25rem;    min-width: 4.5rem;    margin: 0;    padding: 0 .875rem;    border: 0;    border-inline-start: 1px solid var(--color-line-hair);    border-radius: 0;    background: transparent;    color: var(--color-text-body);    font: var(--font-weight-control) .78125rem/1.2 var(--font-family-sans);    font-feature-settings: inherit;    text-decoration: none;    white-space: nowrap;    appearance: none;    cursor: pointer;    touch-action: manipulation;    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    @media (hover: hover) {      &:hover:not(:disabled, [aria-disabled="true"]) {        background: var(--color-surface-inset-hover);        color: var(--color-text-strong);      }    }    &:active:not(:disabled, [aria-disabled="true"]) {      background: color-mix(in oklab, currentColor 9%, transparent);    }    /* The ring stays inside the cell: the scroller would cut one drawn outside it. */    &:focus-visible {      outline: 2px solid var(--color-focus);      outline-offset: -2px;    }    /* The action that cannot be undone, in the danger ink on its own tint. */    &.swipe-action-danger {      background: color-mix(in oklab, var(--color-danger) 9%, transparent);      color: var(--color-danger);      @media (hover: hover) {        &:hover:not(:disabled, [aria-disabled="true"]) {          background: color-mix(in oklab, var(--color-danger) 14%, transparent);          color: var(--color-danger);        }      }      &:active:not(:disabled, [aria-disabled="true"]) {        background: color-mix(in oklab, var(--color-danger) 18%, transparent);      }    }    /* An action that cannot be taken now: disabled ink on the bare well, answering neither pointer nor press. */    &:is(:disabled, [aria-disabled="true"]) {      background: transparent;      color: var(--color-text-disabled);      cursor: not-allowed;    }    @media (forced-colors: active) {      border-inline-start-color: CanvasText;      &:focus-visible {        outline-color: Highlight;      }      &:is(:disabled, [aria-disabled="true"]) {        color: GrayText;      }    }  }}@keyframes swipe-arrive {  from {    opacity: 0;  }  60% {    opacity: 1;  }}