Sheet Modal - 图1

Sheet Modal React Component

Sheet Modal is a special overlay type which is similar to Picker/Calendar’s overlay. Such modal allows to create custom picker overlays with custom content.

Sheet Modal React component represents Sheet Modal component.

Sheet Modal Components

There are following components included:

  • Sheet / F7Sheet - sheet modal element

Sheet Modal Properties

PropTypeDescription
<Sheet> properties
positionstringSheet position, can be top or bottom. By default is bottom
topbooleanSame as position=”top”
bottombooleanSame as position=”bottom”
backdropbooleanEnable to render additional sheet modal backdrop when required
backdropElstring
object
HTML element or string CSS selector of custom backdrop element
openedbooleanAllows to open/close Sheet Modal and set its initial state
closeByBackdropClickbooleanWhen enabled, sheet will be closed on backdrop click. By default inherits same app parameter value
closeByOutsideClickbooleanWhen enabled, sheet will be closed on when click outside of it. By default inherits same app parameter value
closeOnEscapebooleanWhen enabled, sheet will be closed on ESC keyboard key press
swipeToClosebooleanWhether the Sheet can be closed with swipe gesture
swipeToStepbooleanWhen enabled it will be possible to split opened sheet into two states: partially opened and fully opened that can be controlled with swipe
swipeHandlerHTMLElement
string
If not passed, then whole Sheet can be swiped to close. You can pass here HTML element or string CSS selector of custom element that will be used as a swipe target. (swipeToClose or swipeToStep must be also enabled)
pushbooleanWhen enabled it will push view behind on open. Works only when top safe area is in place. It can also be enabled by adding sheet-modal-push class to Sheet element.

Sheet Modal Methods

<Sheet> methods
.open(animate)Open sheet modal
.close(animate)Close sheet modal

Sheet Modal Events

EventDescription
<Sheet> events
sheetOpenEvent will be triggered when Sheet Modal starts its opening animation
sheetOpenedEvent will be triggered after Sheet Modal completes its opening animation
sheetCloseEvent will be triggered when Sheet Modal starts its closing animation
sheetClosedEvent will be triggered after Sheet Modal completes its closing animation
sheetStepOpenEvent will be triggered on Sheet swipe step open/expand
sheetStepCloseEvent will be triggered on Sheet swipe step close/collapse
sheetStepProgressEvent will be triggered on Sheet swipe step between step opened and closed state. As event.detail it receives step open progress number (from 0 to 1)

Open And Close Sheet Modal

You can control Sheet Modal state, open and closing it:

  • using its Sheet Modal API
  • by passing true or false to its opened prop
  • by clicking on Link or Button with relevant sheetOpen property (to open it) and sheetClose property to close it

Access To Sheet Modal Instance

You can access Sheet Modal initialized instance by accessing .f7Sheet component’s property.

