Action Sheet / Actions - 图1

Action Sheet React 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 React component represents Action Sheet component.

Action Sheet Components

There are following components included:

  • Actions / F7Actions - action sheet element
  • ActionsGroup / F7ActionsGroup - action sheet buttons group
  • ActionsButton / F7ActionsButton - action sheet button
  • ActionsLabel / F7ActionsLabel - 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 accessing .f7Actions component’s property.

Examples

  1. export default class extends React.Component {
  2. constructor() {
  3. super();
  4. this.state = {
  5. actionGridOpened: false,
  6. oneGroupOpened: false
  7. };
  8. }
  9. render() {
  10. return (
  11. <Page>
  12. <Navbar title="Action Sheet"></Navbar>
  13. <Block strong>
  14. <p className="row">
  15. {/* One group, open by direct accessing instance .open() method */}
  16. <Button className="col" raised onClick={() => this.refs.actionsOneGroup.open()}>One group</Button>
  17. {/* Two groups, open by "actionsOpen" attribute */}
  18. <Button className="col" raised actionsOpen="#actions-two-groups">Two groups</Button>
  19. </p>
  20. <p>
  21. {/* Actions Grid, open by changing actionGridOpened state property */}
  22. <Button raised onClick={() => this.setActionsGridOpened(true)}>Action Grid</Button>
  23. </p>
  24. </Block>
  25. <BlockTitle>Action Sheet To Popover</BlockTitle>
  26. <Block strong>
  27. <p ref={e => this.buttonToPopoverWrapper = e}>
  28. Action Sheet can be automatically converted to Popover (for tablets). This button will open Popover on tablets and Action Sheet on phones:
  29. <Button
  30. style={{ display: 'inline-block' }}
  31. className="button-to-popover"
  32. onClick={this.openActionsPopover.bind(this)}>
  33. Actions
  34. </Button>
  35. </p>
  36. </Block>
  37. {/* One Group */}
  38. <Actions ref="actionsOneGroup">
  39. <ActionsGroup>
  40. <ActionsLabel>Do something</ActionsLabel>
  41. <ActionsButton bold>Button 1</ActionsButton>
  42. <ActionsButton>Button 2</ActionsButton>
  43. <ActionsButton color="red">Cancel</ActionsButton>
  44. </ActionsGroup>
  45. </Actions>
  46. {/* Two Groups */}
  47. <Actions id="actions-two-groups">
  48. <ActionsGroup>
  49. <ActionsLabel>Do something</ActionsLabel>
  50. <ActionsButton bold>Button 1</ActionsButton>
  51. <ActionsButton>Button 2</ActionsButton>
  52. </ActionsGroup>
  53. <ActionsGroup>
  54. <ActionsButton color="red">Cancel</ActionsButton>
  55. </ActionsGroup>
  56. </Actions>
  57. {/* Grid */}
  58. <Actions grid={true} opened={this.state.actionGridOpened} onActionsClosed={() => this.setActionsGridOpened(false)}>
  59. <ActionsGroup>
  60. <ActionsButton>
  61. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-1.jpg" width="48"/>
  62. <span>Button 1</span>
  63. </ActionsButton>
  64. <ActionsButton>
  65. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-2.jpg" width="48"/>
  66. <span>Button 2</span>
  67. </ActionsButton>
  68. <ActionsButton>
  69. <img slot="media" src="https://cdn.framework7.io/placeholder/people-96x96-3.jpg" width="48"/>
  70. <span>Button 3</span>
  71. </ActionsButton>
  72. </ActionsGroup>
  73. <ActionsGroup>
  74. <ActionsButton>
  75. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-4.jpg" width="48"/>
  76. <span>Button 4</span>
  77. </ActionsButton>
  78. <ActionsButton>
  79. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-5.jpg" width="48"/>
  80. <span>Button 5</span>
  81. </ActionsButton>
  82. <ActionsButton>
  83. <img slot="media" src="https://cdn.framework7.io/placeholder/fashion-96x96-6.jpg" width="48"/>
  84. <span>Button 6</span>
  85. </ActionsButton>
  86. </ActionsGroup>
  87. </Actions>
  88. </Page>
  89. )
  90. }
  91. componentWillUnmount() {
  92. if (this.actionsToPopover) {
  93. this.actionsToPopover.destroy();
  94. }
  95. }
  96. openActionsPopover() {
  97. const app = this.$f7;
  98. if (!this.actionsToPopover) {
  99. this.actionsToPopover = app.actions.create({
  100. buttons: [
  101. {
  102. text: 'Do something',
  103. label: true,
  104. },
  105. {
  106. text: 'Button 1',
  107. bold: true,
  108. },
  109. {
  110. text: 'Button 2',
  111. },
  112. {
  113. text: 'Cancel',
  114. color: 'red',
  115. },
  116. ],
  117. // Need to specify popover target
  118. targetEl: this.buttonToPopoverWrapper.querySelector('.button-to-popover'),
  119. });
  120. }
  121. // Open
  122. this.actionsToPopover.open();
  123. }
  124. setOneGroupOpened(oneGroupOpened) {
  125. this.setState({
  126. oneGroupOpened
  127. });
  128. }
  129. setActionsGridOpened(actionGridOpened) {
  130. this.setState({
  131. actionGridOpened
  132. });
  133. }
  134. }

← Accordion

Appbar →