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>
  22. </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:

ParameterTypeDefaultDescription
elHTMLElementSheet element. Can be useful if you already have Sheet element in your HTML and want to create new instance using this element
contentstringFull Sheet HTML layout string. Can be useful if you want to create Sheet element dynamically
backdropbooleanEnables Sheet backdrop (dark semi transparent layer behind). By default it is true for MD and Aurora themes and false for iOS theme
backdropElHTMLElement
string
HTML element or string CSS selector of custom backdrop element
scrollToElHTMLElement
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
closeByBackdropClickbooleantrueWhen enabled will be closed on backdrop click
closeByOutsideClickbooleanfalseWhen enabled will be closed on when click outside of it
closeOnEscapebooleanfalseWhen enabled will be closed on ESC keyboard key press
animatebooleantrueWhether the Sheet should be opened/closed with animation or not. Can be overwritten in .open() and .close() methods
swipeToClosebooleanfalseWhether the Sheet can be closed with swipe gesture
swipeToStepbooleanfalseWhen 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)
pushbooleanfalseWhen 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.
onobject

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.appLink to global app instance
sheet.elSheet HTML element
sheet.$elDom7 instance with sheet HTML element
sheet.backdropElBackdrop HTML element
sheet.$backdropElDom7 instance with backdrop HTML element
sheet.paramsSheet parameters
sheet.openedBoolean 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

Control Sheet With Links

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

EventTargetDescription
sheet:openSheet Element<div class=”sheet”>Event will be triggered when Sheet starts its opening animation
sheet:openedSheet Element<div class=”sheet”>Event will be triggered after Sheet completes its opening animation
sheet:closeSheet Element<div class=”sheet”>Event will be triggered when Sheet starts its closing animation
sheet:closedSheet Element<div class=”sheet”>Event will be triggered after Sheet completes its closing animation
sheet:stepopenSheet Element<div class=”sheet”>Event will be triggered on Sheet swipe step open/expand
sheet:stepcloseSheet Element<div class=”sheet”>Event will be triggered on Sheet swipe step close/collapse
sheet:stepprogressSheet 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.

