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

flex_accordion

v1.0.0

Published

Flex accordion component in React

Downloads

5

Readme

React Flex Accordion

Demo available here: http://emilebres.github.io/react-flex-accordion/

react-flex-accordion-demo

Getting started

Install react-flex-accordion using npm.

npm install react-flex-accordion --save

ES6, CommonJS, and UMD builds are available with each distribution. For example:

import FlexAccordion from 'react-flex-accordion'

Alternately you can load a global-friendly UMD build:

<script src="path-to-react-flex-accordion/dist/umd/react-flex-accordion.js"></script>

Simple Example

FlexAccordion is a controlled component. You pass react-flex-accordion headers and panels as children. You pass the opened panels and an onChange function as props. Here's a simple example:

import React, { Component } from 'react'
import FlexAccordion from 'react-flex-accordion'

export default class FlexAccordionExample extends Component {

  constructor () {
    super()
    this.opened = {0: true}
    this.onChange = (id) => {
      this.opened = ({...this.opened, [id]: !this.opened[id]})
      this.forceUpdate()
    }
  }

  render () {
    return (
      <Accordion opened={this.opened} onChange={this.onChange} >
        <AccordionHeader id={0}>
          Header0
        </AccordionHeader>
        <AccordionPanel id={0}>
          Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </AccordionPanel>
        <AccordionHeader id={1}>
          Header1
        </AccordionHeader>
        <AccordionPanel id={1}>
          Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </AccordionPanel>
      </Accordion>
    )
  }
}

By default, FlexAccordion will span the whole height of its container but you can overwrite this behavior with inline style.

Flex Accordion Props

| Property | Type | Description | |:---|:---|:---| | children | AccordionHeader or AccordionPanel | Children are checked to be of the correct type. | | opened | PropTypes.object | Object defining which panels are open at startup. Keys are the panel ids and values are booleans. Defaults to {}.| | onChange | PropTypes.func | Callback called when a header is clicked; takes the clicked header id as argument. Defaults to () => null. | | style | PropTypes.object | Overwrite the accordion default style. It will merge with the default style: {display: 'flex', position: 'fixed', left: 0, top: 0, bottom: 0}|

The children can take props as well.

For the Accordion headers:

| Property | Type | Description | |:---|:---|:---| | id | PropTypes.number or PropTypes.string | Header id; must match with a panel id (checked at initialization).| | children | React.Element | What is displayed in the header. Only tested with strings. | | disabled | PropTypes.boolean | Disable the header. | | style | PropTypes.object | Overwrite the header default style. It will merge with the default style: {width: '2em', cursor: 'pointer'}| | disabledStyle | PropTypes.object | Style for disabled header.|

For the Accordion panels:

| Property | Type | Description | |:---|:---|:---| | id | PropTypes.number or PropTypes.string | Header id; must match with a header id (checked at initialization).| | children | React.Element | What is displayed in the panel. Only tested with strings. | | onActive | PropTypes.func | Callback when the header is displayed. | | style | PropTypes.object | Overwrite the header default style. It will merge with the default style: {width: '2em', cursor: 'pointer'}|