Skip to content

Commit

Permalink
fix: margin animation, width animation, transition context
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `react-transition-context` v5 is now used by default,
requiring React ^16.8.0, and `withTransitionContext` has been removed.
The `measureHeight` property is no longer used, and the `heightTransitionX`
properties have been renamed to `sizeTransitionX`.
  • Loading branch information
jedwards1211 committed Apr 16, 2019
1 parent fb9771a commit 944ec37
Show file tree
Hide file tree
Showing 22 changed files with 2,271 additions and 4,005 deletions.
5 changes: 2 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
!yarn.lock
/src
/test
/demo
/coverage
/flow-typed
/karma.conf.js
/webpack.config.js
__tests__
/.*
/stories
/storybook-static
/.storybook
!/.flowconfig
1 change: 0 additions & 1 deletion .storybook/preview-head.html

This file was deleted.

82 changes: 11 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# react-fader

<<<<<<< HEAD
[![Build Status](https://travis-ci.org/jcoreio/react-fader.svg?branch=master)](https://travis-ci.org/jcoreio/react-fader)
[![Coverage Status](https://codecov.io/gh/jcoreio/react-fader/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/react-fader)
=======
[![CircleCI](https://circleci.com/gh/jedwards1211/react-karma-library-skeleton.svg?style=svg)](https://circleci.com/gh/jedwards1211/react-karma-library-skeleton)
[![Coverage Status](https://codecov.io/gh/jedwards1211/react-karma-library-skeleton/branch/master/graph/badge.svg)](https://codecov.io/gh/jedwards1211/react-karma-library-skeleton)
>>>>>>> bd321b17d93e21512aed627731d12d4564af5057
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![npm version](https://badge.fury.io/js/es2015-library-skeleton.svg)](https://badge.fury.io/js/es2015-library-skeleton)
[![CircleCI](https://circleci.com/gh/jcoreio/react-fader.svg?style=svg)](https://circleci.com/gh/jcoreio/react-fader)
[![Coverage Status](https://codecov.io/gh/jcoreio/react-fader/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/react-fader)

<<<<<<< HEAD
A React Component that fades out its old child, then fades in its new child when its children change.
It can also optionally animate its height from one child's height to the other.
It can also optionally animate its height and/or width from one child's size to the other.
Works well with `react-router`!
=======
This is my personal skeleton for creating a React library npm package with Karma tests. You are welcome to use it.
>>>>>>> bd321b17d93e21512aed627731d12d4564af5057

## Usage

Expand Down Expand Up @@ -67,30 +57,19 @@ import Fader from 'react-fader'
<Router>
```

## Transitioning between child routes with `react-router` version 2 or 3

Use [`react-router-fader`](https://github.com/jcoreio/react-router-fader), which builds off of this.

## Props

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

If truthy and `fillParent` is falsy, `Fader` will animate its height to match the height of its children.
If truthy, `Fader` will animate its height to match the height of its children.

##### `measureHeight: (node: HTMLElement) => number` (default: `node => node.offsetHeight`)
##### `animateWidth: boolean` (default: `true`)

Allows you to override the height measurement function used for `animateHeight`. For instance, you might want to use:
```js
import getNodeDimensions from 'get-node-dimensions'

<Fader measureHeight={node => getNodeDimensions(node, {margin: true}).height} ...>
...
</Fader>
```
If truthy, `Fader` will animate its width to match the height of its children.

##### `shouldTransition: (oldChildren: any, newChildren: any) => boolean` (default: compares keys)

Allows you to determine whether `Fader` should perform a transition from `oldChildren` to `newChildren`. By default,
Allows you to determine whether `Fader` should perform a transition from `oldChildren` to `newChildren`. By default,
it returns true if `oldChildren !== newChildren` or their keys are not equal.

##### `fadeOutTransitionDuration: number` (default: `200`)
Expand All @@ -109,61 +88,22 @@ The duration of the fade in transition, in milliseconds.

The timing function for the fade in transition.

##### `heightTransitionDuration: number` (default: `200`)
##### `sizeTransitionDuration: number` (default: `200`)

The duration of the height transition, in milliseconds.
The duration of the size transition, in milliseconds.

##### `heightTransitionTimingFunction: string` (default: `'ease'`)
##### `sizeTransitionTimingFunction: string` (default: `'ease'`)

The timing function for the height transition.
The timing function for the size transition.

##### `prefixer: Prefixer`

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

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

If truthy, `Fader` will use absolute positioning to fill its parent element.

##### `className: string`

Any extra class names to add to the root element.

##### `style: Object`

Extra inline styles to add to the root element.

## `withTransitionContext`

```sh
npm install --save react-fader react-transition-context
```
```js
import Fader from 'react-fader/lib/withTransitionContext'
```

This works exactly like `Fader` except that it renders its children within a `TransitionContext` component from
`react-transition-context` with the given `transitionState`. This is useful for doing things like focusing an `<input>`
element after the children have transitioned in.

=======
npx 0-60 clone https://github.com/jedwards1211/react-karma-library-skeleton.git
```
## Tools used
- babel 7
- mocha
- chai
- eslint
- flow
- enzyme
- karma
- karma-webpack
- karma-coverage
- husky
- semantic-release
- renovate
- Circle CI
- Codecov.io
>>>>>>> bd321b17d93e21512aed627731d12d4564af5057
3 changes: 2 additions & 1 deletion stories/.eslintrc → demo/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"env": {
"browser": true,
"commonjs": true
}
}
}
112 changes: 112 additions & 0 deletions demo/Demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import * as React from 'react'
import withStyles from '@material-ui/core/styles/withStyles'
import Code from '@material-ui/icons/Code'
import Collapse from '@material-ui/core/Collapse'
import Button from '@material-ui/core/Button'
import IconButton from '@material-ui/core/IconButton'
import Typography from '@material-ui/core/Typography'
import Tooltip from '@material-ui/core/Tooltip'

const { useState, useCallback } = React

const styles = {
title: {
marginTop: 40,
marginBottom: 0,
},
root: {
margin: '20px auto',
},
toolbar: {
display: 'flex',
alignItems: 'center',
},
toolbarSpacer: {
flex: '1 1 auto',
},
code: {
margin: 0,
padding: 20,
backgroundColor: 'white',
borderRadius: 4,
},
example: {
backgroundColor: '#eee',
borderRadius: 4,
display: 'flex',
alignContent: 'center',
alignItems: 'center',
justifyContent: 'center',
padding: 40,
},
titleAnchor: {
color: '#aaa',
marginLeft: 10,
textDecoration: 'none',
visibility: 'hidden',
'$title:hover > &': {
visibility: 'visible',
},
},
}

const Demo = ({
headerId,
classes,
title,
code,
example,
hooksCode,
hooksExample,
}) => {
const [showSource, setShowSource] = useState(false)
const [api, setApi] = useState('hooks')
const setRenderProps = useCallback(() => setApi('render-props'), [])
const setHooks = useCallback(() => setApi('hooks'), [])
return (
<div className={classes.root}>
<Typography variant="h4" className={classes.title} id={headerId}>
{title}
{headerId && (
<a href={`#${headerId}`} className={classes.titleAnchor}>
#
</a>
)}
</Typography>
<div className={classes.toolbar}>
{code != null && hooksCode != null && (
<React.Fragment>
<Button
variant={api === 'render-props' ? 'outlined' : 'text'}
onClick={setRenderProps}
>
Render Props
</Button>
<Button
variant={api === 'hooks' ? 'outlined' : 'text'}
onClick={setHooks}
>
Hooks
</Button>
</React.Fragment>
)}
<div className={classes.toolbarSpacer} />
<Tooltip title="Show Source" placement="top">
<IconButton onClick={() => setShowSource(!showSource)}>
<Code />
</IconButton>
</Tooltip>
</div>
<Collapse in={showSource}>
<pre className={classes.code}>
{api === 'hooks' ? hooksCode || code : code || hooksCode}
</pre>
</Collapse>
<div className={classes.example}>
{api === 'hooks' ? hooksExample || example : example || hooksExample}
</div>
</div>
)
}

export default withStyles(styles)(Demo)
20 changes: 20 additions & 0 deletions demo/Root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react'
import withStyles from '@material-ui/core/styles/withStyles'
import SignupDemo from './examples/SignupDemo'
import Typography from '@material-ui/core/Typography'

const styles = {
root: {
margin: '0 auto',
maxWidth: 600,
},
}

const Root = ({ classes }) => (
<div className={classes.root}>
<Typography variant="h4">react-fader demo</Typography>
<SignupDemo />
</div>
)

export default withStyles(styles)(Root)

0 comments on commit 944ec37

Please sign in to comment.