Skip to content

Commit 8cf965a

Browse files
stephenmathiesontimneutkens
authored andcommitted
examples: add svg-components (vercel#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.

examples/svg-components/package.json

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+
)

examples/svg-components/svgs/cat.svg

Lines changed: 17 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy