-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(va-config): colors prop * feat(va-config): i18n config * chore(docs): remove unused code Co-authored-by: Vitaly <[email protected]> --------- Co-authored-by: Vitaly <[email protected]>
- Loading branch information
1 parent
f5d3d6b
commit 06db00e
Showing
10 changed files
with
124 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,65 @@ | ||
<template> | ||
<slot /> | ||
<CssVarsRenderer v-bind="$attrs"> | ||
<slot /> | ||
</CssVarsRenderer> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent, PropType } from 'vue' | ||
import { computed, defineComponent, PropType, h, Fragment } from 'vue' | ||
import { useComponentPresetProp } from '../../composables/useComponentPreset' | ||
import { ComponentConfig } from '../../services/component-config' | ||
import { provideLocalConfig, useLocalConfig } from '../../composables/useLocalConfig' | ||
import { useGlobalConfigProvider } from './hooks/useGlobalConfigProvider' | ||
import { PartialGlobalConfig } from '../../services/global-config' | ||
import { renderSlotNodes } from '../../utils/headless' | ||
import { useColors } from '../../composables' | ||
const CssVarsRenderer = defineComponent({ | ||
name: 'VaCssVarsRenderer', | ||
inheritAttrs: false, | ||
setup (props, { slots, attrs }) { | ||
const { colorsToCSSVariable, colors } = useColors() | ||
const style = computed(() => { | ||
return colorsToCSSVariable(colors) | ||
}) | ||
return () => h(Fragment, attrs, renderSlotNodes(slots.default, {}, { | ||
style: style.value, | ||
}) || undefined) | ||
}, | ||
}) | ||
export default defineComponent({ | ||
name: 'VaConfig', | ||
components: { CssVarsRenderer }, | ||
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: () => ({}) }, | ||
}, | ||
inheritAttrs: false, | ||
setup (props) { | ||
const prevChain = useLocalConfig() | ||
// We want it to be an array and not a merged object for optimization purposes | ||
const nextChain = computed(() => [...prevChain.value, props.components]) | ||
provideLocalConfig(nextChain) | ||
return {} | ||
const newConfig = useGlobalConfigProvider(computed(() => { | ||
return { | ||
colors: props.colors, | ||
i18n: props.i18n, | ||
} | ||
})) | ||
return { | ||
newConfig, | ||
} | ||
}, | ||
}) | ||
</script> |
29 changes: 29 additions & 0 deletions
29
packages/ui/src/components/va-config/hooks/useGlobalConfigProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { mergeDeep } from './../../../utils/merge-deep' | ||
import cloneDeep from 'lodash/cloneDeep' | ||
import { provide, computed, Ref } from 'vue' | ||
import { useGlobalConfig } from '../../../composables' | ||
import { GLOBAL_CONFIG, GlobalConfig, GlobalConfigUpdater, PartialGlobalConfig } from '../../../services/global-config' | ||
import { makeColorsConfig } from '../../../services/color/config/make-config' | ||
|
||
export const useGlobalConfigProvider = (next: Ref<PartialGlobalConfig>) => { | ||
const { globalConfig, mergeGlobalConfig, setGlobalConfig, getGlobalConfig } = useGlobalConfig() | ||
|
||
const nextChain = computed(() => { | ||
const gcCopy = cloneDeep(globalConfig.value) | ||
const compiledCopy: GlobalConfig = { | ||
...gcCopy, | ||
colors: makeColorsConfig(gcCopy.colors), | ||
} | ||
|
||
return mergeDeep(compiledCopy, next.value) as GlobalConfig | ||
}) | ||
|
||
provide(GLOBAL_CONFIG, { | ||
mergeGlobalConfig, | ||
setGlobalConfig, | ||
getGlobalConfig, | ||
globalConfig: nextChain, | ||
}) | ||
|
||
return nextChain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ColorConfig } from '../types' | ||
|
||
export const makeColorsConfig = (values: Omit<ColorConfig, 'variables'>): ColorConfig => ({ | ||
get variables () { | ||
return this.presets[this.currentPresetName] | ||
}, | ||
set variables (value) { | ||
this.presets[this.currentPresetName] = value | ||
}, | ||
...values, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters