flekschas / svelte-simple-modal

A simple, small, and content-agnostic modal for Svelte v3 and v4
https://svelte.dev/repl/b95ce66b0ef34064a34afc5c0249f313
MIT License
422 stars 31 forks source link

How to hide the modal component using svelte store? #69

Closed Gokulnath31 closed 2 years ago

Gokulnath31 commented 2 years ago

There is an example showing how to open a modal using svelte-store. It would be better to have an example to hide using svelte-store

flekschas commented 2 years ago

Simply unset the store: modal.set(null);.

<script>
  import { writable } from 'svelte/store';
  import Modal, { bind } from 'svelte-simple-modal';
  import Popup from './Popup.svelte';
  const modal = writable(null);
  const showModal = () => modal.set(bind(Popup, { message: "It's a modal!" }));
  const hideModal = () => modal.set(null);
</script>

<Modal show={$modal}>
  <button on:click={showModal}>Show modal</button>
  <button on:click={hideModal}>Hide modal</button>
</Modal>