Popup - 图1

Popup React Component

Popup is a popup window with any HTML content that pops up over App’s main content. Popup as all other overlays is part of so called “Temporary Views”.

Popup React component represents Popup component.

Popup Components

There are following components included:

  • Popup / F7Popup - popup element

Popup Properties

PropTypeDescription
<Popup> properties
tabletFullscreenbooleanDefines whether the popup should be displayed fullscreen on tablets or not
openedbooleanAllows to open/close Popup and set its initial state
backdropbooleanEnables Popup backdrop (dark semi transparent layer behind). By default inherits same app parameter value (true)
backdropElstring
object
HTML element or string CSS selector of custom backdrop element
closeByBackdropClickbooleanWhen enabled, popup will be closed on backdrop click. By default inherits same app parameter value (true)
closeOnEscapebooleanWhen enabled, popup will be closed on ESC keyboard key press
animatebooleanWhether the Popup should be opened/closed with animation or not. Can be overwritten in .open() and .close() methods. By default inherits same app parameter value (true)
swipeToCloseboolean
string
Whether the Popup can be closed with swipe gesture. Can be true to allow to close popup with swipes to top and to bottom, or can be to-top (string) to allow only swipe to top to close popup, or to-bottom (string) to allow only swipe to bottom to close.
swipeHandlerHTMLElement
string
If not passed, then whole popup 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 must be also enabled)
pushbooleanWhen enabled it will push view behind on open. Works only when top safe area is in place. It can also be enabled by adding popup-push class to Popup element.

Popup Methods

<Popup> methods
.open(animate)Open popup
.close(animate)Close popup

Popup Events

EventDescription
<Popup> events
popupOpenEvent will be triggered when Popup starts its opening animation
popupOpenedEvent will be triggered after Popup completes its opening animation
popupCloseEvent will be triggered when Popup starts its closing animation
popupClosedEvent will be triggered after Popup completes its closing animation
popupSwipeStartEvent will be triggered in the beginning of swipe-to-close interaction (when user just started to drag popup)
popupSwipeMoveEvent will be triggered on swipe-to-close move interaction
popupSwipeEndEvent will be triggered on swipe-to-close release
popupSwipeCloseEvent will be triggered when popup closed with swipe

Open And Close Popup

You can control Popup state, open and closing it:

  • using Popup API
  • by passing true or false to its opened prop
  • by clicking on Link or Button with relevant popupOpen property (to open it) and popupClose property to close it

Access To Popup Instance

You can access Popup initialized instance by accessing .f7Popup component’s property.

Examples

  1. export default class extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. popupOpened: false,
  6. }
  7. }
  8. render() {
  9. return (
  10. <Page onPageBeforeRemove={this.onPageBeforeRemove.bind(this)}>
  11. <Navbar title="Popup"></Navbar>
  12. <Block>
  13. <p>Popup is a modal window with any HTML content that pops up over App's main content. Popup as all other overlays is part of so called "Temporary Views".</p>
  14. <p>
  15. <Button fill popupOpen=".demo-popup">Open Popup</Button>
  16. </p>
  17. <p>
  18. <Button fill onClick={() => this.setState({ popupOpened : true })}>Open Via Prop Change</Button>
  19. </p>
  20. <p>
  21. <Button fill onClick={this.createPopup.bind(this)}>Create Dynamic Popup</Button>
  22. </p>
  23. <p>
  24. <Button fill popupOpen=".demo-popup-swipe">Swipe To Close</Button>
  25. </p>
  26. <p>
  27. <Button fill popupOpen=".demo-popup-swipe-handler">With Swipe Handler</Button>
  28. </p>
  29. <p>
  30. <Button fill popupOpen=".demo-popup-push">Popup Push</Button>
  31. </p>
  32. </Block>
  33. <Popup className="demo-popup" opened={this.state.popupOpened} onPopupClosed={() => this.setState({popupOpened : false})}>
  34. <Page>
  35. <Navbar title="Popup Title">
  36. <NavRight>
  37. <Link popupClose>Close</Link>
  38. </NavRight>
  39. </Navbar>
  40. <Block>
  41. <p>Here comes popup. You can put here anything, even independent view with its own navigation. Also not, that by default popup looks a bit different on iPhone/iPod and iPad, on iPhone it is fullscreen.</p>
  42. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
  43. <p>Duis ut mauris sollicitudin, venenatis nisi sed, luctus ligula...</p>
  44. </Block>
  45. </Page>
  46. </Popup>
  47. <Popup className="demo-popup-swipe" swipeToClose>
  48. <Page>
  49. <Navbar title="Swipe To Close">
  50. <NavRight>
  51. <Link popupClose>Close</Link>
  52. </NavRight>
  53. </Navbar>
  54. <div style={{height: '100%'}} className="display-flex justify-content-center align-items-center">
  55. <p>Swipe me up or down</p>
  56. </div>
  57. </Page>
  58. </Popup>
  59. <Popup className="demo-popup-swipe-handler" swipeToClose swipeHandler=".swipe-handler">
  60. <Page>
  61. <BlockTitle large>Hello!</BlockTitle>
  62. <Block strong>
  63. <p className="swipe-handler"><b>Swipe works only on this paragraph</b></p>
  64. <p>Lorem ipsum dolor sit amet...</p>
  65. </Block>
  66. </Page>
  67. </Popup>
  68. <Popup className="demo-popup-push" push>
  69. <Page>
  70. <Navbar title="Popup Push">
  71. <NavRight>
  72. <Link popupClose>Close</Link>
  73. </NavRight>
  74. </Navbar>
  75. <Block strong>
  76. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
  77. </Block>
  78. </Page>
  79. </Popup>
  80. </Page>
  81. )
  82. }
  83. createPopup() {
  84. const self = this;
  85. // Create popup
  86. if (!self.popup) {
  87. self.popup = self.$f7.popup.create({
  88. content: `
  89. <div class="popup">
  90. <div class="page">
  91. <div class="navbar">
  92. <div class="navbar-bg">
  93. <div class="navbar-inner">
  94. <div class="title">Dynamic Popup</div>
  95. <div class="right"><a href="#" class="link popup-close">Close</a></div>
  96. </div>
  97. </div>
  98. <div class="page-content">
  99. <div class="block">
  100. <p>This popup was created dynamically</p>
  101. <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>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. `.trim(),
  107. });
  108. }
  109. // Open it
  110. self.popup.open();
  111. }
  112. onPageBeforeRemove() {
  113. const self = this;
  114. // Destroy popup when page removed
  115. if (self.popup) self.popup.destroy();
  116. }
  117. };

← Popover

Preloader →