アクションシート
アクションシートは、特定のタスクをどのように進めるかの選択肢をユーザーに提示するためのスライドアップパネルです。
アクションシートを使用して、潜在的に危険なアクションを確認するようにユーザーに促すこともできます。
アクションシートには、オプションのタイトルと、実行するアクションに対応する1つ以上のボタンが含まれています。
大きな画面(iPad)ではアクションシートを使用しないことをお勧めします。大きな画面では、代わりにポップオーバーを使用する必要があります。
アクションシートアプリメソッド
アクションシートを操作するための関連するアプリメソッドを見てみましょう。
app.actions.create(parameters)- アクションシートインスタンスを作成します。
- parameters - object。アクションシートのパラメーターを持つオブジェクト。
メソッドは、作成されたアクションシートのインスタンスを返します。
app.actions.destroy(el)- アクションシートインスタンスを破棄します。
- el - HTMLElement または string (CSSセレクター付き) または object。破棄するアクション要素のインスタンス。
app.actions.get(el)- HTML要素によるアクションシートインスタンスを取得します。
- el - HTMLElement または string (CSSセレクター付き)。アクションシート要素。
メソッドは、アクションシートのインスタンスを返します。
app.actions.open(el, animate)- アクションシートを開きます。
- el - HTMLElement または string (CSSセレクター付き)。開くアクションシート要素。
- animate - boolean。アニメーション付きでアクションシートを開きます。
メソッドは、アクションシートのインスタンスを返します。
app.actions.close(el, animate)- アクションシートを閉じます。
- el - HTMLElement または string (CSSセレクター付き)。閉じるアクションシート要素。
- animate - boolean。アニメーション付きでアクションシートを閉じます。
メソッドは、アクションシートのインスタンスを返します。
アクションシートのパラメーター
次に、アクションシートを作成するために必要な使用可能なパラメーターのリストを見てみましょう。
パラメーター | タイプ | デフォルト | 説明 |
---|---|---|---|
el | HTMLElement string | アクションシート要素。HTMLに既にアクションシート要素があり、この要素を使用して新しいインスタンスを作成する場合に便利です。 | |
content | string | アクションシートの完全なHTMLコンテンツ文字列。カスタムHTMLでアクションシート要素を作成する場合に便利です。 | |
backdrop | boolean | true | アクションシートの背景(背後の暗い半透明レイヤー)を有効にします。 |
backdropEl | HTMLElement string | カスタム背景要素のHTML要素または文字列CSSセレクター | |
backdropUnique | boolean | false | 有効にすると、このモーダルのために排他的にユニークな背景要素が作成されます。 |
closeByBackdropClick | boolean | true | 有効にすると、アクションシートは背景クリックで閉じられます。 |
closeByOutsideClick | boolean | false | 有効にすると、アクションシートの外側をクリックすると閉じられます。 |
closeOnEscape | boolean | false | 有効にすると、アクションシートはESCキーの押下で閉じられます。 |
animate | boolean | true | アクションシートをアニメーション付きで開閉するかどうか。.open() および.close() メソッドで上書きできます。 |
buttons | array | アクションシートグループ/ボタン。この場合、アクションのレイアウトは、渡されたグループとボタンに基づいて動的に生成されます。groupsの場合、各項目がグループのボタンを持つ配列を表す配列である必要があります。 | |
grid | boolean | false | グリッドボタンレイアウトを有効にします。 |
convertToPopover | boolean | true | 有効にすると、アクションシートは大きな画面でポップオーバーに変換されます。 |
forceToPopover | boolean | false | 有効にすると、アクションシートは常にポップオーバーに変換されます。 |
targetEl | HTMLElement string | ターゲット要素のHTML要素または文字列CSSセレクター。ポップオーバーへの変換を使用する場合は必須です。 | |
targetX | number | 画面の左側からの仮想ターゲット要素の水平方向オフセット。実際のターゲット要素(targetEl )を使用せずにポップオーバーへの変換を使用する場合は必須です。 | |
targetY | number | 画面の上からの仮想ターゲット要素の垂直方向オフセット。実際のターゲット要素(targetEl )を使用せずにポップオーバーへの変換を使用する場合は必須です。 | |
targetWidth | number | 0 | 仮想ターゲット要素の幅(px単位)。実際のターゲット要素(targetEl )を使用せずにポップオーバーへの変換を使用する場合は必須です。 |
targetHeight | number | 0 | 仮想ターゲット要素の高さ(px単位)。実際のターゲット要素(targetEl )を使用せずにポップオーバーへの変換を使用する場合は必須です。 |
cssClass | string | アクションシート要素に設定する追加のCSSクラス名 | |
onClick | function(actions, e) | アクションシートボタンのクリック後に実行されるコールバック関数 | |
render | function | アクションシートをレンダリングするためのカスタム関数。アクションシートのhtmlを返す必要があります。 | |
renderPopover | function | ポップオーバーへの変換を使用する場合にポップオーバーをレンダリングするためのカスタム関数。ポップオーバーのhtmlを返す必要があります。 | |
containerEl | HTMLElement string | モーダルをマウントする要素(デフォルトはアプリのルート要素) | |
on | object | イベントハンドラーを持つオブジェクト。たとえば
|
次のすべてのパラメーターは、actions
プロパティの下のグローバルアプリパラメーターで使用して、すべてのアクションシートのデフォルトを設定できることに注意してください。例:
var app = new Framework7({
actions: {
convertToPopover: false,
grid: true,
}
});
ボタンパラメーター
buttons
配列の各ボタンは、ボタンパラメーターを持つオブジェクトとして表示する必要があります。
パラメーター | タイプ | デフォルト | 説明 |
---|---|---|---|
text | string | ボタンのテキスト(HTML文字列の場合もあります)を持つ文字列 | |
icon | string | アイコンのHTML文字列 | |
strong | boolean | false | ボタンテキストを太字にします。 |
color | string | ボタンの色、デフォルトの色の1つ | |
bg | string | ボタンの背景色、デフォルトの色の1つ | |
label | boolean | false | 有効にすると、ボタンではなくラベルとしてレンダリングされます。 |
disabled | boolean | false | ボタンが無効かどうかを定義します。 |
close | boolean | true | 有効にすると、ボタンをクリックするとアクションシートが閉じます。 |
onClick | function(actions, e) | このボタンのクリック後に実行されるコールバック関数 |
アクションシートのメソッドとプロパティ
アクションシートを作成するには、次のコードを呼び出す必要があります。
var actions = app.actions.create({ /* parameters */ })
その後、便利なメソッドとプロパティを持つ初期化されたインスタンス(上記の例のactions
変数など)があります。
プロパティ | |
---|---|
actions.app | グローバルアプリインスタンスへのリンク |
actions.el | アクションシートのHTML要素 |
actions.$el | アクションシートのHTML要素を持つDom7インスタンス |
actions.backdropEl | 背景HTML要素 |
actions.$backdropEl | 背景HTML要素を持つDom7インスタンス |
actions.params | アクションシートインスタンスのパラメーター |
actions.opened | アクションシートが開いているかどうかを示すブール値のプロパティ |
メソッド | |
actions.open(animate) | アクションシートを開きます。ここで
|
actions.close(animate) | アクションシートを閉じます。ここで
|
actions.destroy() | アクションシートを破棄します。 |
actions.on(event, handler) | イベントハンドラーを追加します。 |
actions.once(event, handler) | 発生後に削除されるイベントハンドラーを追加します。 |
actions.off(event, handler) | イベントハンドラーを削除します。 |
actions.off(event) | 指定されたイベントのすべてのハンドラーを削除します。 |
actions.emit(event, ...args) | インスタンスでイベントを発生させます。 |
リンクを使用したアクションシートの制御
リンク上の特別なクラスとデータ属性を使用して、必要なアクションシート(DOMにある場合)を開閉できます。
アクションシートを開くには、「actions-open」クラスを任意のHTML要素(リンクに推奨)に追加する必要があります。
アクションシートを閉じるには、「actions-close」クラスを任意のHTML要素(リンクに推奨)に追加する必要があります。
DOMに複数のアクションシートがある場合は、このHTML要素の追加のdata-actions=".my-actions"属性を介して適切なアクションシートを指定する必要があります。
上記のメモに従って
<!-- In data-actions attribute we specify CSS selector of action sheet we need to open -->
<p><a href="#" data-actions=".my-actions" class="actions-open">Open Actions</a></p>
<!-- And somewhere in DOM -->
<div class="actions-modal my-actions">
...
</div>
アクションシートイベント
アクションシートは、アクションシート要素とアプリとアクションシートインスタンスのイベントで次のDOMイベントを発生させます。
DOMイベント
イベント | ターゲット | 説明 |
---|---|---|
actions:open | アクションシート要素<div class="actions-modal"> | アクションシートが開くアニメーションを開始するとイベントがトリガーされます。 |
actions:opened | アクションシート要素<div class="actions-modal"> | アクションシートが開くアニメーションを完了するとイベントがトリガーされます。 |
actions:close | アクションシート要素<div class="actions-modal"> | アクションシートが閉じるアニメーションを開始するとイベントがトリガーされます。 |
actions:closed | アクションシート要素<div class="actions-modal"> | アクションシートが閉じるアニメーションを完了するとイベントがトリガーされます。 |
アプリとアクションシートインスタンスのイベント
アクションシートインスタンスは、自己インスタンスとアプリインスタンスの両方でイベントを発生させます。アプリインスタンスのイベントには、actions
で始まる同じ名前が付いています。
イベント | 引数 | ターゲット | 説明 |
---|---|---|---|
open | actions | actions | アクションシートが開きのアニメーションを開始したときにイベントがトリガーされます。イベントハンドラーは、引数としてアクションシートのインスタンスを受け取ります。 |
actionsOpen | actions | app | |
opened | actions | actions | アクションシートが開きのアニメーションを完了した後にイベントがトリガーされます。イベントハンドラーは、引数としてアクションシートのインスタンスを受け取ります。 |
actionsOpened | actions | app | |
close | actions | actions | アクションシートが閉じのアニメーションを開始したときにイベントがトリガーされます。イベントハンドラーは、引数としてアクションシートのインスタンスを受け取ります。 |
actionsClose | actions | app | |
closed | actions | actions | アクションシートが閉じのアニメーションを完了した後にイベントがトリガーされます。イベントハンドラーは、引数としてアクションシートのインスタンスを受け取ります。 |
actionsClosed | actions | app | |
beforeDestroy | actions | actions | アクションシートのインスタンスが破棄される直前にイベントがトリガーされます。イベントハンドラーは、引数としてアクションシートのインスタンスを受け取ります。 |
actionsBeforeDestroy | actions | app |
CSS変数
以下は、関連するCSS変数(CSSカスタムプロパティ)の一覧です。
コメントアウトされた変数はデフォルトでは指定されておらず、その値はこの場合のフォールバック値であることに注意してください。
:root {
--f7-actions-grid-button-font-size: 12px;
--f7-actions-grid-button-icon-size: 48px;
}
.ios {
--f7-actions-transition-timing-function: initial;
--f7-actions-border-radius: 13px;
/*
--f7-actions-button-text-color: var(--f7-theme-color);
*/
--f7-actions-grid-button-text-color: #757575;
--f7-actions-button-padding: 0px;
--f7-actions-button-text-align: center;
--f7-actions-button-height: 57px;
--f7-actions-button-height-landscape: 44px;
--f7-actions-button-font-size: 20px;
--f7-actions-button-icon-size: 28px;
--f7-actions-button-justify-content: center;
--f7-actions-label-padding: 8px 10px;
--f7-actions-label-font-weight: 400;
--f7-actions-label-font-size: 13px;
--f7-actions-label-justify-content: center;
--f7-actions-group-border-color: transparent;
--f7-actions-group-margin: 8px;
--f7-actions-bg-color: rgba(255, 255, 255, 0.95);
--f7-actions-bg-color-rgb: 255, 255, 255;
--f7-actions-button-border-color: rgba(0, 0, 0, 0.2);
--f7-actions-button-pressed-bg-color: rgba(230, 230, 230, 0.9);
--f7-actions-button-pressed-bg-color-rgb: 230, 230, 230;
--f7-actions-label-text-color: #8a8a8a;
}
.ios .dark,
.ios.dark {
--f7-actions-bg-color: rgba(45, 45, 45, 0.95);
--f7-actions-bg-color-rgb: 45, 45, 45;
--f7-actions-button-border-color: rgba(255, 255, 255, 0.15);
--f7-actions-button-pressed-bg-color: rgba(50, 50, 50, 0.9);
--f7-actions-button-pressed-bg-color-rgb: 50, 50, 50;
--f7-actions-label-text-color: rgba(255, 255, 255, 0.55);
}
.md {
--f7-actions-transition-timing-function: cubic-bezier(0, 0.8, 0.34, 1);
--f7-actions-border-radius: 16px;
--f7-actions-button-border-color: transparent;
--f7-actions-button-padding: 0 16px;
--f7-actions-button-text-align: left;
--f7-actions-button-height: 48px;
--f7-actions-button-height-landscape: 48px;
--f7-actions-button-font-size: 16px;
--f7-actions-button-icon-size: 24px;
--f7-actions-button-justify-content: space-between;
--f7-actions-label-padding: 12px 16px;
--f7-actions-label-font-size: 14px;
--f7-actions-label-font-weight: 500;
--f7-actions-label-justify-content: flex-start;
--f7-actions-group-margin: 0px;
--f7-actions-button-pressed-bg-color: #e5e5e5;
}
.md .dark,
.md.dark {
--f7-actions-button-pressed-bg-color: #2e2e2e;
}
.md,
.md .dark,
.md [class*='color-'] {
--f7-actions-button-text-color: var(--f7-md-on-surface);
--f7-actions-bg-color: var(--f7-md-surface-3);
--f7-actions-group-border-color: var(--f7-md-outline);
--f7-actions-label-text-color: var(--f7-theme-color);
--f7-actions-grid-button-text-color: var(--f7-md-on-surface);
}
例
<template>
<div class="page">
<div class="navbar">
<div class="navbar-bg"></div>
<div class="navbar-inner sliding">
<div class="title">Action Sheet</div>
</div>
</div>
<div class="page-content">
<div class="block block-strong inset">
<p class="grid grid-cols-2 grid-gap">
<a class="button button-fill" @click=${openDemo1}>One group</a>
<a class="button button-fill" @click=${openDemo2}>Two groups</a>
</p>
<p>
<a class="button button-fill" @click=${openGrid}>Action Grid</a>
</p>
</div>
<div class="block-title">Action Sheet To Popover</div>
<div class="block block-strong inset">
<p>Action Sheet can be automatically converted to Popover (for tablets). This button will open Popover on
tablets and Action Sheet on phones: <a style="display:inline-block"
class="button button-to-popover button-small" @click=${openActionsPopover}>Actions</a></p>
</div>
</div>
</div>
</template>
<script>
export default (props, { $on, $f7, $el }) => {
let actions1;
let actions2;
let actionsGrid;
let actionsToPopover;
const openDemo1 = () => {
actions1.open();
}
const openDemo2 = () => {
actions2.open();
}
const openGrid = () => {
actionsGrid.open();
}
const openActionsPopover = () => {
actionsToPopover.open();
}
$on('pageInit', () => {
// 1 Group
const buttons1 = [
{
text: 'Do something',
label: true
},
{
text: 'Button 1',
strong: true
},
{
text: 'Button 2',
},
{
text: 'Cancel',
color: 'red'
},
];
// 2 Groups
const buttons2 = [
// First Group
[
{
text: 'Do something',
label: true
},
{
text: 'Button 1',
strong: true
},
{
text: 'Button 2',
}
],
// Second Group
[
{
text: 'Cancel',
color: 'red'
}
]
]
// Grid buttons with icons/images
const gridButtons = [
[
{
text: 'Button 1',
icon: '<img src="https://cdn.framework7.io/placeholder/people-96x96-1.jpg" width="48" style="max-width: 100%; border-radius: 8px"/>'
},
{
text: 'Button 2',
icon: '<img src="https://cdn.framework7.io/placeholder/people-96x96-2.jpg" width="48" style="max-width: 100%; border-radius: 8px">'
},
{
text: 'Button 3',
icon: '<img src="https://cdn.framework7.io/placeholder/people-96x96-3.jpg" width="48" style="max-width: 100%; border-radius: 8px">'
},
],
[
{
text: 'Button 1',
icon: '<img src="https://cdn.framework7.io/placeholder/fashion-96x96-4.jpg" width="48" style="max-width: 100%; border-radius: 8px"/>'
},
{
text: 'Button 2',
icon: '<img src="https://cdn.framework7.io/placeholder/fashion-96x96-5.jpg" width="48" style="max-width: 100%; border-radius: 8px">'
},
{
text: 'Button 3',
icon: '<img src="https://cdn.framework7.io/placeholder/fashion-96x96-6.jpg" width="48" style="max-width: 100%; border-radius: 8px">'
},
],
]
actions1 = $f7.actions.create({ buttons: buttons1 });
actions2 = $f7.actions.create({ buttons: buttons2 });
actionsGrid = $f7.actions.create({ buttons: gridButtons, grid: true });
// Actions To Popover
actionsToPopover = $f7.actions.create({
buttons: buttons1,
// Need to specify popover target
targetEl: $el.value.find('.button-to-popover')
});
})
$on('pageBeforeRemove', () => {
actions1.destroy();
actions2.destroy();
actionsGrid.destroy();
actionsToPopover.destroy();
})
return $render;
}
</script>