# 공유 채널 선택창 (Share Dialog)

판화 옆의 공유 아이콘을 누르면 배경이 어두워지고 채널을 고를 수 있습니다.

## 체험 방법

판화 오른쪽의 공유 아이콘을 누르고 채널을 골라 보세요. 예제는 고른 채널을 작품 아래에 표시합니다.

## 재현 기준

창을 열고 닫을 때 배경의 어두운 막이 250ms 동안 나타나고 사라집니다. 창이 열려 있는 동안 배경 조작을 막고, 동작 줄이기 설정에서는 즉시 전환합니다.

## 기기별 조작

- iOS · 공유 아이콘을 탭하고 채널을 고르세요. 창 밖을 탭하면 선택을 취소합니다.
- Android · 공유 아이콘을 탭하고 채널을 고르세요. 닫기 버튼으로 작품에 돌아갈 수 있습니다.
- PC · 공유 아이콘에서 Enter를 누르세요. Tab으로 채널을 고르거나 Escape로 닫으세요.

## 적용할 때

상품이나 작품을 보던 자리에서 공유할 채널을 고를 때.

## 그대로 보낼 요청

> 작은 공유 아이콘으로 채널 선택창을 열어 줘. 배경을 서서히 어둡게 하고, 닫으면 아이콘으로 초점을 돌려줘.

## 참고한 동작

