Home

Awesome

react-sanfona

NPM info

Travis build status Depfu

React accordion component

giphy 1

Usage

Install via NPM:

npm install react-sanfona

Then:

import { Accordion, AccordionItem } from 'react-sanfona';

…

  render() {
    return (
      <Accordion>
        {[1, 2, 3, 4, 5].map(item => {
          return (
            <AccordionItem title={`Item ${item}`} expanded={item === 1}>
              <div>
                {`Item ${item} content`}
              </div>
            </AccordionItem>
          );
        })}
      </Accordion>
    );
  }

…

options / PropTypes

Accordion

PropertyTypeDescriptionDefault
allowMultipleBooleanAllow multiple items to be open at the same time.false
isHoveredBooleanAllow expanding an element after the mouse hovers an item.false
openNextAccordionItemBooleanOpens the next accordion item after the previous one is closed. Defaults first one as active and applies for each accordion item except the last one.false
classNameStringCustom classname applied to root elementnull
styleObjectInline styles applied to root elementnull
onChangeFunctionTriggered when component updates and passes new state as an argumentnull
rootTagStringCustom HTML tag used for root element'div'
durationNumberOpen/close transition duration in milliseconds300
easingStringOpen/close transition easing'ease'

AccordionItem

PropertyTypeDescriptionDefault
titleString/ ObjectText or Object to display in header.null
expandedBooleanIf item body should be expanded or notfalse
onExpandFunctionCallback for when item is expandednull
onCloseFunctionCallback for when item closesnull
classNameStringCustom classname applied to root item elementnull
bodyClassNameStringCustom classname applied to the accordion item bodynull
expandedClassNameStringCustom classname applied when accordion is expandednull
titleClassNameStringCustom classname applied to accordion item header textnull
disabledBooleanIf item should be disabled or notfalse
disabledClassNameStringCustom classname applied to accordion item header text when item is disablednull
rootTagStringCustom HTML tag used for root element'div'
titleTagStringCustom HTML tag used for title element'h3'
bodyTagStringCustom HTML tag used for body element'div'
durationNumberOpen/close transition duration in milliseconds300
easingStringOpen/close transition easing'ease'
slugStringSlug key to allow indexing by a string

Styling with classnames

ClassnameTargets
react-sanfonaAccordion container
react-sanfona-itemAccordionItem container
react-sanfona-item-expandedAccordionItem container when expanded
react-sanfona-item-titleAccordionItem header text
react-sanfona-item-bodyAccordionItem body container
react-sanfona-item-body-wrapperAccordionItem body children wrapper
react-sanfona-item-disabledAccordionItem is disabled

development

npm install

npm start // served on localhost:8080

npm test