├── .eslintrc ├── .gitignore ├── .npmignore ├── .storybook ├── addons.js └── config.js ├── .travis.yml ├── README.md ├── package-lock.json ├── package.json ├── src ├── ReactRevealText.js ├── TestWrapper.js ├── index.js └── utils.js └── stories ├── demo.js ├── documentation.js ├── examples.js ├── index.stories.js ├── styles.css └── tutorial.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb", 3 | "rules": { 4 | "import/no-extraneous-dependencies": "off", 5 | "react/forbid-prop-types": "warn", 6 | "react/jsx-filename-extension": "off", 7 | "react/no-multi-comp": "warn" 8 | } 9 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | dist 4 | storybook-static 5 | yarn-error.log 6 | npm-debug.log -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adrianmcli/react-reveal-text/3c2d921cdeaa9e7007e6faeb1c2937e1a1c9545d/.npmignore -------------------------------------------------------------------------------- /.storybook/addons.js: -------------------------------------------------------------------------------- 1 | import '@storybook/addon-knobs/register'; 2 | import '@storybook/addon-options/register'; 3 | -------------------------------------------------------------------------------- /.storybook/config.js: -------------------------------------------------------------------------------- 1 | import { configure } from '@storybook/react'; 2 | 3 | // automatically import all files ending in *.stories.js 4 | const req = require.context('../stories', true, /.stories.js$/); 5 | function loadStories() { 6 | req.keys().forEach((filename) => req(filename)); 7 | } 8 | 9 | configure(loadStories, module); 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | React Reveal Text 2 | --------------- 3 | [![npm](https://img.shields.io/npm/v/react-reveal-text.svg)](https://www.npmjs.com/package/react-reveal-text) 4 | [![dependencies](https://img.shields.io/david/adrianmcli/react-reveal-text.svg)](https://github.com/adrianmcli/react-reveal-text/blob/master/package.json) 5 | [![travis](https://img.shields.io/travis/adrianmcli/react-reveal-text.svg)](https://travis-ci.org/adrianmcli/react-reveal-text) 6 | [![bithound](https://img.shields.io/bithound/code/github/adrianmcli/react-reveal-text.svg)](https://www.bithound.io/github/adrianmcli/react-reveal-text) 7 | ![license](https://img.shields.io/npm/l/react-reveal-text.svg) 8 | 9 | A small react library for animating the revealing of text. 10 | 11 | ![gif animation](https://cloud.githubusercontent.com/assets/943555/21519497/988cbd5c-ccbb-11e6-9fa0-1911f133de61.gif) 12 | 13 | ### Demo/Tutorial available here: https://adrianmcli.github.io/react-reveal-text/ 14 | 15 | The demo page was built with [React Storybook](https://github.com/storybooks/react-storybook). 16 | 17 | Features 🎉 18 | --------------- 19 | 20 | * **Simple** – Just plain ol' CSS transition animations. 21 | * **Zero dependencies** – Keeping it light and lit up! 22 | * **Flexible** – Choose your own easing function and timing. 23 | * **Customizable** – Customize and theme like a regular div. 24 | * **Dynamic** – Intelligent generation of random transition delay numbers. 25 | 26 | Getting Started 27 | --------------- 28 | 29 | 1. Install: 30 | 31 | ``` 32 | npm install --save react-reveal-text 33 | ``` 34 | 35 | 2. Use: 36 | 37 | ```jsx 38 | WELCOME! 39 | ``` 40 | 41 | API 42 | --------------- 43 | 44 | ### Interactive docs with live-editable props [here](https://adrianmcli.github.io/react-reveal-text/?knob-text=AMAZING%20TEXT&knob-show=true&knob-className=my-class-name&knob-style=%7B%22color%22%3A%22tomato%22%2C%22fontSize%22%3A%2224px%22%2C%22lineHeight%22%3A%2236px%22%2C%22textAlign%22%3A%22center%22%2C%22fontFamily%22%3A%22sans-serif%22%2C%22letterSpacing%22%3A%221.2em%22%2C%22paddingLeft%22%3A%221.2em%22%7D&selectedKind=Documentation&selectedStory=Basic%20Properties&full=0&down=1&left=1&panelRight=1&downPanel=kadirahq%2Fstorybook-addon-knobs). 45 | 46 | This component has many props that you can manipulate; below is a list of all of them. 47 | 48 | Note that the component only re-renders when the `show` property has been changed. 49 | 50 | ## Basic Properties 51 | 52 | - **text** *(string)* 53 | You can set the text either by passing in text as children or by using the text property. 54 | 55 | - **show** *(boolean)* 56 | This prop allows you to control what state the component is in. It allows you to hide or reveal the text. 57 | 58 | - **className** *(string)* 59 | This prop allows you to set the className for the div surrounding the text. 60 | 61 | - **style** *(object)* 62 | This prop allows you to pass in styles for the div surrounding the text. 63 | 64 | ## Transition Properties 65 | 66 | Each letter has its own randomly generated delay before its transition begins. 67 | 68 | - **transitionTime** *(integer)* [default: 1300] 69 | The time it takes for each letter's transition. 70 | 71 | - **timingFunction** *(string)* [default: 'linear'] 72 | The CSS transition-timing-function property. On this page, you are given a dropdown selection, but in practice (and in the sandbox), you can enter in any valid string. 73 | 74 | - **delayMin** *(integer)* [default: 200] 75 | The minimum allowable delay before the transition for a letter is to begin. 76 | 77 | - **delayMax** *(integer)* [default: 1200] 78 | The maximum allowable delay before the transition for a letter is to begin. 79 | 80 | - **threshold** *(float)* [default: 0.2] 81 | The difference between the random numbers generated for each letter compared to the previous letter. Setting this higher will force the delays to be very different between each letter, spreading out the effect. Setting this lower will allow delays to be similar between letters, sometimes creating a chunking effect. 82 | 83 | Contributing 84 | --------------- 85 | 86 | This project was built using my two other tools: [React Build Lib](https://github.com/adrianmcli/react-build-lib) and [React Build Dist](https://github.com/adrianmcli/react-build-dist). These tools are still very early in development, so if you are building these libraries, you may encounter some bugs. PRs and issues are welcomed and encouraged! Should probably add some testing too. 87 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-reveal-text", 3 | "version": "0.1.1", 4 | "description": "A small react library for animating the revealing of text.", 5 | "main": "lib/index.js", 6 | "homepage": "https://github.com/adrianmcli/react-reveal-text", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/adrianmcli/react-reveal-text.git" 10 | }, 11 | "scripts": { 12 | "test": "npm run lint", 13 | "start": "npm run storybook", 14 | "build": "npm run build:lib && npm run build:dist && npm run build-storybook", 15 | "build:lib": "react-build-lib", 16 | "build:dist": "react-build-dist --bundle-name ReactRevealText.js", 17 | "prepublish": "npm run build", 18 | "storybook": "start-storybook -p 6006", 19 | "build-storybook": "build-storybook", 20 | "deploy-storybook": "storybook-to-ghpages", 21 | "lint": "eslint src stories", 22 | "lint:fix": "eslint src stories --fix" 23 | }, 24 | "author": "Adrian Li", 25 | "license": "MIT", 26 | "devDependencies": { 27 | "babel-core": "^6.26.0", 28 | "eslint": "^4.16.0", 29 | "eslint-config-airbnb": "^16.1.0", 30 | "eslint-plugin-import": "^2.8.0", 31 | "eslint-plugin-jsx-a11y": "^6.0.3", 32 | "eslint-plugin-react": "^7.6.1", 33 | "react-build-dist": "^0.0.8", 34 | "react-build-lib": "adrianmcli/react-build-lib", 35 | "@storybook/addon-actions": "^3.3.11", 36 | "@storybook/addon-info": "^3.3.11", 37 | "@storybook/addon-knobs": "^3.3.11", 38 | "@storybook/addon-links": "^3.3.11", 39 | "@storybook/addon-options": "^3.3.11", 40 | "@storybook/addons": "^3.3.11", 41 | "@storybook/react": "^3.3.11", 42 | "@storybook/storybook-deployer": "^2.2.0" 43 | }, 44 | "peerDependencies": {}, 45 | "keywords": [ 46 | "react", 47 | "react-component" 48 | ], 49 | "dependencies": { 50 | "prop-types": "^15.6.0", 51 | "react": "^16.0.0", 52 | "react-dom": "^16.0.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/ReactRevealText.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | import { getRandoms, randomToDelay } from './utils'; 5 | 6 | class ReactRevealText extends React.Component { 7 | constructor(props) { 8 | super(props); 9 | this.getDelays = this.getDelays.bind(this); 10 | this.renderToSpan = this.renderToSpan.bind(this); 11 | } 12 | 13 | shouldComponentUpdate(nextProps) { 14 | const showChanged = this.props.show !== nextProps.show; 15 | const textChanged = this.props.text !== nextProps.text; 16 | const childrenChanged = this.props.children !== nextProps.children; 17 | return showChanged || textChanged || childrenChanged; 18 | } 19 | 20 | getDelays(length) { 21 | const { threshold, delayMin, delayMax } = this.props; 22 | 23 | // generate random numbers and then convert to delays 24 | const randoms = () => getRandoms(length, threshold); 25 | const toDelay = num => randomToDelay(num, delayMin, delayMax); 26 | 27 | return randoms().map(toDelay); 28 | } 29 | 30 | renderToSpan({ character, delay }, index) { 31 | const { show, transitionTime, timingFunction } = this.props; 32 | const style = { 33 | opacity: show ? '1' : '0', 34 | transition: `opacity ${transitionTime}ms`, 35 | transitionDelay: `${delay}ms`, 36 | transitionTimingFunction: timingFunction, 37 | }; 38 | return {character}; 39 | } 40 | 41 | renderSpans(text) { 42 | const textArray = text.split(''); 43 | 44 | const delays = this.getDelays(textArray.length); 45 | const combineWithDelays = 46 | (character, index) => ({ character, delay: delays[index] }); 47 | 48 | return textArray 49 | .map(combineWithDelays) 50 | .map(this.renderToSpan); 51 | } 52 | 53 | render() { 54 | const { style, className } = this.props; 55 | const text = this.props.text || this.props.children; 56 | 57 | return ( 58 |
59 | {this.renderSpans(text)} 60 |
61 | ); 62 | } 63 | } 64 | 65 | ReactRevealText.propTypes = { 66 | text: PropTypes.string, 67 | show: PropTypes.bool, 68 | transitionTime: PropTypes.number, 69 | timingFunction: PropTypes.string, 70 | delayMin: PropTypes.number, 71 | delayMax: PropTypes.number, 72 | threshold: PropTypes.number, 73 | style: PropTypes.object, 74 | className: PropTypes.string, 75 | children: PropTypes.string, 76 | }; 77 | 78 | ReactRevealText.defaultProps = { 79 | transitionTime: 1300, 80 | timingFunction: 'linear', 81 | delayMin: 200, 82 | delayMax: 1200, 83 | threshold: 0.2, 84 | text: '', 85 | className: '', 86 | style: {}, 87 | show: false, 88 | children: undefined, 89 | }; 90 | 91 | export default ReactRevealText; 92 | -------------------------------------------------------------------------------- /src/TestWrapper.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/require-default-props */ 2 | import React from 'react'; 3 | import PropTypes from 'prop-types'; 4 | 5 | class TestWrapper extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | this.onClick = this.onClick.bind(this); 9 | this.state = { 10 | show: false, 11 | }; 12 | } 13 | 14 | onClick() { 15 | this.setState({ show: !this.state.show }); 16 | } 17 | 18 | render() { 19 | const { show } = this.state; 20 | const { children, ...other } = this.props; 21 | 22 | const child = React.Children.only(children); 23 | const ChildComponent = React.cloneElement(child, { show, ...other }); 24 | 25 | return ( 26 |
27 | { ChildComponent } 28 | 29 |
30 | ); 31 | } 32 | } 33 | 34 | TestWrapper.propTypes = { 35 | children: PropTypes.element, 36 | }; 37 | 38 | export default TestWrapper; 39 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./ReactRevealText').default; 2 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | export const getRandoms = (length, threshold) => { 2 | const tooClose = (a, b) => Math.abs(a - b) < threshold; 3 | 4 | const result = []; 5 | let random; 6 | 7 | for (let i = 0; i < length; i += 1) { 8 | random = Math.random(); 9 | if (i !== 0) { 10 | const prev = result[i - 1]; 11 | while (tooClose(random, prev)) { 12 | random = Math.random(); 13 | } 14 | } 15 | result.push(random); 16 | } 17 | return result; 18 | }; 19 | 20 | export const randomToDelay = (random, min, max) => { 21 | const float = random * (max - min); 22 | return parseInt(float, 10) + min; 23 | }; 24 | -------------------------------------------------------------------------------- /stories/demo.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/no-unused-state */ 2 | import React from 'react'; 3 | import { storiesOf } from '@storybook/react'; 4 | import { withInfo } from '@storybook/addon-info'; 5 | 6 | import TestWrapper from '../src/TestWrapper'; 7 | import ReactRevealText from '../src/index'; 8 | 9 | export default () => 10 | storiesOf('Demo', module) 11 | .add('Revealing Text', withInfo({ 12 | propTables: false, 13 | inline: true, 14 | source: false, 15 | text: ` 16 | A simple component for revealing text in a gradual way. 17 | 18 | Each letter gets a transition applied to it with a random distribution of delays so that they come into (and out of) view sporadically. 19 | 20 | This controlled component is great for landing pages and anywhere you need to show some kind of transition. 21 | 22 | Inspired by Adam Schwartz's [Magic of CSS](http://adamschwartz.co/magic-of-css/chapters/6-transitions/). 23 | `, 24 | })(() => { 25 | class Wrapper extends React.Component { 26 | constructor() { 27 | super(); 28 | this.state = { show: false }; 29 | } 30 | 31 | componentDidMount() { 32 | setTimeout(() => { 33 | this.setState({ show: true }); 34 | }, 2000); 35 | } 36 | 37 | render() { 38 | const bgStyles = { 39 | background: 'linear-gradient(135deg, #723362, #9d223c)', 40 | padding: '36px', 41 | paddingTop: '48px', 42 | }; 43 | const textStyles = { 44 | color: 'white', 45 | fontSize: '24px', 46 | lineHeight: '36px', 47 | fontFamily: 'sans-serif', 48 | textAlign: 'center', 49 | letterSpacing: '1em', 50 | paddingLeft: '1em', // to compensate for letter spacing 51 | }; 52 | return ( 53 |
54 |
55 | 56 | 57 | 58 |
59 |
60 | ); 61 | } 62 | } 63 | 64 | return ( 65 | 66 | ); 67 | })); 68 | -------------------------------------------------------------------------------- /stories/documentation.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { storiesOf } from '@storybook/react'; 3 | import { withInfo } from '@storybook/addon-info'; 4 | import { withKnobs, text, boolean, object, number, select } from '@storybook/addon-knobs'; 5 | 6 | import { setOptions } from '@storybook/addon-options'; 7 | 8 | import TestWrapper from '../src/TestWrapper'; 9 | import ReactRevealText from '../src/index'; 10 | 11 | export default () => 12 | storiesOf('Documentation', module) 13 | .addDecorator(withKnobs) 14 | .add('Basic Properties', withInfo({ 15 | propTables: false, 16 | inline: true, 17 | text: ` 18 | This component has many props that you can manipulate. Please see below and use the knobs panel on the right to experiment. 19 | 20 | Note that the component only re-renders when the \`show\` property has been changed. 21 | 22 | # Basic Properties 23 | 24 | **text** *(string)* 25 | You can set the text either by passing in text as children or by using the text property. 26 | 27 | **show** *(boolean)* 28 | This prop allows you to control what state the component is in. It allows you to hide or reveal the text. 29 | 30 | **className** *(string)* 31 | This prop allows you to set the className for the div surrounding the text. 32 | 33 | **style** *(object)* 34 | This prop allows you to pass in styles for the div surrounding the text. 35 | `, 36 | })(() => { 37 | setOptions({ showDownPanel: true }); 38 | return ( 39 | 53 | ); 54 | })) 55 | .add('Transition Properties', withInfo({ 56 | propTables: false, 57 | inline: true, 58 | text: ` 59 | Each letter has its own randomly generated delay before its transition begins. 60 | 61 | # Transition Properties 62 | 63 | **transitionTime** *(integer)* [default: 1300] 64 | The time it takes for each letter's transition. 65 | 66 | **timingFunction** *(string)* [default: 'linear'] 67 | The CSS transition-timing-function property. On this page, you are given a dropdown selection, but in practice (and in the sandbox), you can enter in any valid string. 68 | 69 | **delayMin** *(integer)* [default: 200] 70 | The minimum allowable delay before the transition for a letter is to begin. 71 | 72 | **delayMax** *(integer)* [default: 1200] 73 | The maximum allowable delay before the transition for a letter is to begin. 74 | 75 | **threshold** *(float)* [default: 0.2] 76 | The difference between the random numbers generated for each letter compared to the previous letter. 77 | Setting this higher will force the delays to be very different between each letter, spreading out the effect. 78 | Setting this lower will allow delays to be similar between letters, sometimes creating a chunking effect. 79 | `, 80 | })(() => { 81 | setOptions({ showDownPanel: true }); 82 | const timingFnOptions = { 83 | linear: 'linear', 84 | ease: 'ease', 85 | 'ease-in': 'ease-in', 86 | 'ease-out': 'ease-out', 87 | 'ease-in-out': 'ease-in-out', 88 | 'step-start': 'step-end', 89 | }; 90 | const thresholdOptions = { 91 | range: true, 92 | min: 0, 93 | max: 0.5, 94 | step: 0.1, 95 | }; 96 | return ( 97 | 98 | 105 | AMAZING TEXT! 106 | 107 | 108 | ); 109 | })) 110 | .add('Sandbox', withInfo({ 111 | propTables: false, 112 | inline: true, 113 | text: ` 114 | This page has all the properties for you to play with. 115 | 116 | Note that you can input \`timingFunction\` as a string on the knobs tab. 117 | `, 118 | })(() => { 119 | setOptions({ showDownPanel: true }); 120 | const thresholdOptions = { 121 | range: true, 122 | min: 0, 123 | max: 0.5, 124 | step: 0.1, 125 | }; 126 | return ( 127 | 128 | 147 | 148 | ); 149 | })); 150 | -------------------------------------------------------------------------------- /stories/examples.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { storiesOf } from '@storybook/react'; 3 | import { withInfo } from '@storybook/addon-info'; 4 | 5 | import ReactRevealText from '../src/index'; 6 | 7 | export default () => 8 | storiesOf('Examples', module) 9 | .add('1. Show on load', withInfo({ 10 | propTables: false, 11 | inline: true, 12 | source: false, 13 | text: ` 14 | Here is an example that will reveal the text once the component has been mounted. 15 | 16 | # Source 17 | 18 | ~~~jsx 19 | class Wrapper extends React.Component { 20 | 21 | constructor() { 22 | super(); 23 | this.state = { show: false }; 24 | } 25 | 26 | componentDidMount() { 27 | setTimeout(() => { 28 | this.setState({ show: true }); 29 | }, 2000); 30 | } 31 | 32 | render() { 33 | return ( 34 |
35 |

36 | 37 | WELCOME TO MY SITE 38 | 39 |

40 |
41 | ); 42 | } 43 | } 44 | ~~~ 45 | `, 46 | })(() => { 47 | class Wrapper extends React.Component { 48 | constructor() { 49 | super(); 50 | this.state = { show: false }; 51 | } 52 | 53 | componentDidMount() { 54 | setTimeout(() => { 55 | this.setState({ show: true }); 56 | }, 2000); 57 | } 58 | 59 | render() { 60 | return ( 61 |
62 |

63 | 64 | WELCOME TO MY SITE 65 | 66 |

67 |
68 | ); 69 | } 70 | } 71 | 72 | return ( 73 | 74 | ); 75 | })) 76 | .add('2. Show only on hover', withInfo({ 77 | propTables: false, 78 | inline: true, 79 | source: false, 80 | text: ` 81 | Here is an example that will reveal the text only when it is being hovered on top of. 82 | 83 | # Source 84 | 85 | ~~~jsx 86 | class Wrapper extends React.Component { 87 | 88 | constructor() { 89 | super(); 90 | this.state = { show: false }; 91 | this.onMouseEnter = this.onMouseEnter.bind(this); 92 | this.onMouseLeave = this.onMouseLeave.bind(this); 93 | } 94 | 95 | onMouseEnter() { 96 | console.log('true'); 97 | this.setState({ show: true }); 98 | } 99 | 100 | onMouseLeave() { 101 | console.log('false'); 102 | this.setState({ show: false }); 103 | } 104 | 105 | render() { 106 | return ( 107 |
112 |

113 | 114 | WELCOME TO MY SITE 115 | 116 |

117 |
118 | ); 119 | } 120 | } 121 | ~~~ 122 | `, 123 | })(() => { 124 | class Wrapper extends React.Component { 125 | constructor() { 126 | super(); 127 | this.state = { show: false }; 128 | this.onMouseEnter = this.onMouseEnter.bind(this); 129 | this.onMouseLeave = this.onMouseLeave.bind(this); 130 | } 131 | 132 | onMouseEnter() { 133 | this.setState({ show: true }); 134 | } 135 | 136 | onMouseLeave() { 137 | this.setState({ show: false }); 138 | } 139 | 140 | render() { 141 | return ( 142 |
147 |

148 | 149 | WELCOME TO MY SITE 150 | 151 |

152 |
153 | ); 154 | } 155 | } 156 | 157 | return ( 158 | 159 | ); 160 | })) 161 | .add('3. Pretty', withInfo({ 162 | propTables: false, 163 | inline: true, 164 | source: false, 165 | text: ` 166 | A simple example to show off how pretty the effect can look. 167 | 168 | Imagine this with a moving background! 169 | 170 | # Source 171 | 172 | ~~~jsx 173 | class Wrapper extends React.Component { 174 | 175 | constructor() { 176 | super(); 177 | this.state = { show: false }; 178 | } 179 | 180 | componentDidMount() { 181 | setTimeout(() => { 182 | this.setState({ show: true }); 183 | }, 2000); 184 | } 185 | 186 | render() { 187 | const bgStyles = { 188 | background: 'linear-gradient(135deg, #723362, #9d223c)', 189 | padding: '36px', 190 | }; 191 | const textStyles = { 192 | color: 'white', 193 | fontSize: '24px', 194 | lineHeight: '36px', 195 | fontFamily: 'sans-serif', 196 | textAlign: 'center', 197 | letterSpacing: '1em', 198 | paddingLeft: '1em', // to compensate for letter spacing 199 | }; 200 | return ( 201 |
202 |
203 | 204 |
205 |
206 | ); 207 | } 208 | } 209 | ~~~ 210 | `, 211 | })(() => { 212 | class Wrapper extends React.Component { 213 | constructor() { 214 | super(); 215 | this.state = { show: false }; 216 | } 217 | 218 | componentDidMount() { 219 | setTimeout(() => { 220 | this.setState({ show: true }); 221 | }, 2000); 222 | } 223 | 224 | render() { 225 | const bgStyles = { 226 | background: 'linear-gradient(135deg, #723362, #9d223c)', 227 | padding: '36px', 228 | }; 229 | const textStyles = { 230 | color: 'white', 231 | fontSize: '24px', 232 | lineHeight: '36px', 233 | fontFamily: 'sans-serif', 234 | textAlign: 'center', 235 | letterSpacing: '1em', 236 | paddingLeft: '1em', // to compensate for letter spacing 237 | }; 238 | return ( 239 |
240 |
241 | 242 |
243 |
244 | ); 245 | } 246 | } 247 | 248 | return ( 249 | 250 | ); 251 | })); 252 | -------------------------------------------------------------------------------- /stories/index.stories.js: -------------------------------------------------------------------------------- 1 | import './styles.css'; 2 | 3 | import demo from './demo'; 4 | import tutorial from './tutorial'; 5 | import examples from './examples'; 6 | import documentation from './documentation'; 7 | 8 | demo(); 9 | tutorial(); 10 | examples(); 11 | documentation(); 12 | -------------------------------------------------------------------------------- /stories/styles.css: -------------------------------------------------------------------------------- 1 | code { 2 | font-size: 15px; 3 | font-weight: 600; 4 | padding: 2px 5px; 5 | border: 1px solid #eae9e9; 6 | border-radius: 4px; 7 | background-color: #f3f2f2; 8 | color: #3a3a3a; 9 | } 10 | 11 | pre > code { 12 | border: none; 13 | border-radius: 0; 14 | padding: 0; 15 | margin: 0; 16 | font-weight: 400; 17 | } -------------------------------------------------------------------------------- /stories/tutorial.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { storiesOf } from '@storybook/react'; 3 | import { withInfo } from '@storybook/addon-info'; 4 | import { withKnobs, text, boolean, object } from '@storybook/addon-knobs'; 5 | 6 | import { setOptions } from '@storybook/addon-options'; 7 | 8 | import TestWrapper from '../src/TestWrapper'; 9 | import ReactRevealText from '../src/index'; 10 | 11 | // const stories = storiesOf('Tutorial', module); 12 | // stories.addDecorator(withKnobs); 13 | 14 | export default () => 15 | storiesOf('Tutorial', module) 16 | .addDecorator(withKnobs) 17 | .add('1. A controlled component', withInfo({ 18 | propTables: false, 19 | inline: true, 20 | source: true, 21 | text: ` 22 | React Reveal Text is a controlled component. 23 | 24 | That means you control its appearance by passing in a prop. 25 | In this case, it's the \`show\` prop. 26 | 27 | Click the "Knobs" tab on the bottom and try changing the state. 28 | `, 29 | })(() => { 30 | setOptions({ showDownPanel: true }); 31 | return ( 32 | 33 | WELCOME! 34 | 35 | ); 36 | })) 37 | .add('2. Styling your text', withInfo({ 38 | propTables: false, 39 | inline: true, 40 | source: true, 41 | text: ` 42 | ~~~jsx 43 | 48 | ~~~ 49 | 50 | You can style an object by passing in a style object into the \`styles\` prop. 51 | 52 | Or, you can also pass in a string to the \`className\` prop. 53 | 54 | Note that the component only re-renders when the \`show\` prop is changed. 55 | `, 56 | })(() => { 57 | setOptions({ showDownPanel: true }); 58 | return ( 59 | 70 | WELCOME! 71 | 72 | ); 73 | })) 74 | .add('3. Testing with TestWrapper', withInfo({ 75 | propTables: false, 76 | inline: true, 77 | text: ` 78 | This library ships with a component to help you develop with React Reveal Text. 79 | 80 | The TestWrapper component renders a button for you to toggle its 81 | show/hide state, and controls the ReactRevealText \`show\` prop for you. 82 | Any props you pass in will be passed through to its child. 83 | 84 | Simply import it like this and use it in the way shown below: 85 | 86 | ~~~jsx 87 | import TestWrapper from 'react-reveal-text/lib/TextWrapper'; 88 | ~~~ 89 | `, 90 | })(() => { 91 | setOptions({ showDownPanel: true }); 92 | return ( 93 | 105 | 106 | 107 | ); 108 | })); 109 | --------------------------------------------------------------------------------