Visitar URL original
feat(svg-sprite): Adds build sprite script with tests and docs by ivanquirino · Pull Request #319 · feathericons/feather · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(svg-sprite): Adds build sprite script with tests and docs
fixes requested by @colebemis
  • Loading branch information
Ivan Quirino
Ivan Quirino committed Feb 20, 2018
commit c28aeea10f87fa0cba5759bc88dceda30ddcb504
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,42 +120,6 @@ Call the `feather.replace()` method.

All elements that have a `data-feather` attribute will be replaced with SVG markup corresponding to their `data-feather` attribute value. See the [API Reference](#api-reference) for more information about `feather.replace()`.

#### 5. SVG Sprite
A SVG Sprite is also provided, which can be used as following:
```html
<svg class="feather feather-[iconName]"
width="24"
height="24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<use xlink:href="feather-sprite.svg#[iconName]"/>
</svg>
```
Where `iconName` is the name of the icon you want to display.

Same result but using a CSS class:
```css
.feather-default {
width: 24px;
height: 24px;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
fill: none
}
```
```html
<svg class="feather-default feather feather-[iconName]">
<use xlink:href="feather-sprite.svg#[iconName]"/>
</svg>
```
This way

### Node
#### 1. Install

Expand Down Expand Up @@ -202,6 +166,42 @@ feather.icons.x.toSvg({ class: 'foo bar', 'stroke-width': 1, color: 'red' })

See the [API Reference](#api-reference) for more information about the available properties and methods of the `feather` object.

### SVG Sprite

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, can you add this to the table of contents?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sure! I forgot that, I'm not used to contribute to such well made projects.

A SVG Sprite is also provided, which can be used as following:
```html
<svg class="feather feather-[iconName]"
width="24"
height="24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<use xlink:href="feather-sprite.svg#[iconName]"/>
</svg>
```
Where `iconName` is the name of the icon you want to display.

Same result but using a CSS class:
```css
.feather {
width: 24px;
height: 24px;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
fill: none

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor] Oops, we're missing a semicolon here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

}
```
```html
<svg class="feather feather-[iconName]">
<use xlink:href="feather-sprite.svg#[iconName]"/>
</svg>
```
Prefer using CSS classes to keep things organized.

## API Reference

### `feather.icons`
Expand Down
2 changes: 1 addition & 1 deletion bin/__tests__/build-sprite.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env jest */
import buildSprite from '../build-sprite-function';
import buildSprite from '../build-sprite-string';

const icons = {
icon1:
Expand Down
5 changes: 3 additions & 2 deletions bin/build-sprite-function.js → bin/build-sprite-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import defaultAttrs from '../src/default-attrs.json';

/**
* Renders a SVG symbol tag
* @param {*} name The name of the icon
* @param {*} contents The contents of the icon
* @param {string} name The name of the icon
* @param {string} contents The contents of the icon
* @returns {string} the rendered SVG symbol
*/
function toSvgSymbol(name, contents) {
return ` <symbol id="${name}" viewBox="${defaultAttrs.viewBox}">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we need to have add indentation to the strings? It might help with performance if we omit unneeded whitespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just for reading the svg. But since this is a build artifact, you are correct. I'm out now but I'm gonna fix this too.

Expand Down
2 changes: 1 addition & 1 deletion bin/build-sprite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import icons from '../dist/icons.json';
import buildSprite from './build-sprite-function';
import buildSprite from './build-sprite-string';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const sprite = buildSprite(icons);

Expand Down