Sheet Modal React Component
- Sheet Modal Components
- Sheet Modal Properties
- Sheet Modal Events
- Sheet Modal Slots
- Open And Close Sheet Modal
- Examples
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
- 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 | |
backdropUnique | boolean | If enabled it creates unique backdrop element exclusively for this modal | |
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) | |
push | boolean | 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. | |
animate | boolean | Whether the modal should be opened/closed with animation or not | |
containerEl | HTMLElement string | Element to mount modal to (default to app root element) |
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 ) |
Sheet Modal Slots
<Sheet>
component has additional slots for custom elements:
default
- element will be inserted as a child of scrollable<div class="sheet-modal-inner">
elementstatic
- same asdefault
fixed
- element will be inserted before the scrollable<div class="sheet-modal-inner">
element
<Sheet>
<span slot="fixed">Fixed slot</span>
<span slot="static">Static slot</span>
<span>Default slot</span>
</Sheet>
Renders to
<div class="sheet-modal">
<span>Fixed slot</span>
<div class="sheet-modal-inner">
<span>Default slot</span>
<span>Static slot</span>
</div>
</div>
Open And Close Sheet Modal
You can control Sheet Modal state, open and closing it:
- using its Sheet Modal API
- by passing
true
orfalse
to itsopened
prop - by clicking on Link or Button with relevant
sheetOpen
property (to open it) andsheetClose
property to close it
Examples
import React, { useState, useRef } from 'react';
import {
Page,
Navbar,
Block,
Button,
Sheet,
Toolbar,
Link,
PageContent,
BlockTitle,
List,
ListItem,
f7,
} from 'framework7-react';
export default () => {
const [sheetOpened, setSheetOpened] = useState(false);
const sheet = useRef(null);
const createSheet = () => {
// Create sheet modal
if (!sheet.current) {
sheet.current = f7.sheet.create({
content: `
<div class="sheet-modal">
<div class="toolbar">
<div class="toolbar-inner justify-content-flex-end">
<a href="#" class="link sheet-close">Close</a>
</div>
</div>
<div class="sheet-modal-inner">
<div class="page-content">
<div class="block">
<p>This sheet modal was created dynamically</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse faucibus mauris leo, eu bibendum neque congue non. Ut leo mauris, eleifend eu commodo a, egestas ac urna. Maecenas in lacus faucibus, viverra ipsum pulvinar, molestie arcu. Etiam lacinia venenatis dignissim. Suspendisse non nisl semper tellus malesuada suscipit eu et eros. Nulla eu enim quis quam elementum vulputate. Mauris ornare consequat nunc viverra pellentesque. Aenean semper eu massa sit amet aliquam. Integer et neque sed libero mollis elementum at vitae ligula. Vestibulum pharetra sed libero sed porttitor. Suspendisse a faucibus lectus.</p>
</div>
</div>
</div>
</div>
`.trim(),
});
}
// Close inline sheet
if (f7.$('.demo-sheet.modal-in').length > 0) f7.sheet.close('.demo-sheet');
// Open it
sheet.current.open();
};
const onPageBeforeOut = () => {
// Close opened sheets on page out
f7.sheet.close();
};
const onPageBeforeRemove = () => {
// Destroy sheet modal when page removed
if (sheet.current) sheet.current.destroy();
};
return (
<Page onPageBeforeOut={onPageBeforeOut} onPageBeforeRemove={onPageBeforeRemove}>
<Navbar title="Sheet Modal"></Navbar>
<Block>
<p>
Sheet Modals slide up from the bottom of the screen to reveal more content. Such
modals allow to create custom overlays with custom content.
</p>
<p>
<Button fill sheetOpen=".demo-sheet">
Open Sheet
</Button>
</p>
<p>
<Button fill onClick={createSheet}>
Create Dynamic Sheet
</Button>
</p>
<p>
<Button
fill
onClick={() => {
setSheetOpened(true);
}}
>
Open Via Prop Change
</Button>
</p>
<p>
<Button fill sheetOpen=".demo-sheet-swipe-to-close">
Swipe To Close
</Button>
</p>
<p>
<Button fill sheetOpen=".demo-sheet-swipe-to-step">
Swipe To Step
</Button>
</p>
<p>
<Button fill sheetOpen=".demo-sheet-push">
Sheet Push
</Button>
</p>
</Block>
<Sheet
className="demo-sheet"
opened={sheetOpened}
onSheetClosed={() => {
setSheetOpened(false);
}}
>
<Toolbar>
<div className="left"></div>
<div className="right">
<Link sheetClose>Close</Link>
</div>
</Toolbar>
{/* Scrollable sheet content */}
<PageContent>
<Block>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae ducimus dolorum
ipsa aliquid accusamus perferendis laboriosam delectus numquam minima animi,
libero illo in tempora harum sequi corporis alias ex adipisci.
</p>
<p>
Sunt magni enim saepe quasi aspernatur delectus consectetur fugiat necessitatibus
qui sed, similique quis facere tempora, laudantium quae expedita ea, aperiam
dolores. Aut deserunt soluta alias magnam. Consequatur, nisi, enim.
</p>
<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>
<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>
<p>
Illum id laborum tempore, doloribus culpa labore ex iusto odit. Quibusdam
consequuntur totam nam obcaecati, enim cumque nobis, accusamus, quos voluptates,
voluptatibus sapiente repellendus nesciunt praesentium velit ipsa illo iusto.
</p>
</Block>
</PageContent>
</Sheet>
<Sheet
className="demo-sheet-swipe-to-close"
style={{ height: 'auto', '--f7-sheet-bg-color': '#fff' }}
swipeToClose
backdrop
>
<PageContent>
<BlockTitle large>Hello!</BlockTitle>
<Block>
<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>
<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>
</Block>
</PageContent>
</Sheet>
<Sheet
className="demo-sheet-swipe-to-step"
style={{ height: 'auto', '--f7-sheet-bg-color': '#fff' }}
swipeToClose
swipeToStep
backdrop
>
<div className="sheet-modal-swipe-step">
<div className="display-flex padding justify-content-space-between align-items-center">
<div style={{ fontSize: '18px' }}>
<b>Total:</b>
</div>
<div style={{ fontSize: '22px' }}>
<b>$500</b>
</div>
</div>
<div className="padding-horizontal padding-bottom">
<Button large fill>
Make Payment
</Button>
<div className="margin-top text-align-center">Swipe up for more details</div>
</div>
</div>
<BlockTitle medium className="margin-top">
Your order:
</BlockTitle>
<List noHairlines>
<ListItem title="Item 1">
<b slot="after" className="text-color-black">
$200
</b>
</ListItem>
<ListItem title="Item 2">
<b slot="after" className="text-color-black">
$180
</b>
</ListItem>
<ListItem title="Delivery">
<b slot="after" className="text-color-black">
$120
</b>
</ListItem>
</List>
</Sheet>
<Sheet className="demo-sheet-push" push>
<Toolbar>
<div className="left"></div>
<div className="right">
<Link sheetClose>Close</Link>
</div>
</Toolbar>
<PageContent>
<Block>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae ducimus dolorum
ipsa aliquid accusamus perferendis laboriosam delectus numquam minima animi,
libero illo in tempora harum sequi corporis alias ex adipisci.
</p>
<p>
Sunt magni enim saepe quasi aspernatur delectus consectetur fugiat necessitatibus
qui sed, similique quis facere tempora, laudantium quae expedita ea, aperiam
dolores. Aut deserunt soluta alias magnam. Consequatur, nisi, enim.
</p>
<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>
<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>
<p>
Illum id laborum tempore, doloribus culpa labore ex iusto odit. Quibusdam
consequuntur totam nam obcaecati, enim cumque nobis, accusamus, quos voluptates,
voluptatibus sapiente repellendus nesciunt praesentium velit ipsa illo iusto.
</p>
</Block>
</PageContent>
</Sheet>
</Page>
);
};