From e416ef46720a0e0765166cf9b54e38077fdc80d6 Mon Sep 17 00:00:00 2001 From: Alexandra Petrova Date: Wed, 1 May 2024 22:42:20 +0300 Subject: [PATCH] Sizes styles rendering --- packages/nuxt/src/runtime/plugin.ts | 26 +++++-- packages/ui/.storybook/preview.ts | 4 +- .../ui/src/components/va-button/VaButton.vue | 17 ++--- .../components/va-config/VaConfig.demo.vue | 20 ++++- .../ui/src/components/va-config/VaConfig.vue | 76 +++++++++++++------ .../src/composables/useComponentVariables.ts | 12 +-- packages/ui/src/composables/useSize.ts | 2 +- .../component-config/config/default.ts | 11 +++ .../ui/src/services/component-config/index.ts | 1 + .../services/component-config/plugin/index.ts | 49 ++++++++++++ .../theme/index.ts} | 0 .../utils/render-styles-from-config.tsx | 36 +++++++++ .../utils/use-component-config-props.ts | 3 +- packages/ui/src/services/size/index.ts | 1 - .../create-vuestic/create-vuestic.ts | 12 ++- .../ui/src/services/vue-plugin/plugins.ts | 1 + packages/ui/src/utils/bem.ts | 14 ++++ packages/ui/src/utils/css-variables.ts | 6 +- packages/ui/src/utils/css.ts | 8 ++ 19 files changed, 236 insertions(+), 63 deletions(-) create mode 100644 packages/ui/src/services/component-config/plugin/index.ts rename packages/ui/src/services/{size/types.ts => component-config/theme/index.ts} (100%) create mode 100644 packages/ui/src/services/component-config/utils/render-styles-from-config.tsx delete mode 100644 packages/ui/src/services/size/index.ts create mode 100644 packages/ui/src/utils/bem.ts diff --git a/packages/nuxt/src/runtime/plugin.ts b/packages/nuxt/src/runtime/plugin.ts index b7cf91b70f3..6fa535a29e1 100644 --- a/packages/nuxt/src/runtime/plugin.ts +++ b/packages/nuxt/src/runtime/plugin.ts @@ -9,28 +9,27 @@ import { type PartialGlobalConfig } from 'vuestic-ui' import { markRaw, computed, watch, type Ref } from 'vue' -import { useHead, ReactiveHead, defineNuxtPlugin, useCookie } from '#imports' +import type { VuesticOptions } from '../types' +import { useHead, ReactiveHead, defineNuxtPlugin, useCookie } from '#imports' import NuxtLink from '#app/components/nuxt-link' import configFromFile from '#vuestic-config' -import type { VuesticOptions } from '../types' - function getGlobalProperty (app, key) { return app.config.globalProperties[key] } -export default defineNuxtPlugin(async (nuxtApp) => { +export default defineNuxtPlugin((nuxtApp) => { const { vueApp: app } = nuxtApp // It's important to use `, because TS will compile qoutes to " and JSON will not be parsed... - const moduleOptions: VuesticOptions = JSON.parse(`<%= options.value %>`) + const moduleOptions: VuesticOptions = JSON.parse('<%= options.value %>') const themeCookie = useCookie(moduleOptions.themeCookieKey) const userConfig = configFromFile || moduleOptions.config || {} const configWithColors: PartialGlobalConfig = { ...userConfig, colors: { currentPresetName: themeCookie.value || userConfig.colors?.currentPresetName || 'light', - ...userConfig.colors, + ...userConfig.colors } } @@ -44,7 +43,7 @@ export default defineNuxtPlugin(async (nuxtApp) => { VaDropdownPlugin, VaToastPlugin, VaModalPlugin, - ColorsClassesPlugin, + ColorsClassesPlugin }, /** Do not import any components. Nuxt will import them automatically */ components: {} @@ -76,6 +75,19 @@ export default defineNuxtPlugin(async (nuxtApp) => { })) } + const componentConfig = getGlobalProperty(app, '$vaComponentConfig') + if (componentConfig) { + useHead(computed(() => { + return { + style: [ + { + innerHTML: componentConfig.renderStyles() + } + ] + } satisfies ReactiveHead + })) + } + // Watch for preset name change and update cookie const { globalConfig } = getGlobalProperty(app, '$vaConfig') as { globalConfig: Ref } watch(() => globalConfig.value.colors.currentPresetName, (newTheme) => { diff --git a/packages/ui/.storybook/preview.ts b/packages/ui/.storybook/preview.ts index 5bde006a8d5..9eb72fc69c1 100644 --- a/packages/ui/.storybook/preview.ts +++ b/packages/ui/.storybook/preview.ts @@ -9,7 +9,7 @@ import { VaToastPlugin, VaModalPlugin, VaDropdownPlugin, - BreakpointConfigPlugin, + BreakpointConfigPlugin, ComponentConfigPlugin, } from './../src/main' import demoIconAliases from './vuestic-config/demo-icon-aliases' import demoIconFonts from './vuestic-config/demo-icon-fonts' @@ -49,7 +49,7 @@ setup((app) => { }, }, }, - plugins: { VaToastPlugin, VaDropdownPlugin, VaModalPlugin, BreakpointConfigPlugin }, + plugins: { VaToastPlugin, VaDropdownPlugin, VaModalPlugin, BreakpointConfigPlugin, ComponentConfigPlugin }, })) }) diff --git a/packages/ui/src/components/va-button/VaButton.vue b/packages/ui/src/components/va-button/VaButton.vue index 78416afe271..812aaef5530 100644 --- a/packages/ui/src/components/va-button/VaButton.vue +++ b/packages/ui/src/components/va-button/VaButton.vue @@ -5,7 +5,7 @@ class="va-button" :class="computedClass" :style="computedStyle" - v-bind="attributesComputed" + v-bind="{ ...variablesComputed, ...attributesComputed }" > , + type: [String, Number] as PropType< + 'small' | 'medium' | 'large' | string | number + >, default: 'medium', }, icon: { type: String, default: '' }, @@ -188,7 +190,6 @@ const variablesComputed = useComponentVariables(props) const computedStyle = computed(() => ({ borderColor: props.borderColor ? getColor(props.borderColor) : 'transparent', ...contentColorComputed.value, - ...variablesComputed.value, })) defineExpose({ @@ -294,9 +295,7 @@ defineExpose({ .va-button__content { font-size: var(--va-button-font-size); - padding: - var(--va-button-content-py) - var(--va-button-content-px); + padding: var(--va-button-content-py) var(--va-button-content-px); line-height: var(--va-button-line-height); } @@ -323,13 +322,11 @@ defineExpose({ .va-button__content { padding-top: calc( - var(--va-button-content-py) - - var(--va-button-bordered-border) + var(--va-button-content-py) - var(--va-button-bordered-border) ); padding-bottom: calc( - var(--va-button-content-py) - - var(--va-button-bordered-border) + var(--va-button-content-py) - var(--va-button-bordered-border) ); } } diff --git a/packages/ui/src/components/va-config/VaConfig.demo.vue b/packages/ui/src/components/va-config/VaConfig.demo.vue index 945f16d6caf..044d3464a6b 100644 --- a/packages/ui/src/components/va-config/VaConfig.demo.vue +++ b/packages/ui/src/components/va-config/VaConfig.demo.vue @@ -86,8 +86,19 @@ - + } }" :components="isOn ? { + VaButton: { + size: 'xs', + sizesConfig: { + xs: { + variables: { + fontSize: '10px', + }, + }, + }, + }, + } : undefined"> + Button inside va-config @@ -106,7 +117,7 @@