From 9bc4686e3f4c14a5c4c8cba077622ec67aa01ffc Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Tue, 12 Nov 2024 23:39:51 +0300 Subject: [PATCH] Support for custom tokens --- .../components/layout/AppDesigner.vue | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/apps/showcase/components/layout/AppDesigner.vue b/apps/showcase/components/layout/AppDesigner.vue index 10958a5d6..c5b96dfd8 100644 --- a/apps/showcase/components/layout/AppDesigner.vue +++ b/apps/showcase/components/layout/AppDesigner.vue @@ -6,6 +6,7 @@ Primitive Semantic Component + Custom @@ -75,7 +76,47 @@ -
Component tokens are not supported by the Visual Editor at the moment.
+ Component tokens are not supported by the Visual Editor at the moment. + + Extend the theming system with your own design tokens e.g. accent.color. Do not use curly braces in the name field. +
    +
  • +
    + + + +
    +
  • +
+
+ + +
+
@@ -134,8 +175,7 @@ export default { { label: 'Lara', value: 'Lara' }, { label: 'Nora', value: 'Nora' } ], - customThemes: {}, - newThemeName: null + customTokens: [] }; }, mounted() { @@ -146,7 +186,6 @@ export default { methods: { apply() { this.saveTheme(); - console.log(this.preset); updatePreset(this.preset); }, download() { @@ -210,9 +249,35 @@ app.mount("#app"); const savedTheme = localStorage.getItem(this.$appState.designerKey); if (savedTheme) { - this.preset = JSON.parse(savedTheme).defaultTheme; + const loadedThemeState = JSON.parse(savedTheme); + + this.preset = loadedThemeState.defaultTheme; + this.customTokens = loadedThemeState.customTokens; this.$toast.add({ severity: 'success', summary: 'Success', detail: 'Theme loaded to Designer', life: 3000 }); } + }, + addToken() { + this.customTokens = [...this.customTokens, ...[{}]]; + }, + removeToken(index) { + this.customTokens.splice(index, 1); + }, + saveTokens() { + const themeRecordState = localStorage.getItem(this.$appState.designerKey); + let themeRecord = null; + + if (themeRecordState) { + themeRecord = JSON.parse(themeRecordState); + themeRecord.customTokens = this.customTokens; + } else { + themeRecord = { + customTokens: this.customTokens + }; + } + + localStorage.setItem(this.$appState.designerKey, JSON.stringify(themeRecord)); + + this.$toast.add({ severity: 'success', summary: 'Success', detail: 'Tokens saved', life: 3000 }); } } };