|
|
@@ -6,107 +6,101 @@ import { ObjectUtils } from "@imengyu/imengyu-utils";
|
|
|
|
|
|
export function useBaseViewStyleBuilder(props: FlexProps) {
|
|
|
|
|
|
+ const styleObj : Record<string, any> = {};
|
|
|
+
|
|
|
const themeContext = useTheme();
|
|
|
const commonStyle = computed(() => {
|
|
|
- const obj : Record<string, any> = {
|
|
|
- display: 'flex',
|
|
|
- flexDirection: props.direction,
|
|
|
- flexBasis: props.flexBasis,
|
|
|
- flexGrow: props.flexGrow,
|
|
|
- flexShrink: props.flexShrink,
|
|
|
- justifyContent: props.center ? (props.justify || 'center') : props.justify,
|
|
|
- alignItems: props.center ? (props.align || 'center') : props.align,
|
|
|
- position: props.position,
|
|
|
- alignSelf: props.alignSelf,
|
|
|
- flexWrap: props.wrap ? 'wrap' : 'nowrap',
|
|
|
- backgroundColor: themeContext.resolveThemeColor(props.backgroundColor),
|
|
|
- width: themeContext.resolveThemeSize(props.width),
|
|
|
- height: themeContext.resolveThemeSize(props.height),
|
|
|
- gap: !Array.isArray(props.gap) ? themeContext.resolveThemeSize(props.gap) : props.gap,
|
|
|
- rowGap: Array.isArray(props.gap) ? themeContext.resolveSize(props.gap[0]) : undefined,
|
|
|
- columnGap: Array.isArray(props.gap) ? themeContext.resolveSize(props.gap[1]) : undefined,
|
|
|
- borderRadius: themeContext.resolveThemeSize(props.radius),
|
|
|
- overflow: props.overflow,
|
|
|
- border: props.border && !props.border.includes(' ') ? themeContext.getVar('border.' + props.border, undefined) : props.border,
|
|
|
- borderColor: themeContext.resolveThemeColor(props.borderColor),
|
|
|
- borderWidth: themeContext.resolveThemeSize(props.borderWidth),
|
|
|
- borderStyle: props.borderStyle,
|
|
|
- boxShadow: props.shadow ? themeContext.getVar('shadow.' + props.shadow, undefined) : undefined,
|
|
|
- zIndex: props.zIndex,
|
|
|
- pointerEvents: props.pointerEvents,
|
|
|
- }
|
|
|
+ styleObj.display = 'flex';
|
|
|
+ styleObj.flexDirection = props.direction;
|
|
|
+ styleObj.flexBasis = props.flexBasis;
|
|
|
+ styleObj.flexGrow = props.flexGrow;
|
|
|
+ styleObj.flexShrink = props.flexShrink;
|
|
|
+ styleObj.justifyContent = props.center ? (props.justify || 'center') : props.justify;
|
|
|
+ styleObj.alignItems = props.center ? (props.align || 'center') : props.align;
|
|
|
+ styleObj.position = props.position;
|
|
|
+ styleObj.alignSelf = props.alignSelf;
|
|
|
+ styleObj.flexWrap = props.wrap ? 'wrap' : 'nowrap';
|
|
|
+ styleObj.backgroundColor = themeContext.resolveThemeColor(props.backgroundColor);
|
|
|
+ styleObj.width = themeContext.resolveThemeSize(props.width);
|
|
|
+ styleObj.height = themeContext.resolveThemeSize(props.height);
|
|
|
+ styleObj.gap = !Array.isArray(props.gap) ? themeContext.resolveThemeSize(props.gap) : props.gap;
|
|
|
+ styleObj.rowGap = Array.isArray(props.gap) ? themeContext.resolveSize(props.gap[0]) : undefined;
|
|
|
+ styleObj.columnGap = Array.isArray(props.gap) ? themeContext.resolveSize(props.gap[1]) : undefined;
|
|
|
+ styleObj.borderRadius = themeContext.resolveThemeSize(props.radius);
|
|
|
+ styleObj.overflow = props.overflow;
|
|
|
+ styleObj.border = props.border && !props.border.includes(' ') ? themeContext.getVar('border.' + props.border, undefined) : props.border;
|
|
|
+ styleObj.borderColor = themeContext.resolveThemeColor(props.borderColor);
|
|
|
+ styleObj.borderWidth = themeContext.resolveThemeSize(props.borderWidth);
|
|
|
+ styleObj.borderStyle = props.borderStyle;
|
|
|
+ styleObj.boxShadow = props.shadow ? themeContext.getVar('shadow.' + props.shadow, undefined) : undefined;
|
|
|
+ styleObj.zIndex = props.zIndex;
|
|
|
+ styleObj.pointerEvents = props.pointerEvents;
|
|
|
|
|
|
//内边距样式
|
|
|
- configPadding(obj, themeContext, props.padding);
|
|
|
+ configPadding(styleObj, themeContext, props.padding);
|
|
|
//外边距样式
|
|
|
- configMargin(obj, themeContext, props.margin);
|
|
|
+ configMargin(styleObj, themeContext, props.margin);
|
|
|
|
|
|
if (props.innerStyle)
|
|
|
- ObjectUtils.cloneValuesToObject(props.innerStyle, obj);
|
|
|
+ ObjectUtils.cloneValuesToObject(props.innerStyle, styleObj);
|
|
|
|
|
|
- if (obj.paddingVertical) {
|
|
|
- if (obj.paddingTop === undefined)
|
|
|
- obj.paddingTop = obj.paddingVertical;
|
|
|
- if (obj.paddingBottom === undefined)
|
|
|
- obj.paddingBottom = obj.paddingVertical;
|
|
|
- delete obj.paddingVertical;
|
|
|
+ if (styleObj.paddingVertical) {
|
|
|
+ if (styleObj.paddingTop === undefined)
|
|
|
+ styleObj.paddingTop = styleObj.paddingVertical;
|
|
|
+ if (styleObj.paddingBottom === undefined)
|
|
|
+ styleObj.paddingBottom = styleObj.paddingVertical;
|
|
|
+ delete styleObj.paddingVertical;
|
|
|
}
|
|
|
- if (obj.paddingHorizontal) {
|
|
|
- if (obj.paddingLeft === undefined)
|
|
|
- obj.paddingLeft = obj.paddingHorizontal;
|
|
|
- if (obj.paddingRight === undefined)
|
|
|
- obj.paddingRight = obj.paddingHorizontal;
|
|
|
- delete obj.paddingHorizontal;
|
|
|
+ if (styleObj.paddingHorizontal) {
|
|
|
+ if (styleObj.paddingLeft === undefined)
|
|
|
+ styleObj.paddingLeft = styleObj.paddingHorizontal;
|
|
|
+ if (styleObj.paddingRight === undefined)
|
|
|
+ styleObj.paddingRight = styleObj.paddingHorizontal;
|
|
|
+ delete styleObj.paddingHorizontal;
|
|
|
}
|
|
|
- if (obj.marginVertical) {
|
|
|
- obj.marginTop = obj.marginVertical;
|
|
|
- obj.marginBottom = obj.marginVertical;
|
|
|
- delete obj.marginVertical;
|
|
|
+ if (styleObj.marginVertical) {
|
|
|
+ styleObj.marginTop = styleObj.marginVertical;
|
|
|
+ styleObj.marginBottom = styleObj.marginVertical;
|
|
|
+ delete styleObj.marginVertical;
|
|
|
}
|
|
|
- if (obj.marginHorizontal) {
|
|
|
- obj.marginLeft = obj.marginHorizontal;
|
|
|
- obj.marginRight = obj.marginHorizontal;
|
|
|
- delete obj.marginHorizontal;
|
|
|
+ if (styleObj.marginHorizontal) {
|
|
|
+ styleObj.marginLeft = styleObj.marginHorizontal;
|
|
|
+ styleObj.marginRight = styleObj.marginHorizontal;
|
|
|
+ delete styleObj.marginHorizontal;
|
|
|
}
|
|
|
|
|
|
if (props.inset != undefined) {
|
|
|
if (Array.isArray(props.inset)) {
|
|
|
- obj.top = themeContext.resolveThemeSize(props.inset[0]);
|
|
|
- obj.right = themeContext.resolveThemeSize(props.inset[1]);
|
|
|
- obj.bottom = themeContext.resolveThemeSize(props.inset[2]);
|
|
|
- obj.left = themeContext.resolveThemeSize(props.inset[3]);
|
|
|
+ styleObj.top = themeContext.resolveThemeSize(props.inset[0]);
|
|
|
+ styleObj.right = themeContext.resolveThemeSize(props.inset[1]);
|
|
|
+ styleObj.bottom = themeContext.resolveThemeSize(props.inset[2]);
|
|
|
+ styleObj.left = themeContext.resolveThemeSize(props.inset[3]);
|
|
|
} else if (typeof props.inset === 'object') {
|
|
|
- obj.left = themeContext.resolveThemeSize(props.inset.l);
|
|
|
- obj.right = themeContext.resolveThemeSize(props.inset.r);
|
|
|
- obj.top = themeContext.resolveThemeSize(props.inset.t);
|
|
|
- obj.bottom = themeContext.resolveThemeSize(props.inset.b);
|
|
|
+ styleObj.left = themeContext.resolveThemeSize(props.inset.l);
|
|
|
+ styleObj.right = themeContext.resolveThemeSize(props.inset.r);
|
|
|
+ styleObj.top = themeContext.resolveThemeSize(props.inset.t);
|
|
|
+ styleObj.bottom = themeContext.resolveThemeSize(props.inset.b);
|
|
|
} else {
|
|
|
const v = themeContext.resolveThemeSize(props.inset);
|
|
|
- obj.left = v;
|
|
|
- obj.right = v;
|
|
|
- obj.top = v;
|
|
|
- obj.bottom = v;
|
|
|
+ styleObj.left = v;
|
|
|
+ styleObj.right = v;
|
|
|
+ styleObj.top = v;
|
|
|
+ styleObj.bottom = v;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//绝对距样式
|
|
|
if (typeof props.left !== 'undefined')
|
|
|
- obj.left = themeContext.resolveThemeSize(props.left);
|
|
|
+ styleObj.left = themeContext.resolveThemeSize(props.left);
|
|
|
if (typeof props.right !== 'undefined')
|
|
|
- obj.right = themeContext.resolveThemeSize(props.right);
|
|
|
+ styleObj.right = themeContext.resolveThemeSize(props.right);
|
|
|
if (typeof props.top !== 'undefined')
|
|
|
- obj.top = themeContext.resolveThemeSize(props.top);
|
|
|
+ styleObj.top = themeContext.resolveThemeSize(props.top);
|
|
|
if (typeof props.bottom !== 'undefined')
|
|
|
- obj.bottom = themeContext.resolveThemeSize(props.bottom);
|
|
|
+ styleObj.bottom = themeContext.resolveThemeSize(props.bottom);
|
|
|
if (typeof props.flex !== 'undefined')
|
|
|
- obj.flex = props.flex;
|
|
|
-
|
|
|
- for (const key in obj) {
|
|
|
- if (obj[key] === undefined)
|
|
|
- delete obj[key];
|
|
|
- }
|
|
|
-
|
|
|
- return obj
|
|
|
+ styleObj.flex = props.flex;
|
|
|
+ return styleObj
|
|
|
});
|
|
|
|
|
|
return {
|