
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 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
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 theme and false for iOS theme |
|
| 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, sheet will be closed on backdrop click |
| closeByOutsideClick | boolean | false | When enabled, sheet will be closed on when click outside of it |
| animate | boolean | true | Whether the Sheet should be opened/closed with animation or not. Can be overwritten in .open() and .close() methods |
| 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. });
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.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>
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>
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 |
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 |
Examples
1. <body>
2. ...
3. <div class="page">
4. <div class="navbar">
5. <div class="navbar-inner">
6. <!-- In data-sheet attribute we specify CSS selector of sheet we need to open-->
7. <div class="title">Sheet Modal</div>
8. <div class="right"><a class="link sheet-open" href="#" data-sheet=".my-sheet">Open Sheet</a></div>
9. </div>
10. </div>
11. <div class="page-content">
12. <div class="block">
13. <!-- In data-sheet attribute we specify CSS selector of sheet we need to open-->
14. <p><a class="link sheet-open" href="#" data-sheet=".my-sheet">Open Sheet</a></p>
15. <!-- Link to close sheet-->
16. <p><a class="link sheet-close" href="#" data-sheet=".my-sheet">Close Sheet</a></p>
17. <p><a class="link dynamic-sheet" href="#">Create Dynamic Sheet</a></p>
18. </div>
19. </div>
20. </div>
21. ...
23. <div class="sheet-modal my-sheet">
24. <div class="toolbar">
25. <div class="toolbar-inner">
26. <div class="left"></div>
27. <div class="right"><a class="link sheet-close" href="#">Done</a></div>
28. </div>
29. </div>
30. <div class="sheet-modal-inner">
31. <div class="block">
32. <h4>Info</h4>
33. <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>
34. </div>
35. </div>
36. </div>
37. </body>
1. var app = new Framework7();
3. var $$ = Dom7;
5. // DOM events for my-sheet sheet
6. $$('.my-sheet').on('sheet:open', function (e, sheet) {
7. console.log('my-sheet open');
8. });
9. $$('.my-sheet').on('sheet:opened', function (e, sheet) {
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. });
