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-tutorial-builder

v1.1.1

Published

A library for Svelte to simplify creating a linear in-app tutorial for new users.

Downloads

11

Readme

svelte-tutorial-builder

A library for Svelte to simplify creating a linear in-app tutorial for new users.

Loading HTML Elements into TutorialStore

import { TutorialStore } from "svelte-tutorial-builder";

To create a Tutorial, you first need to load HTML Elements into the TutorialStore. This allows the Tutorial Component to access it later.

When loading elements into TutorialStore, they can be inserted as one of five types.

  • addNonClickable: The standard item. Pass in an HTMLElement and it will be highlighted to the user. When finished, the user clicks the "Next" button to advance.
  • addClickable: Pass in an HTMLElement, and the user will have to click on it to advance the tutorial. Other behaviors will apply, so this works great for clicking an "open" button that reveals some other element you want to show the user.
  • addTextOnly: Shows some explanation in the popup without focusing on any specific elements. Great for introductory/completion messages.
  • addPause: Pause the tutorial to allow the user to complete a task independently, and resume the tutorial on task completion. Takes in a prePauseTask which should ensure their environment does not already have the desired condition true.
  • addPauseWithoutSetup: Like addPause but does not take in a prePauseTask. Use with caution.

It's also important to plan out the order of your tutorial before coding! TutorialStore expects each item to have a numeric ID, which should be a positive integer starting from 1. The Tutorial will advance in order, and if elements are missing the tutorial will end abruptly.

To insert items into TutorialStore:

  1. Inside your app's components, create bindings to individual HTML elements you want to call attention to in the tutorial.
  2. Import the TutorialStore in each component containing HTML elements to reference.
  3. Consider how you want users to interact with each component, and use the appropriate "add" method on TutorialStore.
  4. When the component mounts, add your HTMLElements to the store using the chosen methods. Note that you can mix-and-match, just ensure your IDs are consecutive, positive integers starting from 1.
  5. Import and add the Tutorial component to the top-level component for the app/page you want to show tutorials on.

Using the Tutorial Component

import { Tutorial } from "svelte-tutorial-builder";
  • By default, the Tutorial Component will immediately start from item #1 in the TutorialStore when it mounts. You can pass the autoStart prop to change this behavior.
  • By using bind:this on the tutorial component, you can call startTutorial() on the Tutorial component at some arbitrary time, such as when the user clicks a button.
  • You can pass the show prop to the component to manually highlight the Element with that ID

Props

  • onCompletion: Optional, but recommended. Pass a function to execute when the user exits the Tutorial. Should trigger the Tutorial Component to unmount.
  • show: Optional. Takes an ID of an item in TutorialStore, and immediately puts the tutorial to that item. Provides no way for user to advance, so ideally this will use a binding to provide another way to advance.
  • curtainZIndex: Optional, default 50. Sets the Z-Index for the backdrop used to dim the application.
  • autoStart: Optional, default true. If true, the tutorial will begin as soon as the Tutorial component mounts. If false, use the exported function startTutorial() to start at an arbitrary time.
  • buttonClasses: Optional. Pass a string containing (global) CSS classes to apply to the buttons that appear on the floating explanations panel.
  • boxClasses: Optional. Pass a string containing (global) CSS classes to apply to the floating explanations panel.
  • clickableMessage: Optional, default 'Click it to continue.' Takes a string to display instead of the Next button for any Clickable elements.

Exported Functions

startTutorial: Assuming the Tutorial Component is mounted but autoStart = false, calling this function will begin the tutorial.

Full Usage with Props

{#if condition}
    <Tutorial {onCompletion}></Tutorial>
{/if}

The above is the recommended configuration. The component should be wrapped in a conditional, which is only true when the user engages with the tutorial. Upon exit, onCompletion() is called, which triggers the condition to become false.

<Tutorial bind:this={TutorialComponent} curtainZIndex={20} autoStart={false} buttonClasses="custom-btn" boxClasses="custom-box" />

The above creates a Tutorial but does not start until user calls.TutorialComponent.startTutorial().

<Tutorial show={13} autoStart={false} />

Creates a Tutorial and immediately highlights #13. autoStart has no effect since the show prop was specified.

Developing & Contributing

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

Everything inside src/lib is part of the library, everything inside src/routes can be used as a showcase or preview app.

Suggested changes to this repo should be suggested as Pull Requests on GitHub. I look forward to seeing your contributions!

Building

To build the library:

npm run package