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

react-sliding-form

v3.2.1

Published

Reusable react component and hook that makes building new multi-step forms and managing the state of all steps easy. Uses css translateX with bezier curve animation for a smooth sliding transition between each step.

Downloads

297

Readme

react-sliding-form

  • Easily build sliding forms (multi-step optional) inside of a mui dialog popup. (live example can be found at https://www.carbodylab.com/)
  • Conveniently collect all data gathered in each step only when you need to (reduce the use of context and re-renders caused by passing state down).
  • Store all state logic inside of each step themselves, rather than using a context or passing state down. Allow each step to validate itself and inform react-sliding-form when it is complete.
  • Conveniently determine when to disable or enable "next" buttons for you, by passing each child (step) of react-sliding-form a setIsReady function, freely called by each child when complete.

What this does

Allows you to easily build sliding forms (multi-step optional) inside of a dialog popup like the three screenshots below: image image image

How to use SlidingForm

import { Box, Dialog, Button } from '@mui/material
import { SlidingForm } from 'react-sliding-form'
import Slide1 from './Slide1'
import Slide2 from './Slide2'
import Slide3 from './Slide3'
import Slide4 from './Slide4'
import { styles } from './styles'

const slideItems = [
  { slide: Step1, label: 'Vehicle' },
  { slide: Step2, label: 'Photos' },
  { slide: Step3, label: 'Contact' },
  { slide: Step4 }
]

const Container = () => {
  const submitRequest = data = () => fetch('https://www.arrontaylor.me/submit_request', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    })
  
  return (
    <Box>
      <Dialog open={open}>
        <SlidingForm 
          slideItems={slideItems}
          submitAction={v => submitRequest(v)}
          closeAction={() => setOpen(false)}
          styles={styles}
        />  
      </Dialog>
      <Button onClick={_ => setOpen(true)}> Open Dialog </Button>
    </Box>
}

How to write each step

  1. Make sure to consume the properties { setIsReady, refValue }
  2. Make sure to use the useElevateChildState hook and pass it all of the values you want to keep track of, along with the refValue prop, and finally a list of dependencies.
  3. When the step is considered "ready", call the setIsReady function with the current "ready state" of the step.
  4. Once the step calls setIsReady, the buttons in the stepper will automatically update to allow for "next".
import React, { useState, useEffect } from 'react'
import { TextField, Box } from '@mui/material'
import { useElevateChildState } from 'react-sliding-form'

const Step3 = ({ setIsReady, refValue, currentData }) => {
  const [zip, setZip] = useState(null)
  const [name, setName] = useState(null)
  const [phone, setPhone] = useState(null)
  const [email, setEmail] = useState(null)
  const nameIsValid = name && name.trim().length > 1
  const phoneIsValid = phone && /\d{10}/.test(phone)
  const zipIsValid = zip && /^\d{5}$/.test(zip)
  const emailIsValid =
    email && /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(email)

  // currentData is an up to date global state of all steps

  const contactIsValid =
    (nameIsValid && phoneIsValid && zipIsValid && emailIsValid) || false

  setIsReady(contactIsValid)

  useElevateChildState({ zip, name, phone, email },
    refValue, [zip, name, phone, email])

  return (
    <Box>
      <Box>
        Enter your contact details Full name
        <TextField
          onChange={e => setName(e.target.value)}
          value={name || ''}
          placeholder='Full Name'
        />
        <br />
        Phone
        <TextField
          onChange={e => setPhone(e.target.value)}
          value={phone || ''}
          placeholder=' (123)  456 &#8212; 7890 '
        />
        <br />
        Your email
        <TextField
          onChange={e => setEmail(e.target.value)}
          value={email || ''}
          placeholder='[email protected]'
        />
        <br />
        Zip code
        <TextField
          onChange={e => setZip(e.target.value)}
          value={zip || ''}
          placeholder='5-Digit ZIP Code'
        />
      </Box>
    </Box>
  )
}

export default Step3