@aspnxdd/react-stepper
TypeScript icon, indicating that this package has built-in type declarations

0.0.42 • Public • Published

React-stepper

Basic react stepper component:

image

Demo!

Install:

$ npm i @aspnxdd/react-stepper

Npm link

Example:

const options: Options = {
  squared: false,
  color: "blue",
  noAnimation: false,
  distance: 9,
};

const defaultSteps: Props[] = [
  {
    text: "Fetching users",
    status: "loading",
    id: 1,
  },
  {
    text: "Fetching data",
    status: "loading",
    id: 2,
  },
  {
    text: "Uploading data",
    status: "loading",
    id: 3,
  },
];

async function sleep(ms: number) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

export default function App() {
  const [steps, setSteps] = useState<Props[]>([]);

  async function simulation() {
    setSteps(defaultSteps);
    await sleep(2000);
    setSteps((e) => {
      e[0].status = "completed";
      return [...e];
    });
    await sleep(2000);
    setSteps((e) => {
      e[1].status = "completed";
      return [...e];
    });
    await sleep(2000);
    setSteps((e) => {
      e[2].status = "completed";
      return [...e];
    });
  }

  return (
    <>
      <button onClick={simulation}>Simulation</button>
      <Stepper steps={steps} options={options} />
    </>
  );
}

Package Sidebar

Install

npm i @aspnxdd/react-stepper

Weekly Downloads

1

Version

0.0.42

License

MIT

Unpacked Size

7.04 kB

Total Files

8

Last publish

Collaborators

  • aspnxdd