Skip to content

Commit

Permalink
Merge pull request #42 from glennflanagan/release/2.0
Browse files Browse the repository at this point in the history
Version 2 Release
  • Loading branch information
glennflanagan authored Aug 22, 2017
2 parents 1898366 + 82157b3 commit 3edd413
Show file tree
Hide file tree
Showing 18 changed files with 4,450 additions and 23,595 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist/Collapsible.js
node_modules
.DS_Store
npm-debug.log
dist/*.js
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Glenn Flanagan
Copyright (c) 2017 Glenn Flanagan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
111 changes: 56 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,18 @@ Supported by [Browserstack](https://www.browserstack.com).

![Browserstack Logo](example/img/browserstack-logo.png "Browserstack")

## What's new in 1.5.0
* Added `onClose` and `onOpen` callback props.
---
## Migrating from v1.x to v2.0
Version 2 is 100% API complete to version 1. However, there is a breaking change in the `onOpen` and `onClose` callbacks. These methods now fire at the end of the collapsing animation. There is also the addition of `onOpening` and `onClosing` callbacks which fire at the beginning of the animation.

### 1.4.0 Notes
* Added the ability to add non-triggering elemnts to the trigger using `triggerSibling`.
To migrate to v2 from v1 simply change the `onOpen` prop to `onOpening` and `onClose` to `onClosing`.

### 1.3.0 Notes
* You can now disable triggers programatically using the `triggerDisabled` prop.
* More granular control over CSS classes allowing easier integration to your chosen CSS framework.

### 1.2.0 Notes
* `overflowWhenOpen` props added to allow setting of the CSS overflow property when Collapsible is open.

### 1.1.0 Notes
* `lazyRender` props added to allow lazy-loading of Collapsible content.

### 1.0.0 Notes
* Trigger can now be a React Element as well as a string.
## What's new in 2.0
* Added `onClosing` and `onOpening` callback props.
* Several issue fixes (#12, #21, #24)


---
## Installation
Installation can be achieved via NPM.
```
Expand All @@ -38,6 +30,7 @@ npm install react-collapsible

Alternatively just download the `Collapsible.js` file form the `src` folder and include it in your project in your chosen way.

---
## Usage
Collapsible can receive any HTML elements or React component as it's children. Collapsible will wrap the contents, as well as generate a trigger element which will control showing and hiding.

Expand Down Expand Up @@ -69,71 +62,78 @@ With a little CSS becomes

![Alt text](example/img/becomes.png)


---
## Properties *(Options)*

### `trigger` | *string* or *React Element* | **required**
### **trigger** | *string* or *React Element* | **required**
The text or element to appear in the trigger link.

### `triggerWhenOpen` | *string* or *React Element*
### **triggerWhenOpen** | *string* or *React Element*
Optional trigger text or element to change to when the Collapsible is open.

### `triggerDisabled` | *boolean* | default: false
### **triggerDisabled** | *boolean* | default: false
Disables the trigger handler if `true`. Note: this has no effect other than applying the `.is-disabled` CSS class if you've provided a `handleTriggerClick` prop.

### `transitionTime` | *number* | default: 400
### **transitionTime** | *number* | default: 400
The number of milliseconds for the open/close transition to take.

### `easing` | *string* | default: 'liner'
### **easing** | *string* | default: 'linear'
The CSS easing method you wish to apply to the open/close transition. This string can be any valid value of CSS `transition-timing-function`. For reference view the [MDN documentation](https://developer.mozilla.org/en/docs/Web/CSS/transition-timing-function).

### `open` | *bool* | default: false
### **open** | *bool* | default: false
Set to true if you want the Collapsible to begin in the open state. You can also use this prop to manage the state from a parent component.

### `classParentString` | *string* | default: Collapsible
Use this to overwrite the parent CSS class for the Collapsible component parts. Read more in the CSS section below.

### `className` | *string*
`.Collapsible` element (root) when closed

### `openedClassName` | *string*
`.Collapsible` element (root) when open

### `triggerClassName` | *string*
`.Collapsible__trigger` element (root) when closed

### `triggerOpenedClassName` | *string*
`.Collapsible__trigger` element (root) when open

### `contentOuterClassName` | *string*
`.Collapsible__contentOuter` element

### `contentInnerClassName` | *string*
`.Collapsible__contentInner` element

### `accordionPosition` | *string*
### **accordionPosition** | *string*
Unique key used to identify the `Collapse` instance when used in an accordion.

### `handleTriggerClick` | *function*
### **handleTriggerClick** | *function*
Define this to override the click handler for the trigger link. Takes one parameter, which is `props.accordionPosition`.

### `onOpen` | *function*
### **onOpen** | *function*
Is called when the Collapsible has opened.

### **onClose** | *function*
Is called when the Collapsible has closed.

### **onOpening** | *function*
Is called when the Collapsible is opening.

### `onClose` | *function*
Is called when the Collapsible is closing.
### **onClosing** | *function*
Is called when the Collapsible has closing.

### `lazyRender` | *bool* | default: false
### **lazyRender** | *bool* | default: false
Set this to true to postpone rendering of all of the content of the Collapsible until before it's opened for the first time

### `overflowWhenOpen` | *enum* | default: 'hidden'
### **overflowWhenOpen** | *enum* | default: 'hidden'
The CSS overflow property once the Collapsible is open. This can be any one of the valid CSS values of `'hidden'`, `'visible'`, `'auto'`, `'scroll'`, `'inherit'`, `'initial'`, or `'unset'`

### `triggerSibling` | *element* | default: null
### **triggerSibling** | *element* | default: null
Escape hatch to add arbitrary content on the trigger without triggering expand/collapse. It's up to you to style it as needed. This is inserted in component tree and DOM directly
after `.Collapsible__trigger`

---
## CSS Class String Props
### **classParentString** | *string* | default: Collapsible
Use this to overwrite the parent CSS class for the Collapsible component parts. Read more in the CSS section below.

### **className** | *string*
`.Collapsible` element (root) when closed

### **openedClassName** | *string*
`.Collapsible` element (root) when open

### **triggerClassName** | *string*
`.Collapsible__trigger` element (root) when closed

### **triggerOpenedClassName** | *string*
`.Collapsible__trigger` element (root) when open

### **contentOuterClassName** | *string*
`.Collapsible__contentOuter` element

### **contentInnerClassName** | *string*
`.Collapsible__contentInner` element

---
## CSS Styles
In theory you don't need any CSS to get this to work, but let's face it, it'd be pretty rubbish without it.

Expand All @@ -158,11 +158,12 @@ The outer container that hides the content. This is set to `overflow: hidden` wi
### `.Collapsible__contentInner`
This is a container for the content passed into the compoenent. This keeps everything nice and neat and allows the component to do all it's whizzy calculations.


If you're using a CSS framework such as Foundation or Bootstrap, you probably want to use their classes instead of styling `.Collapsible`. See Properties above.

---
## Example
An example of the component in action is available in the example folder. To see it in action you can run `npm install` and then run `gulp`. This will compile all the JSX into JS and open the example page using BrowserSync.
An example of the component in action is available in the example folder. To see it in action you can run `wepback-dev-server` which will run the webpack build and open the example.

---
## Licence
React Responsive Collapsible Section Component is [MIT licensed](LICENSE.md)
12 changes: 0 additions & 12 deletions browserconfig.xml

This file was deleted.

Empty file added dist/.gitkeep
Empty file.
87 changes: 87 additions & 0 deletions example/_src/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Collapsible from '../../../src/Collapsible';

import '../sass/main.scss';

const triggerSiblingExample = () => <div className="Collapsible__custom-sibling">This is a sibling to the trigger which wont cause the Collapsible to open!</div>;

const App = () => {
return (
<div>
<Collapsible trigger="Start here">
<p>This is the collapsible content. It can be any element or React component you like.</p>
<p>It can even be another Collapsible component. Check out the next section!</p>
</Collapsible>

<Collapsible transitionTime={400} trigger="Then try this one">
<p>Would you look at that!</p>
<p>See; you can nest as many Collapsible components as you like.</p>

<Collapsible trigger="Mmmmm, it's all cosy nested here">
<p>And there's no limit to how many levels deep you go. Or how many you have on the same level.</p>

<Collapsible trigger="This is just another Collapsible">
<p>It just keeps going and going! Well, actually we've stopped here. But that's only because I'm running out of things to type.</p>
</Collapsible>
<Collapsible trigger="But this one is open by default!" open={true}>
<p>And would you look at that! This one is open by default. Sexy huh!?</p>
<p>You can pass the prop of open=&#123;true&#125; which will make the Collapsible open by default.</p>
</Collapsible>
<Collapsible trigger="That's not all. Check out the speed of this one" transitionTime={100}>
<p>Whoosh! That was fast right?</p>
<p>You can control the time it takes to animate (transition) by passing the prop transitionTime a value in milliseconds. This one was set to transitionTime=&#123;100&#125;</p>
</Collapsible>

</Collapsible>
</Collapsible>

<Collapsible transitionTime={400} trigger="This one will blow your mind." easing={'cubic-bezier(0.175, 0.885, 0.32, 2.275)'}>
<p>Well maybe not. But did you see that little wiggle at the end. That is using a CSS cubic-beizer for the easing!</p>
<p>You can pass any string into the prop easing that you would declare in a CSS transition-timing-function. This means you have complete control over how that Collapsible appears.</p>
</Collapsible>

<Collapsible transitionTime={400} trigger="Oh and did I mention that I'm responsive?" triggerWhenOpen="Plus you can change the trigger text when I'm open too">
<p>That's correct. This collapsible section will animate to the height it needs to and then set it's height back to auto.</p>
<p>This means that no matter what width you stretch that viewport to, the Collapsible it will respond to it.</p>
<p>And no matter what height the content within it is, it will change height too.</p>
<h2>CSS Styles</h2>
<p>All of the style of the Collapsible (apart from the overflow and transition) are controlled by your own CSS too.</p>
<p>By default the top-level CSS class is Collapsible, but you have control over this too so you can easily add it into your own project. Neato!</p>
<p>So by setting the prop of classParentString=&#123;"MyNamespacedClass"&#125; then the top-level class will become MyNamespacedClass.</p>
</Collapsible>

<Collapsible lazyRender transitionTime={600} trigger="What happens if there's a shed-load of content?" easing={'cubic-bezier(0.175, 0.885, 0.32, 2.275)'} overflowWhenOpen="visible">
<p>Add the prop of <strong style={{ fontWeight: 'bold' }}>lazyRender</strong> and the content will only be rendered when the trigger is pressed</p>
<img src="https://lorempixel.com/320/240?random=1" />
<img src="https://lorempixel.com/320/240?random=2" />
<img src="https://lorempixel.com/320/240?random=3" />
<img src="https://lorempixel.com/320/240?random=4" />
<img src="https://lorempixel.com/320/240?random=5" />
<img src="https://lorempixel.com/320/240?random=6" />
</Collapsible>

<Collapsible trigger="You can customise the CSS a bit more too"
triggerClassName="CustomTriggerCSS"
triggerOpenedClassName="CustomTriggerCSS--open"
contentOuterClassName="CustomOuterContentCSS"
contentInnerClassName="CustomInnerContentCSS"
>
<p>This is the collapsible content. It can be any element or React component you like.</p>
</Collapsible>

<Collapsible trigger="You can disable them programatically too" open triggerDisabled>
<p>This one has it's trigger disabled in the open position. Nifty.</p>
<p>You also get the <strong>is-disabled</strong> CSS class so you can style it.</p>
</Collapsible>

<Collapsible trigger="You can have siblings to the trigger too which won't trigger the Collapsible" triggerSibling={triggerSiblingExample}>
<p>This one has it's trigger disabled in the open position. Nifty.</p>
<p>You also get the <strong>is-disabled</strong> CSS class so you can style it.</p>
</Collapsible>

</div>
);
};

ReactDOM.render(<App />, document.querySelector('#root'));
8 changes: 0 additions & 8 deletions example/_src/jsx/app.js

This file was deleted.

86 changes: 0 additions & 86 deletions example/_src/jsx/components/App.js

This file was deleted.

7 changes: 7 additions & 0 deletions example/_src/sass/components/_Collapsible.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@

.CustomTriggerCSS--open {
background-color: darkslateblue;
}

.Collapsible__custom-sibling {
padding: 5px;
font-size: 12px;
background-color: #CBB700;
color: black;
}
Loading

0 comments on commit 3edd413

Please sign in to comment.