본문으로 건너뛰기

예제

문서 공유 카드

복사할 수 있는 공유 링크 아래에 사람 목록을 두고, 간결한 선택 메뉴로 각 사람의 권한을 설정합니다.

미리보기

Share this document

Anyone with the link can view this document.

People with access
Olivia Martin b@example.com
Isabella Nguyen i@example.com
Ethan Thompson e@example.com
HTML
<bs:bsui-card>
  <bs:bsui-card-header>
    <bs:bsui-card-title label="Share this document" />
    <bs:bsui-card-description label="Anyone with the link can view this document." />
  </bs:bsui-card-header>
  <bs:bsui-card-content>
    <bs:bsui-stack direction="column" gap="4" align="stretch">
      <bs:bsui-stack direction="row" gap="2" align="center">
        <bs:bsui-input name="share_link" defaultValue="https://acme.app/d/q3-forecast" />
        <bs:bsui-button label="Copy link" variant="outline" />
      </bs:bsui-stack>
      <bs:bsui-separator />
      <bs:bsui-text content="People with access" variant="label" tag="span" />
      <bs:bsui-stack direction="row" gap="3" align="center" justify="space-between">
        <bs:bsui-stack direction="row" gap="3" align="center">
          <bs:bsui-avatar fallback="OM" alt="Olivia Martin" />
          <bs:bsui-stack direction="column" gap="1">
            <bs:bsui-text content="Olivia Martin" variant="label" tag="span" />
            <bs:bsui-text content="b@example.com" variant="muted" tag="span" />
          </bs:bsui-stack>
        </bs:bsui-stack>
        <bs:bsui-select defaultValue="edit" placeholder="Permission">
          <bs:bsui-select-trigger />
          <bs:bsui-select-popup>
            <bs:bsui-select-option value="edit" label="Can edit" />
            <bs:bsui-select-option value="view" label="Can view" />
          </bs:bsui-select-popup>
        </bs:bsui-select>
      </bs:bsui-stack>
      <bs:bsui-stack direction="row" gap="3" align="center" justify="space-between">
        <bs:bsui-stack direction="row" gap="3" align="center">
          <bs:bsui-avatar fallback="IN" alt="Isabella Nguyen" />
          <bs:bsui-stack direction="column" gap="1">
            <bs:bsui-text content="Isabella Nguyen" variant="label" tag="span" />
            <bs:bsui-text content="i@example.com" variant="muted" tag="span" />
          </bs:bsui-stack>
        </bs:bsui-stack>
        <bs:bsui-select defaultValue="view" placeholder="Permission">
          <bs:bsui-select-trigger />
          <bs:bsui-select-popup>
            <bs:bsui-select-option value="edit" label="Can edit" />
            <bs:bsui-select-option value="view" label="Can view" />
          </bs:bsui-select-popup>
        </bs:bsui-select>
      </bs:bsui-stack>
      <bs:bsui-stack direction="row" gap="3" align="center" justify="space-between">
        <bs:bsui-stack direction="row" gap="3" align="center">
          <bs:bsui-avatar fallback="ET" alt="Ethan Thompson" />
          <bs:bsui-stack direction="column" gap="1">
            <bs:bsui-text content="Ethan Thompson" variant="label" tag="span" />
            <bs:bsui-text content="e@example.com" variant="muted" tag="span" />
          </bs:bsui-stack>
        </bs:bsui-stack>
        <bs:bsui-select defaultValue="view" placeholder="Permission">
          <bs:bsui-select-trigger />
          <bs:bsui-select-popup>
            <bs:bsui-select-option value="edit" label="Can edit" />
            <bs:bsui-select-option value="view" label="Can view" />
          </bs:bsui-select-popup>
        </bs:bsui-select>
      </bs:bsui-stack>
    </bs:bsui-stack>
  </bs:bsui-card-content>
</bs:bsui-card>

작동 방식

복사 작업은 상태에서 링크 입력값을 읽어 클립보드에 기록하고, 컨텍스트를 통해 2초 동안 버튼 레이블을 Copied로 바꿉니다. 각 권한 선택 메뉴는 스토어의 액세스 목록에 바로 값을 확정합니다.

이 페이지의 모든 동작은 WordPress Interactivity API입니다. 각 컴포넌트가 자체 스토어를 등록하고, 서버 렌더링 컨텍스트에서 상태를 설정하며, 위 마크업의 디렉티브로 이벤트를 연결합니다. 페이지별 JavaScript는 없습니다.