From 26f20fa0cf98b52cffef9705e6bc94792b2bda22 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Wed, 13 Nov 2024 02:36:24 +0300 Subject: [PATCH] Generate autocomplete tokens dynamically --- .../components/layout/AppDesigner.vue | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/showcase/components/layout/AppDesigner.vue b/apps/showcase/components/layout/AppDesigner.vue index f485ea1d0..6b761de29 100644 --- a/apps/showcase/components/layout/AppDesigner.vue +++ b/apps/showcase/components/layout/AppDesigner.vue @@ -182,7 +182,7 @@ export default { }, mounted() { this.replaceColorPalette(); - this.generateACTokens(); + this.generateACTokens(null, this.preset); }, methods: { apply() { @@ -270,6 +270,8 @@ app.mount("#app"); if (defaultTheme.customTokens) { this.customTokens = defaultTheme.customTokens; + this.acTokens = []; + this.generateACTokens(null, this.preset); } this.$toast.add({ severity: 'success', summary: 'Success', detail: 'Theme loaded to Designer', life: 3000 }); @@ -310,8 +312,25 @@ app.mount("#app"); return name; } }, - generateACTokens() { - //@TODO: parse preset to generate tokens + camelCaseToDotCase(name) { + return '{' + name.replace(/([a-z])([A-Z])/g, '$1.$2').toLowerCase() + '}'; + }, + generateACTokens(parentPath, obj) { + for (let key in obj) { + if (key === 'dark') { + continue; + } + + if (key === 'primitive' || key === 'semantic' || key === 'colorScheme' || key === 'light' || key === 'extend') { + this.generateACTokens(null, obj[key]); + } else { + if (typeof obj[key] === 'object') { + this.generateACTokens(parentPath ? parentPath + '.' + key : key, obj[key]); + } else { + this.acTokens.push(this.camelCaseToDotCase(parentPath ? parentPath + '.' + key : key)); + } + } + } } } };