woocommerce/plugins/woocommerce-admin/client/components/animation-slider
Kelly Dwan d36511479e Docs Project: Add documentation parser + inline documentation (https://github.com/woocommerce/woocommerce-admin/pull/336)
* Switch all components to default exports

This ensures we can read all components for documentation generation (plus, standardizing is good)

* Add documentation to component file

* Fix table exports

* Move readme docs into inline docs

Includes updating new props, adding prop shapes

* Add doc-generation scripts to pull exported component docs into folder

* Remove key propType, causing react special-keys warning

* Fix proptype

* Update incorrect comment

* Remove template import, we can just use string concat

* Fix typo, update docs
2018-08-31 13:27:21 -04:00
..
README.md FilterPicker: Add Animation 2018-07-20 15:42:36 +12:00
index.js Docs Project: Add documentation parser + inline documentation (https://github.com/woocommerce/woocommerce-admin/pull/336) 2018-08-31 13:27:21 -04:00
style.scss Animation mixin + add `prefers-reduced-motion` support to existing animations (https://github.com/woocommerce/woocommerce-admin/pull/317) 2018-08-23 13:47:27 -04:00

README.md

AnimationSlider

This component creates slideable content controlled by an animate prop to direct the contents to slide left or right

How to use:

import AnimationSlider from 'components/animation-slider';

class MySlider extends Component {
	constructor() {
		super();
		this.state = {
			pages: [ 44, 55, 66, 77, 88 ],
			page: 0,
			animate: null,
		};
		this.forward = this.forward.bind( this );
		this.back = this.forward.back( this );
	}

	forward() {
		this.setState( state => ( {
			page: state.page + 1,
			animate: 'left',
		} ) );
	}

	back() {
		this.setState( state => ( {
			page: state.page - 1,
			animate: 'right',
		} ) );
	}

	render() {
		const { page, pages, animate } = this.state;
		return (
			<div>
				<button onClick={ this.back } disabled={ page === 0 }>
					Back
				</button>
				<button onClick={ this.forward } disabled={ page === pages.length + 1 }>
					Forward
				</button>
				<AnimationSlider animationKey={ page } animate={ animate }>
					{ status => (
						<img
							className={ `my-slider my-slider-${ status }` }
							src={ `/pages/${ pages[ page ] }` }
							alt={ pages[ page ] }
						/>
					) }
				</AnimationSlider>
			</div>
		);
	}
}

AnimationSlider Props

  • children (required): A function returning rendered content with argument status, reflecting CSSTransition status
  • animationKey (required): A unique identifier for each slideable page
  • animate: null, 'left', 'right', to designate which direction to slide on a change
  • focusOnChange: When set to true, the first focusable element will be focused after an animation has finished

All other props are passed to CSSTransition. More info at http://reactcommunity.org/react-transition-group/css-transition