Sheet Modal - 图1

Sheet Modal

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

Sheet Layout

Sheet layout is pretty simple:

1. <body>
2. ...
3. <!-- Sheet Modal Container -->
4. <div class="sheet-modal">
5. <!-- Sheet Modal Toolbar, optional -->
6. <div class="toolbar">
7. <div class="toolbar-inner">
8. <div class="left"></div>
9. <div class="right">
10. <a href="#" class="link sheet-close">Done</a>
11. </div>
12. </div>
13. </div>
14. <!-- Sheet Modal Inner -->
15. <div class="sheet-modal-inner">
16. <!-- Sheet Modal content -->
17. <div class="block">
18. <p>Integer mollis nulla id nibh elementum finibus...</p>
19. </div>
20. </div>
21. </div>

23. </body>

Sheet Top Layout

By default sheet modal opens from the bottom of the screen. It is also possible to open it from the top of the screen. In this case we need to add sheet-modal-top class to sheet element. It is also recommended to use bottom toolbar in this case:

1. <!-- Additional "sheet-modal-top" class to open it from top -->
2. <div class="sheet-modal sheet-modal-top">
3. <!-- Bottom toolbar for top sheet -->
4. <div class="toolbar toolbar-bottom">
5. <div class="toolbar-inner">
6. <div class="left"></div>
7. <div class="right">
8. <a href="#" class="link sheet-close">Done</a>
9. </div>
10. </div>
11. </div>
12. <!-- Sheet Modal Inner -->
13. <div class="sheet-modal-inner">
14. <!-- Sheet Modal content -->
15. <div class="block">
16. <p>Integer mollis nulla id nibh elementum finibus...</p>
17. </div>
18. </div>
19. </div>

Sheet App Methods

Let’s look at related App methods to work with Sheet:

app.sheet.create(parameters)- create Sheet instance

  • parameters - object. Object with sheet parameters

Method returns created Sheet’s instance

app.sheet.destroy(el)- destroy Sheet instance

  • el - HTMLElement or string (with CSS Selector) or object. Sheet element or Sheet instance to destroy.

app.sheet.get(el)- get Sheet instance by HTML element

  • el - HTMLElement or string (with CSS Selector). Sheet element.

Method returns Sheet’s instance

app.sheet.open(el, animate)- opens Sheet

  • el - HTMLElement or string (with CSS Selector). Sheet element to open.
  • animate - boolean. Open Sheet with animation.

Method returns Sheet’s instance

app.sheet.close(el, animate)- closes Sheet

  • el - HTMLElement or string (with CSS Selector). Sheet element to close.
  • animate - boolean. Close Sheet with animation.

Method returns Sheet’s instance

app.sheet.stepOpen(el)- open/expand Sheet swipe step

  • el - HTMLElement or string (with CSS Selector). Sheet element to open swipe step.

Method returns Sheet’s instance

app.sheet.stepClose(el)- close/collapse Sheet swipe step

  • el - HTMLElement or string (with CSS Selector). Sheet element to close swipe step.

Method returns Sheet’s instance

app.sheet.stepToggle(el)- toggle (open or close) Sheet swipe step

  • el - HTMLElement or string (with CSS Selector). Sheet element to toggle swipe step.

Method returns Sheet’s instance

Sheet Parameters

Now let’s look at list of available parameters we need to create Sheet:

Parameter Type Default Description
el HTMLElement Sheet element. Can be useful if you already have Sheet element in your HTML and want to create new instance using this element
content string Full Sheet HTML layout string. Can be useful if you want to create Sheet element dynamically
backdrop boolean Enables Sheet backdrop (dark semi transparent layer behind). By default it is true for MD and Aurora themes and false for iOS theme
backdropEl HTMLElement string HTML element or string CSS selector of custom backdrop element
scrollToEl HTMLElement string HTML element or string (with CSS selector) of element. If specified, then sheet will try to scroll page content to this element on open
closeByBackdropClick boolean true When enabled will be closed on backdrop click
closeByOutsideClick boolean false When enabled will be closed on when click outside of it
closeOnEscape boolean false When enabled will be closed on ESC keyboard key press
animate boolean true Whether the Sheet should be opened/closed with animation or not. Can be overwritten in .open() and .close() methods
swipeToClose boolean false Whether the Sheet can be closed with swipe gesture
swipeToStep boolean false 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)
push boolean false When 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.
on object Object with events handlers. For example: 1. var sheet = app.sheet.create({ 2. content: ‘<div class=”sheet-modal”>…</div>’, 3. on: { 4. opened: function () { 5. console.log(‘Sheet opened’) 6. } 7. } 8. })

