1. @idui/react-collapse
React Collapse Component
@idui/react-collapse
Package: @idui/react-collapse
Created by: id-ui
Last modified: Tue, 05 Apr 2022 19:17:35 GMT
Version: 2.1.3
License: MIT
Downloads: 697
Repository: https://github.com/id-ui/react-collapse

Install

npm install @idui/react-collapse
yarn add @idui/react-collapse

Collapse React Component

NPM
Size
JavaScript Style Guide
Coverage Status
LICENSE

Install

 npm install --save @idui/react-collapse
 yarn add @idui/react-collapse

See props in Docs

Basic Example

 import React from 'react'
import Collapse from '@idui/react-collapse'

function Example() {
  return <Collapse>
    <Collapse.Header>Open</Collapse.Header>
    <Collapse.Body>:)</Collapse.Body>
  </Collapse>
}

Header Function

 import React, { Fragment } from 'react'
import Collapse from '@idui/react-collapse'

function Example() {
  return <Collapse>
      <Header>
        {({ open, close, toggle }) => (
          <Fragment>
            <button onClick={open}>Open</button>
            <button onClick={close}>Close</button>
            <button onClick={toggle}>Toggle</button>
          </Fragment>
        )}
      </Header>
      <Collapse.Body>:)</Collapse.Body>
  </Collapse>
}

Body Function

 import React from 'react'
import Collapse from '@idui/react-collapse'

function Example() {
  return <Collapse>
    <Collapse.Header>Open</Collapse.Header>
    <Collapse.Body>
        {({ close }) => (
            <Button onClick={close}>Close</Button>
        )}
    </Collapse.Body>
  </Collapse>
}

Styling

 import React from 'react'
import styled from 'styled-components';
import Collapse from '@idui/react-collapse'

const Header = styled(Collapse.Header)`
  padding: 10px;
  line-height: 20px;
  cursor: pointer;
  box-shadow: rgba(0, 0, 0, 0.35) 0 5px 15px;
  width: 100%;
`;

const Body = styled(Collapse.Body)`
  box-shadow: rgba(0, 0, 0, 0.35) 0 5px 15px;
  padding: 20px;
  border-bottom-right-radius: 10px;
  border-bottom-left-radius: 10px;
  width: 100%;
`;

const Content = styled.div`
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
`;

function Example() {
  return <Collapse>
    <Header>Open</Header>
    <Body>
        <Content>:)</Content>
    </Body>
  </Collapse>
}

Custom Animation

 import React from 'react'
import Collapse from '@idui/react-collapse'

function Example() {
  return  <Collapse>
     <Collapse.Header>Open</Collapse.Header>
     <Collapse.Body animation={{
       close: {
         opacity: 0,
       },
       open: {
         opacity: 1
       },
       transition: {
            open: {duration: 0.2, ease: [0.3, 0.6, 0.3, 0.2]},
            close: {duration: 0.1, ease: [0.3, 0.6, 0.3, 0.2]},
       },
     }}>
       :)
     </Collapse.Body>
  </Collapse>
}

See more details in storybook

License

MIT © [email protected]

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code