Skip to content

Commit 8cf965a

Browse files
stephenmathiesontimneutkens
authored andcommitted
examples: add svg-components (#982)
1 parent db7c286 commit 8cf965a

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

examples/svg-components/.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": [ "next/babel" ],
3+
"plugins": [ "inline-react-svg" ]
4+
}

examples/svg-components/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# SVG components example
3+
4+
## How to use
5+
6+
Download the example [or clone the repo](https://github.com/zeit/next.js):
7+
8+
```bash
9+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/svg-components
10+
cd svg-components
11+
```
12+
13+
Install it and run:
14+
15+
```bash
16+
npm install
17+
npm run dev
18+
```
19+
20+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
21+
22+
```bash
23+
now
24+
```
25+
26+
## The idea behind the example
27+
28+
This example uses a custom `.babelrc` to add support for importing `.svg` files and rendering them as React components. [babel-plugin-inline-react-svg](https://www.npmjs.com/package/babel-plugin-inline-react-svg) is used to handle transpiling the SVGs.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "svg-components",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "next",
6+
"build": "next build",
7+
"start": "next start"
8+
},
9+
"dependencies": {
10+
"next": "beta"
11+
},
12+
"devDependencies": {
13+
"babel-plugin-inline-react-svg": "^0.2.0"
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import Cat from '../svgs/cat.svg'
3+
4+
export default () => (
5+
<div className='container'>
6+
<marquee>SVG Cat!</marquee>
7+
<Cat />
8+
<style jsx>{`
9+
.container {
10+
width: 600px;
11+
margin: 100px auto;
12+
}
13+
`}</style>
14+
</div>
15+
)
Lines changed: 17 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)