Socket
Socket
Sign inDemoInstall

@commercetools-uikit/collapsible

Package Overview
Dependencies
64
Maintainers
3
Versions
726
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @commercetools-uikit/collapsible

A render-prop component to manage a toggle state


Version published
Weekly downloads
4.4K
increased by83.79%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

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

yarn add @commercetools-uikit/collapsible
npm --save install @commercetools-uikit/collapsible

Additionally install the peer dependencies (if not present)

yarn add react
npm --save install react

Usage

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

PropsTypeRequiredDefaultDescription
isDefaultClosedbooleanfalseThis is only used to initialize the isOpen state once, when the component mounts. Therefore there should not be any componentWillReceiveProps to update the state from an external source.
childrenFunction
See signature.
A render-prop function.
children will be called with options: { isOpen: boolean; toggle: TToggleCallback }
options.toggle will be defined given that Collapsible is a controlled component.
isClosedbooleanPassing this prop makes the component a controlled component. Controlled components also require to pass a onToggle callback function.
onToggleFunction
See signature.
A callback function, called when the consumer calls the toggle function. This function is only required when the component is controlled.

Signatures

Signature children

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

Signature onToggle

(toggleState?: boolean) => void

Keywords

FAQs

Last updated on 29 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc