We are using SVG Icons in GitLab with a SVG Sprite, due to this the icons are only loaded once and then referenced through an ID. The sprite SVG is located under `/assets/icons.svg`. Our goal is to replace one by one all inline SVG Icons (as those currently bloat the HTML) and also all Font Awesome usages.
We manage our own Icon and Illustration library in the [gitlab-svgs][gitlab-svgs] repository.
This repository is published on [npm][npm] and managed as a dependency via yarn.
You can browse all available Icons and Illustrations [here][svg-preview].
To upgrade to a new version run `yarn upgrade @gitlab-org/gitlab-svgs`.
### Usage in HAML/Rails
## Icons
To use a sprite Icon in HAML or Rails we use a specific helper function :
We are using SVG Icons in GitLab with a SVG Sprite.
This means the icons are only loaded once, and are referenced through an ID.
The sprite SVG is located under `/assets/icons.svg`.
Our goal is to replace one by one all inline SVG Icons (as those currently bloat the HTML) and also all Font Awesome icons.
@@ -28,33 +46,71 @@ We have a special Vue component for our sprite icons in `\vue_shared\components\
...
@@ -28,33 +46,71 @@ We have a special Vue component for our sprite icons in `\vue_shared\components\
Sample usage :
Sample usage :
`<icon
```javascript
name="retry"
<script>
:size="32"
importIconfrom"~/vue_shared/components/icon.vue"
css-classes="top"
/>`
exportdefault{
components:{
**name** Name of the Icon in the SVG Sprite ([Overview is available here](http://gitlab-org.gitlab.io/gitlab-svgs/)`).
Icon,
},
**size (optional)** Number value for the size which is then mapped to a specific CSS class (Available Sizes: 8,12,16,18,24,32,48,72 are mapped to `sXX` css classes)
};
<script>
**css-classes (optional)** Additional CSS Classes to add to the svg tag.
<template>
<icon
name="issues"
:size="72"
css-classes="icon-danger"
/>
</template>
```
-**name** Name of the Icon in the SVG Sprite ([Overview is available here][svg-preview]).
-**size (optional)** Number value for the size which is then mapped to a specific CSS class
(Available Sizes: 8, 12, 16, 18, 24, 32, 48, 72 are mapped to `sXX` css classes)
-**css-classes (optional)** Additional CSS Classes to add to the svg tag.
### Usage in HTML/JS
### Usage in HTML/JS
Please use the following function inside JS to render an icon:
Please use the following function inside JS to render an icon:
`gl.utils.spriteIcon(iconName)`
`gl.utils.spriteIcon(iconName)`
## Adding a new icon to the sprite
## SVG Illustrations
All Icons and Illustrations are managed in the [gitlab-svgs](https://gitlab.com/gitlab-org/gitlab-svgs) repository which is added as a dev-dependency.
Please use from now on for any SVG based illustrations simple `img` tags to show an illustration by simply using either `image_tag` or `image_path` helpers.
Please use the class `svg-content` around it to ensure nice rendering.
To upgrade to a new SVG Sprite version run `yarn upgrade @gitlab-org/gitlab-svgs`.
### Usage in HAML/Rails
# SVG Illustrations
**Example**
Please use from now on for any SVG based illustrations simple `img` tags to show an illustration by simply using either `image_tag` or `image_path` helpers. Please use the class `svg-content` around it to ensure nice rendering. The illustrations are also organised in the [gitlab-svgs](https://gitlab.com/gitlab-org/gitlab-svgs) repository (as they are then automatically optimised).
```haml
.svg-content
=image_tag'illustrations/merge_requests.svg'
```
**Example**
### Usage in Vue
`= image_tag 'illustrations/merge_requests.svg'`
To use an SVG illustrations in a template provide the path as a property and display it through a standard img tag.
@@ -87,13 +88,11 @@ document.addEventListener('DOMContentLoaded', () => new Vue({
...
@@ -87,13 +88,11 @@ document.addEventListener('DOMContentLoaded', () => new Vue({
```
```
#### Accessing the `gl` object
#### Accessing the `gl` object
When we need to query the `gl` object for data that won't change during the application's lyfecyle, we should do it in the same place where we query the DOM.
When we need to query the `gl` object for data that won't change during the application's life cyle, we should do it in the same place where we query the DOM.
By following this practice, we can avoid the need to mock the `gl` object, which will make tests easier.
By following this practice, we can avoid the need to mock the `gl` object, which will make tests easier.
It should be done while initializing our Vue instance, and the data should be provided as `props` to the main component:
It should be done while initializing our Vue instance, and the data should be provided as `props` to the main component:
@@ -121,25 +120,6 @@ in one table would not be a good use of this pattern.
...
@@ -121,25 +120,6 @@ in one table would not be a good use of this pattern.
You can read more about components in Vue.js site, [Component System][component-system]
You can read more about components in Vue.js site, [Component System][component-system]
#### Components Gotchas
1. Using SVGs icons in components: To use an SVG icon in a template use the `icon.vue`
1. Using SVGs illustrations in components: To use an SVG illustrations in a template provide the path as a prop and display it through a standard img tag.
```javascript
<script>
exportdefault{
props:{
svgIllustrationPath:{
type:String,
required:true,
},
},
};
<script>
<template>
<img:src="svgIllustrationPath"/>
</template>
```
### A folder for the Store
### A folder for the Store
#### Vuex
#### Vuex
...
@@ -163,13 +143,13 @@ Refer to [axios](axios.md) for more details.
...
@@ -163,13 +143,13 @@ Refer to [axios](axios.md) for more details.
Axios instance should only be imported in the service file.
Axios instance should only be imported in the service file.