🔥 Meet Our New Project: t0ggles - Your Ultimate Project Management Tool!

Popup Svelte 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 Svelte component represents Popup component.

There are following components included:

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
backdropUniquebooleanIf enabled it creates unique backdrop element exclusively for this modal
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.
containerElHTMLElement
string
Element to mount modal to (default to app root element)
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:

Access To Popup Instance

You can access Popup initialized instance by calling .instance() component's method. For example:

<Popup bind:this={component}>...</Popup>

<script>
  let component;

  // to get instance in some method
  component.instance()
</script>

Examples

popup.svelte
<script>
  import {
    f7,
    Navbar,
    Page,
    Popup,
    BlockTitle,
    Block,
    NavRight,
    Link,
    Button,
    View,
  } from 'framework7-svelte';

  let popupOpened = false;
  let dynamicPopup;

  function createPopup() {
    // Create popup
    if (!dynamicPopup) {
      dynamicPopup = f7.popup.create({
        content: `
          <div class="popup">
            <div class="page">
              <div class="navbar">
                <div class="navbar-inner">
                  <div class="navbar-bg"></div>
                  <div class="title">Dynamic Popup</div>
                  <div class="right"><a  class="link popup-close">Close</a></div>
                </div>
              </div>
              <div class="page-content">
                <div class="block">
                  <p>This popup 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(),
      });
    }
    // Open it
    dynamicPopup.open();
  }

  function onPageBeforeRemove() {
    // Destroy popup when page removed
    if (dynamicPopup) dynamicPopup.destroy();
  }
</script>

<Page {onPageBeforeRemove}>
  <Navbar title="Popup" />
  <Block strongIos outlineIos>
    <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>
    <p>
      <Button fill popupOpen=".demo-popup">Open Popup</Button>
    </p>
    <p>
      <Button fill onClick={() => (popupOpened = true)}>Open Via Prop Change</Button>
    </p>
    <p>
      <Button fill onClick={createPopup}>Create Dynamic Popup</Button>
    </p>
  </Block>

  <BlockTitle>Swipe To Close</BlockTitle>
  <Block strongIos outlineIos>
    <p>Popup can be closed with swipe to top or bottom:</p>
    <p>
      <Button fill popupOpen=".demo-popup-swipe">Swipe To Close</Button>
    </p>
    <p>Or it can be closed with swipe on special swipe handler and, for example, only to bottom:</p>
    <p>
      <Button fill popupOpen=".demo-popup-swipe-handler">With Swipe Handler</Button>
    </p>
  </Block>

  <BlockTitle>Push View</BlockTitle>
  <Block strongIos outlineIos>
    <p>
      Popup can push view behind. By default has effect only when `safe-area-inset-top` is more than
      zero (iOS fullscreen webapp or iOS cordova app)
    </p>
    <p>
      <Button fill popupOpen=".demo-popup-push">Popup Push</Button>
    </p>
  </Block>

  <Popup class="demo-popup" opened={popupOpened} onPopupClosed={() => (popupOpened = false)}>
    <Page>
      <Navbar title="Popup Title">
        <NavRight>
          <Link popupClose>Close</Link>
        </NavRight>
      </Navbar>
      <Block>
        <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>
        <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>
        <p>
          Duis ut mauris sollicitudin, venenatis nisi sed, luctus ligula. Phasellus blandit nisl ut
          lorem semper pharetra. Nullam tortor nibh, suscipit in consequat vel, feugiat sed quam.
          Nam risus libero, auctor vel tristique ac, malesuada ut ante. Sed molestie, est in
          eleifend sagittis, leo tortor ullamcorper erat, at vulputate eros sapien nec libero.
          Mauris dapibus laoreet nibh quis bibendum. Fusce dolor sem, suscipit in iaculis id,
          pharetra at urna. Pellentesque tempor congue massa quis faucibus. Vestibulum nunc eros,
          convallis blandit dui sit amet, gravida adipiscing libero.
        </p>
      </Block>
    </Page>
  </Popup>

  <Popup push class="demo-popup-push">
    <View>
      <Page>
        <Navbar title="Push Popup" large transparent>
          <NavRight>
            <Link popupClose>Close</Link>
          </NavRight>
        </Navbar>
        <Block>
          <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>
          <p>
            Duis ut mauris sollicitudin, venenatis nisi sed, luctus ligula. Phasellus blandit nisl
            ut lorem semper pharetra. Nullam tortor nibh, suscipit in consequat vel, feugiat sed
            quam. Nam risus libero, auctor vel tristique ac, malesuada ut ante. Sed molestie, est in
            eleifend sagittis, leo tortor ullamcorper erat, at vulputate eros sapien nec libero.
            Mauris dapibus laoreet nibh quis bibendum. Fusce dolor sem, suscipit in iaculis id,
            pharetra at urna. Pellentesque tempor congue massa quis faucibus. Vestibulum nunc eros,
            convallis blandit dui sit amet, gravida adipiscing libero.
          </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>
        </Block>
      </Page>
    </View>
  </Popup>

  <Popup class="demo-popup-swipe" swipeToClose>
    <Page>
      <Navbar title="Swipe To Close">
        <NavRight>
          <Link popupClose>Close</Link>
        </NavRight>
      </Navbar>

      <div style="height: 100%" class="display-flex justify-content-center align-items-center">
        <p>Swipe me up or down</p>
      </div>
    </Page>
  </Popup>

  <Popup class="demo-popup-swipe-handler" swipeToClose="to-bottom" swipeHandler=".swipe-handler">
    <Page>
      <div slot="fixed" class="swipe-handler" />
      <BlockTitle large>Hello!</BlockTitle>
      <Block strongIos outlineIos>
        <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>
        <p>
          Duis ut mauris sollicitudin, venenatis nisi sed, luctus ligula. Phasellus blandit nisl ut
          lorem semper pharetra. Nullam tortor nibh, suscipit in consequat vel, feugiat sed quam.
          Nam risus libero, auctor vel tristique ac, malesuada ut ante. Sed molestie, est in
          eleifend sagittis, leo tortor ullamcorper erat, at vulputate eros sapien nec libero.
          Mauris dapibus laoreet nibh quis bibendum. Fusce dolor sem, suscipit in iaculis id,
          pharetra at urna. Pellentesque tempor congue massa quis faucibus. Vestibulum nunc eros,
          convallis blandit dui sit amet, gravida adipiscing libero.
        </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>
        <p>
          Duis ut mauris sollicitudin, venenatis nisi sed, luctus ligula. Phasellus blandit nisl ut
          lorem semper pharetra. Nullam tortor nibh, suscipit in consequat vel, feugiat sed quam.
          Nam risus libero, auctor vel tristique ac, malesuada ut ante. Sed molestie, est in
          eleifend sagittis, leo tortor ullamcorper erat, at vulputate eros sapien nec libero.
          Mauris dapibus laoreet nibh quis bibendum. Fusce dolor sem, suscipit in iaculis id,
          pharetra at urna. Pellentesque tempor congue massa quis faucibus. Vestibulum nunc eros,
          convallis blandit dui sit amet, gravida adipiscing libero.
        </p>
      </Block>
    </Page>
  </Popup>
</Page>