Skip to content

Commit 5403d9a

Browse files
feat(vue): enhance theme prop to reset default styles
1 parent 1a5c981 commit 5403d9a

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

packages/vue/src/components/ReactiveBase/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const ReactiveBase = {
3131
credentials: types.string,
3232
headers: types.headers,
3333
queryParams: types.string,
34-
theme: VueTypes.object.def({}),
34+
theme: VueTypes.oneOf([VueTypes.object.def({}), false]),
3535
themePreset: VueTypes.string.def('light'),
3636
type: types.string,
3737
url: types.string,
@@ -54,6 +54,7 @@ const ReactiveBase = {
5454
if (createCache.default) {
5555
createCacheFn = createCache.default;
5656
}
57+
console.log(composeThemeObject(getTheme(this.$props.themePreset), this.$props.theme));
5758
return {
5859
theme_reactivesearch: composeThemeObject(
5960
getTheme(this.$props.themePreset),

packages/vue/src/utils/index.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,41 @@ export const connect = (...args) => connectToStore(...args);
1515

1616
export const X_SEARCH_CLIENT = 'ReactiveSearch Vue';
1717

18-
export const composeThemeObject = (ownTheme = {}, userTheme = {}) => ({
19-
typography: {
20-
...ownTheme.typography,
21-
...userTheme.typography,
22-
},
23-
colors: {
24-
...ownTheme.colors,
25-
...userTheme.colors,
26-
},
27-
component: {
28-
...ownTheme.component,
29-
...userTheme.component,
30-
},
31-
});
18+
export const composeThemeObject = (ownTheme = {}, userThemeParam = {}) => {
19+
let userTheme = {};
20+
if (userThemeParam) {
21+
userTheme = { ...userThemeParam };
22+
} else {
23+
userTheme = {
24+
typography: {
25+
fontFamily: 'inherit',
26+
fontSize: 'inherit',
27+
},
28+
colors: {
29+
textColor: 'inherit',
30+
primaryTextColor: 'inherit',
31+
primaryColor: 'inherit',
32+
titleColor: 'inherit',
33+
alertColor: 'inherit',
34+
borderColor: 'inherit',
35+
},
36+
};
37+
}
38+
return {
39+
typography: {
40+
...ownTheme.typography,
41+
...userTheme.typography,
42+
},
43+
colors: {
44+
...ownTheme.colors,
45+
...userTheme.colors,
46+
},
47+
component: {
48+
...ownTheme.component,
49+
...userTheme.component,
50+
},
51+
};
52+
};
3253
/**
3354
* To determine wether an element is a function
3455
* @param {any} element
@@ -120,15 +141,15 @@ export const hasQuerySuggestionsRenderer = (_ref = {}) => {
120141
* @returns {string}
121142
*/
122143
export const getCamelCase = (str = '') => {
123-
const propsWhichRequirePascalCase = ['u-r-l-params']
144+
const propsWhichRequirePascalCase = ['u-r-l-params'];
124145
const arr = str.split('-');
125146
const capital = arr.map((item, index) =>
126147
index ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase() : item,
127148
);
128149
// ^-- change here.
129150
let capitalString = capital.join('');
130-
if(propsWhichRequirePascalCase.includes(str))
131-
capitalString = capitalString[0].toUpperCase() + capitalString.substring(1)
151+
if (propsWhichRequirePascalCase.includes(str))
152+
capitalString = capitalString[0].toUpperCase() + capitalString.substring(1);
132153
return capitalString || '';
133154
};
134155

0 commit comments

Comments
 (0)