1.4.1 • Published 3 years ago

react-faq-toggler v1.4.1

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

React FAQ Toggler Component

Simple FAQ component with individual question/answer toggle, with smooth icon rotate on click.

Usage:

Pass in the props of faqs, containing an array of objects, with the keys of 'question' and 'answer':

import FaqComponent from "react-faq-toggler";
function App() {
    const data = [
        { question: "Hello there?", answer: "Boo" },
        { question: "You what?", answer: "Meh" },
        { question: "A third question, I have", answer: "Well, do you now!" },
    ];
    return (
        <div className="App">
            <h1>My Super App</h1>
            <div className="faq-cont">
                <FaqComponent faqs={data} />
            </div>
        </div>
    );
}

Default Width

By default, the FaqComponent will have a width of 100% of its parent container.

Paragraphs

Use '\n' to break individual FAQ question/answer into paragraphs (uses CSS rule, "white-space:pre-wrap")

Styling

Uses the following class names to style the question/answers:

<p class="faq-question-style"></p>
<p class="faq-answer-style"></p>

Recommended default styles:

.faq-question-style {
    width: 100%;
    background-color: rgb(255, 102, 0);
    color: white;
    border-radius: 5px;
    padding: 1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.25em;
    margin: 0.25em 0;
    white-space: pre-wrap;
}

.faq-question-style:hover {
    cursor: pointer;
}
.faq-cont {
    width: 70%;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 1.5em;
    -webkit-user-select: none; /* Chrome/Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+ */
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}
.faq-answer-style {
    display: none;
    font-weight: 300;
    width: 100%;
    color: black;
    border-radius: 5px;
    padding: 0 1em;
    text-align: left;
    font-size: 1.25em;
    margin: 0.5em 0;
    white-space: pre-wrap;
}

.faq-show-animation {
    display: block;
    height: fit-content;
    animation: faq-answer-slide 0.8s;
}

.faq-rotate-forwards {
    transform: rotate(180deg);
    transition: 0.2s transform;
}

.faq-rotate-back {
    transform: rotate(0deg);
    transition: 0.2s transform;
}
@keyframes faq-answer-slide {
    0% {
        opacity: 0;
        max-height: 0;
    }

    100% {
        opacity: 1;
        max-height: 500px;
    }
}

Custom Icon

Uses FontAwesome icons for responsiveness - default icon is a chevron, but you can pass in your own FontAwesome icon by importing and passing it through the 'icon' props:

import FaqComponent from "react-faq-toggler";
import { SomeOtherIcon } from "@fortawesome/free-solid-svg-icons";
function App() {
    const data = [
        { question: "Hello there?", answer: "Boo" },
        { question: "You what?", answer: "Meh" },
        { question: "A third question, I have", answer: "Well, do you now!" },
    ];
    return (
        <div className="App">
            <h1>My Super App</h1>
            <div className="faq-cont">
                <FaqComponent faqs={data} icon={someOtherIcon} />
            </div>
        </div>
    );
}

Screenshot

screenshot

1.4.1

3 years ago

1.4.0

3 years ago

1.3.9

3 years ago

1.3.7

4 years ago

1.2.8

4 years ago

1.3.6

4 years ago

1.2.7

4 years ago

1.3.5

4 years ago

1.2.6

4 years ago

1.3.4

4 years ago

1.2.5

4 years ago

1.3.3

4 years ago

1.2.4

4 years ago

1.3.2

4 years ago

1.2.3

4 years ago

1.3.1

4 years ago

1.2.2

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.3.8

4 years ago

1.2.9

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago