Giter Club home page Giter Club logo

react-css-collapse's Introduction

react-css-collapse

Collapse component with css transition for elements with variable and dynamic height.

Build Status npm version npm downloads

Example

Install

rc-collapse

Support

Global coverage > 92% - browserl.ist

Usage

import Collapse from 'react-css-collapse';

<Collapse isOpen={true || false}>
  <div>content</div>
</Collapse>

Properties

isOpen: PropTypes.boolean

Expands or collapses content.

children: PropTypes.node

<Collapse isOpen={true}>
  <p>Paragraph of text</p>
  <p>Another paragraph is also OK</p>
  <p>Images and any other content are ok too</p>
  <img src="cutecat.gif" />
</Collapse>

className: PropType.string

Specify transition using the class selector with transition or the style property. The react-css-collapse-transition class selector is added by default unless you specify your own.
The default transition can be overridden using the transition prop, or with custom styling ๐Ÿ‘‡. Note: replace the selector with your selector if you have specified a different className.

.react-css-collapse-transition {
  transition: height 250ms cubic-bezier(.4, 0, .2, 1);
}

onRest: PropTypes.func

Callback function for when your transition on height (specified in className) is finished. It can be used to trigger any function after transition is done.

ARIA and data attributes

Collapse transfers aria- and data- attributes to the component's rendered DOM element. For example this can be used to set the aria-hidden attribute:

<Collapse isOpen={isOpenState} aria-hidden={isOpenState ? 'false' : 'true'}>
  <p>Paragraph of text</p>
</Collapse>

Development and testing

To run example covering all features, use npm run storybook.

git clone [repo]
cd [repo]
npm install
npm run storybook

Open http://localhost:6006 ๐ŸŽ†

react-css-collapse's People

Contributors

c624ds0 avatar cdeutsch avatar dependabot-preview[bot] avatar dependabot[bot] avatar deshiknaves avatar devbeard avatar floppey avatar kegulf avatar kwltrs avatar mshwery avatar tobiasla avatar tonyhopland avatar torleifhalseth avatar xslemx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-css-collapse's Issues

TypeError: null is not an object (evaluating 'this.content.style')

I'm not sure what is causing this issue specifically only that it happens sporadically.

stacktrace:

webpack:///~/react-css-collapse/lib/components/Collapse.js:99setContentStyleProperty

  }, {
    key: 'setContentStyleProperty',
    value: function setContentStyleProperty(property, value) {
      this.content.style[property] = value;
    }
  }, {
    key: 'setCollapsed',

webpack:///~/react-css-collapse/lib/components/Collapse.js:104setCollapsed

}, {
   key: 'setCollapsed',
   value: function setCollapsed() {
     this.setContentStyleProperty('height', '0px');
     this.setContentStyleProperty('overflow', 'hidden');
   }
 }, {

Create a CONTRIBUTE document

The repo should have a contribute document documenting how one should contribute to this projects. PRs, tests, etc.

`overflow: hidden` should be removed after initial render when `isOpen={true}`

First off thanks for this component โ€“ came in handy in a pinch.

I have children components that have dropdowns that might spill over beyond the <Collapse /> parent component's height. The problem I'm encountering only happens when the initial render has isOpen={true}.

The inline style overflow: hidden is applied and remains on the component until you switch the state from isOpen={false}. In fact, once you toggle it yet again to isOpen={true} after being in the isOpen={false} state it does remove the overflow: hidden style with overflow: visible, which is what my child components require after the animation is complete.

ComponentWillReceiveProps warning after upgrade to React 16.9.0

After upgrade to React 16.9.0, React prints console warning because react-css-collapse still uses componentWillReceiveProps life-cycle method. This method will be removed in React 17.0.0.
Would you please rewrite the code to make it work after React 17.0.0 release?
Thank you!

Possibility to specify CSS transition as component property

Thank you for this component. It work's quite well :).

However, I have an idea for improvement: Right now it is required to specify the className to set the desired CSS transition. While this might be fine for most use cases, because most people should have some kind of CSS-in-JS solution or a bundler in use anyway, it is also somewhat limiting. In my opinion it would be very handy, if the transition could also be set directly as Component property. This way users are not forced to use some library to inject the styles into the HTML or to do this manually.

Example:

<Collapse isOpen={isOpen} transition="height 250ms cubic-bezier(.4, 0, .2, 1)">
   <div>foo</div>
</Collapse>

Moreover it might be a good idea to offer a reasonable default transition (could be the default value of this potentially new component property). I was confused first, because the element collapsed without an animation. I think you should make it clearer in the README, that it is required to define a CSS transition first to make the animation work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.