Skip to content

Commit 7015563

Browse files
author
Tane Morgan
authored
Merge pull request tanem#178 from tanem/add-loading
Add loading prop
2 parents 2a8e505 + aac6c85 commit 7015563

File tree

13 files changed

+112
-2
lines changed

13 files changed

+112
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ render(<ReactSVG src="svg.svg" />, document.getElementById('root'))
2828
- API Usage: [Source](https://github.com/tanem/react-svg/tree/master/examples/api-usage) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/api-usage)
2929
- External Stylesheet: [Source](https://github.com/tanem/react-svg/tree/master/examples/external-stylesheet) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/external-stylesheet)
3030
- Fallbacks: [Source](https://github.com/tanem/react-svg/tree/master/examples/fallbacks) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/fallbacks)
31+
- Loading: [Source](https://github.com/tanem/react-svg/tree/master/examples/loading) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/loading)
3132
- Typescript: [Source](https://github.com/tanem/react-svg/tree/master/examples/typescript) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/typescript)
3233
- CSS-in-JS: [Source](https://github.com/tanem/react-svg/tree/master/examples/css-in-js) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/css-in-js)
3334
- UMD Build (Development): [Source](https://github.com/tanem/react-svg/tree/master/examples/umd-dev) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/umd-dev)
@@ -40,6 +41,7 @@ render(<ReactSVG src="svg.svg" />, document.getElementById('root'))
4041
- `src` - The SVG URL.
4142
- `evalScripts` - _Optional_ Run any script blocks found in the SVG. One of `'always'`, `'once'`, or `'never'`. Defaults to `'never'`.
4243
- `fallback` - _Optional_ Fallback to use if an injection error occurs. Can be a string, class component, or function component. Defaults to `null`.
44+
- `loading` - _Optional_ Component to use during loading. Can be a string, class component, or function component. Defaults to `null`.
4345
- `onInjected` - _Optional_ Function to call after the SVG is injected. If an injection error occurs, this function receives an `Error` object as the first parameter. Otherwise, the first parameter is `null` and the second parameter is the injected SVG DOM element. Defaults to `() => {}`.
4446
- `renumerateIRIElements` - _Optional_ Boolean indicating if SVG IRI addressable elements should be renumerated. Defaults to `true`.
4547
- `svgClassName` - _Optional_ Class name to be added to the injected SVG DOM element. Defaults to `null`.
@@ -54,6 +56,7 @@ Other non-documented properties are applied to the wrapper element.
5456
src="svg.svg"
5557
evalScripts="always"
5658
fallback={() => <span>Error!</span>}
59+
loading={() => <span>Loading</span>}
5760
onInjected={(error, svg) => {
5861
if (error) {
5962
console.error(error)

examples/api-usage/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ReactDOM.render(
99
// Optional props.
1010
evalScripts="always"
1111
fallback={() => <span>Error!</span>}
12+
loading={() => <span>Loading</span>}
1213
onInjected={(error, svg) => {
1314
if (error) {
1415
console.error(error)

examples/loading/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REACT_APP_DESCRIPTION=$npm_package_description

examples/loading/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

examples/loading/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ReactSVG Loading Example
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.<br>
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.<br>
15+
You will also see any lint errors in the console.

examples/loading/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "loading",
3+
"description": "ReactSVG Loading Example",
4+
"keywords": [
5+
"react-svg"
6+
],
7+
"version": "0.1.0",
8+
"private": true,
9+
"dependencies": {
10+
"react": "^16.6.1",
11+
"react-dom": "^16.6.1",
12+
"react-scripts": "2.1.1",
13+
"react-spinkit": "^3.0.0",
14+
"react-svg": "latest"
15+
},
16+
"scripts": {
17+
"start": "react-scripts start"
18+
},
19+
"browserslist": [
20+
">0.2%",
21+
"not dead",
22+
"not ie <= 11",
23+
"not op_mini all"
24+
]
25+
}

examples/loading/public/doge.png

8.92 KB
Loading

examples/loading/public/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
<title>%REACT_APP_DESCRIPTION%</title>
8+
</head>
9+
10+
<body>
11+
<div id="root"></div>
12+
</body>
13+
14+
</html>

examples/loading/public/svg.svg

Lines changed: 3 additions & 0 deletions
Loading

examples/loading/src/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
import Spinner from 'react-spinkit'
4+
import ReactSVG from 'react-svg'
5+
6+
const Loading = ({ size }) => (
7+
<Spinner name="cube-grid" style={{ height: size, width: size }} />
8+
)
9+
10+
ReactDOM.render(
11+
<React.Fragment>
12+
<ReactSVG loading={() => <Loading size={40} />} src="svg.svg" />
13+
<ReactSVG
14+
fallback={() => <img alt="doge" src="doge.png" />}
15+
loading={() => <Loading size={60} />}
16+
src="notfound.svg"
17+
/>
18+
</React.Fragment>,
19+
document.getElementById('root')
20+
)

0 commit comments

Comments
 (0)