Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chakra-ui/accordion

Package Overview
Dependencies
Maintainers
2
Versions
521
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chakra-ui/accordion

A simple and accessible accordion component for React & Chakra UI

  • 0.0.0-dev-20230830093747
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
293K
decreased by-35.41%
Maintainers
2
Weekly downloads
 
Created

What is @chakra-ui/accordion?

@chakra-ui/accordion is a component library for creating accessible and customizable accordion components in React applications. It is part of the Chakra UI library, which provides a set of accessible, reusable, and composable React components.

What are @chakra-ui/accordion's main functionalities?

Basic Accordion

This code demonstrates a basic accordion with two sections. Each section can be expanded or collapsed by clicking on the header.

import { Accordion, AccordionItem, AccordionButton, AccordionPanel, AccordionIcon } from '@chakra-ui/accordion';

function BasicAccordion() {
  return (
    <Accordion>
      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 1
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 1
        </AccordionPanel>
      </AccordionItem>

      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 2
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 2
        </AccordionPanel>
      </AccordionItem>
    </Accordion>
  );
}

Accordion with Multiple Expandable Sections

This code demonstrates an accordion where multiple sections can be expanded at the same time. The `allowMultiple` prop enables this functionality.

import { Accordion, AccordionItem, AccordionButton, AccordionPanel, AccordionIcon } from '@chakra-ui/accordion';

function MultipleExpandableAccordion() {
  return (
    <Accordion allowMultiple>
      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 1
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 1
        </AccordionPanel>
      </AccordionItem>

      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 2
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 2
        </AccordionPanel>
      </AccordionItem>
    </Accordion>
  );
}

Accordion with Controlled State

This code demonstrates an accordion with controlled state. The `index` state variable controls which sections are expanded, and the `onChange` handler updates this state.

import { useState } from 'react';
import { Accordion, AccordionItem, AccordionButton, AccordionPanel, AccordionIcon } from '@chakra-ui/accordion';

function ControlledAccordion() {
  const [index, setIndex] = useState([0]);

  return (
    <Accordion index={index} onChange={setIndex} allowMultiple>
      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 1
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 1
        </AccordionPanel>
      </AccordionItem>

      <AccordionItem>
        <h2>
          <AccordionButton>
            <Box flex='1' textAlign='left'>
              Section 2
            </Box>
            <AccordionIcon />
          </AccordionButton>
        </h2>
        <AccordionPanel pb={4}>
          Content for section 2
        </AccordionPanel>
      </AccordionItem>
    </Accordion>
  );
}

Other packages similar to @chakra-ui/accordion

Keywords

FAQs

Package last updated on 30 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc