npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@moxy/react-accordion

v1.0.0

Published

A react component that renders an accordion with accessible navigation.

Downloads

15

Readme

react-accordion

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

A react component that renders an accessible accordion.

Installation

$ npm install @moxy/react-accordion

This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.

Motivation

An accordion allows users to toggle the display of content sections. This package was created to make it easier to implement an accordion with accessible navigation.

Usage

import React from 'react';
import { Accordion, AccordionItem } from '@moxy/react-accordion';

const MyComponent = () => {
    <div>
        <Accordion defaultActiveItems={ [0, 1] } multiple scrollIntoView>
            <AccordionItem title="Foo">
                Bar
            </AccordionItem>
            <AccordionItem title="Foo1">
                Bar1
            </AccordionItem>
        </Accordion>
    </div>
}

To import a stylesheet, one can import it on the project's entry CSS file:

/* src/index.css */
@import "@moxy/react-accordion/dist/index.css";

Or in the project's entry JavaScript file:

/* src/index.js */
import "@moxy/react-accordion/dist/index.css";

API

These are the props available in @moxy/react-accordion.

Accordion Props

children

Type: node | Required: true

One or more AccordionItem elements that will be rendered inside the Accordion.

defaultActiveItems

Type: array | Required: false | Default: []

The indexes of the items that should be open by default.
It is necessary to have the prop multiple enabled to have more than one item open.

multiple

Type: boolean | Required: false | Default: false

Whether or not multiple items can be open at the same time.

className

Type: string | Required: false

A className to apply to the accordion container.

closedClassName

Type: string | Required: false

A className to apply to the accordion container when all the items are closed.

onItemToggling

Type: function | Required: false | Arguments: index: Number, options: { active: Boolean }

Callback to be invoked before an item is opened or closed.

AccordionItem Props

title

Type: any | Required: true

The content of the title.

children

Type: node or function | Required: false

The content of the item.

Example with function:

<AccordionItem { ...props }>
    { ({ isActive }) => isActive ? 'Open' : 'Closed' }
</AccordionItem>

⚠️ All the following props can be defined at the Accordion level whenever you want a specific prop to be the same for all accordion items.

Keep in mind that if you define a prop in Accordion and in an AccordionItem, the one that will be used is the AccordionItem one.

animationDuration

Type: number | Required: false | Default: 300

Duration of the animation for both opening and closing states.

animationEasing

Type: string | Required: false | Default: ease-in-out

Type of animation easing for both opening and closing states.

itemContainerClassName

Type: string | Required: false

A className to apply to the item container.

headingContainerClassName

Type: string | Required: false

A className to apply to the heading container.

titleContainerClassName

Type: string | Required: false

A className to apply to the title.

contentContainerClassName

Type: string | Required: false

A className to apply to the content container.

contentClassName

Type: string | Required: false

A className to apply to the content.

iconClassName

Type: string | Required: false

A className to apply to the icon container.

icon

Type: any | Required: false

The content of the icon.

Tests

$ npm test
$ npm test -- --watch # during development

Demo

A demo Next.js project is available in the /demo folder so you can try out this component.

First, build the react-accordion project with:

$ npm run build

To run the demo, do the following inside the demo's folder:

$ npm i
$ npm run dev

Note: Everytime a change is made to the package a rebuild is required to reflect those changes on the demo.

FAQ

I can't override the component's CSS, what's happening?

There is an ongoing next.js issue about the loading order of modules and global CSS in development mode. This has been fixed in v9.3.6-canary.0, so you can either update next.js to a version higher than v9.3.5, or simply increase the CSS specificity when overriding component's classes, as we did in the demo, e.g. having the page or section CSS wrap the component's one.

License

Released under the MIT License.