操作表 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
- 通过将其
opened
属性传递true
或false
访问操作表实例
您可以通过调用 .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>