Skip to content

Commit

Permalink
feat(Collapse): add horizontal animation (#5993)
Browse files Browse the repository at this point in the history
* fix: changed .modal-backdrop to .offcanvas-backdrop

* Removed modalBsPrefix in Offcanvas

* feat: Added Horizontal Collapse

* Added width transition to Collapse API
  • Loading branch information
nsi319 committed Aug 26, 2021
1 parent 95f16d2 commit c8f0d1d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ const propTypes = {
/**
* The dimension used when collapsing, or a function that returns the
* dimension
*
* _Note: Bootstrap only partially supports 'width'!
* You will need to supply your own CSS animation for the `.width` CSS class._
*/
dimension: PropTypes.oneOfType([
PropTypes.oneOf(['height', 'width']),
Expand Down Expand Up @@ -245,7 +242,7 @@ const Collapse = React.forwardRef<Transition<any>, CollapseProps>(
className,
children.props.className,
collapseStyles[state],
computedDimension === 'width' && 'width',
computedDimension === 'width' && 'collapse-horizontal',
),
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/CollapseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ describe('<Collapse>', () => {
assert.ok(node.className.indexOf('width') === -1);
});

it('Should have width in class', () => {
it('Should have collapse-horizontal in class', () => {
function dimension() {
return 'width';
}

wrapper.setProps({ dimension });
let node = wrapper.getDOMNode();
assert.ok(node.className.indexOf('width') !== -1);
assert.ok(node.className.indexOf('collapse-horizontal') !== -1);
});
});

Expand Down
28 changes: 28 additions & 0 deletions www/src/examples/CollapseHorizontal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Example() {
const [open, setOpen] = useState(false);

return (
<>
<Button
onClick={() => setOpen(!open)}
aria-controls="example-collapse-text"
aria-expanded={open}
>
click
</Button>
<div style={{minHeight: '150px'}}>
<Collapse in={open} dimension="width">
<div id="example-collapse-text">
<Card body style={{width: '400px'}}>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident.
</Card>
</div>
</Collapse>
</div>
</>
);
}

render(<Example />);
18 changes: 18 additions & 0 deletions www/src/pages/utilities/transitions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ComponentApi from '../../components/ComponentApi';
import ReactPlayground from '../../components/ReactPlayground';

import Collapse from '../../examples/Collapse';
import CollapseHorizontal from '../../examples/CollapseHorizontal'
import Fade from '../../examples/Fade';

# Transitions
Expand All @@ -19,6 +20,8 @@ as well as portable for using in other libraries. All React-bootstrap component

## Collapse

### Basic Example

Add a collapse toggle animation to an element or component.

<Callout title="Smooth animations">
Expand All @@ -32,6 +35,21 @@ Add a collapse toggle animation to an element or component.

<ReactPlayground codeText={Collapse} />

### Horizontal

Add a collapse toggle animation to an element or component to transition the width instead of height.

<Callout title="Smooth animations">
If you're noticing choppy animations, and the component that's being
collapsed has non-zero margin or padding, try wrapping the contents of
your <code>{'<Collapse>'}</code> inside a node with no margin or
padding, like the <code>{'<div>'}</code> in the example below. This will
allow the height to be computed properly, so the animation can proceed
smoothly.
</Callout>

<ReactPlayground codeText={CollapseHorizontal} />

## Fade

Add a fade animation to a child element or component.
Expand Down

0 comments on commit c8f0d1d

Please sign in to comment.