mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-04-12 21:50:23 +08:00
Merge pull request #400 from webzard-io/feat/merge-style
use concat method when merging customStyles
This commit is contained in:
commit
b36dfddeb5
@ -68,9 +68,11 @@ export const ImplWrapperMain = React.forwardRef<HTMLDivElement, ImplWrapperProps
|
||||
return prevProps;
|
||||
}
|
||||
|
||||
return mergeWith(prevProps, result.props, (obj, src) => {
|
||||
if (isArray(obj)) {
|
||||
return obj.concat(src);
|
||||
return mergeWith({}, prevProps, result.props, (target, src, key) => {
|
||||
if (isArray(target)) {
|
||||
return target.concat(src);
|
||||
} else if (key === 'customStyle') {
|
||||
return mergeCustomStyle(target, src);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -175,3 +177,14 @@ const useDidUpdate = (fn: Function) => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function mergeCustomStyle(s1?: Record<string, string>, s2?: Record<string, string>) {
|
||||
if (s1 && s2) {
|
||||
return mergeWith({}, s1, s2, (target: string, src: string) => {
|
||||
if (target && src) {
|
||||
return `${target};${src}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
return s1 || s2;
|
||||
}
|
||||
|
@ -25,8 +25,12 @@ export default implementRuntimeTrait({
|
||||
})(() => {
|
||||
return ({ styles }) => {
|
||||
const customStyle: Record<string, string> = {};
|
||||
styles.forEach(style => {
|
||||
customStyle[style.styleSlot] = style.style;
|
||||
styles.forEach(({ style, styleSlot }) => {
|
||||
if (!customStyle[styleSlot]) {
|
||||
customStyle[styleSlot] = '';
|
||||
}
|
||||
// add a ';' between css texts, in case user forgets to add ';' in the end
|
||||
customStyle[styleSlot] = `${customStyle[styleSlot]};${style}`;
|
||||
});
|
||||
return {
|
||||
props: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user