Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #206 from fourkitchens/SVG-method-switch
Browse files Browse the repository at this point in the history
SVG sprite method change
  • Loading branch information
Evan Willhite authored May 8, 2018
2 parents 3356325 + cf11793 commit 14fb9f1
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 55 deletions.
23 changes: 23 additions & 0 deletions components/_patterns/01-atoms/04-images/icons/_icon.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{#
/**
* Available variables:
* - icon_base_class - base class name
* - icon_modifiers - modifiers for icons (array)
* - icon_blockname - blockname prepended to the base classname
* - icon_name - the name of the icon
*/
#}
{% set icon_base_class = icon_base_class|default('icon') %}
{% set icon_url = '' %}

{# Drupal #}
{# {% if attributes or theme_hook_original %}
{% set icon_url = '/themes/custom/YOURTHEME/dist/img/sprite/' %}
{{ attach_library('emulsify/sprite') }}
{% else %} #}
{% set icon_url = '/dist/img/sprite/' %}
{# {% endif %} #}

<svg {{ bem(icon_base_class, (icon_modifiers), icon_blockname, (icon_js_class)) }}>
<use xlink:href="{{ icon_url }}sprite.svg#{{ icon_name }}"></use>
</svg>
14 changes: 0 additions & 14 deletions components/_patterns/01-atoms/04-images/icons/_icon_sprite.scss

This file was deleted.

17 changes: 0 additions & 17 deletions components/_patterns/01-atoms/04-images/icons/_icons.scss

This file was deleted.

41 changes: 34 additions & 7 deletions components/_patterns/01-atoms/04-images/icons/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,42 @@ title: Icons
---
### How to use icons

We are using a gulp SVG sprite generator, which automatically creates the SVG CSS in `_icon_sprite.scss`. Simply add separate SVG files into `images/icons/src/` and they will be added to the sprite the next time `gulp icons` is run.
We are using a gulp SVG sprite generator (details [here](https://una.im/svg-icons)), which automatically creates the SVG in `/images/icons/sprite/sprite.svg`. Simply run `gulp icons` to add to the sprite.

**Writing Sass**
**Usage**

If you look in `_icon_sprite.scss`, you will notice there is a mixin and class for each sprite. You can use whatever approach suits your situation. **Note: You will need to tweak the background-size in 04-images/icons/_icons.scss each time a sprite is added.** You can also make use of the following mixins from `00-base/_mixins.scss` to provide inline icons before text:
The SVG component is found here: `/components/_patterns/01-atoms/04-images/icons/_icon.twig`. See available variables in that file. Examples of usage below:

Simple: (no BEM renaming)

```
{% include "@atoms/04-images/icons/_icon.twig" with {
icon_name: 'bars',
} %}
```

... creates...

```
<svg class="icon">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/images/sprite/sprite.svg#src--bars"></use>
</svg>
```

Complex (BEM classes):

```
{% include "@atoms/04-images/icons/_icon.twig" with {
icon_base_class: 'icon',
icon_blockname: 'toggle-expand',
icon_name: 'bars',
} %}
```

... creates...

```
.TEXT_WITH_ICON_BEFORE_IT {
@include ICONNAME; // e.g., sprite-chevron-right
@include with-icon;
}
<svg class="toggle-expand__icon">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/images/sprite/sprite.svg#src--bars"></use>
</svg>
```
11 changes: 6 additions & 5 deletions components/_patterns/01-atoms/04-images/icons/icons.twig
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<div class="icons-demo" id="icons">

{% for item in items %}
<div><span class="sprite-{{ item.value }} sprite-icon"></span><p>{{ item.name }}</p></div>
<div>
{% include "@atoms/04-images/icons/_icon.twig" with {
icon_name: item.value,
} %}
<p>{{ item.value }}</p>
</div>
{% endfor %}

</div>

<br>

<h3 class="h3">Inline icon examples</h3>

<p class="icon-inline-menu">Menu</p>
4 changes: 2 additions & 2 deletions components/_patterns/01-atoms/04-images/icons/icons.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
items:
1:
name: "Menu"
value: "menu"
name: "Bars"
value: "bars"
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
}
}

// SVG icon
.toggle-expand__icon {
width: 5rem;
padding-bottom: 3rem;
height: 3rem;
width: 3rem;
margin: 0 auto;
}

Expand Down
10 changes: 5 additions & 5 deletions components/_patterns/02-molecules/menus/main-menu/main-menu.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<a href="#" id="toggle-expand" class="toggle-expand">
<span class="toggle-expand__open">
<span class="toggle-expand__icon sprite-menu sprite-icon">
<span class="visually-hidden">
Mobile menu expand icon.
</span>
</span>
{% include "@atoms/04-images/icons/_icon.twig" with {
icon_base_class: 'icon',
icon_blockname: 'toggle-expand',
icon_name: 'bars',
} %}
<span class="toggle-expand__text">Main Menu</span>
</span>
<span class="toggle-expand__close">
Expand Down
8 changes: 6 additions & 2 deletions components/_patterns/05-pages/_styleguide-specific.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

& > div {
border: 1px solid #eee;
margin-right: 1%;
margin-right: 1em;
padding: 1em;
text-align: center;
width: 10%;
}

.icon {
height: 4rem;
width: 4rem;
}
}
}
12 changes: 12 additions & 0 deletions components/js/svgxuse.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion emulsify.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ global:
theme:
dist/style.css: {}

# Example of Library syntax
main_menu:
js:
dist/02-molecules/menus/main-menu/main-menu.js: {}
dependencies:
- core/drupal

sprite:
js:
components/js/svgxuse.min.js: { attributes: { defer: true } }
File renamed without changes

0 comments on commit 14fb9f1

Please sign in to comment.