Action Sheet / Actions - 图1

Action Sheet Svelte Component

Action Sheet is a slide-up pane for presenting the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt the user to confirm a potentially dangerous action. The action sheet contains an optional title and one or more buttons, each of which corresponds to an action to take.

Action Sheet Svelte component represents Action Sheet component.

Action Sheet Components

There are following components included:

  • Actions - action sheet element
  • ActionsGroup - action sheet buttons group
  • ActionsButton - action sheet button
  • ActionsLabel - action sheet label

Action Sheet Properties

Prop Type Default Description
<Actions> properties
--- --- --- ---
opened boolean false Allows to open/close Action Sheet and set its initial state
grid boolean false Enables grid buttons layout
convertToPopover boolean When enabled, action sheet will be converted to Popover on large screens. By default inherits same app parameter value
forceToPopover boolean When enabled, action sheel will be always converted to Popover. By default inherits same app parameter value
target HTMLElement string HTML element or string CSS selector of target element. Required when converstion to popover is in use
backdrop boolean Enables action sheet backdrop (dark semi transparent layer behind). By default inherits same app parameter value (true)
backdropEl string object HTML element or string CSS selector of custom backdrop element
closeByBackdropClick boolean true When enabled, action sheet will be closed on backdrop click. By default inherits same app parameter value
closeByOutsideClick boolean false When enabled, action sheet will be closed on when click outside of it. By default inherits same app parameter value
closeOnEscape boolean When enabled, action sheet will be closed on ESC keyboard key press
<ActionsLabel> properties
bold boolean false Defines whether the label text is bold or not
<ActionsButton> properties
bold boolean false Defines whether the button text is bold or not
close boolean true Should Action Sheet be closed on button click or not

Action Sheet Methods

<Actions> methods
.open(animate) Open Action Sheet
.close(animate) Close Action Sheet

Action Sheet Events

Event Description
<Actions> events
--- ---
actionsOpen Event will be triggered when Action Sheet starts its opening animation
actionsOpened Event will be triggered after Action Sheet completes its opening animation
actionsClose Event will be triggered when Action Sheet starts its closing animation
actionsClosed Event will be triggered after Action Sheet completes its closing animation

Open And Close Action Sheet

In addition to Action Sheet open()/close() methods, you can open and close it:

Access To Action Sheet Instance

You can access Action Sheet initialized instance by calling .instance() component’s method. For example:

1. <Actions bind:this={component}>...</Actions>

3. <script>
4. let component;

6. // to get instance in some method
7. component.instance()
8. </script>

Examples

1. <Page>
2. <Navbar title="Action Sheet" />
3. <Block strong>
4. <p class="row">
5. <!-- One group, open by direct accessing instance .open() method -->
6. <Button class="col" raised onClick={() => actionsOneGroup.open()}>One group</Button>
7. <!--  Two groups, open by "actionsOpen" attribute -->
8. <Button class="col" raised actionsOpen="#actions-two-groups">Two groups</Button>
9. </p>
10. <p>
11. <!-- Actions Grid, open by changing actionGridOpened state property -->
12. <Button raised onClick={() => actionGridOpened = true}>Action Grid</Button>
13. </p>
14. </Block>

16. <BlockTitle>Action Sheet To Popover</BlockTitle>
17. <Block strong>
18. <p bind:this={buttonToPopoverWrapper}>
19. Action Sheet can be automatically converted to Popover (for tablets). This button will open Popover on tablets and Action Sheet on phones:
20. <Button
21. style="display: inline-block"
22. class="button-to-popover"
23. onClick={openActionsPopover}
24. >
25. Actions
26. </Button>
27. </p>
28. </Block>

30. <!-- One Group -->
31. <Actions bind:this={actionsOneGroup}>
32. <ActionsGroup>
33. <ActionsLabel>Do something</ActionsLabel>
34. <ActionsButton bold>Button 1</ActionsButton>
35. <ActionsButton>Button 2</ActionsButton>
36. <ActionsButton color="red">Cancel</ActionsButton>
37. </ActionsGroup>
38. </Actions>

40. <!-- Two Groups -->
41. <Actions id="actions-two-groups">
42. <ActionsGroup>
43. <ActionsLabel>Do something</ActionsLabel>
44. <ActionsButton bold>Button 1</ActionsButton>
45. <ActionsButton>Button 2</ActionsButton>
46. </ActionsGroup>
47. <ActionsGroup>
48. <ActionsButton color="red">Cancel</ActionsButton>
49. </ActionsGroup>
50. </Actions>

52. <!-- Grid -->
53. <Actions grid={true} opened={actionGridOpened} onActionsClosed={() => actionGridOpened = false}>
54. <ActionsGroup>
55. <ActionsButton>
56. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-1.jpg" width="48"/>
57. <span>Button 1</span>
58. </ActionsButton>
59. <ActionsButton>
60. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-2.jpg" width="48"/>
61. <span>Button 2</span>
62. </ActionsButton>
63. <ActionsButton>
64. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-3.jpg" width="48"/>
65. <span>Button 3</span>
66. </ActionsButton>
67. </ActionsGroup>
68. <ActionsGroup>
69. <ActionsButton>
70. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-4.jpg" width="48"/>
71. <span>Button 4</span>
72. </ActionsButton>
73. <ActionsButton>
74. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-5.jpg" width="48"/>
75. <span>Button 5</span>
76. </ActionsButton>
77. <ActionsButton>
78. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-6.jpg" width="48"/>
79. <span>Button 6</span>
80. </ActionsButton>
81. </ActionsGroup>
82. </Actions>
83. </Page>

86. <script>
87. import { onDestroy } from 'svelte';
88. import { f7, Page, Navbar, Block, BlockTitle, Button, Actions, ActionsGroup, ActionsLabel, ActionsButton } from 'framework7-svelte';

90. let actionGridOpened = false;
91. let actionsOneGroup;
92. let actionsToPopover = null;
93. let buttonToPopoverWrapper;

95. onDestroy(() => {
96. if (actionsToPopover) {
97. actionsToPopover.destroy();
98. }
99. })

101. function openActionsPopover() {
102. if (!actionsToPopover) {
103. actionsToPopover = f7.actions.create({
104. buttons: [
105. {
106. text: 'Do something',
107. label: true,
108. },
109. {
110. text: 'Button 1',
111. bold: true,
112. },
113. {
114. text: 'Button 2',
115. },
116. {
117. text: 'Cancel',
118. color: 'red',
119. },
120. ],
121. // Need to specify popover target
122. targetEl: buttonToPopoverWrapper.querySelector('.button-to-popover'),
123. });
124. }

126. // Open
127. actionsToPopover.open();
128. }

130. </script>

← Accordion

Appbar →