0.0.3 • Published 6 months ago

react-stepflow v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

React StepFlow

An onboarding component for react, with a simple and easy to use API and a set of built-in components.

NPM Version License: MIT TypeScript

Features

šŸŽØ Fully customizable UI components
šŸ”„ Smooth animations powered by Framer Motion
šŸŒ— Dark/Light theme support built-in
šŸ“± Mobile-first responsive design
⚔ Zero-config Tailwind CSS integration
✨ Type-safe with full TypeScript support

Installation

npm install react-stepflow

Peer Dependencies

{
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
  "framer-motion": "^10.12.16",
  "lucide-react": "^0.244.0",
  "clsx": "^1.2.1",
  "tailwind-merge": "^1.12.0"
}

Quick Start

import {
  OnboardingProvider,
  OnboardingStep,
  OnboardingHeader,
  OnboardingStepIndicator,
} from "react-stepflow";
import "react-stepflow/index.css";

function App() {
  const steps: OnboardingStep[] = [
    { id: 1, component: <Welcome /> },
    { id: 2, component: <Setup /> },
    { id: 3, component: <Complete /> },
  ];

  return (
    <OnboardingProvider stepsCount={steps.length}>
      <div className="flex flex-col gap-4">
        <OnboardingHeader title="Welcome" />
        <OnboardingStepIndicator totalSteps={steps.length} />
        <OnboardingSteps steps={steps} />
      </div>
    </OnboardingProvider>
  );
}

Components API

OnboardingProvider

Root component that provides onboarding context.

PropTypeDefaultDescription
childrenReactNoderequiredChild components
stepsCountnumberrequiredTotal number of onboarding steps

OnboardingSteps

Container component with animation support.

PropTypeDefaultDescription
stepsOnboardingStep[]requiredArray of step components
customAnimationConfigAnimationConfigoptionalCustom animation settings
customAnimationVariantsAnimationVariantsoptionalCustom animation variants

OnboardingStepIndicator

Progress indicator component.

PropTypeDefaultDescription
totalStepsnumberrequiredTotal number of steps
classNamestringoptionalCustom container class
customAnimationConfigAnimationConfigoptionalCustom animation settings

Button

Customizable button component.

PropTypeDefaultDescription
variant'primary' \| 'secondary' \| 'outline' \| 'ghost''primary'Button style variant
size'sm' \| 'md' \| 'lg''md'Button size
loadingbooleanfalseLoading state
disabledbooleanfalseDisabled state

Input

Form input component with validation.

PropTypeDefaultDescription
labelstringoptionalInput label
requiredbooleanfalseRequired field indicator
errorMessagestringoptionalValidation error message

TextLabel

Label text component.

PropTypeDefaultDescription
textstringrequiredLabel text
classNamestringoptionalCustom class

Checkbox

Custom checkbox component.

PropTypeDefaultDescription
namestringrequiredCheckbox name
checkedbooleanrequiredChecked state
onChange(checked: boolean) => voidrequiredChange handler
childrenReactNoderequiredLabel content

Dropdown

Customizable dropdown component.

PropTypeDefaultDescription
valuestring \| nullrequiredSelected value
setValueDispatch<SetStateAction<string \| null>>requiredValue setter
childrenReactNoderequiredDropdown content
classNamestringoptionalCustom styling

FormField

Base form field wrapper component.

PropTypeDefaultDescription
labelstringrequiredField label
idstringoptionalInput element ID
classNamestringoptionalContainer class
inputClassNamestringoptionalInput element class
labelClassNamestringoptionalLabel element class
requiredbooleanfalseRequired field indicator
errorMessagestringoptionalValidation error message

Spinner

Loading spinner component.

PropTypeDefaultDescription
classNamestringoptionalCustom styling class

Default styling includes:

  • Animated spinning effect
  • Responsive sizing (w-5 h-5)
  • Semi-transparent appearance
  • Current color inheritance

Extras

For the components like that can't be targetted direcly, I've provided classnames to target them

  • OnboardingStepDivider: onboarding-divider-outer and onboarding-divider-inner
  • OnboardingStepCircle: onboarding-step-circle

Animation Types

AnimationConfig

PropertyTypeDefaultDescription
durationnumber0.3Animation duration
easestring'easeInOut'Easing function
direction'horizontal' \| 'vertical''horizontal'Animation direction

AnimationVariants

PropertyTypeDescription
initialAnimationPropertyStarting animation state
animateAnimationPropertyActive animation state
exitAnimationPropertyExit animation state

Hook APIs

useOnboarding

PropertyTypeDescription
currentStepnumberCurrent active step
totalStepsnumberTotal number of steps
next() => voidGo to next step
prev() => voidGo to previous step
goToStep(step: number) => voidGo to specific step

Types API

OnboardingStep

PropertyTypeDescription
idnumberUnique step identifier
componentReactNodeStep content component

AnimationConfig

PropertyTypeDescription
durationnumberAnimation duration
easestringEasing function
direction'horizontal' \| 'vertical'Animation direction

AnimationProperty

PropertyTypeDescription
opacitynumberOpacity value
xnumberX-axis translation
ynumberY-axis translation

AnimationVariants

PropertyTypeDescription
initialAnimationPropertyInitial state
animateAnimationPropertyAnimation state
exitAnimationPropertyExit state

ButtonProps

PropertyTypeDescription
variant'primary' \| 'secondary' \| 'outline' \| 'ghost'Button style
size'sm' \| 'md' \| 'lg'Button size
loadingbooleanLoading state

FormFieldProps

PropertyTypeDescription
labelstringField label
classNamestringContainer class
inputClassNamestringInput element class
labelClassNamestringLabel element class
errorMessagestringError message

CheckboxProps

PropertyTypeDescription
namestringCheckbox name
childrenReactNodeLabel content
checkedbooleanChecked state
onChange(checked: boolean) => voidChange handler
classNamestringCustom class

OnboardingContextValue

PropertyTypeDescription
currentStepnumberCurrent step index
totalStepsnumberTotal steps count
next() => voidNext step function
prev() => voidPrevious step function
goToStep(step: number) => voidGo to step function

DropdownProps

PropertyTypeDescription
childrenReactNodeDropdown content
classNamestringCustom class

TextLabelProps

PropertyTypeDescription
textstringLabel text
classNamestringCustom class

Styling

The package uses Tailwind CSS for styling.
Import import "react-stepflow/index.css"; into your app component.

Browser Support

  • Chrome (latest 3 versions)
  • Firefox (latest 3 versions)
  • Safari (latest 2 versions)
  • Edge (latest 3 versions)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Created by David Jaja