summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/icon.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/icon.vue')
-rw-r--r--app/assets/javascripts/vue_shared/components/icon.vue40
1 files changed, 28 insertions, 12 deletions
diff --git a/app/assets/javascripts/vue_shared/components/icon.vue b/app/assets/javascripts/vue_shared/components/icon.vue
index c42c4a1fbe7..e7ff76c8218 100644
--- a/app/assets/javascripts/vue_shared/components/icon.vue
+++ b/app/assets/javascripts/vue_shared/components/icon.vue
@@ -1,24 +1,40 @@
<script>
-/* This is a re-usable vue component for rendering a svg sprite
- icon
- Sample configuration:
-
- <icon
- name="retry"
- :size="32"
- css-classes="top"
- />
-
-*/
// only allow classes in images.scss e.g. s12
const validSizes = [8, 12, 16, 18, 24, 32, 48, 72];
+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
+ const data = require('@gitlab-org/gitlab-svgs/dist/icons.json');
+ 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;
+ };
+}
+/** This is a re-usable vue component for rendering a svg sprite icon
+ * @example
+ * <icon
+ * name="retry"
+ * :size="32"
+ * css-classes="top"
+ * />
+ */
export default {
props: {
name: {
type: String,
required: true,
+ validator: iconValidator,
},
size: {
@@ -83,6 +99,6 @@ export default {
:x="x"
:y="y"
>
- <use v-bind="{ 'xlink:href':spriteHref }" />
+ <use v-bind="{ 'xlink:href':spriteHref }"/>
</svg>
</template>