Skip to content

Commit

Permalink
Merge branch 'collapse-fixes' into collapse-fixes-0.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeSidSmith committed Aug 9, 2018
2 parents 217e4fb + 962c780 commit ffa3322
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 54 deletions.
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 ffa3322

Please sign in to comment.