Skip to content

Commit 2dc6c7e

Browse files
Merge pull request #2209 from appbaseio/disable-styling-prop
feat(vue): enhance theme prop to reset default styles
2 parents e0efa51 + 012bf89 commit 2dc6c7e

File tree

5 files changed

+1765
-1141
lines changed

5 files changed

+1765
-1141
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.bool, VueTypes.object.def({})]),
3535
themePreset: VueTypes.string.def('light'),
3636
type: types.string,
3737
url: types.string,
@@ -275,6 +275,7 @@ const ReactiveBase = {
275275
className={className}
276276
getSearchParams={this.getSearchParams}
277277
setSearchParams={this.setSearchParams}
278+
userThemeProp={this.$props.theme}
278279
>
279280
{children()}
280281
</URLParamsProvider>

packages/vue/src/components/URLParamsProvider.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const URLParamsProvider = {
1717
getSearchParams: types.func,
1818
setSearchParams: types.func,
1919
as: VueTypes.string.def('div'),
20+
userThemeProp: VueTypes.oneOf([VueTypes.bool, VueTypes.object.def({})]),
2021
},
2122
mounted() {
2223
this.init();
@@ -238,7 +239,11 @@ const URLParamsProvider = {
238239
render() {
239240
const children = this.$slots.default();
240241
return (
241-
<Base as={this.$props.as} class={this.$props.className}>
242+
<Base
243+
as={this.$props.as}
244+
class={this.$props.className}
245+
userThemeProp={this.$props.userThemeProp}
246+
>
242247
{children}
243248
</Base>
244249
);

packages/vue/src/styles/Base.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const Base = ({
1313
};
1414

1515
export default styled(Base)`
16-
font-family: ${({ theme }) =>
17-
theme && theme.typography ? theme.typography.fontFamily : 'unset'};
18-
font-size: ${({ theme }) => (theme && theme.typography ? theme.typography.fontSize : 'unset')};
19-
color: ${({ theme }) => (theme && theme.colors ? theme.colors.textColor : 'unset')};
16+
${({ userThemeProp, theme }) =>
17+
userThemeProp === false
18+
? ''
19+
: `font-family: ${theme && theme.typography ? theme.typography.fontFamily : 'unset'};
20+
font-size: ${theme && theme.typography ? theme.typography.fontSize : 'unset'};
21+
color: ${theme && theme.colors ? theme.colors.textColor : 'unset'};`}
2022
width: 100%;
2123
2224
input,

packages/vue/src/utils/index.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@ 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 (typeof userThemeParam !== 'boolean' && Object.keys(userThemeParam).length) {
21+
userTheme = { ...userThemeParam };
22+
}
23+
return {
24+
typography: {
25+
...ownTheme.typography,
26+
...userTheme.typography,
27+
},
28+
colors: {
29+
...ownTheme.colors,
30+
...userTheme.colors,
31+
},
32+
component: {
33+
...ownTheme.component,
34+
...userTheme.component,
35+
},
36+
};
37+
};
3238
/**
3339
* To determine wether an element is a function
3440
* @param {any} element
@@ -120,15 +126,15 @@ export const hasQuerySuggestionsRenderer = (_ref = {}) => {
120126
* @returns {string}
121127
*/
122128
export const getCamelCase = (str = '') => {
123-
const propsWhichRequirePascalCase = ['u-r-l-params']
129+
const propsWhichRequirePascalCase = ['u-r-l-params'];
124130
const arr = str.split('-');
125131
const capital = arr.map((item, index) =>
126132
index ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase() : item,
127133
);
128134
// ^-- change here.
129135
let capitalString = capital.join('');
130-
if(propsWhichRequirePascalCase.includes(str))
131-
capitalString = capitalString[0].toUpperCase() + capitalString.substring(1)
136+
if (propsWhichRequirePascalCase.includes(str))
137+
capitalString = capitalString[0].toUpperCase() + capitalString.substring(1);
132138
return capitalString || '';
133139
};
134140

0 commit comments

Comments
 (0)