アクションシート React コンポーネント

アクションシートは、特定のタスクをどのように進めるかについて、ユーザーに一連の選択肢を提示するためのスライドアップペインです。アクションシートを使用して、潜在的に危険なアクションを確認するようにユーザーに促すこともできます。アクションシートには、オプションのタイトルと、実行するアクションに対応する1つ以上のボタンが含まれています。

アクションシートReactコンポーネントは、アクションシートコンポーネントを表します。

アクションシートコンポーネント

以下のコンポーネントが含まれています

アクションシートプロパティ

プロパティタイプデフォルト説明
<Actions> プロパティ
openedbooleanfalseアクションシートを開閉したり、初期状態を設定したりできます
gridbooleanfalseグリッドボタンレイアウトを有効にします
convertToPopoverboolean有効にすると、アクションシートは大きな画面でポップオーバーに変換されます。デフォルトでは、同じアプリのパラメーター値を継承します
forceToPopoverboolean有効にすると、アクションシートは常にポップオーバーに変換されます。デフォルトでは、同じアプリのパラメーター値を継承します
targetHTMLElement
string
ターゲット要素のHTML要素または文字列CSSセレクター。ポップオーバーへの変換を使用する場合は必須
backdropbooleanアクションシートの背景(背後の暗い半透明のレイヤー)を有効にします。デフォルトでは、同じアプリのパラメーター値(true)を継承します
backdropUniqueboolean有効にすると、このモーダルのための専用のユニークな背景要素を作成します
backdropElstring
object
カスタム背景要素のHTML要素または文字列CSSセレクター
closeByBackdropClickbooleantrue有効にすると、背景をクリックするとアクションシートが閉じられます。デフォルトでは、同じアプリのパラメーター値を継承します
closeByOutsideClickbooleanfalse有効にすると、アクションシートの外側をクリックすると閉じられます。デフォルトでは、同じアプリのパラメーター値を継承します
closeOnEscapeboolean有効にすると、ESCキーを押すとアクションシートが閉じられます
animatebooleanモーダルをアニメーション付きで開閉するかどうか
containerElHTMLElement
string
モーダルをマウントする要素(デフォルトはアプリのルート要素)
<ActionsLabel> プロパティ
strongbooleanfalseラベルテキストを太字にするかどうかを定義します
<ActionsButton> プロパティ
strongbooleanfalseボタンテキストを太字にするかどうかを定義します
closebooleantrueボタンをクリックしたときにアクションシートを閉じるかどうか

アクションシートイベント

イベント説明
<Actions> イベント
actionsOpenアクションシートが開くアニメーションを開始するときにイベントがトリガーされます
actionsOpenedアクションシートが開くアニメーションが完了した後にイベントがトリガーされます
actionsCloseアクションシートが閉じるアニメーションを開始するときにイベントがトリガーされます
actionsClosedアクションシートが閉じるアニメーションが完了した後にイベントがトリガーされます

アクションシートを開閉する

アクションシートの open()/close()メソッドに加えて、開閉することもできます。

action-sheet.jsx
import React, { useRef, useState, useEffect } from 'react';
import {
  Navbar,
  Page,
  BlockTitle,
  Block,
  Button,
  Actions,
  ActionsGroup,
  ActionsLabel,
  ActionsButton,
  f7,
} from 'framework7-react';

