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

@washingtonpost/wpds-accordion

v1.24.0

Published

WPDS Accordion

Downloads

768

Readme

Accordion

The accordion component is composed of four parts: Root, Item, Trigger, and Content. This component expands the Radix Accordion component.

import {
  Accordion,
  ACCORDION_DENSITY,
  ACCORDION_TYPE,
} from "@washingtonpost/wpds-ui-kit";

const Component = () => {
  const myLoader = ({ src }) => {
    return `${src}`;
  };

  return (
    <Accordion.Root type={ACCORDION_TYPE.single} defaultValue="item-1">
      <Accordion.Item value="item-1">
        <Accordion.Trigger
          density={ACCORDION_DENSITY.compact}
          ref={myHeaderRef}
        >
          This is a header
        </Accordion.Trigger>
        <Accordion.Content ref={myContentRef}>
          This the text that can either be expanded or hidden.
        </Accordion.Content>
      </Accordion.Item>
      <Accordion.Item value="item-2">
        <Accordion.Trigger
          density={ACCORDION_DENSITY.compact}
          ref={myHeaderRef}
        >
          This is another header. This item has an image.
        </Accordion.Trigger>
        <Accordion.Content {...args} ref={myContentRef}>
          <Image
            loader={myLoader}
            src="https://i.pravatar.cc/300/300"
            width="100"
            height="100"
            layout="fixed"
            alt="You can have anything as a child, including an image!"
          />
        </Accordion.Content>
      </Accordion.Item>
    </Accordion.Root>
  );
};

Accordion.Root

This is the main wrapper for the accordion component. This is where most of the props get passed. The different types can be found inside the ACCORDION_TYPE enum.

export enum ACCORDION_TYPE {
  single = "single",
  multiple = "multiple",
}

Props:

| Name | Description | Type | Required | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------- | | type | Dictates whether you can have multiple accordion items open at the same time or not. This also affects the TS types of some of other props. | enum | true | | disabled | Whether the accordion is disabled or not | bool | false | | defaultValue | Item(s) that should be expanded from the start. Should match the values assigned to each Accordion.Item . | string | string[] | false |

Accordion.Item

Each Accordion.Item should contain an Accordion.Trigger and an Accordion.Content. Each item should also have a value which will function as a key that you can use to set the defaultValue.

Props:

| Name | Description | Type | Required | | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | | value | A unique value for the item. | string | true | | disabled | Whether the accordion is disabled or not | bool | false | | asChild | Change the component to the HTML tag or custom component of the only child. This will merge the original component props with the props of the supplied element/component and change the underlying DOM node. | bool | false |

Accordion.Trigger

Toggles the collapsed state of its associated item. There are different density options that affect the padding inside the ACCORDION_DENSITY enum.

export enum ACCORDION_DENSITY {
  compact = "compact",
  loose = "loose",
  default = "default",
}

Props:

| Name | Description | Type | Required | | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | -------- | | density | Applies a certain amount of padding to the accordion trigger/header | enum | false | | ref | A standard React ref | ref | false | | asChild | Change the component to the HTML tag or custom component of the only child. This will merge the original component props with the props of the supplied element/component and change the underlying DOM node. | bool | false |

Accordion.Content

Contains the collapsible content for an item. The Accordion.Content can hold anything, from text to images to other components.

Props:

| Name | Description | Type | Required | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | -------- | | ref | A standard React reference | ref | false | | asChild | Change the component to the HTML tag or custom component of the only child. This will merge the original component props with the props of the supplied element/component and change the underlying DOM node. | bool | false | | forceMount | Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. | bool | false |