useTheme.js 1.3 KB

1234567891011121314151617181920212223
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { defaultConfig } from '../../theme/internal';
  3. import { computed } from 'vue';
  4. export default function useTheme(theme, parentTheme) {
  5. const themeConfig = computed(() => (theme === null || theme === void 0 ? void 0 : theme.value) || {});
  6. const parentThemeConfig = computed(() => themeConfig.value.inherit === false || !(parentTheme === null || parentTheme === void 0 ? void 0 : parentTheme.value) ? defaultConfig : parentTheme.value);
  7. const mergedTheme = computed(() => {
  8. if (!(theme === null || theme === void 0 ? void 0 : theme.value)) {
  9. return parentTheme === null || parentTheme === void 0 ? void 0 : parentTheme.value;
  10. }
  11. // Override
  12. const mergedComponents = _extends({}, parentThemeConfig.value.components);
  13. Object.keys(theme.value.components || {}).forEach(componentName => {
  14. mergedComponents[componentName] = _extends(_extends({}, mergedComponents[componentName]), theme.value.components[componentName]);
  15. });
  16. // Base token
  17. return _extends(_extends(_extends({}, parentThemeConfig.value), themeConfig.value), {
  18. token: _extends(_extends({}, parentThemeConfig.value.token), themeConfig.value.token),
  19. components: mergedComponents
  20. });
  21. });
  22. return mergedTheme;
  23. }