Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can anyone please help for functional component ? #293

Open
sandipthemes opened this issue Dec 2, 2021 · 3 comments
Open

Can anyone please help for functional component ? #293

sandipthemes opened this issue Dec 2, 2021 · 3 comments

Comments

@sandipthemes
Copy link

I have used below code
https://stackblitz.com/edit/bs-stepper-react

But this is a class component, can anyone help how can we create the same using functional component.

@albert-92
Copy link

I would like to know too.

@innv-imtinan
Copy link

me too

@yusufugurozbek
Copy link

Hello guys 👋🏼

Probably, below example could work for you:

import React, {useEffect, useState} from 'react';
import Stepper from "bs-stepper";

import 'bs-stepper/dist/css/bs-stepper.min.css';

function onSubmit(e: React.FormEvent<HTMLFormElement>) {
    e.preventDefault()
}

function App() {
    const [stepper, setStepper] = useState<Stepper>();

    useEffect(() => {
        const stepperDiv = document.querySelector('#stepper')
        setStepper(new Stepper(stepperDiv!, {
            linear: false,
            animation: true
        }))
    }, []);

    return (
        <div>
            <div id="stepper" className="bs-stepper">
                <div className="bs-stepper-header">
                    <div className="step" data-target="#test-l-1">
                        <button className="step-trigger">
                            <span className="bs-stepper-circle">1</span>
                            <span className="bs-stepper-label">Email</span>
                        </button>
                    </div>
                    <div className="line"></div>
                    <div className="step" data-target="#test-l-2">
                        <button className="step-trigger">
                            <span className="bs-stepper-circle">2</span>
                            <span className="bs-stepper-label">Password</span>
                        </button>
                    </div>
                    <div className="line"></div>
                    <div className="step" data-target="#test-l-3">
                        <button className="step-trigger">
                            <span className="bs-stepper-circle">3</span>
                            <span className="bs-stepper-label">Validate</span>
                        </button>
                    </div>
                </div>
                <div className="bs-stepper-content">
                    <form onSubmit={(e) => onSubmit(e)}>
                        <div id="test-l-1" className="content">
                            <div className="form-group">
                                <label htmlFor="exampleInputEmail1">Email address</label>
                                <input type="email" className="form-control" id="exampleInputEmail1"
                                       placeholder="Enter email"/>
                            </div>
                            <button className="btn btn-primary" onClick={() => stepper?.next()}>Next</button>
                        </div>
                        <div id="test-l-2" className="content">
                            <div className="form-group">
                                <label htmlFor="exampleInputPassword1">Password</label>
                                <input type="password" className="form-control" id="exampleInputPassword1"
                                       placeholder="Password"/>
                            </div>
                            <button className="btn btn-primary" onClick={() => stepper?.next()}>Next</button>
                        </div>
                        <div id="test-l-3" className="content text-center">
                            <button type="submit" className="btn btn-primary mt-5">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    );
}

export default App;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants