1.24.0 • Published 1 month ago

@washingtonpost/wpds-accordion v1.24.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

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:

NameDescriptionTypeRequired
typeDictates 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.enumtrue
disabledWhether the accordion is disabled or notboolfalse
defaultValueItem(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:

NameDescriptionTypeRequired
valueA unique value for the item.stringtrue
disabledWhether the accordion is disabled or notboolfalse
asChildChange 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.boolfalse

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:

NameDescriptionTypeRequired
densityApplies a certain amount of padding to the accordion trigger/headerenumfalse
refA standard React refreffalse
asChildChange 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.boolfalse

Accordion.Content

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

Props:

NameDescriptionTypeRequired
refA standard React referencereffalse
asChildChange 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.boolfalse
forceMountUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries.boolfalse
1.24.0

1 month ago

1.23.1

2 months ago

1.23.0

2 months ago

1.22.6

2 months ago

1.22.0

3 months ago

1.21.0

3 months ago

1.20.0

4 months ago

1.19.0

4 months ago

1.18.0

5 months ago

1.15.0

7 months ago

1.14.0

8 months ago

1.13.0

8 months ago

1.12.0

8 months ago

1.11.1

9 months ago

1.16.2

7 months ago

1.17.0

6 months ago

1.16.1

7 months ago

1.16.0

7 months ago

1.9.1

10 months ago

1.9.0

10 months ago

1.8.5

11 months ago

1.8.4

11 months ago

1.11.0

9 months ago

1.10.0

10 months ago

1.8.2

11 months ago

1.8.1

11 months ago

1.8.0

11 months ago

1.7.1

11 months ago

1.6.2

12 months ago

1.7.0

12 months ago

1.6.1

12 months ago

1.5.2

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

0.25.1

1 year ago

0.25.0

1 year ago

0.24.0

1 year ago

0.23.2

1 year ago

0.21.0

1 year ago

0.20.1

2 years ago

0.20.0

2 years ago

0.19.1

2 years ago

0.23.1

1 year ago

0.22.0

1 year ago

0.19.0

2 years ago

0.18.0

2 years ago

0.17.0

2 years ago

0.16.0

2 years ago