2017-10-05 17:16:37 -04:00
|
|
|
<script>
|
2019-07-29 16:25:35 -04:00
|
|
|
import iconsPath from '@gitlab/svgs/dist/icons.svg';
|
|
|
|
|
2018-04-19 11:07:11 -04:00
|
|
|
// only allow classes in images.scss e.g. s12
|
2018-11-08 08:11:25 -05:00
|
|
|
const validSizes = [8, 10, 12, 14, 16, 18, 24, 32, 48, 72];
|
2018-07-18 12:56:19 -04:00
|
|
|
let iconValidator = () => true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
During development/tests we want to validate that we are just using icons that are actually defined
|
|
|
|
*/
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
// eslint-disable-next-line global-require
|
2018-10-31 07:35:33 -04:00
|
|
|
const data = require('@gitlab/svgs/dist/icons.json');
|
2018-07-18 12:56:19 -04:00
|
|
|
const { icons } = data;
|
|
|
|
iconValidator = value => {
|
|
|
|
if (icons.includes(value)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.warn(`Icon '${value}' is not a known icon of @gitlab/gitlab-svg`);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2017-10-05 17:16:37 -04:00
|
|
|
|
2018-07-18 12:56:19 -04:00
|
|
|
/** This is a re-usable vue component for rendering a svg sprite icon
|
|
|
|
* @example
|
|
|
|
* <icon
|
|
|
|
* name="retry"
|
|
|
|
* :size="32"
|
2019-10-02 17:06:22 -04:00
|
|
|
* class="top"
|
2018-07-18 12:56:19 -04:00
|
|
|
* />
|
|
|
|
*/
|
2018-04-19 11:07:11 -04:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2018-07-18 12:56:19 -04:00
|
|
|
validator: iconValidator,
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
2017-10-05 17:16:37 -04:00
|
|
|
|
2018-04-19 11:07:11 -04:00
|
|
|
size: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 16,
|
2019-10-02 17:06:22 -04:00
|
|
|
validator: value => validSizes.includes(value),
|
2018-08-07 08:30:08 -04:00
|
|
|
},
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
2017-10-05 17:16:37 -04:00
|
|
|
|
2018-04-19 11:07:11 -04:00
|
|
|
computed: {
|
|
|
|
spriteHref() {
|
2019-07-29 16:25:35 -04:00
|
|
|
return `${iconsPath}#${this.name}`;
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
iconTestClass() {
|
|
|
|
return `ic-${this.name}`;
|
|
|
|
},
|
2018-04-19 11:07:11 -04:00
|
|
|
iconSizeClass() {
|
|
|
|
return this.size ? `s${this.size}` : '';
|
2017-10-05 17:16:37 -04:00
|
|
|
},
|
2018-04-19 11:07:11 -04:00
|
|
|
},
|
|
|
|
};
|
2017-10-05 17:16:37 -04:00
|
|
|
</script>
|
2017-11-27 14:34:03 -05:00
|
|
|
|
2017-10-05 17:16:37 -04:00
|
|
|
<template>
|
2019-11-11 07:06:23 -05:00
|
|
|
<svg :class="[iconSizeClass, iconTestClass]" aria-hidden="true" v-on="$listeners">
|
2018-11-16 15:07:38 -05:00
|
|
|
<use v-bind="{ 'xlink:href': spriteHref }" />
|
2017-10-05 17:16:37 -04:00
|
|
|
</svg>
|
|
|
|
</template>
|