動作表 Svelte 組件
動作表是一個滑動式面板,用於向使用者提供如何執行特定任務的一組替代方案。您也可以使用動作表提示使用者確認潛在的危險動作。動作表包含一個選用的標題和一個或多個按鈕,每個按鈕都對應於一個要執行的動作。
動作表 Svelte 組件代表 動作表 組件。
動作表單元件
包含下列元件
Actions
- 動作表單元件ActionsGroup
- 動作表單按鈕群組ActionsButton
- 動作表單按鈕ActionsLabel
- 動作表單標籤
動作表單屬性
屬性 | 類型 | 預設值 | 說明 |
---|---|---|---|
<Actions> 屬性 | |||
opened | 布林值 | false | 允許開啟/關閉動作表單並設定其初始狀態 |
grid | 布林值 | false | 啟用網格按鈕版面配置 |
convertToPopover | 布林值 | 啟用時,動作表單將在大螢幕上轉換為彈出視窗。預設繼承相同的應用程式參數值 | |
forceToPopover | 布林值 | 啟用時,動作表單將始終轉換為彈出視窗。預設繼承相同的應用程式參數值 | |
target | HTMLElement 字串 | 目標元素的 HTML 元素或字串 CSS 選擇器。在使用轉換為彈出視窗時需要 | |
backdrop | 布林值 | 啟用動作表單背景(深色半透明圖層)。預設繼承相同的應用程式參數值 (true ) | |
backdropEl | 字串 物件 | 自訂背景元素的 HTML 元素或字串 CSS 選擇器 | |
backdropUnique | 布林值 | 啟用時,會為此模式建立獨特的背景元素 | |
closeByBackdropClick | 布林值 | true | 啟用時,動作表單將在背景按一下時關閉。預設繼承相同的應用程式參數值 |
closeByOutsideClick | 布林值 | false | 啟用時,動作表單將在按一下其外部時關閉。預設繼承相同的應用程式參數值 |
closeOnEscape | 布林值 | 啟用時,動作表單將在按下 ESC 鍵盤按鍵時關閉 | |
animate | 布林值 | 模式是否應以動畫開啟/關閉 | |
containerEl | HTMLElement 字串 | 要將模式掛載到的元素(預設為應用程式根元素) | |
<ActionsLabel> 屬性 | |||
strong | 布林值 | false | 定義標籤文字是否為粗體 |
<ActionsButton> 屬性 | |||
strong | 布林值 | false | 定義按鈕文字是否為粗體 |
close | 布林值 | true | 動作表單是否應在按一下按鈕時關閉 |
動作表單事件
事件 | 說明 |
---|---|
<Actions> 事件 | |
actionsOpen | 動作表單開始開啟動畫時,將觸發事件 |
actionsOpened | 動作表單完成開啟動畫後,將觸發事件 |
actionsClose | 當動作表開始其關閉動畫時,將觸發事件 |
actionsClosed | 在動作表完成其關閉動畫後,將觸發事件 |
開啟和關閉動作表
除了動作表的 open()/close() 方法之外,您還可以開啟和關閉它
- 使用 動作表 API
- 通過將
true
或false
傳遞給其opened
屬性
存取動作表實例
您可以透過呼叫元件的 .instance()
方法存取動作表初始化的實例。例如
<Actions bind:this={component}>...</Actions>
<script>
let component;
// to get instance in some method
component.instance()
</script>
範例
action-sheet.svelte
<script>
import { onDestroy } from 'svelte';
import {
f7,
Navbar,
Page,
BlockTitle,
Block,
Button,
Actions,
ActionsGroup,
ActionsLabel,
ActionsButton,
} from 'framework7-svelte';
let actionsOneGroupOpened = false;
let actionGridOpened = false;
let actionsToPopover;
let buttonToPopoverWrapper;
function openActionsPopover() {
if (!actionsToPopover) {
actionsToPopover = 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.querySelector('.button-to-popover'),
});
}
// Open
actionsToPopover.open();
}
onDestroy(() => {
if (actionsToPopover) {
actionsToPopover.destroy();
}
});
</script>
<!-- svelte-ignore a11y-missing-attribute -->
<Page>
<Navbar title="Action Sheet" />
<Block strong inset>
<p class="grid grid-cols-2 grid-gap">
<!-- One group, open by direct accessing instance .open() method -->
<Button
fill
onClick={() => {
actionsOneGroupOpened = 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 actionGridOpened state property -->
<Button
fill
onClick={() => {
actionGridOpened = true;
}}
>
Action Grid
</Button>
</p>
</Block>
<BlockTitle>Action Sheet To Popover</BlockTitle>
<Block strong inset>
<p bind:this={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" class="button-to-popover" onClick={openActionsPopover}>
Actions
</Button>
</p>
</Block>
<!-- One Group -->
<Actions bind:opened={actionsOneGroupOpened}>
<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} bind:opened={actionGridOpened}>
<ActionsGroup>
<ActionsButton>
<img
slot="media"
src="https://cdn.framework7.io/placeholder/people-96x96-1.jpg"
width="48"
style="max-width: 100%; border-radius: 8px"
/>
<span>Button 1</span>
</ActionsButton>
<ActionsButton>
<img
slot="media"
src="https://cdn.framework7.io/placeholder/people-96x96-2.jpg"
width="48"
style="max-width: 100%; border-radius: 8px"
/>
<span>Button 2</span>
</ActionsButton>
<ActionsButton>
<img
slot="media"
src="https://cdn.framework7.io/placeholder/people-96x96-3.jpg"
width="48"
style="max-width: 100%; border-radius: 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="max-width: 100%; border-radius: 8px"
/>
<span>Button 4</span>
</ActionsButton>
<ActionsButton>
<img
slot="media"
src="https://cdn.framework7.io/placeholder/fashion-96x96-5.jpg"
width="48"
style="max-width: 100%; border-radius: 8px"
/>
<span>Button 5</span>
</ActionsButton>
<ActionsButton>
<img
slot="media"
src="https://cdn.framework7.io/placeholder/fashion-96x96-6.jpg"
width="48"
style="max-width: 100%; border-radius: 8px"
/>
<span>Button 6</span>
</ActionsButton>
</ActionsGroup>
</Actions>
</Page>