Skip to content

Commit

Permalink
Fix/color config (#3446)
Browse files Browse the repository at this point in the history
* fix(docs): fix theme switch re-render

* docs(config): update colors example

* fix(docs): hide colors VaConfig demo
  • Loading branch information
m0ksem committed May 26, 2023
1 parent 92adcff commit f2ac864
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 60 deletions.
2 changes: 2 additions & 0 deletions packages/docs/components/layout/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export default defineComponent({
@import "@/assets/smart-grid.scss";
.sidebar {
--va-sidebar-transition: none;
&__collapse-custom-header {
position: relative;
padding: 1rem 1.2rem;
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="docs-layout" :key="currentPresetName + isMounted">
<div class="docs-layout" :key="isMounted + ''">
<div v-if="!isMounted" class="docs-layout__loader" />
<div
ref="header"
Expand Down
21 changes: 21 additions & 0 deletions packages/docs/page-config/ui-elements/config/examples/Colors.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<VaConfig :colors="{ variables: { primary: color }, currentPresetName: presetName }">
<VaCard>
<VaCardContent class="flex flex-col gap-2">
<VaColorInput v-model="color" />
<VaButton @click="presetName === 'light' ? presetName = 'dark' : presetName = 'light'">Toggle theme</VaButton>
<VaInput label="login" />
<VaInput label="password" type="password" />
<div class="flex gap-2">
<VaButton>login</VaButton>
<VaButton color="secondary">register</VaButton>
</div>
</VaCardContent>
</VaCard>
</VaConfig>
</template>

<script setup lang="ts">
const color = ref('#f0f')
const presetName = ref('light')
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<va-button-toggle
v-model="config"
:options="[
{
label: 'Outline',
value: {
VaInput: { outline: true },
VaSelect: { outline: true },
VaButton: { preset: 'secondary' },
},
},
{
label: 'Solid',
value: {
VaInput: { bordered: true },
VaSelect: { bordred: true },
},
},
]"
class="mb-4"
/>

<va-config :components="config">
<va-card>
<va-card-title>My Card</va-card-title>
<va-card-content class="flex gap-2 flex-col">
<va-input label="Login" />
<va-input label="Password" />
<va-select :options="['one', 'two', 'three']" label="Country" />
</va-card-content>
<va-card-actions align="right">
<va-button>My Button</va-button>
</va-card-actions>
</va-card>
</va-config>
</template>

<script setup lang="ts">
const config = ref();
</script>
45 changes: 0 additions & 45 deletions packages/docs/page-config/ui-elements/config/examples/Default.vue

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<VaConfig :i18n="{
dropzone: 'Перетягніть файли сюди або натисніть, щоб вибрати',
uploadFile: 'Завантажити',
}">
<VaFileUpload dropzone />
</VaConfig>
</template>
7 changes: 6 additions & 1 deletion packages/docs/page-config/ui-elements/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export default definePageConfig({

block.subtitle("all.examples"),

block.example("Default"),
block.example("Components"),
block.link('config.examples.components.see', '/services/components-config'),
// block.example("Colors"),
// block.link('config.examples.colors.see', '/services/colors-config'),
block.example("Internalization"),
block.link('config.examples.internalization.see', '/services/i18n'),

block.subtitle("all.api"),
block.api("VaConfig", apiOptions),
Expand Down
17 changes: 14 additions & 3 deletions packages/docs/page-config/ui-elements/config/translation/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
"description": "`VaConfig` is a utility component that allows you to configure components (provide specific default prop values to components) locally in a section of your application. This is useful when you have a local scope where your components have props other than global ones.",
"link": "Find out more about components config",
"examples": {
"default": {
"title": "Default usage",
"text": "By default, `VaConfig` does nothing. You must provide the `components` prop with the `vuestic` components configuration."
"components": {
"title": "Components",
"text": "By default, `VaConfig` does nothing. You must provide the `components` prop with the `vuestic` components configuration.",
"see": "Learn more about Components Config"
},
"colors": {
"title": "Colors",
"text": "You can configure colors for components. For example, you can change color whole preset name.",
"see": "Learn more about Colors Config"
},
"internalization": {
"title": "i18n",
"text": "You can configure i18n translations for components.",
"see": "Learn more about i18n Config"
}
}
}
4 changes: 3 additions & 1 deletion packages/ui/src/components/va-button-toggle/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export type ButtonOption = {
icon?: string,
iconRight?: string
[prop: string]: string | number | boolean | undefined
label?: string,
value?: unknown,
[prop: string]: any
}
1 change: 0 additions & 1 deletion packages/ui/src/components/va-color-input/VaColorInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export default defineComponent({
&__input {
margin-bottom: 0;
margin-left: 0.25rem;
min-width: 5.6rem;
&__pointer {
Expand Down
25 changes: 19 additions & 6 deletions packages/ui/src/components/va-config/VaConfig.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<CssVarsRenderer v-bind="$attrs">
<CssVarsRenderer v-if="doRenderCssVars" v-bind="$attrs">
<slot />
</CssVarsRenderer>
<slot v-else />
</template>

<script lang="ts">
Expand Down Expand Up @@ -39,8 +40,8 @@ export default defineComponent({
props: {
...useComponentPresetProp,
components: { type: Object as PropType<ComponentConfig>, default: () => ({}) },
colors: { type: Object as PropType<PartialGlobalConfig['colors']>, default: () => ({}) },
i18n: { type: Object as PropType<PartialGlobalConfig['i18n']>, default: () => ({}) },
colors: { type: Object as PropType<PartialGlobalConfig['colors']> },
i18n: { type: Object as PropType<PartialGlobalConfig['i18n']> },
},
inheritAttrs: false,
setup (props) {
Expand All @@ -51,14 +52,26 @@ export default defineComponent({
provideLocalConfig(nextChain)
const newConfig = useGlobalConfigProvider(computed(() => {
return {
colors: props.colors,
i18n: props.i18n,
const config = {} as any
if (props.colors) {
config.colors = props.colors
}
if (props.i18n) {
config.i18n = props.i18n
}
return config
}))
const doRenderCssVars = computed(() => {
return Boolean(props.colors)
})
return {
newConfig,
doRenderCssVars,
}
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ export const useGlobalConfigProvider = (next: Ref<PartialGlobalConfig>) => {
colors: makeColorsConfig(gcCopy.colors),
}

return mergeDeep(compiledCopy, next.value) as GlobalConfig
const config = mergeDeep(compiledCopy, next.value) as GlobalConfig

// Variables is a virtual property, so we need to merge it manually after preset in chosen!
if (next.value.colors?.variables) {
Object.keys(next.value.colors.variables).forEach((key) => {
config.colors.variables[key] = next.value.colors!.variables![key]!
})
}

return config
})

provide(GLOBAL_CONFIG, {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/services/color/config/make-config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ColorConfig } from '../types'

export const makeColorsConfig = (values: Omit<ColorConfig, 'variables'>): ColorConfig => ({
...values,
get variables () {
return this.presets[this.currentPresetName]
},
set variables (value) {
this.presets[this.currentPresetName] = value
},
...values,
})

0 comments on commit f2ac864

Please sign in to comment.