npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-dialog-component

v0.0.1

Published

## Installation

Downloads

1

Readme

svelte-dialog-component

Installation

  1. Ensure you have node installed on your OS (v19 and above - recommended)
  2. Navigate to the app where you would like to use the component and run the following in your terminal
npm install svelte-dialog-component --save

How to use the component

  1. Inside the script tag of your .svelte file
import { Dialog } from 'svelte-dialog-component'
  1. Inside an HTML element use the imported Menu component like so
<Dialog 
        bind:dialog 
        headerText={"Your header text"} 
        {footerButtons}
        on:footerButtonHandler={handleFooterButton} 
        on:escapePressed={handleEscape}
    >
    Some text or html here that will be passed in via a slot
  </Dialog>

Props, handlers

  1. bind:dialog Required
  2. headerText={"Your header text"} Optional, String to display as header text
  3. {footerButtons} Optional, Array of objects
  4. on:footerButtonHandler={handleFooterButton} Optional, Function to handle te events emited by the footerButtons
  5. on:escapePressed={handleEscape} Optional, a function to handle the behaviour of the dialog when the Escape key is pressed

Example

+layout.svelte

    <script>
    import { onMount } from "svelte";
    import Dialog from "$lib/Dialog/Dialog.svelte";
    import {tick} from 'svelte';

    /**
     * @type {{ showModal: () => void; close: () => void; }}
     */
    let dialog;

    // Declaring the variable(s) used to show and hide the dialog
    let showDialog = false;

    // Declaring  a list of buttons that will appear in the footer of the dialog
    let footerButtons = [
        {label: "Cancel", code: "cancel"},
        {label: "Clear", code: "clear"},
        {label: "Submit", code: "submit"}
    ]


    // A function that will show the dialog
    async function openDialog() {
        showDialog = true;
        await tick(); // waits for dialog to be set
        dialog.showModal();
    }

    // A function that will hide the dialog
    function hideDialog() {
        dialog.close();
        showDialog = false;
    }

    /**
     * A function to handel all the footerButtons for the dialog
     * @param {{ detail: { code: string; }; }} e
     */
    function handleFooterButton(e) {
        if(e.detail && e.detail.code === 'cancel') {
            // handle cancel
        }
        if(e.detail && e.detail.code === 'clear') {
            // handle clear
        }
        if(e.detail && e.detail.code === 'submit') {
            // handle submit
        }
        hideDialog();
    }

    /**
     * A function to handel escape key pressed
     */
    function handleEscape() {
        // handle escape
        hideDialog();
    }

</script>

<!-- The imported dialog component  -->
{#if showDialog}
  <Dialog 
        bind:dialog 
        headerText={"Your header text"} 
        {footerButtons}
        on:footerButtonHandler={handleFooterButton} 
        on:escapePressed={handleEscape}
    >
    Some text or html here that will be passed in via a slot
  </Dialog>
{/if}
<button on:click={openDialog}>Open</button>

Styling

Can be set with variables associated with every element

--dialogContainerBackgroundColor
--dialogHeaderColor
--dialogFooterFirstButtonBackgroundColor
--dialogFooterFirstButtonColor
--dialogFooterFirstButtonHoverBackgroundColor
--dialogFooterButtonBorder
--dialogFooterButtonColor
--dialogFooterButtonHoverBorder

Feedback and recommendations

Please send me feedback or recommendations for improvements at [email protected]. I would love to here from you. Donations are welcome but not necessary.