<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
<!-- This file is created by the `pnpm generate-readme` script. -->

# Collapsible

## Description

A render-prop component to manage a toggle state. The component can be controlled or uncontrolled, depending if the `isClosed` props is defined or not. A controlled component additionally requires the `onToggle` prop.

## Installation

```
pnpm add @commercetools-uikit/collapsible
```

```
npm --save install @commercetools-uikit/collapsible
```

Additionally install the peer dependencies (if not present)

```
pnpm add react
```

```
npm --save install react
```

## Usage

```jsx
import Collapsible from '@commercetools-uikit/collapsible';

const Example = () => (
  <Collapsible>
    {({ isOpen, toggle }) => (
      <div>
        <div>Status: {isOpen ? 'open' : 'closed'}</div>
        <button onClick={toggle}>Toggle</button>
      </div>
    )}
  </Collapsible>
);

export default Example;
```

## Properties

| Props             | Type                                                 | Required | Default | Description                                                                                                                                                                                                                    |
| ----------------- | ---------------------------------------------------- | :------: | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `isDefaultClosed` | `boolean`                                            |          | `false` | This is only used to initialize the `isOpen` state once, when the component mounts.&#xA;Therefore there should not be any `componentWillReceiveProps` to update the state&#xA;from an external source.                         |
| `children`        | `Function`<br/>[See signature.](#signature-children) |    ✅    |         | A render-prop function.&#xA;<br/>&#xA;`children` will be called with `options: { isOpen: boolean; toggle: TToggleCallback }`&#xA;<br />&#xA;`options.toggle` will be defined given that Collapsible is a controlled component. |
| `isClosed`        | `boolean`                                            |          |         | Passing this prop makes the component a controlled component.&#xA;Controlled components also require to pass a `onToggle` callback function.                                                                                   |
| `onToggle`        | `Function`<br/>[See signature.](#signature-ontoggle) |          |         | A callback function, called when the consumer calls the `toggle` function.&#xA;This function is only required when the component is controlled.                                                                                |

## Signatures

### Signature `children`

```ts
(options: { isOpen: boolean; toggle?: TToggleCallback }) => ReactNode;
```

### Signature `onToggle`

```ts
(toggleState?: boolean) => void
```
