Git Product home page Git Product logo

svelte-steps's Introduction





Svelte Steps

js-standard-style Svelte v3 publish

Svelte Steps component

Demo

A hosted demo exists

pnpm i && pnpm dev

About

Demonstrates progress in a multi-step process in your application, such as a payment flow.

  • Current step info is denoted by the step store
  • If the current step is the last step, the steps component shows as fully complete.

Usage

Install the library

npm i --save-dev @beyonk/svelte-steps

Steps Component

See the example directory for an example.

  1. Import the Steps component and the setup function from the library.
  2. Configure the Steps component by passing an array of step names and icons
  3. Configure the theme option by setting an rgb colour value for the complete theme variable
  4. Set the current step by passing it's array index. Usually 0.
  5. Add the <Steps> component to your page, and pass it the theme, and the current attributes.
<Steps {theme} />

<script>
	import { Steps, setup, current } from '@beyonk/svelte-steps'
	import { UserIcon, CreditCardIcon, BriefcaseIcon } from 'svelte-feather-icons'
	
	setup([
		{ name: 'About You', icon: UserIcon },
		{ id: 'payment', name: 'Payment', icon: CreditCardIcon }, // id is optional and will be autogenerated
		{ name: 'Confirmation', icon: BriefcaseIcon }
	])
	
	const theme = [
		{ name: 'complete', value: { r: 6, g: 160, b: 146 } }
	]
</script>

Pages Component

The pages component is a mini steps component for pages where space is of the essence.

API

Change Step

To go to a specific step, call to() passing the id of the desired step

<Steps {theme} />

<script>
	import { to } from '@beyonk/svelte-steps'
	
	to('second-step')
</script>

The $step store gives you the ability to implement next and back buttons trivially:

<Steps {theme} />

<button on:click={() => to($step.next)}>Next Step</button>
<button on:click={() => to($step.previous)}>Previous Step</button>

<script>
	import { to, step } from '@beyonk/svelte-steps'
</script>

Add a Step dynamically

After a specified position

To add a new step, pass it to the addStep method:

after is the id of the step which should sit previous to the new step. id is optional, and is the step id. It will be generated in the absence of passing an id

addStep(step, after, id)

<script>
	import { addStep } from '@beyonk/svelte-steps'
	import { StarIcon } from 'svelte-feather-icons'
	
	addStep({ name: 'Thank You!', icon: StarIcon }, 'payment')
</script>

After the current position

To add a new step at the current position, don't pass the position attribute.

addStep(step)

<script>
	import { addStep } from '@beyonk/svelte-steps'
	import { StarIcon } from 'svelte-feather-icons'
	
	addStep({ name: 'New Step', icon: StarIcon })
</script>

With a custom id

To add a new step with an id, pass it as the third param

addStep(step, after, id)

<script>
	import { addStep } from '@beyonk/svelte-steps'
	import { StarIcon } from 'svelte-feather-icons'
	
	addStep({ name: 'New Step', icon: StarIcon }, 'payment', 'foo123')
</script>

Remove a Step dynamically

At a specified position

To add a new step, use the removeStep function, passing the id of the step to remove

removeStep(id)

<script>
	import { removeStep } from '@beyonk/svelte-steps'
	
	removeStep(2)
</script>

Get Presence of Step

To determine if a step exists, query it by id

Step exists? {hasStep('my-step-id')}

<script>
	import { hasStep } from '@beyonk/svelte-steps'
</script>

Step State

The step state import is called step and contains metadata about the steps:

Total Steps: {$step.total}
Current Index: {$step.index}
Current Step Name: {$step.name}
Current Step Id: {$step.id}
Is Last Step? {$step.isLast}
Is First Step? {$step.isFirst}
Next step id: {$step.next} (false if last step)
Previous step id: {$step.previous} (false if first step)

<script>
	import { step } from '@beyonk/svelte-steps'
</script>

Events

The step icons dispatch a step event when clicked, and the event's details.step contains the id and index of the step which was clicked.

svelte-steps's People

Contributors

ahpercival avatar antony avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

tarentino76

svelte-steps's Issues

Hosted demo does not work

Recently (v1.2?) the concept of the current store was introduced.
The demo on REPL does not seem to have picked up this change.

Changes to be made:

import current from the library

import { Steps, Pages, setup, current } from '@beyonk/svelte-steps'

bind input to the current store

zinput type="range" min=0 max=2 bind:value={$current}/> {$current}

remove property current from Steps

<Steps {theme} />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.