From fcf2f967c30b5ebc3a2787ad0365f44f8b586781 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Thu, 1 Dec 2022 09:50:34 -0800 Subject: [PATCH 1/2] Robustly handle missing icons. --- docs/pages/kicon.vue | 2 ++ docs/rstIconReplacements.txt | 1 + lib/KIcon/iconDefinitions.js | 6 +++++- lib/KIcon/index.vue | 14 ++++++++++---- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/pages/kicon.vue b/docs/pages/kicon.vue index c4aa74cb2..f7b2b6800 100644 --- a/docs/pages/kicon.vue +++ b/docs/pages/kicon.vue @@ -3,6 +3,8 @@ See for design guidance and a list of available icons. + If an invalid icon is used, in development Vue.js validation will warn about the error. + The icon will display as a broken image icon. diff --git a/docs/rstIconReplacements.txt b/docs/rstIconReplacements.txt index 6bc778115..c5a808e6f 100644 --- a/docs/rstIconReplacements.txt +++ b/docs/rstIconReplacements.txt @@ -8,6 +8,7 @@ .. |back| replace:: :raw-html:`` .. |bookmarkEmpty| replace:: :raw-html:`` .. |bookmark| replace:: :raw-html:`` +.. |brokenImage| replace:: :raw-html:`` .. |channel| replace:: :raw-html:`` .. |checked| replace:: :raw-html:`` .. |check| replace:: :raw-html:`` diff --git a/lib/KIcon/iconDefinitions.js b/lib/KIcon/iconDefinitions.js index 1dea79c3a..04a66bc7f 100644 --- a/lib/KIcon/iconDefinitions.js +++ b/lib/KIcon/iconDefinitions.js @@ -1,4 +1,4 @@ -import { themeTokens } from '../styles/theme'; +import { themePalette, themeTokens } from '../styles/theme'; /** * Defines all icons in the Kolibri Design System @@ -60,6 +60,10 @@ const KolibriIcons = { icon: require('./precompiled-icons/material-icons/error/baseline.vue').default, defaultColor: themeTokens().error, }, + brokenImage: { + icon: require('./precompiled-icons/material-icons/broken_image/baseline.vue').default, + defaultColor: themePalette().grey.v_400, + }, // Features and links learn: { icon: require('./precompiled-icons/material-icons/school/baseline.vue').default }, diff --git a/lib/KIcon/index.vue b/lib/KIcon/index.vue index ed0d92118..4ebb1afc6 100644 --- a/lib/KIcon/index.vue +++ b/lib/KIcon/index.vue @@ -50,22 +50,28 @@ }, }, computed: { + selectedIcon() { + if (!KolibriIcons[this.icon]) { + return KolibriIcons.brokenImage; + } + return KolibriIcons[this.icon]; + }, computedColor() { if (this.disableColor) { return null; } if (this.color) { return this.color; - } else if (KolibriIcons[this.icon].defaultColor) { - return KolibriIcons[this.icon].defaultColor; + } else if (this.selectedIcon.defaultColor) { + return this.selectedIcon.defaultColor; } return this.$themeTokens.text; }, rtlFlip() { - return KolibriIcons[this.icon].rtlFlip && this.isRtl; + return this.selectedIcon.rtlFlip && this.isRtl; }, svgIconComponent() { - return KolibriIcons[this.icon].icon; + return this.selectedIcon.icon; }, }, }; From 553b243a04a7771afa052b16481d0c38c0844f50 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Fri, 2 Dec 2022 13:05:15 -0800 Subject: [PATCH 2/2] Update docs/pages/kicon.vue Co-authored-by: Devon Rueckner --- docs/pages/kicon.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/pages/kicon.vue b/docs/pages/kicon.vue index f7b2b6800..368dadd37 100644 --- a/docs/pages/kicon.vue +++ b/docs/pages/kicon.vue @@ -2,9 +2,7 @@ - See for design guidance and a list of available icons. - If an invalid icon is used, in development Vue.js validation will warn about the error. - The icon will display as a broken image icon. + See for design guidance and a list of available icons. If an invalid icon is used, in development Vue.js validation will warn about the error. The icon will display as a broken image icon.