Skip to content

Commit 4603503

Browse files
committed
fix: height animation when there are margins, other changes
BREAKING CHANGE: now uses `react-transition-context` v5 by default, requiring React ^16.8.0. `withTransitionContext` and `simpleWithTransitionContext` have been removed. Also, `renderView` no longer receives `style`, `ref`, `key`, etc. to pass along to the `div` it returns; rendering that wrapper `div` is now managed internally.
2 parents f86365b + 7e5e0b4 commit 4603503

18 files changed

+4990
-3550
lines changed

Diff for: .npmignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
!yarn.lock
66
/lib
77
/src
8-
/stories
8+
/demo
9+
/webpack.config.js
910
/test
1011
/coverage
1112
/flow-typed

Diff for: .storybook/config.js

-8
This file was deleted.

Diff for: README.md

+5-33
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
77
[![npm version](https://badge.fury.io/js/react-view-slider.svg)](https://badge.fury.io/js/react-view-slider)
88

9-
Not another carousel; a simpler component that animates horizontal slide transitions between steps of a wizard or levels
10-
of a drilldown.
9+
Not another carousel; animates horizontal slide transitions between steps of
10+
a form or levels of a drilldown.
1111

1212
# Table of Contents
1313

1414
- [Usage](#usage)
1515
- [Props](#props)
16-
- [`withTransitionContext`](#withtransitioncontext)
1716
- [`SimpleViewSlider`](#simpleviewslider)
1817

1918
## Usage
@@ -28,17 +27,8 @@ import ReactDOM from 'react-dom'
2827
import ViewSlider from 'react-view-slider'
2928

3029
// This function renders the view at the given index.
31-
// At minimum you should pass the key, ref, style, and className props to the returned element.
32-
const renderView = ({
33-
index,
34-
key,
35-
ref,
36-
style,
37-
className,
38-
active,
39-
transitionState,
40-
}) => (
41-
<div key={key} ref={ref} style={style} className={className}>
30+
const renderView = ({ index, active, transitionState }) => (
31+
<div>
4232
<h3>View {index}</h3>
4333
<p>I am {active ? 'active' : 'inactive'}</p>
4434
<p>transitionState: {transitionState}</p>
@@ -61,19 +51,14 @@ ReactDOM.render(
6151

6252
## Props
6353

64-
##### `renderView: (props: ViewProps) => React.Element<any>` **(required)**
54+
##### `renderView: (props: ViewProps) => React.Node` **(required)**
6555

6656
This function renders each view. `ViewSlider` will call it with the following `props`:
6757

6858
- `index: number` - the index of the view (starting at 0)
69-
- `key: number` - the key you should pass to the returned element
70-
- `ref: (c: HTMLElement) => any` - the ref you should pass to the returned element
71-
- `style: Object` - the style you should pass to the returned element
7259
- `active: boolean` - whether the view should currently be showing
7360
- `transitionState: 'in' | 'out' | 'entering' | 'leaving'` - the view's transition state
7461

75-
At minimum you should pass the `key`, `ref`, `style`, and `className` props to the returned element.
76-
7762
##### `numViews: number` **(required)**
7863

7964
The number of views present. `ViewSlider` will only render all views when transitioning; when idle, it will
@@ -135,16 +120,6 @@ The `ref` to pass to the root `<div>` element rendered by `ViewSlider`.
135120

136121
The `ref` to pass to the viewport `<div>` element rendered inside the root `<div>` by `ViewSlider`.
137122

138-
## `withTransitionContext`
139-
140-
```js
141-
import ViewSlider from 'react-view-slider/lib/withTransitionContext'
142-
```
143-
144-
This works exactly like `ViewSlider` except that it renders its views within a `TransitionContext` component from
145-
`react-transition-context` with the given `transitionState`. This is useful for doing things like focusing an `<input>`
146-
element after one of the views has transitioned in.
147-
148123
## `SimpleViewSlider`
149124

150125
This is a wrapper for `ViewSlider` that takes a single child element. It renders the `ViewSlider` with the child's key
@@ -170,6 +145,3 @@ ReactDOM.render(
170145
document.getElementById('root')
171146
)
172147
```
173-
174-
If you want to use `SimpleViewSlider` with `react-transition-context`,
175-
use `react-view-slider/lib/simpleWithTransitionContext`.

Diff for: demo/.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true
5+
}
6+
}

Diff for: demo/Demo.js

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import * as React from 'react'
2+
import withStyles from '@material-ui/core/styles/withStyles'
3+
import Code from '@material-ui/icons/Code'
4+
import Collapse from '@material-ui/core/Collapse'
5+
import Button from '@material-ui/core/Button'
6+
import IconButton from '@material-ui/core/IconButton'
7+
import Typography from '@material-ui/core/Typography'
8+
import Tooltip from '@material-ui/core/Tooltip'
9+
10+
const { useState, useCallback } = React
11+
12+
const styles = {
13+
title: {
14+
marginTop: 40,
15+
marginBottom: 0,
16+
},
17+
root: {
18+
margin: '20px auto',
19+
},
20+
toolbar: {
21+
display: 'flex',
22+
alignItems: 'center',
23+
},
24+
toolbarSpacer: {
25+
flex: '1 1 auto',
26+
},
27+
code: {
28+
margin: 0,
29+
padding: 20,
30+
backgroundColor: 'white',
31+
borderRadius: 4,
32+
},
33+
example: {
34+
backgroundColor: '#eee',
35+
borderRadius: 4,
36+
display: 'flex',
37+
alignContent: 'center',
38+
alignItems: 'center',
39+
justifyContent: 'center',
40+
padding: 40,
41+
},
42+
titleAnchor: {
43+
color: '#aaa',
44+
marginLeft: 10,
45+
textDecoration: 'none',
46+
visibility: 'hidden',
47+
'$title:hover > &': {
48+
visibility: 'visible',
49+
},
50+
},
51+
}
52+
53+
const Demo = ({
54+
headerId,
55+
classes,
56+
title,
57+
code,
58+
example,
59+
hooksCode,
60+
hooksExample,
61+
}) => {
62+
const [showSource, setShowSource] = useState(false)
63+
const [api, setApi] = useState('hooks')
64+
const setRenderProps = useCallback(() => setApi('render-props'), [])
65+
const setHooks = useCallback(() => setApi('hooks'), [])
66+
return (
67+
<div className={classes.root}>
68+
<Typography variant="h4" className={classes.title} id={headerId}>
69+
{title}
70+
{headerId && (
71+
<a href={`#${headerId}`} className={classes.titleAnchor}>
72+
#
73+
</a>
74+
)}
75+
</Typography>
76+
<div className={classes.toolbar}>
77+
{code != null && hooksCode != null && (
78+
<React.Fragment>
79+
<Button
80+
variant={api === 'render-props' ? 'outlined' : 'text'}
81+
onClick={setRenderProps}
82+
>
83+
Render Props
84+
</Button>
85+
<Button
86+
variant={api === 'hooks' ? 'outlined' : 'text'}
87+
onClick={setHooks}
88+
>
89+
Hooks
90+
</Button>
91+
</React.Fragment>
92+
)}
93+
<div className={classes.toolbarSpacer} />
94+
<Tooltip title="Show Source" placement="top">
95+
<IconButton onClick={() => setShowSource(!showSource)}>
96+
<Code />
97+
</IconButton>
98+
</Tooltip>
99+
</div>
100+
<Collapse in={showSource}>
101+
<pre className={classes.code}>
102+
{api === 'hooks' ? hooksCode || code : code || hooksCode}
103+
</pre>
104+
</Collapse>
105+
<div className={classes.example}>
106+
{api === 'hooks' ? hooksExample || example : example || hooksExample}
107+
</div>
108+
</div>
109+
)
110+
}
111+
112+
export default withStyles(styles)(Demo)

Diff for: demo/Root.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from 'react'
2+
import withStyles from '@material-ui/core/styles/withStyles'
3+
import SignupDemo from './examples/SignupDemo'
4+
import Typography from '@material-ui/core/Typography'
5+
6+
const styles = {
7+
root: {
8+
margin: '0 auto',
9+
maxWidth: 600,
10+
},
11+
}
12+
13+
const Root = ({ classes }) => (
14+
<div className={classes.root}>
15+
<Typography variant="h4">react-view-slider demo</Typography>
16+
<SignupDemo />
17+
</div>
18+
)
19+
20+
export default withStyles(styles)(Root)

Diff for: demo/bundle.js

+3,281
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)