ui icon indicating copy to clipboard operation
ui copied to clipboard

feat(stepper): new stepper component

Open damianricobelli opened this issue 1 year ago • 278 comments

Hi! In this opportunity I present a new component: Stepper.

The idea of this in its beginnings was to make it as modular and flexible as possible for development.

A basic example of the application is this:

const steps = [
  { label: "Step 1" },
  { label: "Step 2" },
  { label: "Step 3" },
] satisfies StepConfig[]

export const StepperDemo = () => {
  const {
    nextStep,
    prevStep,
    resetSteps,
    setStep,
    activeStep,
    isDisabledStep,
    isLastStep,
    isOptionalStep,
  } = useStepper({
    initialStep: 0,
    steps,
  })

  return (
    <>
      <Steps activeStep={activeStep}>
        {steps.map((step, index) => (
          <Step index={index} key={index} {...step}>
            <div className="bg-muted h-40 w-full p-4">
              <p>Step {index + 1} content</p>
            </div>
          </Step>
        ))}
      </Steps>
      <div className="flex items-center justify-end gap-2">
        {activeStep === steps.length ? (
          <>
            <h2>All steps completed!</h2>
            <Button onClick={resetSteps}>Reset</Button>
          </>
        ) : (
          <>
            <Button disabled={isDisabledStep} onClick={prevStep}>
              Prev
            </Button>
            <Button onClick={nextStep}>
              {isLastStep ? "Finish" : isOptionalStep ? "Skip" : "Next"}
            </Button>
          </>
        )}
      </div>
    </>
  )
}

Here is a complete video of the different use cases:

https://user-images.githubusercontent.com/22398603/236876155-5cafd5c4-5aea-41ab-aaf4-76e8b20a2eed.mov

damianricobelli avatar May 08 '23 16:05 damianricobelli

@damianricobelli is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 08 '23 16:05 vercel[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 17, 2024 7:14pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-template ⬜️ Ignored (Inspect) Visit Preview Apr 17, 2024 7:14pm

vercel[bot] avatar May 08 '23 16:05 vercel[bot]

love it 👀

jocarrd avatar May 09 '23 09:05 jocarrd

This looks incredible @damianricobelli I'll review.

shadcn avatar May 09 '23 20:05 shadcn

Looks amazing 😍 Unfortunately I don't have time to review and research about this component. However, look what I recently found: https://saas-ui.dev/docs/components/navigation/stepper.
https://github.com/saas-js/saas-ui/tree/main/packages/saas-ui-core/src/stepper

This can serve as reference to improve or borrow ideas to simplify the implementation. From what I can suggest it is to rename Step to StepperStep and useSteps to useStepper to comply with the general API conventions of the components and it will be more unique name to prevent conflicts.

its-monotype avatar May 09 '23 23:05 its-monotype

Looks amazing 😍 Unfortunately I don't have time to review and research about this component. However, look what I recently found: https://saas-ui.dev/docs/components/navigation/stepper. https://github.com/saas-js/saas-ui/tree/main/packages%2Fsaas-ui-stepper

This can serve as reference to improve or borrow ideas to simplify the implementation. From what I can suggest it is to rename Step to StepperStep and useSteps to useStepper to comply with the general API conventions of the components and it will be more unique name to prevent conflicts.

Thank you very much for your feedback! I'll be reviewing tomorrow what you just shared and your suggestions 🫶

damianricobelli avatar May 10 '23 02:05 damianricobelli

@shadcn What do you think about this component? Do you think we should adjust anything so that it can be launched on prod?

damianricobelli avatar May 30 '23 13:05 damianricobelli

Is this is still in progress?

destino92 avatar Jun 17 '23 20:06 destino92

Is this is still in progress?

@destino92 From my side the component is ready. Just need to know if @shadcn agrees to move forward and add it to the CLI that brings and details that you think are missing in terms of documentation.

damianricobelli avatar Jun 20 '23 22:06 damianricobelli

This looks good!

drewhoffer avatar Jun 30 '23 13:06 drewhoffer

Hi @damianricobelli, this component looks very good. Could you please update it to the new version (different themes, registry, docs, etc.)?