EventArgumentsTargetDescription
opensheetsheetEvent will be triggered when Sheet starts its opening animation. As an argument event handler receives sheet instance
sheetOpensheetapp
openedsheetsheetEvent will be triggered after Sheet completes its opening animation. As an argument event handler receives sheet instance
sheetOpenedsheetapp
closesheetsheetEvent will be triggered when Sheet starts its closing animation. As an argument event handler receives sheet instance
sheetClosesheetapp
closedsheetsheetEvent will be triggered after Sheet completes its closing animation. As an argument event handler receives sheet instance
sheetClosedsheetapp
beforeDestroysheetsheetEvent will be triggered right before Sheet instance will be destroyed. As an argument event handler receives sheet instance
sheetBeforeDestroysheetapp
stepOpensheetsheetEvent will be triggered on Sheet swipe step open/expand
sheetStepOpensheetapp
stepClosesheetsheetEvent will be triggered on Sheet swipe step close/collapse
sheetStepClosesheetapp
stepProgresssheet,progresssheetEvent 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)
sheetStepProgresssheet,progressapp

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>
  16. <!-- Button to close sheet-->
  17. <p><a class="button sheet-close" href="#" data-sheet=".my-sheet">Close Sheet</a></p>
  18. <p><a class="button dynamic-sheet" href="#">Create Dynamic Sheet</a></p>
  19. <!-- Button to open another top sheet-->
  20. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-top">Open Top Sheet</a></p>
  21. <!-- Button to open swipe-to-close sheet-->
  22. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-swipe-to-close">Swipe To Close</a></p>
  23. <!-- Button to open swipe-to-step sheet-->
  24. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-swipe-to-step">Swipe To Step</a></p>
  25. <!-- Button to open sheet push -->
  26. <p><a class="button sheet-open" href="#" data-sheet=".my-sheet-push">Sheet Push</a></p>
  27. </div>
  28. </div>
  29. </div>
  30. ...
  31. <!-- Default bottom sheet -->
  32. <div class="sheet-modal my-sheet">
  33. <div class="toolbar">
  34. <div class="toolbar-inner">
  35. <div class="left"></div>
  36. <div class="right"><a class="link sheet-close" href="#">Done</a></div>
  37. </div>
  38. </div>
  39. <div class="sheet-modal-inner">
  40. <div class="block">
  41. <h4>Info</h4>
  42. <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>
  43. </div>
  44. </div>
  45. </div>
  46. <!-- Top sheet -->
  47. <div class="sheet-modal sheet-modal-top my-sheet-top">
  48. <div class="toolbar toolbar-bottom">
  49. <div class="toolbar-inner">
  50. <div class="left"></div>
  51. <div class="right"><a class="link sheet-close" href="#">Done</a></div>
  52. </div>
  53. </div>
  54. <div class="sheet-modal-inner">
  55. <div class="block">
  56. <h4>Info</h4>
  57. <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>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- Swipe to close sheet -->
  62. <div class="sheet-modal my-sheet-swipe-to-close" style="height:auto; --f7-sheet-bg-color: #fff;">
  63. <div class="sheet-modal-inner">
  64. <div class="page-content">
  65. <div class="block-title block-title-large">Hello!</div>
  66. <div class="block">
  67. <p><b>Swipe me down to close</b></p>
  68. <p>Eaque maiores ducimus, impedit unde culpa qui...</p>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. <!-- Swipe to step sheet -->
  74. <div class="sheet-modal my-sheet-swipe-to-step" style="height:auto; --f7-sheet-bg-color: #fff;">
  75. <div class="sheet-modal-inner">
  76. <div class="sheet-modal-swipe-step">
  77. <div class="display-flex padding justify-content-space-between align-items-center">
  78. <div style="font-size: 18px"><b>Total:</b></div>
  79. <div style="font-size: 22px"><b>$500</b></div>
  80. </div>
  81. <div class="padding-horizontal padding-bottom">
  82. <a class="button button-large button-fill">Make Payment</a>
  83. <div class="margin-top text-align-center">Swipe up for more details</div>
  84. </div>
  85. </div>
  86. <div class="block-title block-title-medium margin-top">Your order:</div>
  87. <div class="list no-hairlines">
  88. <ul>
  89. <li class="item-content">
  90. <div class="item-inner">
  91. <div class="item-title">Item 1</div>
  92. <div class="item-after text-color-black"><b>$200</b></div>
  93. </div>
  94. </li>
  95. <li class="item-content">
  96. <div class="item-inner">
  97. <div class="item-title">Item 2</div>
  98. <div class="item-after text-color-black"><b>$180</b></div>
  99. </div>
  100. </li>
  101. <li class="item-content">
  102. <div class="item-inner">
  103. <div class="item-title">Delivery</div>
  104. <div class="item-after text-color-black"><b>$120</b></div>
  105. </div>
  106. </li>
  107. </ul>
  108. </div>
  109. </div>
  110. </div>
  111. <!-- Sheet Push -->
  112. <div class="sheet-modal sheet-modal-push my-sheet-push">
  113. <div class="toolbar">
  114. <div class="toolbar-inner">
  115. <div class="left"></div>
  116. <div class="right">
  117. <a class="link sheet-close">Close</a>
  118. </div>
  119. </div>
  120. </div>
  121. <div class="sheet-modal-inner">
  122. <div class="page-content">
  123. <div class="block">
  124. <p>Lorem ipsum dolor sit amet....</p>
  125. </div>
  126. </div>
  127. </div>
  128. </div>
  129. </body>
  1. var app = new Framework7();
  2. var $$ = Dom7;
  3. // DOM events for my-sheet sheet
  4. $$('.my-sheet').on('sheet:open', function (e) {
  5. console.log('my-sheet open');
  6. });
  7. $$('.my-sheet').on('sheet:opened', function (e) {
  8. console.log('my-sheet opened');
  9. });
  10. // Create dynamic Sheet
  11. var dynamicSheet = app.sheet.create({
  12. content: '<div class="sheet-modal">'+
  13. '<div class="toolbar">'+
  14. '<div class="toolbar-inner">'+
  15. '<div class="left"></div>'+
  16. '<div class="right">'+
  17. '<a class="link sheet-close">Done</a>'+
  18. '</div>'+
  19. '</div>'+
  20. '</div>'+
  21. '<div class="sheet-modal-inner">'+
  22. '<div class="block">'+
  23. '<p>Sheet created dynamically.</p>'+
  24. '<p><a href="#" class="link sheet-close">Close me</a></p>'+
  25. '</div>'+
  26. '</div>'+
  27. '</div>',
  28. // Events
  29. on: {
  30. open: function (sheet) {
  31. console.log('Sheet open');
  32. },
  33. opened: function (sheet) {
  34. console.log('Sheet opened');
  35. },
  36. }
  37. });
  38. // Events also can be assigned on instance later
  39. dynamicSheet.on('close', function (sheet) {
  40. console.log('Sheet close');
  41. });
  42. dynamicSheet.on('closed', function (sheet) {
  43. console.log('Sheet closed');
  44. });
  45. // Open dynamic sheet
  46. $$('.dynamic-sheet').on('click', function () {
  47. // Close inline sheet before
  48. app.sheet.close('.my-sheet');
  49. // Open dynamic sheet
  50. dynamicSheet.open();
  51. });
  52. // Create swipe-to-close Sheet
  53. app.sheet.create({
  54. el: '.my-sheet-swipe-to-close',
  55. swipeToClose: true,
  56. backdrop: true,
  57. });
  58. // Create swipe-to-step Sheet
  59. app.sheet.create({
  60. el: '.my-sheet-swipe-to-step',
  61. swipeToClose: true,
  62. swipeToStep: true,
  63. backdrop: true,
  64. });

← Searchbar

Skeleton →