Note that all following parameters can be used in global app parameters under sheet property to set defaults for all sheets. For example:

1. var app = new Framework7({
2. sheet: {
3. closeByBackdropClick: false,
4. }
5. });

If you use auto-initialized sheet modals (e.g. you don’t create them via app.sheet.create), it is possible to pass all available sheet parameters via data- attributes. For example:

1. <!-- Pass parameters as kebab-case data attributes -->
2. <div class="sheet-modal" data-close-on-escape="true" data-swipe-to-close="true">
3. ...
4. </div>

Sheet Methods & Properties

So to create Sheet we have to call:

1. var sheet = app.sheet.create({ /* parameters */ })

After that we have its initialized instance (like sheet variable in example above) with useful methods and properties:

Properties
sheet.app Link to global app instance
sheet.el Sheet HTML element
sheet.$el Dom7 instance with sheet HTML element
sheet.backdropEl Backdrop HTML element
sheet.$backdropEl Dom7 instance with backdrop HTML element
sheet.params Sheet parameters
sheet.opened Boolean prop indicating whether sheet is opened or not
Methods
sheet.open(animate) Open sheet. Where - animate - boolean (by default true) - defines whether it should be opened with animation
sheet.close(animate) Close sheet. Where - animate - boolean (by default true) - defines whether it should be closed with animation
sheet.stepOpen() Open/expand sheet swipe step
sheet.stepClose() Close/collapse sheet swipe step
sheet.stepToggle() Toggle (open or close) sheet swipe step
sheet.setSwipeSet() Update step position. Required to call after content of sheet modal has been modified manually when it is opened
sheet.destroy() Destroy sheet
sheet.on(event, handler) Add event handler
sheet.once(event, handler) Add event handler that will be removed after it was fired
sheet.off(event, handler) Remove event handler
sheet.off(event) Remove all handlers for specified event
sheet.emit(event, …args) Fire event on instance

It is possible to open and close required sheet (if you have them in DOM) using special classes and data attributes on links:

  • To open sheet we need to add “sheet-open“ class to any HTML element (prefered to link)
  • To close sheet we need to add “sheet-close“ class to any HTML element (prefered to link)
  • If you have more than one sheet in DOM, you need to specify appropriate sheet via additional data-sheet=”.my-sheet” attribute on this HTML element

According to above note:

1. <!-- In data-sheet attribute we specify CSS selector of sheet we need to open -->
2. <p><a href="#" data-sheet=".my-sheet" class="sheet-open">Open Sheet</a></p>

4. <!-- And somewhere in DOM -->
5. <div class="sheet-modal my-sheet">
6. <div class="sheet-modal-inner">
7. <!-- Link to close sheet -->
8. <a class="link sheet-close">Close</a>
9. </div>
10. </div>

Swipe Step

If you pass swipeToStep parameter, then sheet will be opened partially, and with swipe it can be further expanded. To make it work, we also need to define that first/initial step in sheet HTML, so Framework7 can know on how much Sheet should be opened.

To make it work, we need to wrap initial Sheet content with <div class="sheet-modal-swipe-step"> element, and set height:auto on that Sheet modal:

1. <div class="sheet-modal" style="height: auto">
2. <div class="sheet-modal-inner">
3. <!-- initial sheet modal content -->
4. <div class="sheet-modal-swipe-step">
5. ...
6. </div>
7. <!-- rest of the content that will be opened with extra swipe -->
8. ...
9. </div>
10. </div>

For top-positioned Sheet modal, this swipe step should be at the bottom:

1. <div class="sheet-modal sheet-modal-top" style="height: auto">
2. <div class="sheet-modal-inner">
3. <!-- rest of the content that will be opened with extra swipe -->
4. ...
5. <!-- initial sheet modal content -->
6. <div class="sheet-modal-swipe-step">
7. ...
8. </div>
9. </div>
10. </div>

Sheet Events

Sheet will fire the following DOM events on sheet element and events on app and sheet instance:

DOM Events

Event Target Description
sheet:open Sheet Element<div class=”sheet”> Event will be triggered when Sheet starts its opening animation
sheet:opened Sheet Element<div class=”sheet”> Event will be triggered after Sheet completes its opening animation
sheet:close Sheet Element<div class=”sheet”> Event will be triggered when Sheet starts its closing animation
sheet:closed Sheet Element<div class=”sheet”> Event will be triggered after Sheet completes its closing animation
sheet:stepopen Sheet Element<div class=”sheet”> Event will be triggered on Sheet swipe step open/expand
sheet:stepclose Sheet Element<div class=”sheet”> Event will be triggered on Sheet swipe step close/collapse
sheet:stepprogress Sheet Element<div class=”sheet”> 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)

App and Sheet Instance Events

Sheet instance emits events on both self instance and app instance. App instance events has same names prefixed with popup.

Event Arguments Target Description
open sheet sheet Event will be triggered when Sheet starts its opening animation. As an argument event handler receives sheet instance
sheetOpen sheet app
opened sheet sheet Event will be triggered after Sheet completes its opening animation. As an argument event handler receives sheet instance
sheetOpened sheet app
close sheet sheet Event will be triggered when Sheet starts its closing animation. As an argument event handler receives sheet instance
sheetClose sheet app
closed sheet sheet Event will be triggered after Sheet completes its closing animation. As an argument event handler receives sheet instance
sheetClosed sheet app
beforeDestroy sheet sheet Event will be triggered right before Sheet instance will be destroyed. As an argument event handler receives sheet instance
sheetBeforeDestroy sheet app
stepOpen sheet sheet Event will be triggered on Sheet swipe step open/expand
sheetStepOpen sheet app
stepClose sheet sheet Event will be triggered on Sheet swipe step close/collapse
sheetStepClose sheet app
stepProgress sheet,progress sheet Event will be triggered on Sheet swipe step between step opened and closed state. As progress it receives step open progress number (from 0 to 1)
sheetStepProgress sheet,progress app

CSS Variables

Below is the list of related CSS variables (CSS custom properties).

1. :root {
2. --f7-sheet-height: 260px;
3. --f7-sheet-border-color: transparent;
4. --f7-sheet-transition-duration: 300ms;
5. --f7-sheet-push-border-radius: 10px;
6. --f7-sheet-push-offset: var(--f7-safe-area-top);
7. --f7-sheet-bg-color: #fff;
8. }
9. :root .theme-dark,
10. :root.theme-dark {
11. --f7-sheet-bg-color: #202020;
12. }
13. .ios {
14. --f7-sheet-border-color: var(--f7-bars-border-color);
15. }

Examples

1. <body>
2. ...
3. <div class="page">
4. <div class="navbar">
5. <div class="navbar-bg"></div>
6. <div class="navbar-inner">
7. <!-- In data-sheet attribute we specify CSS selector of sheet we need to open-->
8. <div class="title">Sheet Modal</div>
9. <div class="right"><a class="link sheet-open" href="#" data-sheet=".my-sheet">Open Sheet</a></div>
10. </div>
11. </div>
12. <div class="page-content">
13. <div class="block">
14. <!-- In data-sheet attribute we specify CSS selector of sheet we need to open-->
15. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet">Open Sheet</a></p>

17. <!-- Button to close sheet-->
18. <p><a class="button sheet-close" href="#" data-sheet=".my-sheet">Close Sheet</a></p>
19. <p><a class="button dynamic-sheet" href="#">Create Dynamic Sheet</a></p>

21. <!-- Button to open another top sheet-->
22. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-top">Open Top Sheet</a></p>

24. <!-- Button to open swipe-to-close sheet-->
25. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-swipe-to-close">Swipe To Close</a></p>

27. <!-- Button to open swipe-to-step sheet-->
28. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-swipe-to-step">Swipe To Step</a></p>

30. <!-- Button to open sheet push -->
31. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-push">Sheet Push</a></p>
32. </div>
33. </div>
34. </div>
35. ...
36. <!-- Default bottom sheet -->
37. <div class="sheet-modal my-sheet">
38. <div class="toolbar">
39. <div class="toolbar-inner">
40. <div class="left"></div>
41. <div class="right"><a class="link sheet-close" href="#">Done</a></div>
42. </div>
43. </div>
44. <div class="sheet-modal-inner">
45. <div class="block">
46. <h4>Info</h4>
47. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ac diam ac quam euismod porta vel a nunc. Quisque sodales scelerisque est, at porta justo cursus ac.</p>
48. </div>
49. </div>
50. </div>

52. <!-- Top sheet -->
53. <div class="sheet-modal sheet-modal-top my-sheet-top">
54. <div class="toolbar toolbar-bottom">
55. <div class="toolbar-inner">
56. <div class="left"></div>
57. <div class="right"><a class="link sheet-close" href="#">Done</a></div>
58. </div>
59. </div>
60. <div class="sheet-modal-inner">
61. <div class="block">
62. <h4>Info</h4>
63. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ac diam ac quam euismod porta vel a nunc. Quisque sodales scelerisque est, at porta justo cursus ac.</p>
64. </div>
65. </div>
66. </div>

