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

@nice-digital/nds-accordion

v0.3.0

Published

Accordion component for the NICE Design System

Downloads

466

Readme

@nice-digital/nds-accordion

Accordion component for the NICE Design System

Installation

Install Node, and then:

npm i @nice-digital/nds-accordion --save

Usage

This component is not intended for non-React environments. Please contact the design system project team through necessary channels for guidance under these circumstances. We will not be providing snippets for html, SCSSor JavaScript for this reason.

If you're using a controlled group of Accordions. Import both the Accordion and AccordionGroup components from the package and use within the TSX as below:

import React from "react";
import { Accordion, AccordionGroup } from "@nice-digital/nds-accordion";

<AccordionGroup>
  <Accordion key="1" title="Accordion 1">
    Accordion 1 body
  </Accordion>
  <Accordion key="2" title="Accordion 2">
    Accordion 2 body
  </Accordion>
</AccordionGroup>

If you're using a single accordion, import the Accordion component and use within the TSX, as below.

import React from "react";
import { Accordion } from "@nice-digital/nds-accordion";

<Accordion title="Accordion title">
  <p>Accordion content </p>
</Accordion>

/**
 * ...more content between Accordions
*/

<Accordion title="Accordion caution title" variant="caution">
  <p>Caution accordion content</p>
</Accordion>

Note: The React component automatically imports the SCSS, so there's no need to import the SCSS directly yourself.

Accordion

The Accordion can be used as a standalone component or within an AccordionGroup component.

Accordion Props

title
  • Type: string | number
  • Required: Yes

The title of the accordion. This is nested text within the accordions button.

<Accordion title="An accordion title">
	<p>This is the accordions hidden content. Hidden by default.</p>
</Accordion>
open
  • Type: boolean
  • Required: No

The default state of the the accordion being open or closed.

showLabel
  • Type: string
  • Required: No

The label of the accordion toggle label when the is accordion closed.

<Accordion title="An accordion title" showLabel="Show the content">
	<p>This is the accordions hidden content. Hidden by default.</p>
</Accordion>
hideLabel
  • Type: string
  • Required: No

The label of the accordion toggle label when the is accordion open.

<Accordion title="An accordion title" hideLabel="Hide the content">
  <p>This is the accordions hidden content. Hidden by default.</p>
</Accordion>
children
  • Type: React.ReactNode
  • Required: Yes

The body of the Accordion component, which is hidden by default.

<Accordion title="An accordion title">
  <p>This is the accordions child content. Hidden by default.</p>
</Accordion>
variant
  • Type: "caution" | "default"
  • Required: No
  • Default: "default"

The variant of the accordion. Leave blank for the default variant. When caution is provided it displays a WarningIcon that preceeds the accordion title.

<Accordion title="An accordion title" variant="caution">
  <p>This is the accordions hidden content. Hidden by default.</p>
</Accordion>
className
  • Type: string
  • Required: No
  • Default: ""

Any additional classes that you would like applied to the <Accordion> component, or to target it's hidden content children. Test custom styles thoroughly to ensure they don't override critical component styles inadvertently.

<Accordion title="An accordion title" className={style.StoryAccordion}>
  <p>This is the accordions hidden content. Hidden by default.</p>
</Accordion>
displayTitleAsHeading
  • Type: boolean
  • Required: No
  • Default: false

If true the title will be wrapped in a heading element (h2,h3,h4,h5, or h6), as specified by the headingLevel prop.
If false the title is wrapped in a div element. If true and a headingLevel is not supplied, the title will be wrapped with a div by default.

For headings to wrap the title, both displayTitleAsHeading and headingLevel props need to be provided

headingLevel (optional)
  • Type: number | string | undefined
  • Required: Only if the displayTitleAsHeading is true

Specifies the heading level level to be used around the accordions button. This prop is only applicable when displayTitleAsHeading is true. If displayTitleAsHeading is set to false and a headingLevel is supplied, the title will be wrapped with a div by default. If a value other than 2, 3, 4, 5, 6 or "2", "3", "4", "5", "6" is provided, the title will be wrapped with a div by default. If a value other than 2, 3, 4, 5, 6 or "2", "3", "4", "5", "6" is provided, the title will be wrapped with a div by default.

// Correct
<Accordion title="An accordion title" displayTitleAsHeading={true} headingLevel={2}>
  <p>This is the accordions hidden content. Hidden by default.</p>
</Accordion>

// Incorrect
<Accordion title="An accordion title" displayTitleAsHeading={false} headingLevel={2}>
  <p>This is the accordions hidden content. Hidden by default.</p>
</Accordion>
// Correct
<Accordion title="My Accordion" displayTitleAsHeading={true} headingLevel={3}>
  <p>Content goes here</p>
</Accordion>

// Incorrect
<Accordion title="My Accordion" displayTitleAsHeading={true} headingLevel={7}>
  <p>Content goes here</p>
</Accordion>

AccordionGroup

Represents a group of Accordions with state to control toggling of all grouped Accordions.

AccordionGroup Props

children
  • Type: React.ReactNode
  • Required: Yes

The child Accordion components to be rendered inside the AccordionGroup

toggleText
  • Type: function
  • Required: No

A function that returns the text for the group's toggle button based on whether the group is open or closed. Defaults to adefaultToggleTextFn function that returns "Show all sections" or "Hide all sections" based on the isOpen state.

onToggle
  • Type: function
  • Required: No

Is and optional prop that provides a callback function to be called whenever the AccordionGroup toggle button is clicked.