Skip to content

Commit 049a27f

Browse files
author
Peter Morawiec
committed
JS fallback mode
1 parent 6c9c835 commit 049a27f

19 files changed

+536
-381
lines changed

.npmignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
src/
22
public/
33
test/
4-
karma.conf.js
5-
tests.js
64
webpack.config.js
75
webpack.dist.js
86
showcase.gif

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ react-mt-svg-lines
77

88
[Live Demo](http://moarwick.github.io/react-mt-svg-lines)
99

10-
A tiny React.js wrapper component that lets you trigger "animated lines" in your SVGs. Use it to add visual interest to icons, diagrams, loading spinners, or just any fun stuff!
10+
A React.js wrapper component that lets you trigger an "animated lines" effect within your SVGs by applying CSS animations*. Use it to add visual interest to icons, diagrams, loading spinners, or just any fun stuff!
1111

1212

1313
### How it works
14-
The component wraps your SVG and injects CSS required to animate the `stroke-dashoffset` property on every `path` element within. Since it utilizes CSS, it does not rely on any tweening libs. For a description of the technique, see [this article](https://css-tricks.com/svg-line-animation-works/).
14+
The component wraps your SVG and animates the `stroke-dashoffset` property on every `path` element within. To accomplish this, it injects a `style` tag with a generated string of CSS. For a description of the technique, see [this article](https://css-tricks.com/svg-line-animation-works).
1515

16-
> Sadly, this technique does not work in IE. I'm thinking of adding a JS-powered version soon...
16+
17+
### IE/Edge
18+
While CSS animation comes "free", it doesn't work for SVGs on IE/Edge browsers. As of `0.6.0`, the component falls back to using JavaScript when IE/Edge is detected. The JS implementation relies on [tween.js](https://www.npmjs.com/package/tween.js) and doesn't interpret all prop permutations. It's "experimental" and doesn't seem very performant, so tread lightly!
1719

1820

1921
### Installation
@@ -33,11 +35,10 @@ In your JSX, wrap it around any valid SVG...
3335
```js
3436
<MtSvgLines animate={ true } duration={ 500 }>
3537
<svg viewBox="0 0 100 100">
36-
<path stroke="green" strokeWidth="10" fill="none" d="M20.8,51c0,0,20.8,18.2,21.5,18.2c0.6,0,33.3-38.5,33.3-38.5"/>
38+
<path stroke="green" stroke-width="10" fill="none" d="M20.8,51c0,0,20.8,18.2,21.5,18.2c0.6,0,33.3-38.5,33.3-38.5" />
3739
</svg>
3840
</MtSvgLines>
3941
```
40-
> When you move up to React v15.0+, it appears that it no longer requires SVG attributes to be camel-cased in JSX. So, rather than `strokeWidth` or `strokeLinecap`, you should be good with the standard `stroke-width`, `stroke-linecap`, etc.
4142

4243

4344
### Props
@@ -53,7 +54,7 @@ Your animation "trigger key":
5354
* `false` render the SVG instantly (default)
5455
* `true || string` trigger the animation immediately
5556
* `number` trigger the animation after an initial delay of *number* (ms)
56-
* `"hide"` draw the SVG as invisible (rendered with `opacity: 0.01`)
57+
* `"hide"` draw the SVG as invisible (rendered with `opacity: 0`)
5758

5859
If you need to re-trigger the animation, simply pass in a new `string` or `number` (different from the last value). You can generate it, e.g. `String( Date.now() )`. Have a look at the [DemoPage](https://github.com/moarwick/react-mt-svg-lines/blob/master/src/components/DemoPage.js) code.
5960

@@ -63,18 +64,20 @@ Callback function, executes when animation concludes.
6364
##### `duration: number`
6465
Desired duration of one full cycle of the entire animation, across all paths (ms). Default is `1000`.
6566

66-
##### `stagger: number (0-100)`
67-
Delay between the start times of each path (when multiple paths are present within the SVG). Default is `0`. (The math there is simple, so if you have many staggered paths, you may need to tweak your `duration`.)
67+
##### `jsOnly: bool`
68+
Apply `tween.js` to drive animations using JavaScript regardless of browser. Default is `false` (kick in on IE/Edge only, via browser sniffing).
6869

69-
##### `timing: string`
70-
Desired CSS "timing function" type: `"ease" || "ease-in" || "ease-out" || "ease-in-out" || "linear" || "step-start" || "step-end"`. Default is `"ease"`.
70+
##### `fade: bool`
71+
Apply a *fade-in* transition to each path. If a path has a `fill` color, the entire element will fade in while the line is drawn. Default is `false`. *Not supported in JS mode.*
7172

7273
##### `playback: string`
73-
Any additional valid CSS [`animation`](https://developer.mozilla.org/en-US/docs/Web/CSS/animation) shorthand props, specifically `iteration-count || direction || fill-mode || play-state`. Default is `"forwards"` (play once and stop), but feel free to experiment. For example, the spinner example is set to `"2 alternate-reverse both"`.
74+
Any additional valid CSS [`animation`](https://developer.mozilla.org/en-US/docs/Web/CSS/animation) shorthand props, specifically `iteration-count || direction || fill-mode || play-state`. Default is `"forwards"` (play once and stop), but feel free to experiment. For example, the spinner example is set to `"2 alternate-reverse both"`. *Partially supported in JS mode, respects defaults, `iteration-count`, and `alternate` direction.*
7475

75-
##### `fade: bool`
76-
Apply a *fade-in* transition to each path. If a path has a `fill` color, the entire element will fade in while the line is drawn. Default is `false`.
76+
##### `stagger: number (0-100)`
77+
Delay between the start times of each path (when multiple paths are present within the SVG). Default is `0`. *Not supported in JS mode.*
7778

79+
##### `timing: string`
80+
Desired CSS "timing function" type: `"ease" || "ease-in" || "ease-out" || "ease-in-out" || "linear" || "step-start" || "step-end"`. Default is `"ease"`. *Mostly supported in JS mode, with Tween.js equivalent presets.*
7881

7982
> All other `props` are passed through to the wrapper `span`
8083
@@ -87,3 +90,11 @@ What if you don't want the animation applied to *ALL* paths inside your SVG? Add
8790
* The technique only applies to SVG `path` elements with a `stroke` defined. Other SVG primitives, e.g. circles, rectangles, polylines, will render instantly.
8891
* The path elements should sit at the same nesting level within the SVG structure (otherwise, the generated CSS rules will not target correctly). Also, staggered timing is applied to the elements in the order they appear in the SVG. You can edit your SVGs manually, or try [svgo](https://github.com/svg/svgo).
8992
* Remember to specify the `viewBox` on your SVGs, so they can be scaled to any size. By default, the SVG content will expand to fill its container, but you can give it a `width` attribute (either in finite units, or percentage).
93+
* IE/Edge: Doesn't seem to work on thick lines, round `stroke-linecap` appears regardless of offset, and other irregularities..
94+
95+
### Changelog
96+
**Ver 0.6.0**
97+
* Experimental support for IE/Edge via Tween.js
98+
99+
**Ver 0.5.0**
100+
* Callback prop

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

karma.conf.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

package.json

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"start": "webpack-dev-server --content-base src/demos/",
2424
"build": "rimraf public && node_modules/webpack/bin/webpack.js --progress --profile --colors",
2525
"dist": "node_modules/webpack/bin/webpack.js --config webpack.dist.js",
26-
"prepublish": "npm run dist",
27-
"test": "karma start"
26+
"prepublish": "npm run dist"
2827
},
2928
"browserify": {
3029
"transform": [
@@ -79,48 +78,39 @@
7978
"globals": {
8079
"describe": true,
8180
"expect": true,
82-
"it": true,
83-
"TestUtils": true
81+
"it": true
8482
},
8583
"plugins": [
8684
"react"
8785
]
8886
},
8987
"devDependencies": {
90-
"autoprefixer": "6.3.3",
91-
"babel-core": "6.5.2",
92-
"babel-eslint": "5.0.0",
93-
"babel-loader": "6.2.3",
94-
"babel-preset-es2015": "6.5.0",
95-
"babel-preset-react": "6.5.0",
96-
"babel-preset-stage-0": "6.5.0",
97-
"chai": "3.5.0",
98-
"css-loader": "0.23.1",
99-
"eslint-plugin-react": "3.16.1",
100-
"extract-text-webpack-plugin": "1.0.1",
101-
"file-loader": "0.8.5",
102-
"html-webpack-plugin": "^2.9.0",
103-
"karma": "0.13.21",
104-
"karma-chai": "0.1.0",
105-
"karma-chrome-launcher": "0.2.2",
106-
"karma-cli": "0.1.2",
107-
"karma-mocha": "0.2.2",
108-
"karma-sourcemap-loader": "0.3.7",
109-
"karma-spec-reporter": "0.0.24",
110-
"karma-webpack": "1.7.0",
111-
"mocha": "2.4.5",
112-
"node-sass": "3.4.2",
113-
"postcss-loader": "0.8.1",
114-
"react-addons-test-utils": "0.14.7",
115-
"react-hot-loader": "1.3.0",
116-
"rimraf": "2.5.2",
117-
"sass-loader": "3.1.2",
118-
"style-loader": "0.13.0",
119-
"url-loader": "0.5.7",
120-
"webpack": "1.12.13",
121-
"webpack-dev-server": "1.14.1",
122-
"webpack-merge": "0.7.3",
123-
"react": "0.14.7",
124-
"react-dom": "0.14.7"
88+
"autoprefixer": "^6.3.7",
89+
"babel-core": "^6.10.4",
90+
"babel-eslint": "^6.1.0",
91+
"babel-loader": "^6.2.4",
92+
"babel-preset-es2015": "^6.9.0",
93+
"babel-preset-react": "^6.11.1",
94+
"babel-preset-stage-0": "^6.5.0",
95+
"chai": "^3.5.0",
96+
"css-loader": "^0.23.1",
97+
"eslint-plugin-react": "^5.2.2",
98+
"extract-text-webpack-plugin": "^1.0.1",
99+
"file-loader": "^0.9.0",
100+
"html-webpack-plugin": "^2.22.0",
101+
"mocha": "^2.5.3",
102+
"node-sass": "^3.8.0",
103+
"postcss-loader": "^0.9.1",
104+
"react-hot-loader": "^1.3.0",
105+
"rimraf": "^2.5.3",
106+
"sass-loader": "^4.0.0",
107+
"style-loader": "^0.13.1",
108+
"url-loader": "^0.5.7",
109+
"webpack": "^1.13.1",
110+
"webpack-dev-server": "^1.14.1",
111+
"webpack-merge": "^0.14.0",
112+
"react": "^15.2.0",
113+
"react-dom": "^15.2.0",
114+
"tween.js": "^16.3.4"
125115
}
126116
}

public/2f6dc120081c95e3636f.min.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/b69be6a6dc899a8f6942.min.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

public/css/2f6dc120081c95e3636f.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/b69be6a6dc899a8f6942.min.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<title>Mt React Component</title>
88
<meta name="description" content="Mt React Component" />
99
<meta name="author" content="moarwick" />
10-
<link href="css/b69be6a6dc899a8f6942.min.css" rel="stylesheet"></head>
10+
<link href="css/2f6dc120081c95e3636f.min.css" rel="stylesheet"></head>
1111
<body>
1212
<div id="component"></div>
13-
<script type="text/javascript" src="b69be6a6dc899a8f6942.min.js"></script></body>
13+
<script type="text/javascript" src="2f6dc120081c95e3636f.min.js"></script></body>
1414
</html>

0 commit comments

Comments
 (0)