Examples

  1. export default class extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. sheetOpened: false,
  6. };
  7. }
  8. render() {
  9. return (
  10. <Page onPageBeforeOut={this.onPageBeforeOut.bind(this)} onPageBeforeRemove={this.onPageBeforeRemove.bind(this)}>
  11. <Navbar title="Sheet Modal"></Navbar>
  12. <Block>
  13. <p>
  14. <Button fill sheetOpen=".demo-sheet">Open Sheet</Button>
  15. </p>
  16. <p>
  17. <Button fill onClick={this.createSheet.bind(this)}>Create Dynamic Sheet</Button>
  18. </p>
  19. <p>
  20. <Button fill onClick={() => {this.setState({sheetOpened: true})}}>Open Via Prop Change</Button>
  21. </p>
  22. <p>
  23. <Button fill sheetOpen=".demo-sheet-swipe-to-close">Swipe To Close</Button>
  24. </p>
  25. <p>
  26. <Button fill sheetOpen=".demo-sheet-swipe-to-step">Swipe To Step</Button>
  27. </p>
  28. <p>
  29. <Button fill sheetOpen=".demo-sheet-push">Sheet Push</Button>
  30. </p>
  31. </Block>
  32. <Sheet className="demo-sheet" opened={this.state.sheetOpened} onSheetClosed={() => {this.setState({sheetOpened: false})}}>
  33. <Toolbar>
  34. <div className="left"></div>
  35. <div className="right">
  36. <Link sheetClose>Close</Link>
  37. </div>
  38. </Toolbar>
  39. {/* Scrollable sheet content */}
  40. <PageContent>
  41. <Block>
  42. <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae ducimus dolorum ipsa aliquid accusamus perferendis laboriosam...</p>
  43. </Block>
  44. </PageContent>
  45. </Sheet>
  46. {/* Swipe to close demo sheet */}
  47. <Sheet
  48. className="demo-sheet-swipe-to-close"
  49. style={{height: 'auto', '--f7-sheet-bg-color': '#fff'}}
  50. swipeToClose
  51. backdrop
  52. >
  53. <PageContent>
  54. <BlockTitle large>Hello!</BlockTitle>
  55. <Block>
  56. <p>Eaque maiores ducimus, impedit unde culpa qui, explicabo accusamus, non vero corporis voluptatibus similique odit ab. Quaerat quasi consectetur quidem libero? Repudiandae adipisci vel voluptatum, autem libero minus dignissimos repellat.</p>
  57. <p>Iusto, est corrupti! Totam minus voluptas natus esse possimus nobis, delectus veniam expedita sapiente ut cum reprehenderit aliquid odio amet praesentium vero temporibus obcaecati beatae aspernatur incidunt, perferendis voluptates doloribus?</p>
  58. </Block>
  59. </PageContent>
  60. </Sheet>
  61. {/* Swipe to step demo sheet */}
  62. <Sheet
  63. className="demo-sheet-swipe-to-step"
  64. style={{height: 'auto', '--f7-sheet-bg-color': '#fff'}}
  65. swipeToClose
  66. swipeToStep
  67. backdrop
  68. >
  69. {/* Initial swipe step sheet content */}
  70. <div className="sheet-modal-swipe-step">
  71. <div className="display-flex padding justify-content-space-between align-items-center">
  72. <div style={{fontSize: '18px'}}><b>Total:</b></div>
  73. <div style={{fontSize: '22px'}}><b>$500</b></div>
  74. </div>
  75. <div className="padding-horizontal padding-bottom">
  76. <Button large fill>Make Payment</Button>
  77. <div className="margin-top text-align-center">Swipe up for more details</div>
  78. </div>
  79. </div>
  80. {/* Rest of the sheet content that will opened with swipe */}
  81. <BlockTitle medium className="margin-top">Your order:</BlockTitle>
  82. <List noHairlines>
  83. <ListItem title="Item 1">
  84. <b slot="after" className="text-color-black">$200</b>
  85. </ListItem>
  86. <ListItem title="Item 2">
  87. <b slot="after" className="text-color-black">$180</b>
  88. </ListItem>
  89. <ListItem title="Delivery">
  90. <b slot="after" className="text-color-black">$120</b>
  91. </ListItem>
  92. </List>
  93. </Sheet>
  94. {/* Sheet Push */}
  95. <Sheet className="demo-sheet-push" push>
  96. <Toolbar>
  97. <div className="left"></div>
  98. <div className="right">
  99. <Link sheetClose>Close</Link>
  100. </div>
  101. </Toolbar>
  102. <PageContent>
  103. <Block>
  104. <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
  105. </Block>
  106. </PageContent>
  107. </Sheet>
  108. </Page>
  109. );
  110. }
  111. createSheet() {
  112. const self = this;
  113. const $ = self.$$;
  114. // Create sheet modal
  115. if (!self.sheet) {
  116. self.sheet = self.$f7.sheet.create({
  117. content: `
  118. <div class="sheet-modal">
  119. <div class="toolbar">
  120. <div class="toolbar-inner justify-content-flex-end">
  121. <a href="#" class="link sheet-close">Close</a>
  122. </div>
  123. </div>
  124. <div class="sheet-modal-inner">
  125. <div class="page-content">
  126. <div class="block">
  127. <p>This sheet modal was created dynamically</p>
  128. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. `.trim(),
  134. });
  135. }
  136. // Close inline sheet
  137. if ($('.demo-sheet.modal-in').length > 0) self.$f7.sheet.close('.demo-sheet');
  138. // Open it
  139. self.sheet.open();
  140. }
  141. onPageBeforeOut() {
  142. const self = this;
  143. // Close opened sheets on page out
  144. self.$f7.sheet.close();
  145. }
  146. onPageBeforeRemove() {
  147. const self = this;
  148. // Destroy sheet modal when page removed
  149. if (self.sheet) self.sheet.destroy();
  150. }
  151. };

← Searchbar

Skeleton →