[올리브영 · 상품 상세 공유창](https://www.oliveyoung.co.kr/store/goods/getGoodsDetail.do?goodsNo=A000001004151)

## 독립 실행 코드

아래 전체 코드를 HTML로 저장해 브라우저에서 엽니다.

```html
<!doctype html>
<html lang="ko">
<head><script>if(new URLSearchParams(location.search).get('reduce')==='1')document.documentElement.classList.add('motion-reduced');</script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>판화 공유창</title>
  <style>
    * { box-sizing: border-box }
    body { margin: 0; min-height: 100dvh; display: grid; place-items: center; padding: 20px; color: #242620; background: #ebe9df; font: 16px/1.45 system-ui, sans-serif }
    button { font: inherit; color: inherit; cursor: pointer }
    button:focus-visible { outline: 3px solid #176672; outline-offset: 3px }
    article { width: min(100%, 580px); padding: clamp(12px, 3vw, 23px); background: #fffdf5; box-shadow: 0 3px 15px #302b2815 }
    .print { position: relative; overflow: hidden; height: clamp(100px, 42dvh, 236px); background: #ed875a }
    .print::before,.print::after { content: ""; position: absolute; top: -47%; width: 50%; height: 200%; transform: rotate(31deg); background: repeating-linear-gradient(90deg, #243f40 0 8%, #ed875a 8% 16%) }
    .print::before { left: 12%; border-radius: 50% }
    .print::after { left: 49%; top: -18%; height: 140%; border-radius: 50%; background: repeating-linear-gradient(90deg, #edd7a7 0 9%, #274847 9% 18%) }
    .record { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-top: 14px }
    h1,h2,p { margin: 0 }
    h1 { font: 600 clamp(19px, 3vw, 26px)/1.24 system-ui, sans-serif }
    .medium,.status { color: #595e54; font-size: 14px }
    .medium { margin-top: 3px }
    .status:empty { display: none }
    .status { margin-top: 12px }
    .icon-btn { display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; background: transparent; border: 0; border-radius: 50% }
    .icon-btn:hover,.channel:hover { background: #f2f1e9 }
    svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round }
    dialog { position: fixed; border: none; padding: 19px; width: min(360px,calc(100% - 32px)); max-height: calc(100dvh - 24px); border-radius: 9px; color: #20231e; background: #fff; box-shadow: 0 4px 32px #1e211833 }
    dialog::backdrop { background: rgb(25 28 23 / 61%); animation: veil-in 250ms ease-out both }
    dialog[data-closing]::backdrop { animation: veil-out 250ms ease-in both }
    @keyframes veil-in { from { opacity: 0 } to { opacity: 1 } }
    @keyframes veil-out { from { opacity: 1 } to { opacity: 0 } }
    @media (prefers-reduced-motion: reduce) { dialog::backdrop { animation: none } }
    .motion-reduced dialog::backdrop { animation: none }
    header { display: flex; align-items: center; justify-content: space-between; gap: 12px }
    h2 { font-size: 19px }
    .channels { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; margin-block: 10px 5px }
    .channel { display: grid; justify-items: center; align-content: start; gap: 7px; background: transparent; border: 0; padding: 8px 2px; border-radius: 6px; font-size: 13px }
    .token { display: grid; place-items: center; border-radius: 50%; width: 48px; height: 48px; background: #ecda9d }
    .channel:nth-child(2) .token { background: #d4e4cf }
    .channel:nth-child(3) .token { background: #d8e4e7 }
  </style>
</head>
<body>
  <article>
    <div class="print" aria-hidden="true"></div>
    <div class="record">
      <div><h1>썰물의 결</h1><p class="medium">두 색 리소 인쇄</p></div>
      <button type="button" class="icon-btn" id="open-share" aria-label="판화 공유" aria-haspopup="dialog" aria-controls="share-dialog">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 15V3m-4 4 4-4 4 4M6 10H4v11h16V10h-2"/></svg>
      </button>
    </div>
    <p class="status" role="status" id="result"></p>
  </article>
  <dialog id="share-dialog" aria-labelledby="share-title">
    <header><h2 id="share-title">공유할 채널</h2><button type="button" class="icon-btn" autofocus id="close-share" aria-label="닫기">
      <svg viewBox="0 0 24 24" aria-hidden="true"><path d="m6 6 12 12M18 6 6 18"/></svg>
    </button></header>
    <div class="channels">
      <button type="button" class="channel"><span class="token"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M20 11a8 8 0 0 1-8 8H9l-5 2 1-5a8 8 0 1 1 15-5Z"/></svg></span><span>메시지</span></button>
      <button type="button" class="channel"><span class="token"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m4 7 8 6 8-6"/></svg></span><span>이메일</span></button>
      <button type="button" class="channel"><span class="token"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="m9 15 6-6m-5-2 2-2a4.3 4.3 0 0 1 6 6l-2 2m-2 4-2 2a4.3 4.3 0 0 1-6-6l2-2"/></svg></span><span>링크</span></button>
    </div>
  </dialog>
  <script>
    const panel = document.querySelector('#share-dialog');
    const trigger = document.querySelector('#open-share');
    const result = document.querySelector('#result');
    const reduce = matchMedia('(prefers-reduced-motion: reduce)');
    let closeTimer;
    let chosen = '';
    function finish() {
      clearTimeout(closeTimer);
      if (panel.open) panel.close();
      delete panel.dataset.closing;
      trigger.focus({preventScroll:true});
      if (chosen) {
        result.textContent = '선택한 채널' + ' · ' + chosen;
        chosen = '';
      }
    }
    function dismiss() {
      if (!panel.open || panel.hasAttribute('data-closing')) return;
      if (reduce.matches || document.documentElement.classList.contains('motion-reduced')) return finish();
      panel.dataset.closing = '';
      closeTimer = setTimeout(finish, 250);
    }
    trigger.addEventListener('click', () => {
      result.textContent = '';
      panel.showModal();
    });
    panel.addEventListener('cancel', event => { event.preventDefault(); dismiss(); });
    document.querySelector('#close-share').addEventListener('click', dismiss);
    panel.addEventListener('click', event => {
      if (panel.hasAttribute('data-closing')) return;
      const channel = event.target.closest('.channel');
      if (channel) {
        chosen = channel.innerText.trim();
        dismiss();
      } else if (event.target === panel) {
        const {top,bottom,left,right} = panel.getBoundingClientRect();
        if (event.clientX < left || event.clientX > right || event.clientY < top || event.clientY > bottom) dismiss();
      }
    });
  </script>
</body>
</html>
```

