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

PropTypeDefaultDescription
<Actions> properties
openedbooleanfalseAllows to open/close Action Sheet and set its initial state
gridbooleanfalseEnables grid buttons layout
convertToPopoverbooleanWhen enabled, action sheet will be converted to Popover on large screens. By default inherits same app parameter value
forceToPopoverbooleanWhen enabled, action sheel will be always converted to Popover. By default inherits same app parameter value
targetHTMLElement
string
HTML element or string CSS selector of target element. Required when converstion to popover is in use
backdropbooleanEnables action sheet backdrop (dark semi transparent layer behind). By default inherits same app parameter value (true)
backdropElstring
object
HTML element or string CSS selector of custom backdrop element
closeByBackdropClickbooleantrueWhen enabled, action sheet will be closed on backdrop click. By default inherits same app parameter value
closeByOutsideClickbooleanfalseWhen enabled, action sheet will be closed on when click outside of it. By default inherits same app parameter value
closeOnEscapebooleanWhen enabled, action sheet will be closed on ESC keyboard key press
<ActionsLabel> properties
boldbooleanfalseDefines whether the label text is bold or not
<ActionsButton> properties
boldbooleanfalseDefines whether the button text is bold or not
closebooleantrueShould 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

EventDescription
<Actions> events
actionsOpenEvent will be triggered when Action Sheet starts its opening animation
actionsOpenedEvent will be triggered after Action Sheet completes its opening animation
actionsCloseEvent will be triggered when Action Sheet starts its closing animation
actionsClosedEvent 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>
  2. <script>
  3. let component;
  4. // to get instance in some method
  5. component.instance()
  6. </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>
  15. <BlockTitle>Action Sheet To Popover</BlockTitle>
  16. <Block strong>
  17. <p bind:this={buttonToPopoverWrapper}>
  18. Action Sheet can be automatically converted to Popover (for tablets). This button will open Popover on tablets and Action Sheet on phones:
  19. <Button
  20. style="display: inline-block"
  21. class="button-to-popover"
  22. onClick={openActionsPopover}
  23. >
  24. Actions
  25. </Button>
  26. </p>
  27. </Block>
  28. <!-- One Group -->
  29. <Actions bind:this={actionsOneGroup}>
  30. <ActionsGroup>
  31. <ActionsLabel>Do something</ActionsLabel>
  32. <ActionsButton bold>Button 1</ActionsButton>
  33. <ActionsButton>Button 2</ActionsButton>
  34. <ActionsButton color="red">Cancel</ActionsButton>
  35. </ActionsGroup>
  36. </Actions>
  37. <!-- Two Groups -->
  38. <Actions id="actions-two-groups">
  39. <ActionsGroup>
  40. <ActionsLabel>Do something</ActionsLabel>
  41. <ActionsButton bold>Button 1</ActionsButton>
  42. <ActionsButton>Button 2</ActionsButton>
  43. </ActionsGroup>
  44. <ActionsGroup>
  45. <ActionsButton color="red">Cancel</ActionsButton>
  46. </ActionsGroup>
  47. </Actions>
  48. <!-- Grid -->
  49. <Actions grid={true} opened={actionGridOpened} onActionsClosed={() => actionGridOpened = false}>
  50. <ActionsGroup>
  51. <ActionsButton>
  52. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-1.jpg" width="48"/>
  53. <span>Button 1</span>
  54. </ActionsButton>
  55. <ActionsButton>
  56. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-2.jpg" width="48"/>
  57. <span>Button 2</span>
  58. </ActionsButton>
  59. <ActionsButton>
  60. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-3.jpg" width="48"/>
  61. <span>Button 3</span>
  62. </ActionsButton>
  63. </ActionsGroup>
  64. <ActionsGroup>
  65. <ActionsButton>
  66. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-4.jpg" width="48"/>
  67. <span>Button 4</span>
  68. </ActionsButton>
  69. <ActionsButton>
  70. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-5.jpg" width="48"/>
  71. <span>Button 5</span>
  72. </ActionsButton>
  73. <ActionsButton>
  74. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-6.jpg" width="48"/>
  75. <span>Button 6</span>
  76. </ActionsButton>
  77. </ActionsGroup>
  78. </Actions>
  79. </Page>
  80. <script>
  81. import { onDestroy } from 'svelte';
  82. import { f7, Page, Navbar, Block, BlockTitle, Button, Actions, ActionsGroup, ActionsLabel, ActionsButton } from 'framework7-svelte';
  83. let actionGridOpened = false;
  84. let actionsOneGroup;
  85. let actionsToPopover = null;
  86. let buttonToPopoverWrapper;
  87. onDestroy(() => {
  88. if (actionsToPopover) {
  89. actionsToPopover.destroy();
  90. }
  91. })
  92. function openActionsPopover() {
  93. if (!actionsToPopover) {
  94. actionsToPopover = f7.actions.create({
  95. buttons: [
  96. {
  97. text: 'Do something',
  98. label: true,
  99. },
  100. {
  101. text: 'Button 1',
  102. bold: true,
  103. },
  104. {
  105. text: 'Button 2',
  106. },
  107. {
  108. text: 'Cancel',
  109. color: 'red',
  110. },
  111. ],
  112. // Need to specify popover target
  113. targetEl: buttonToPopoverWrapper.querySelector('.button-to-popover'),
  114. });
  115. }
  116. // Open
  117. actionsToPopover.open();
  118. }
  119. </script>

← Accordion

Appbar →