dan5py avatar Jun 30 '23 13:06 dan5py

@dan5py yes of course. Between today and Monday I will be making the necessary changes so that the component allows the last addition you mention.

damianricobelli avatar Jun 30 '23 18:06 damianricobelli

@shadcn Could you check this? I've already updated the code with all the latest stuff in the main branch. There are already several people watching the release of this component 🤩 🚀

damianricobelli avatar Jul 04 '23 19:07 damianricobelli

Hi @damianricobelli, this component looks very good. Could you please update it to the new version (different themes, registry, docs, etc.)?

Done @dan5py! 🥳

damianricobelli avatar Jul 04 '23 19:07 damianricobelli

any update on this 🤔

FadiAboMsalam avatar Jul 11 '23 14:07 FadiAboMsalam

@shadcn @dan5py Please review it, it must have components and huge work

its-monotype avatar Jul 11 '23 14:07 its-monotype

@its-monotype

@shadcn @dan5py Please review it, it must have components and huge work

You can always just fork what Damian has if you need it that urgently.

drewhoffer avatar Jul 11 '23 14:07 drewhoffer

Any update on this ? @shadcn

Sparsh-Malhotra avatar Jul 22 '23 16:07 Sparsh-Malhotra

@damianricobelli Amazing work! Thank you :)

RamonEbneter avatar Aug 05 '23 13:08 RamonEbneter

@damianricobelli Nice work! Thanks! @shadcn Any update on when will this component be deployed and be available for use?

5hraddha avatar Aug 07 '23 18:08 5hraddha

This is awesome, can it be used in vertical direction? EDIT: Yes!

KryptXBSA avatar Aug 18 '23 03:08 KryptXBSA

@SaadBazaz I have added the class you suggested and also added additionalClassName to the API to be able to add classes and configure the layout of the internal elements such as the buttons containing the step numbers, the label and the label description.

In addition, I extended the StepsProps interface to React.HTMLAttributes<HTMLDivElement> to allow adding props from the parent div.

Do you think it is ready to go into production?

damianricobelli avatar Aug 18 '23 15:08 damianricobelli

Waiting for it...

iamkhalidbashir avatar Aug 21 '23 14:08 iamkhalidbashir

@SaadBazaz I have added the class you suggested and also added additionalClassName to the API to be able to add classes and configure the layout of the internal elements such as the buttons containing the step numbers, the label and the label description.

In addition, I extended the StepsProps interface to React.HTMLAttributes to allow adding props from the parent div.

Do you think it is ready to go into production?

I think it's almost at par to most Stepper implementations out there.

What's most concerning to me:

  1. Mobile responsiveness
  2. Animations (see MUI's implementation, and see the transition animation in this shadcn/ui component)
  3. Improvements of docs

I think mobile responsiveness can use some work. Here's how it looks like on my end: Screenshot 2023-08-21 at 21 23 30

SaadBazaz avatar Aug 21 '23 16:08 SaadBazaz

@SaadBazaz Perfect, I'll be working on it in the next few days

damianricobelli avatar Aug 21 '23 23:08 damianricobelli

@damianricobelli Happy to merge this when ready. Let me know.

shadcn avatar Aug 25 '23 03:08 shadcn

@SaadBazaz Perfect, I'll be working on it in the next few days

Just had a brainfart: maybe Accordion component can be used as a base for the animation. https://ui.shadcn.com/docs/components/accordion

https://github.com/shadcn-ui/ui/assets/51885228/8b27faca-a201-4357-8caa-336e3e7a6205

Also, a nice observation: it seems like even the docs have their own "Stepper" 😁 Hope this new component can replace it! Screenshot 2023-08-25 at 11 58 36

SaadBazaz avatar Aug 25 '23 06:08 SaadBazaz

Thank you @Sparsh-Malhotra awesome work

pappijx avatar Sep 19 '23 07:09 pappijx

Any update here? @damianricobelli @shadcn

guifeliper avatar Oct 09 '23 19:10 guifeliper

Just came here to open an issue for the same component. Glad to see this one is already in the works.

Eagerly awaiting it 🙂

brandonmcconnell avatar Oct 18 '23 20:10 brandonmcconnell