Skip to content

Commit

Permalink
Merge pull request #266 from dabapps/collapse-fixes-0.9.x
Browse files Browse the repository at this point in the history
Collapse fixes 0.9.x
  • Loading branch information
JakeSidSmith authored Aug 10, 2018
2 parents 217e4fb + 4bfa654 commit 3065d79
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dabapps/roe",
"version": "0.9.18",
"version": "0.9.19",
"description": "A Collection of React Components for Project Development",
"main": "dist/js/index.js",
"types": "dist/js/index.d.ts",
Expand Down
99 changes: 99 additions & 0 deletions src/ts/components/misc/collapse.examples.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#### Examples

With lots of content:

```js
class CollapseExample extends React.Component {
constructor (props) {
Expand Down Expand Up @@ -45,3 +47,100 @@ class CollapseExample extends React.Component {

<CollapseExample />
```

With small content:

```js
class CollapseExample extends React.Component {
constructor (props) {
super(props);

this.state = {
open: false
};

this.onClickToggleCollapse = this.onClickToggleCollapse.bind(this);
}

onClickToggleCollapse () {
const { open } = this.state;

this.setState({
open: !open
});
}

render () {
const { open } = this.state;

return (
<div>
<Collapse
open={open}
maxCollapsedHeight={100}
fadeOut
fadeColor="#FFF"
fadeHeight={50}
animationDuration={200}
>
<DabIpsum count={1} />
</Collapse>
<Button className="primary margin-top-base" onClick={this.onClickToggleCollapse}>
{open ? 'Collapse' : 'Expand'}
</Button>
</div>
);
}
}

<CollapseExample />
```

With minimum height:

```js
class CollapseExample extends React.Component {
constructor (props) {
super(props);

this.state = {
open: false
};

this.onClickToggleCollapse = this.onClickToggleCollapse.bind(this);
}

onClickToggleCollapse () {
const { open } = this.state;

this.setState({
open: !open
});
}

render () {
const { open } = this.state;

return (
<div>
<Collapse
open={open}
maxCollapsedHeight={200}
minHeight={100}
fadeOut
fadeColor="#FFF"
fadeHeight={50}
animationDuration={200}
>
<DabIpsum count={1} />
</Collapse>
<Button className="primary margin-top-base" onClick={this.onClickToggleCollapse}>
{open ? 'Collapse' : 'Expand'}
</Button>
</div>
);
}
}

<CollapseExample />
```
15 changes: 11 additions & 4 deletions src/ts/components/misc/collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export interface CollapseProps
* Maximum height when collapsed
* @default 0
*/
maxCollapsedHeight?: number;
maxCollapsedHeight?: number | string;
/**
* Minimum height
* @default auto
*/
minHeight?: number | string;
/**
* Whether to fade out the content
* @default false
Expand All @@ -52,7 +57,7 @@ export interface CollapseProps

export interface CollapseState {
// tslint:disable-line:no-unused-variable
height: number;
height: number | string;
opened: boolean;
opening: boolean;
}
Expand Down Expand Up @@ -134,6 +139,7 @@ export class Collapse extends PureComponent<CollapseProps, CollapseState> {
transparentColor = DEFAULT_TRANSPARENT_COLOR,
open,
maxCollapsedHeight,
minHeight = 'auto',
animationDuration = DEFAULT_DURATION,
component: Component = 'div',
...remainingProps
Expand All @@ -142,10 +148,11 @@ export class Collapse extends PureComponent<CollapseProps, CollapseState> {
const { opening, opened, height } = this.state;

const collapseStyle = {
height: opened ? 'auto' : height,
minHeight,
maxHeight: opened ? 'auto' : height,
position: 'relative' as 'relative',
overflow: 'hidden' as 'hidden',
transition: `ease-in-out ${animationDuration}ms height`,
transition: `ease-in-out ${animationDuration}ms max-height`,
};

const fadeStyle = {
Expand Down
Loading

0 comments on commit 3065d79

Please sign in to comment.