コンテンツへスキップ

使用例

ドキュメント共有カード

コピー可能な共有リンクの下にユーザー一覧があり、コンパクトなセレクトで各ユーザーの権限を設定できます。

プレビュー

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>

仕組み

コピーアクションはstateからリンク入力欄の値を読み取り、クリップボードに書き込んでから、contextを通じて2秒間ボタンのラベルを「コピーしました」に切り替えます。各権限セレクトはストア内のアクセスリストに直接変更を反映します。

このページのすべての動作はWordPress Interactivity APIによるものです。各コンポーネントが独自のストアを登録し、サーバー描画コンテキストで状態を初期化し、上のマークアップにあるディレクティブでイベントを設定します。ページ固有のJavaScriptはありません。