You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@commercetools-uikit/collapsible-panel

Package Overview
Dependencies
Maintainers
3
Versions
911
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools-uikit/collapsible-panel

A panel to collapse and expand your content.


Version published
Weekly downloads
5.1K
decreased by-18.1%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

CollapsiblePanel

Description

A panel to collapse and expand your content.

The component can be used in a controlled or uncontrolled manner. Please refer to the React documentation if you are unsure what either or entails.

Please have a look at the Component Best Practices to ensure that you are using the component as intended from a development and UX perspective.

Installation

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

Additionally install the peer dependencies (if not present)

yarn add react
npm --save install react

Usage

import CollapsiblePanel from '@commercetools-uikit/collapsible-panel';
import Spacings from '@commercetools-uikit/spacings';
import Text from '@commercetools-uikit/text';

const Example = () => (
  <Spacings.Stack>
    {/* 1. Uncontrolled. The `CollapsiblePanel` controls its own state. You do not pass handlers or state related props. */}
    <CollapsiblePanel header="Lorem">
      <Text.Detail>Hello World</Text.Detail>
    </CollapsiblePanel>;{/* 2. Controlled. You control the `CollapsiblePanel`. You do pass handlers or state related props.
    Assume the parent rendering the `CollapsiblePanel` has `isPanelOpen` as state and a `togglePanel` as a handler. */}
    <CollapsiblePanel
      isClosed={this.state.isPanelOpen}
      onToggle={this.togglePanel}
      header="Lorem"
    >
      <Text.Detail>Hello World</Text.Detail>
    </CollapsiblePanel>
    ;
  </Spacings.Stack>
);

export default Example;

Properties

PropsTypeRequiredDefaultDescription
idstringAn unique id for the panel header, which will also be used to generate a prefixed id for the panel content section.
Read about getPanelContentId below for more about this.
headerReactNodeThe title being rendered at top left of the panel
secondaryHeaderReactNodeA secondary header for the panel (only pass if needed)
descriptionstringIf passed will be shown below the title as more information regarding the panel
classNamestringAllow to override the styles by passing a className prop.
Custom styles can also be passed using the css prop from emotion.
isStickybooleanMakes the panel's header sticky in regards to the page's scroll
headerControlsReactNodeControls at the top right part of the panel
isDisabledbooleanfalseDisables the panel and all interactions with it
childrenReactNodeThe actual content rendered inside the panel
toneunion
Possible values:
'urgent' , 'primary'
Indicates the color scheme of the panel.
themeunion
Possible values:
'dark' , 'light'
'dark'Determines the background color of the panel.
condensedbooleanfalseWhenever true the headers and content itself will consume less space in that to the borders are smaller and everything has less padding
hideExpansionControlsbooleanControls the visibility of the expansion controls on the left
headerControlsAlignmentunion
Possible values:
'left' , 'right'
'right'Indicates the position of the control elements in the header component.
isDefaultClosedbooleanIndicates if the panel's content should be collapsed or shown by default.
Updates to this value are not respected. Only used for uncontrolled mode (when noonToggle is passed.)
isClosedbooleanIndicates if the panel's content should be collapsed or shown.
Component becomes *controlled when this is passed.
onToggleFunction
See signature.
function to be triggered whenever the user clicks the top area to collapse the panel's content
Becomes required when isClosed is passed.
horizontalConstraintunion
Possible values:
, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'
'scale'Horizontal size limit of the panel.

Signatures

Signature onToggle

() => void

Where to use

Whenever some content on a given page should be concealed and/or expandible. This often holds true for instance for detailed but hidden information of some entity to save space.

Header

The header of this component should follow our design and UX conventions so it looks the same across the application. It accepts a node to accompany the two scenarios:

  1. Given the CollapsiblePanel is condensed

Whenever the component is configured to be condensed all content pased via the header will be wrapped in a <Text.Detail />. For this use case please ensure that no combinations of components are passed via the header.

import CollapsiblePanel from '@commercetools-uikit/collapsible-panel';

<CollapsiblePanel condensed={true} header={'My title'}>
  <YourComponentAsContentOfThePanel />
</CollapsiblePanel>;
  1. Given the CollapsiblePanel is not condensed

For this use case you will need to explicitly pass the header wrapped by the <CollapsiblePanel.Header /> component to automatically ensure it follows our designs (enforced by the <CollapsiblePanel.Header />).

import CollapsiblePanel from '@commercetools-uikit/collapsible-panel';

<CollapsiblePanel
  header={
    <CollapsiblePanel.Header>
      <FormattedMessage {...messages.title} />
    </CollapsiblePanel.Header>
  }
>
  <YourComponentAsContentOfThePanel />
</CollapsiblePanel>;
  1. Passing a combination of components (e.g. label and input)

Rendering any input(s) inside the header is allowed, but there are certain contraints that need to be taken into account:

  • You can only render a maximum amount of 3 components inside the header.
  • Given a combination of label and input
    • Then the input's label should be bold and the input only a <TextInput />
  • All has to be vertically aligned in the header container.

Theme

The component supports themes (dark and light) to enable nesting of collapsible panels inside one another.

  • Given the background of the parent is dark
    • Then the child needs to be light for better accessibility and visibility

Condensed

There are a some restrictions given using condensed={true}

  1. Nothing complex is passed as the header
  • Nor button or inputs or anything that is not within title itself
  1. The title should be only (if possible) be a string or a combination or text components
  • Everything is automatically wrapped within a <Text.Detail />

SecondaryHeader

The secondaryHeader allow rendering some secondary information in addition to the title.

It accepts a node but with few restrictions:

  1. Bold text is allowed while the text component is <Text.Detail />
  2. Text size should not exceed the font size of <Text.Detail />

headerControls

The headerControls allows rendering a component which should only contain buttons or links. Apart from that there is one more limitation:

  1. You can only render a maximum amount of 3 button inside the headerControls

Static methods

CollapsiblePanel.getPanelContentId

Returns the generated id used for the wrapper of the panel content section. It is used for setting the aria-controls attribute on the header and can also be useful for finding the child element when testing.

CollapsiblePanel.getPanelContentId('example'); // -> panel-content-example

Keywords

FAQs

Package last updated on 19 Jul 2024

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc