
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
| Prop | Type | Description |
|---|---|---|
| <Sheet> properties | ||
| --- | --- | --- |
| position | string | Sheet position, can be top or bottom. By default is bottom |
| top | boolean | Same as position="top" |
| bottom | boolean | Same as position="bottom" |
| backdrop | boolean | Enable to render additional sheet modal backdrop when required |
| backdropEl | string object | HTML element or string CSS selector of custom backdrop element |
| opened | boolean | Allows to open/close Sheet Modal and set its initial state |
| closeByBackdropClick | boolean | When enabled, sheet will be closed on backdrop click. By default inherits same app parameter value |
| closeByOutsideClick | boolean | When enabled, sheet will be closed on when click outside of it. By default inherits same app parameter value |
| closeOnEscape | boolean | When enabled, sheet will be closed on ESC keyboard key press |
| swipeToClose | boolean | Whether the Sheet can be closed with swipe gesture |
| swipeToStep | boolean | When enabled it will be possible to split opened sheet into two states: partially opened and fully opened that can be controlled with swipe |
| swipeHandler | HTMLElement 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) |
Sheet Modal Methods
| <Sheet> methods | |
|---|---|
| .open(animate) | Open sheet modal |
| .close(animate) | Close sheet modal |
Sheet Modal Events
| Event | Description |
|---|---|
| <Sheet> events | |
| --- | --- |
| sheetOpen | Event will be triggered when Sheet Modal starts its opening animation |
| sheetOpened | Event will be triggered after Sheet Modal completes its opening animation |
| sheetClose | Event will be triggered when Sheet Modal starts its closing animation |
| sheetClosed | Event will be triggered after Sheet Modal completes its closing animation |
| sheetStepOpen | Event will be triggered on Sheet swipe step open/expand |
| sheetStepClose | Event will be triggered on Sheet swipe step close/collapse |
| sheetStepProgress | Event 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
trueorfalseto itsopenedprop - by clicking on Link or Button with relevant
sheetOpenproperty (to open it) andsheetCloseproperty 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);
5. this.state = {
6. sheetOpened: false,
7. };
8. }
9. render() {
10. return (
11. <Page onPageBeforeOut={this.onPageBeforeOut.bind(this)} onPageBeforeRemove={this.onPageBeforeRemove.bind(this)}>
12. <Navbar title="Sheet Modal"></Navbar>
14. <Block>
15. <p>
16. <Button fill sheetOpen=".demo-sheet">Open Sheet</Button>
17. </p>
18. <p>
19. <Button fill onClick={this.createSheet.bind(this)}>Create Dynamic Sheet</Button>
20. </p>
21. <p>
22. <Button fill onClick={() => {this.setState({sheetOpened: true})}}>Open Via Prop Change</Button>
23. </p>
24. <p>
25. <Button fill sheetOpen=".demo-sheet-swipe-to-close">Swipe To Close</Button>
26. </p>
27. <p>
28. <Button fill sheetOpen=".demo-sheet-swipe-to-step">Swipe To Step</Button>
29. </p>
30. </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>
47. {/* Swipe to close demo sheet */}
48. <Sheet
49. className="demo-sheet-swipe-to-close"
50. style={{height: 'auto', '--f7-sheet-bg-color': '#fff'}}
51. swipeToClose
52. backdrop
53. >
54. <PageContent>
55. <BlockTitle large>Hello!</BlockTitle>
56. <Block>
57. <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>
58. <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>
59. </Block>
60. </PageContent>
61. </Sheet>
63. {/* Swipe to step demo sheet */}
64. <Sheet
65. className="demo-sheet-swipe-to-step"
66. style={{height: 'auto', '--f7-sheet-bg-color': '#fff'}}
67. swipeToClose
68. swipeToStep
69. backdrop
70. >
71. {/* Initial swipe step sheet content */}
72. <div className="sheet-modal-swipe-step">
73. <div className="display-flex padding justify-content-space-between align-items-center">
74. <div style={{fontSize: '18px'}}><b>Total:</b></div>
75. <div style={{fontSize: '22px'}}><b>$500</b></div>
76. </div>
77. <div className="padding-horizontal padding-bottom">
78. <Button large fill>Make Payment</Button>
79. <div className="margin-top text-align-center">Swipe up for more details</div>
80. </div>
81. </div>
82. {/* Rest of the sheet content that will opened with swipe */}
83. <BlockTitle medium className="margin-top">Your order:</BlockTitle>
84. <List noHairlines>
85. <ListItem title="Item 1">
86. <b slot="after" className="text-color-black">$200</b>
87. </ListItem>
88. <ListItem title="Item 2">
89. <b slot="after" className="text-color-black">$180</b>
90. </ListItem>
91. <ListItem title="Delivery">
92. <b slot="after" className="text-color-black">$120</b>
93. </ListItem>
94. </List>
95. </Sheet>
96. </Page>
97. );
98. }
99. createSheet() {
100. const self = this;
101. const $ = self.$$;
102. // Create sheet modal
103. if (!self.sheet) {
104. self.sheet = self.$f7.sheet.create({
105. content: `
106. <div class="sheet-modal">
107. <div class="toolbar">
108. <div class="toolbar-inner justify-content-flex-end">
109. <a href="#" class="link sheet-close">Close</a>
110. </div>
111. </div>
112. <div class="sheet-modal-inner">
113. <div class="page-content">
114. <div class="block">
115. <p>This sheet modal was created dynamically</p>
116. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
117. </div>
118. </div>
119. </div>
120. </div>
121. `.trim(),
122. });
123. }
124. // Close inline sheet
125. if ($('.demo-sheet.modal-in').length > 0) self.$f7.sheet.close('.demo-sheet');
126. // Open it
127. self.sheet.open();
128. }
129. onPageBeforeOut() {
130. const self = this;
131. // Close opened sheets on page out
132. self.$f7.sheet.close();
133. }
134. onPageBeforeRemove() {
135. const self = this;
136. // Destroy sheet modal when page removed
137. if (self.sheet) self.sheet.destroy();
138. }
139. };