68. <!-- Swipe to close sheet -->
69. <div class="sheet-modal my-sheet-swipe-to-close" style="height:auto; --f7-sheet-bg-color: #fff;">
70. <div class="sheet-modal-inner">
71. <div class="page-content">
72. <div class="block-title block-title-large">Hello!</div>
73. <div class="block">
74. <p><b>Swipe me down to close</b></p>
75. <p>Eaque maiores ducimus, impedit unde culpa qui...</p>
76. </div>
77. </div>
78. </div>
79. </div>

81. <!-- Swipe to step sheet -->
82. <div class="sheet-modal my-sheet-swipe-to-step" style="height:auto; --f7-sheet-bg-color: #fff;">
83. <div class="sheet-modal-inner">
84. <div class="sheet-modal-swipe-step">
85. <div class="display-flex padding justify-content-space-between align-items-center">
86. <div style="font-size: 18px"><b>Total:</b></div>
87. <div style="font-size: 22px"><b>$500</b></div>
88. </div>
89. <div class="padding-horizontal padding-bottom">
90. <a class="button button-large button-fill">Make Payment</a>
91. <div class="margin-top text-align-center">Swipe up for more details</div>
92. </div>
93. </div>
94. <div class="block-title block-title-medium margin-top">Your order:</div>
95. <div class="list no-hairlines">
96. <ul>
97. <li class="item-content">
98. <div class="item-inner">
99. <div class="item-title">Item 1</div>
100. <div class="item-after text-color-black"><b>$200</b></div>
101. </div>
102. </li>
103. <li class="item-content">
104. <div class="item-inner">
105. <div class="item-title">Item 2</div>
106. <div class="item-after text-color-black"><b>$180</b></div>
107. </div>
108. </li>
109. <li class="item-content">
110. <div class="item-inner">
111. <div class="item-title">Delivery</div>
112. <div class="item-after text-color-black"><b>$120</b></div>
113. </div>
114. </li>
115. </ul>
116. </div>
117. </div>
118. </div>

120. <!-- Sheet Push -->
121. <div class="sheet-modal sheet-modal-push my-sheet-push">
122. <div class="toolbar">
123. <div class="toolbar-inner">
124. <div class="left"></div>
125. <div class="right">
126. <a class="link sheet-close">Close</a>
127. </div>
128. </div>
129. </div>
130. <div class="sheet-modal-inner">
131. <div class="page-content">
132. <div class="block">
133. <p>Lorem ipsum dolor sit amet....</p>
134. </div>
135. </div>
136. </div>
137. </div>

139. </body>
1. var app = new Framework7();

3. var $$ = Dom7;

5. // DOM events for my-sheet sheet
6. $$('.my-sheet').on('sheet:open', function (e) {
7. console.log('my-sheet open');
8. });
9. $$('.my-sheet').on('sheet:opened', function (e) {
10. console.log('my-sheet opened');
11. });

13. // Create dynamic Sheet
14. var dynamicSheet = app.sheet.create({
15. content: '<div class="sheet-modal">'+
16. '<div class="toolbar">'+
17. '<div class="toolbar-inner">'+
18. '<div class="left"></div>'+
19. '<div class="right">'+
20. '<a class="link sheet-close">Done</a>'+
21. '</div>'+
22. '</div>'+
23. '</div>'+
24. '<div class="sheet-modal-inner">'+
25. '<div class="block">'+
26. '<p>Sheet created dynamically.</p>'+
27. '<p><a href="#" class="link sheet-close">Close me</a></p>'+
28. '</div>'+
29. '</div>'+
30. '</div>',
31. // Events
32. on: {
33. open: function (sheet) {
34. console.log('Sheet open');
35. },
36. opened: function (sheet) {
37. console.log('Sheet opened');
38. },
39. }
40. });
41. // Events also can be assigned on instance later
42. dynamicSheet.on('close', function (sheet) {
43. console.log('Sheet close');
44. });
45. dynamicSheet.on('closed', function (sheet) {
46. console.log('Sheet closed');
47. });

49. // Open dynamic sheet
50. $$('.dynamic-sheet').on('click', function () {
51. // Close inline sheet before
52. app.sheet.close('.my-sheet');

54. // Open dynamic sheet
55. dynamicSheet.open();
56. });

58. // Create swipe-to-close Sheet
59. app.sheet.create({
60. el: '.my-sheet-swipe-to-close',
61. swipeToClose: true,
62. backdrop: true,
63. });
64. // Create swipe-to-step Sheet
65. app.sheet.create({
66. el: '.my-sheet-swipe-to-step',
67. swipeToClose: true,
68. swipeToStep: true,
69. backdrop: true,
70. });

← Searchbar

Skeleton →