export default () => {
  const actionsToPopover = useRef(null);
  const buttonToPopoverWrapper = useRef(null);
  const [actionsOneGroupOpened, setActionsOneGroupOpened] = useState(false);
  const [actionsGridOpened, setActionsGridOpened] = useState(false);

  useEffect(() => {
    return () => {
      if (actionsToPopover.current) {
        actionsToPopover.current.destroy();
      }
    };
  }, []);

  const openActionsPopover = () => {
    if (!actionsToPopover.current) {
      actionsToPopover.current = f7.actions.create({
        buttons: [
          {
            text: 'Do something',
            label: true,
          },
          {
            text: 'Button 1',
            strong: true,
          },
          {
            text: 'Button 2',
          },
          {
            text: 'Cancel',
            color: 'red',
          },
        ],
        // Need to specify popover target
        targetEl: buttonToPopoverWrapper.current.querySelector('.button-to-popover'),
      });
    }

    // Open
    actionsToPopover.current.open();
  };

  return (
    <Page>
      <Navbar title="Action Sheet"></Navbar>
      <Block strong inset>
        <p className="grid grid-cols-2 grid-gap">
          {/* One group, open by changing actionsOneGroupOpened property */}
          <Button fill onClick={() => setActionsOneGroupOpened(true)}>
            One group
          </Button>
          {/*  Two groups, open by "actionsOpen" attribute */}
          <Button fill actionsOpen="#actions-two-groups">
            Two groups
          </Button>
        </p>
        <p>
          {/* Actions Grid, open by changing actionsGridOpened property */}
          <Button fill onClick={() => setActionsGridOpened(true)}>
            Action Grid
          </Button>
        </p>
      </Block>

      <BlockTitle>Action Sheet To Popover</BlockTitle>
      <Block strong inset>
        <p ref={buttonToPopoverWrapper}>
          Action Sheet can be automatically converted to Popover (for tablets). This button will
          open Popover on tablets and Action Sheet on phones:
          <Button
            style={{ display: 'inline-block' }}
            className="button-to-popover"
            onClick={openActionsPopover}
          >
            Actions
          </Button>
        </p>
      </Block>

      {/* One Group */}
      <Actions
        opened={actionsOneGroupOpened}
        onActionsClosed={() => setActionsOneGroupOpened(false)}
      >
        <ActionsGroup>
          <ActionsLabel>Do something</ActionsLabel>
          <ActionsButton strong>Button 1</ActionsButton>
          <ActionsButton>Button 2</ActionsButton>
          <ActionsButton color="red">Cancel</ActionsButton>
        </ActionsGroup>
      </Actions>

      {/* Two Groups */}
      <Actions id="actions-two-groups">
        <ActionsGroup>
          <ActionsLabel>Do something</ActionsLabel>
          <ActionsButton strong>Button 1</ActionsButton>
          <ActionsButton>Button 2</ActionsButton>
        </ActionsGroup>
        <ActionsGroup>
          <ActionsButton color="red">Cancel</ActionsButton>
        </ActionsGroup>
      </Actions>

      {/* Grid */}
      <Actions
        grid={true}
        opened={actionsGridOpened}
        onActionsClosed={() => setActionsGridOpened(false)}
      >
        <ActionsGroup>
          <ActionsButton>
            <img
              slot="media"
              src="https://cdn.framework7.io/placeholder/people-96x96-1.jpg"
              width="48"
              style={{ maxWidth: '100%', borderRadius: '8px' }}
            />
            <span>Button 1</span>
          </ActionsButton>
          <ActionsButton>
            <img
              slot="media"
              src="https://cdn.framework7.io/placeholder/people-96x96-2.jpg"
              width="48"
              style={{ maxWidth: '100%', borderRadius: '8px' }}
            />
            <span>Button 2</span>
          </ActionsButton>
          <ActionsButton>
            <img
              slot="media"
              src="https://cdn.framework7.io/placeholder/people-96x96-3.jpg"
              width="48"
              style={{ maxWidth: '100%', borderRadius: '8px' }}
            />
            <span>Button 3</span>
          </ActionsButton>
        </ActionsGroup>
        <ActionsGroup>
          <ActionsButton>
            <img
              slot="media"
              src="https://cdn.framework7.io/placeholder/fashion-96x96-4.jpg"
              width="48"
              style={{ maxWidth: '100%', borderRadius: '8px' }}
            />
            <span>Button 4</span>
          </ActionsButton>
          <ActionsButton>
            <img
              slot="media"
              src="https://cdn.framework7.io/placeholder/fashion-96x96-5.jpg"
              width="48"
              style={{ maxWidth: '100%', borderRadius: '8px' }}
            />
            <span>Button 5</span>
          </ActionsButton>
          <ActionsButton>
            <img
              slot="media"
              src="https://cdn.framework7.io/placeholder/fashion-96x96-6.jpg"
              width="48"
              style={{ maxWidth: '100%', borderRadius: '8px' }}
            />
            <span>Button 6</span>
          </ActionsButton>
        </ActionsGroup>
      </Actions>
    </Page>
  );
};