Skip to content

Commit 845db79

Browse files
committed
feat(package): use only inline styles and rename some props
BREAKING CHANGE: The following props have been renamed: * `renderPage` -> `renderView` * `numPages` -> `numViews` * `activePage` -> `activeView` BREAKING CHANGE: The following files have been removed: * `lib/styles.js` * `lib/defaultStyles.js` * `lib/react-view-slider.css` Other changes: * `rootRef` and `viewportRef` props have been added * `keepViewsMounted` prop has been added
1 parent d0c8fee commit 845db79

17 files changed

+514
-400
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
coverage
33
node_modules
44
lib
5+
storybook-static
6+
57

.npmignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ node_modules
99
test
1010
stories
1111
scripts
12-
12+
storybook-static

README.md

+37-50
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ of a drilldown.
1111
# Table of Contents
1212

1313
- [Usage](#usage)
14-
- [Using `react-jss` instead of `react-view-slider.css`](#using-react-jss-instead-of-react-view-slidercss)
1514
- [Props](#props)
1615
- [`withTransitionContext`](#withtransitioncontext)
1716

@@ -26,89 +25,80 @@ import React from 'react'
2625
import ReactDOM from 'react-dom'
2726
import ViewSlider from 'react-view-slider'
2827

29-
// make sure to include react-view-slider/lib/react-view-slider.css in the page.
30-
// for instance if you're using webpack:
31-
import 'react-view-slider/lib/react-view-slider.css'
32-
33-
// This function renders the page at the given index.
28+
// This function renders the view at the given index.
3429
// At minimum you should pass the key, ref, style, and className props to the returned element.
35-
const renderPage = ({index, key, ref, style, className, active, transitionState}) => (
30+
const renderView = ({index, key, ref, style, className, active, transitionState}) => (
3631
<div key={key} ref={ref} style={style} className={className}>
37-
<h3>Page {index}</h3>
32+
<h3>View {index}</h3>
3833
<p>I am {active ? 'active' : 'inactive'}</p>
3934
<p>transitionState: {transitionState}</p>
4035
</div>
4136
)
4237

43-
// activePage specifies which page should currently be showing. Whenever you change it, ViewSlider will make the
44-
// page at the new activePage horizontally slide into view.
38+
// activeView specifies which view should currently be showing. Whenever you change it, ViewSlider will make the
39+
// view at the new activeView horizontally slide into view.
4540

4641
ReactDOM.render(
4742
<ViewSlider
48-
renderPage={renderPage}
49-
numPages={3}
50-
activePage={0}
43+
renderView={renderView}
44+
numViews={3}
45+
activeView={0}
5146
animateHeight
5247
/>,
5348
document.getElementById('root')
5449
)
5550
```
5651

57-
## Using `react-jss` instead of `react-view-slider.css`
58-
59-
```js
60-
import React from 'react'
61-
import BaseViewSlider from 'react-view-slider'
62-
import viewSliderStyles from 'react-view-slider/lib/styles'
63-
import injectSheet from 'react-jss'
64-
65-
const ViewSlider = injectSheet(viewSliderStyles)(BaseViewSlider)
66-
```
67-
6852
## Props
6953

70-
##### `renderPage: (props: PageProps) => React.Element<any>` **(required)**
54+
##### `renderView: (props: ViewProps) => React.Element<any>` **(required)**
7155

72-
This function renders each page. `ViewSlider` will call it with the following `props`:
73-
* `index: number` - the index of the page (starting at 0)
56+
This function renders each view. `ViewSlider` will call it with the following `props`:
57+
* `index: number` - the index of the view (starting at 0)
7458
* `key: number` - the key you should pass to the returned element
7559
* `ref: (c: HTMLElement) => any` - the ref you should pass to the returned element
7660
* `style: Object` - the style you should pass to the returned element
77-
* `className: string` - the className you should pass to the returned element
78-
* `active: boolean` - whether the page should currently be showing
79-
* `transitionState: 'in' | 'out' | 'entering' | 'leaving'` - the page's transition state
61+
* `active: boolean` - whether the view should currently be showing
62+
* `transitionState: 'in' | 'out' | 'entering' | 'leaving'` - the view's transition state
8063

8164
At minimum you should pass the `key`, `ref`, `style`, and `className` props to the returned element.
8265

83-
##### `numPages: number` **(required)**
66+
##### `numViews: number` **(required)**
67+
68+
The number of views present. `ViewSlider` will only render all views when transitioning; when idle, it will
69+
only render the active view.
8470

85-
The number of pages present. `ViewSlider` will only render all pages when transitioning; when idle, it will
86-
only render the active page.
71+
##### `activeView: number` **(required)**
8772

88-
##### `activePage: number` **(required)**
73+
The index of the view that should be showing. Whenever you change this, `ViewSlider` will animate a horizontal slide
74+
transition to the view at the new index.
8975

90-
The index of the page that should be showing. Whenever you change this, `ViewSlider` will animate a horizontal slide
91-
transition to the page at the new index.
76+
##### `keepViewsMounted: boolean` (default: `false`)
77+
78+
If `true`, `ViewSlider` will keep all views mounted after transitioning, not just the active view.
79+
You may want to use this if there is a noticeable lag while other views mount at the beginning of a transition.
80+
However, it disables height animation and will cause the height of `ViewSlider` to be the max of all views' heights,
81+
so you will get best results if you also use `fillParent={true}`.
9282

9383
##### `animateHeight: boolean` (default: `true`)
9484

95-
If truthy, `ViewSlider` will animate its height to match the height of the page at `activePage`.
85+
If truthy, `ViewSlider` will animate its height to match the height of the view at `activeView`.
9686

9787
##### `transitionDuration: number` (default: `500`)
9888

99-
The duration of the transition between pages.
89+
The duration of the transition between views.
10090

10191
##### `transitionTimingFunction: string` (default: `'ease'`)
10292

103-
The timing function for the transition between pages.
93+
The timing function for the transition between views.
10494

10595
##### `prefixer: Prefixer`
10696

10797
If given, overrides the `inline-style-prefixer` used to autoprefix inline styles.
10898

10999
##### `fillParent: boolean` (default: `false`)
110100

111-
If truthy, `ViewSlider` will use absolute positioning on itself and its pages to fill its parent element.
101+
If truthy, `ViewSlider` will use absolute positioning on itself and its views to fill its parent element.
112102

113103
##### `className: string`
114104

@@ -126,24 +116,21 @@ Any extra class names to add to the inner "viewport" element.
126116

127117
Extra inline styles to add to the inner "viewport" element.
128118

129-
##### `classes: {root: string, viewport: string, fillParent: string, page: string}`
119+
##### `rootRef: (node: ?HTMLDivElement) => any`
120+
121+
The `ref` to pass to the root `<div>` element rendered by `ViewSlider`.
130122

131-
The `className`s for the various elements `ViewSlider` renders:
132-
- `root` is the root `div`
133-
- `viewport` is the `div` inside `root` that animates horizontally
134-
- `fillParent` is the `className` applied to the root `div` if the `fillParent` property is `true`
135-
- `page` is the `className` passed to `renderPage`
123+
##### `viewportRef: (node: ?HTMLDivElement) => any`
136124

137-
By default, they match those in `lib/react-view-slider.css`.
138-
Otherwise, you can [use `react-jss` to inject `classes`](#using-react-jss-instead-of-react-view-slidercss).
125+
The `ref` to pass to the viewport `<div>` element rendered inside the root `<div>` by `ViewSlider`.
139126

140127
## `withTransitionContext`
141128

142129
```js
143130
import ViewSlider from 'react-view-slider/lib/withTransitionContext'
144131
```
145132

146-
This works exactly like `ViewSlider` except that it renders its pages within a `TransitionContext` component from
133+
This works exactly like `ViewSlider` except that it renders its views within a `TransitionContext` component from
147134
`react-transition-context` with the given `transitionState`. This is useful for doing things like focusing an `<input>`
148-
element after one of the pages has transitioned in.
135+
element after one of the views has transitioned in.
149136

package.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
"flow:watch": "flow-watch -e js,js.flow,flowconfig --ignore lib/ --ignore node_modules/ --watch .flowconfig --watch src/ --watch test/",
1313
"gen-flow-files": "flow gen-flow-files src/ --out-dir lib",
1414
"copy-flow-files": "cd src; copy *.js.flow **/*.js.flow ../lib",
15-
"build:css": "babel-node scripts/buildCss.js",
16-
"build": "rimraf lib && npm run build:css && babel src --out-dir lib && npm run copy-flow-files",
15+
"build": "rimraf lib && babel src --out-dir lib && npm run copy-flow-files",
1716
"test": "NODE_ENV=production BABEL_ENV=test nyc --reporter=lcov --reporter=text mocha $npm_package_config_mocha",
1817
"test:watch": "mocha --watch $npm_package_config_mocha",
1918
"commitmsg": "validate-commit-msg",
2019
"precommit": "npm run lint && flow",
2120
"prepush": "npm test",
22-
"prepublish": "rimraf lib && npm run build:css && npm run lint && flow && npm test && babel src --out-dir lib && npm run copy-flow-files",
21+
"prepublish": "npm run lint && flow && npm test && npm run build",
2322
"open:coverage": "open coverage/lcov-report/index.html",
2423
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
2524
"storybook": "start-storybook -p 6006",
26-
"build-storybook": "build-storybook"
25+
"build-storybook": "build-storybook",
26+
"deploy-storybook": "storybook-to-ghpages",
27+
"open:storybook-static": "open storybook-static/index.html"
2728
},
2829
"config": {
2930
"mocha": "--compilers js:babel-core/register -r jsdom-global/register ./test/**.js",
@@ -60,6 +61,7 @@
6061
"@jedwards1211/eslint-config-flow": "^1.0.0",
6162
"@jedwards1211/eslint-config-react": "^2.0.1",
6263
"@storybook/react": "^3.1.6",
64+
"@storybook/storybook-deployer": "^2.0.0",
6365
"babel-cli": "^6.22.2",
6466
"babel-core": "^6.22.1",
6567
"babel-eslint": "^7.1.1",
@@ -84,19 +86,17 @@
8486
"eslint-watch": "^3.0.0",
8587
"flow-bin": "^0.46.0",
8688
"flow-watch": "^1.1.0",
89+
"get-node-dimensions": "^1.2.0",
8790
"husky": "^0.13.1",
8891
"istanbul": "^0.4.5",
8992
"jsdom": "^10.1.0",
9093
"jsdom-global": "^3.0.2",
91-
"jss": "^8.1.0",
92-
"jss-nested": "^5.0.0",
9394
"mocha": "^3.2.0",
9495
"nyc": "^10.1.2",
9596
"react": "^15.4.2",
9697
"react-addons-test-utils": "^15.4.2",
9798
"react-dom": "^15.4.2",
9899
"react-hot-loader": "^3.0.0-beta.2",
99-
"react-jss": "^6.1.1",
100100
"react-transition-context": "^1.0.0-beta9",
101101
"rimraf": "^2.5.4",
102102
"semantic-release": "^6.3.6",
@@ -107,8 +107,6 @@
107107
"react": "0.14.x || ^15.0.0"
108108
},
109109
"dependencies": {
110-
"class-names": "^1.0.0",
111-
"get-node-dimensions": "^1.2.0",
112110
"inline-style-prefixer": "^3.0.6",
113111
"lodash.range": "^3.2.0",
114112
"prop-types": "^15.0.0"

scripts/.eslintrc

-6
This file was deleted.

scripts/buildCss.js

-32
This file was deleted.

src/.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"env": {
3-
"es6": true,
4-
"commonjs": true
3+
"es6": true
54
}
65
}

src/defaultClasses.js

-2
This file was deleted.

0 commit comments

Comments
 (0)