|
| 1 | +# 🎠 react-rotator |
| 2 | + |
| 3 | +Flexible React component for composing rotators, carousels, slideshows and more. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +Via [npm](https://npmjs.com/package/react-rotator): |
| 8 | +``` |
| 9 | +npm install --save react-rotator |
| 10 | +``` |
| 11 | + |
| 12 | +Via [Yarn](https://yarn.fyi/react-rotator): |
| 13 | +``` |
| 14 | +yarn add react-rotator |
| 15 | +``` |
| 16 | + |
| 17 | +## How to use |
| 18 | + |
| 19 | +The `Rotator` is built with the intention of offering a truly flexible system for |
| 20 | +building rotators, carousels, slideshows, etc. with a simplified interface for |
| 21 | +managing various ways that these components can exist. |
| 22 | + |
| 23 | +### Properties |
| 24 | + |
| 25 | +* `index:Number` - Index of the currently active child. |
| 26 | +* `onChange:Function` - Callback for when the index is changed internally, either |
| 27 | +via a child or indicator. |
| 28 | + |
| 29 | +### Children & Indicators |
| 30 | + |
| 31 | +Each child within a `<Rotator />` instance has properties applied that allow |
| 32 | +them to manage their own behavior based on those props. Along with callbacks that |
| 33 | +can be passed in to control the rotator’s behavior. |
| 34 | + |
| 35 | +In addition to the `[children]`, an optional `indicator` component can be passed |
| 36 | +in via props that will be rendered alongside the `<Rotator />`’s children, which |
| 37 | +allows for displaying indicators on progress, or building pagination controls for |
| 38 | +the `<Rotator />`. |
| 39 | + |
| 40 | +Here’s a breakdown of how `[children]` and an `indicator` is managed by the |
| 41 | +component. |
| 42 | + |
| 43 | +#### Children |
| 44 | + |
| 45 | +The goal is to allow for maximum flexibility through composition. Feel free to |
| 46 | +set whatever props your components need, but the following properties will be |
| 47 | +applied/overwritten by the `<Rotator />` when rendered to the page. |
| 48 | + |
| 49 | +##### Properties |
| 50 | + |
| 51 | +* `index:Number` - Index of the child amongst the other children they are rendered with. |
| 52 | +* `numChildren:Number` - Number of relative children that are being rendered with this child. |
| 53 | +* `position:Number` - Position of the child in relation the the current `index` set on the `<Rotator />`. |
| 54 | + |
| 55 | +>* If the `position` is `0`, it could be assumed that this is the “active” child. |
| 56 | +>* If the `position` is `<0`, the child is positioned before the current “active” child. |
| 57 | +>* If the `position` is `>0`, the child is positioned after the current “active” child. |
| 58 | +
|
| 59 | +* `onActive:Function` - Callback that could be triggered by the child when the child becomes "active". |
| 60 | +This could have different meanings depending on the child, but `onActive` will |
| 61 | +update the `<Rotator />` to set that child at position `0`. |
| 62 | +* `onFinish:Function` - Callback that could be triggered by the child, in the event that the child is |
| 63 | +managing it’s status or responsible for initiating progression within the `<Rotator />`. |
| 64 | + |
| 65 | +##### Example |
| 66 | + |
| 67 | +``` |
| 68 | +import Rotator from 'react-rotator'; |
| 69 | +
|
| 70 | +... |
| 71 | +
|
| 72 | + render() { |
| 73 | + return ( |
| 74 | + <Rotator> |
| 75 | +
|
| 76 | + </Rotator> |
| 77 | + ); |
| 78 | + } |
| 79 | +
|
| 80 | +... |
| 81 | +
|
| 82 | +``` |
| 83 | + |
| 84 | +#### Indicator |
| 85 | + |
| 86 | +An indicator component can be composed within the `<Rotator />` via the `indicator` prop. |
| 87 | +This makes it really easy to pass in a component that will reflect the current status |
| 88 | +of the rotator, while also allowing for callbacks to be called to control the |
| 89 | +state of the rotator. |
| 90 | + |
| 91 | +You can make your own paging indicators, or I’ve created a companion package that contains |
| 92 | +some common paging indicator components that you can use, [react-paging-indicators](https://github.com/ryanhefner/react-paging-indicators). |
| 93 | + |
| 94 | +##### Properties |
| 95 | + |
| 96 | +* `index:Number` - Index of the currently selected child. |
| 97 | +* `onChange:Function` - Callback for when the indicator changes, passing its |
| 98 | +`index` to set the new `index` state in the `<Rotator />`. |
| 99 | + |
| 100 | +##### Example |
| 101 | + |
| 102 | +``` |
| 103 | +import Rotator from 'react-rotator'; |
| 104 | +import {DotsIndicator} from 'react-paging-indicators'; |
| 105 | +
|
| 106 | +... |
| 107 | +
|
| 108 | + render() { |
| 109 | + return ( |
| 110 | + <Rotator |
| 111 | + indicator={<DotsIndicator />} |
| 112 | + > |
| 113 | +
|
| 114 | + </Rotator> |
| 115 | + ); |
| 116 | + } |
| 117 | +
|
| 118 | +... |
| 119 | +
|
| 120 | +``` |
| 121 | + |
| 122 | +## License |
| 123 | + |
| 124 | +[MIT](LICENSE) |
0 commit comments