Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

accordion reatjs

import React, { useState } from "react";
import "./accordion.css";

const Accordion = ({ heading, content }) => {
  const [isActive, setIsActive] = useState(false);
  return (
    <li className="accordion-item">
      <div className="accordion-toggle" onClick={() => setIsActive(!isActive)}>
        <h3>{heading}</h3><span>{isActive ? "-" : "+"}</span>
      </div>
      {isActive && <div className="accordion-content">{content}</div>}
    </li>
  );
};

export default Accordion;
Comment

accordion reatjs

.accordion {
  max-width: 768px;
}
.accordion-item {
  list-style: none;
}
.accordion-toggle {
  cursor: pointer;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  background-color: #ccc;
  padding: 1em;
}
.accordion-toggle:hover {
  background-color: #ddd;
}
.accordion-toggle h3 {
  margin: 0;
}
.accordion-content {
  background-color: #eee;
  padding: 1em;
}
Comment

accordion reatjs

export const accordionData = [
  {
    heading: "Will my license be automatically renewed?",
    content:
      "Non odit magnam dolorum. Et odio et maxime consequuntur provident. Error eaque est dolor et qui. Ex odit doloremque consequatur quis. Eaque et pariatur dolores. Magni in quasi dolor repudiandae explicabo.",
  },
  {
    heading: "Can I upgrade my license?",
    content:
      "Quos quam ipsam consequatur consequatur et distinctio. Facere vel ut dolorem. Quam quo neque quos voluptates cupiditate sit quae.",
  },
  {
    heading: "Do you provide email support if I need help?",
    content:
      "Vel et quam reprehenderit velit. Possimus accusamus eos esse vero quo modi voluptas hic. Quia illo quisquam vel quis qui. Autem labore aut incidunt. Eius non voluptatem et laboriosam in.",
  },
];
Comment

accordion reatjs

import React from "react";
import Accordion from "./Accordion";
import { accordionData } from "./data";

const App = () => {
  return (
    <ul className="accordion">
      {accordionData.map(({ heading, content }) => (
        <Accordion heading={heading} content={content} />
      ))}
    </ul>
  );
};

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to sort array least to greatest javascript stACK 
Javascript :: firebase functions add to database 
Javascript :: getmonth js 
Javascript :: jest mock mockname 
Javascript :: javascript how to open a file 
Javascript :: how to remove first element from array in javascript 
Javascript :: js output to console 
Javascript :: javascript loop 
Javascript :: how to connect react to backend 
Javascript :: how to set selected value of dropdown in javascript 
Javascript :: Select HTML elements by CSS selectors 
Javascript :: a href javascript 
Javascript :: how to turn decimales into percents with javascript 
Javascript :: react 17 
Javascript :: node save wav base64 
Javascript :: selected text 
Javascript :: js concat 
Javascript :: javascript string new line 
Javascript :: start animation with javascript 
Javascript :: how to print two arrays together 
Javascript :: find all of array which satisfy condition javascript 
Javascript :: node js clear cache 
Javascript :: jQuery intellisence in VSCode 
Javascript :: javascript delete user input value in array 
Javascript :: building a linked list javascript 
Javascript :: apollo client nextjs 
Javascript :: JavaScript POSITIVE_INFINITY 
Javascript :: js array push 
Javascript :: for...of Syntax 
Javascript :: javascript console.log() method in browser 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =