https://github.com/scriptex/react-accordion-ts
A collapsible widget for React
https://github.com/scriptex/react-accordion-ts
accordion accordion-widget collapsible collapsible-component react-component
Last synced: 11 months ago
JSON representation
A collapsible widget for React
- Host: GitHub
- URL: https://github.com/scriptex/react-accordion-ts
- Owner: scriptex
- License: mit
- Created: 2018-10-08T07:57:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-29T00:29:49.000Z (12 months ago)
- Last Synced: 2025-04-10T04:05:47.277Z (11 months ago)
- Topics: accordion, accordion-widget, collapsible, collapsible-component, react-component
- Language: TypeScript
- Homepage: https://react-accordion-ts.atanas.info/
- Size: 5.07 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/scriptex/react-accordion-ts)
[](https://github.com/scriptex/react-accordion-ts/actions?query=workflow%3ABuild)
[](https://www.codacy.com/gh/scriptex/react-accordion-ts/dashboard?utm_source=github.com&utm_medium=referral&utm_content=scriptex/react-accordion-ts&utm_campaign=Badge_Grade)
[](https://codebeat.co/projects/github-com-scriptex-react-accordion-ts-master)
[](https://www.codefactor.io/repository/github/scriptex/react-accordion-ts)
[](https://deepscan.io/dashboard#view=project&tid=3574&pid=5257&bid=40799)
[](https://github.com/scriptex/react-accordion-ts/)
# React Accordion
> An accordion widget for React web applications written in Typescript.
## Visitor stats




## Code stats





## About
This is a collapsible widget for React web applications written in TypeScript without any external dependencies (except React of course).
It uses the Hooks API and CSS to animate the collapsible contents.
The latest version of the widget has been built using the Hooks API introduced with React 16.
If you need to support older versions of React, please install [an older version](https://www.npmjs.com/package/react-accordion-ts/v/0.2.0).
**Please note that this widget does NOT work with React Native.**
[You can see the demo here](https://react-accordion-ts.atanas.info/)
## Install
```sh
npm i react-accordion-ts
# or
yarn add react-accordion-ts
```
## Usage
```javascript
import * as React from 'react';
import { Accordion } from 'react-accordion-ts';
const content = 'Lorem ipsum, dolor sit amet consectetur adipisicing elit.';
const news = [
{
date: '12-10-2018',
title: 'Awesome title',
content: [content]
},
{
date: '13-10-2018',
title: 'Awesome title',
content: [content, content],
open: true
},
{
date: '13-10-2018',
title: 'Awesome title',
content: [content],
open: true
}
];
const items = news.map(({ open, date, title, content }) => ({
open,
title:
{date + ' - ' + title}
,
content: (
<>
{content.map((item: string, index: number) => (
{item}
))}
>
)
}));
export const MyComponent = () => ;
```
You can also use the basic stylesheet included:
```javascript
import 'react-accordion-ts/src/panel.css';
```
or
```css
@import 'react-accordion-ts/src/panel.css';
// If the above doesn't work, add a ~ in the beginning:
@import '~react-accordion-ts/src/panel.css';
```
## Props
### Accordion props
| Prop | Type | Required | Default | Description |
| ---------- | ----------------- | -------- | ------- | ------------------------------------------------------------------------ |
| `open` | `number` | false | -1 | Zero based index representing the accordion item which is initially open |
| `items` | `AccordionItem[]` | true | - | Array of `AccordionPanel` objects (see below) |
| `duration` | `number` | false | 300 | Duration (in milliseconds) of the expanding/collapsing animation |
| `multiple` | `boolean` | false | false | A ReactNode representing the content of the slide |
### Accordion panel props
| Prop | Type | Required | Description |
| --------- | ----------- | -------- | -------------------------------------------------------------------------------------- |
| `open` | `boolean` | false | Whether the panel should be initially open |
| `title` | `ReactNode` | true | The title of the panel. This is the element which expands/collapses the panel on click |
| `content` | `ReactNode` | true | The panel content. |
## LICENSE
MIT
---
Connect with me:
---