mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-01 11:38:36 +08:00
2ee3d43534
* style: affix & util * feat(alert): add customIcon slot * feat(anchor): ts type * style: auto-complete * feat: avatar add crossOrigin & maxPopoverTrigger * style(backTop): v-show instead v-if * style: badge * style: breadcrumb * feat: button add global size * feat: update i18n * feat: picker add disabledTime * test: update snap * doc: update img url * style: fix Card tabs of left position * doc: update cascader doc * feat: collapse * style: comment * style: configprovider * feat: date-picker add soem icon slot * style: update descriptions style * feat: add divider orientationMargin * doc: update drawer * feat: dropdown add destroyPopupOnHide & loading * style: update empty * feat: form add labelWrap * style: update grid * test: update grid snap * fix: image ts error * fix: mentions cannot select, close #5233 * doc: update pagination change info, close #5293 * fix: table dynamic expand error, close #5295 * style: remove not use * release 3.0.0-beta.11 * doc: update typo * feat: input add showCount * feat: inputNumber add prefix slot * style: update layout * style: update list * feat: add locale i18 * style: update locale ts * style: update mentions * feat: menu divider add dashed * perf: menu * perf: menu animate * feat: modal method add wrapClassName * style: update pageheader * feat: update pagination ts * feat: confirm add showCancel & promise * doc: update popover * style: update progress * style: radio * style: update rate、result、row * feat: select add fieldNames * feat: add skeleton button & input * feat: spin tip support slot * style: slider & space * stype: update steps ts type * style: update switch * feat: table add tree filter * test: update input sanp * feat: table add filterMode... * fix: tree autoExpandParent bug * test: update input snap * doc: tabs add destroyInactiveTabPane * style: update tag * style: update timeline & time-picker * fix: Tooltip arrowPointAtCenter 1px shift bug * feat: typography add enterEnterIcon triggerType * doc: update tree-select * fix: deps and TypeScript types * style: udpate transfer * style: update style * doc: add colorScheme * chore: add css var builg * doc: sort api * style: lint code * doc: add css var * test: update snap * chore: add pre script * chore: update lint * perf: collapse animate * perf: collapse tree * perf: typography shaking when edit * doc: update auto-complete demo * fix: table tree not have animate * feat: deprecated dropdown center placement * feat: deprecated dropdown center placement * test: update snap
130 lines
4.3 KiB
Vue
130 lines
4.3 KiB
Vue
import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
|
|
import { defineComponent, computed } from 'vue';
|
|
import classNames from '../_util/classNames';
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
|
import { useInjectRow } from './context';
|
|
|
|
type ColSpanType = number | string;
|
|
|
|
type FlexType = number | 'none' | 'auto' | string;
|
|
|
|
export interface ColSize {
|
|
span?: ColSpanType;
|
|
order?: ColSpanType;
|
|
offset?: ColSpanType;
|
|
push?: ColSpanType;
|
|
pull?: ColSpanType;
|
|
}
|
|
|
|
function parseFlex(flex: FlexType): string {
|
|
if (typeof flex === 'number') {
|
|
return `${flex} ${flex} auto`;
|
|
}
|
|
|
|
if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
|
|
return `0 0 ${flex}`;
|
|
}
|
|
|
|
return flex;
|
|
}
|
|
|
|
const colProps = () => ({
|
|
span: [String, Number],
|
|
order: [String, Number],
|
|
offset: [String, Number],
|
|
push: [String, Number],
|
|
pull: [String, Number],
|
|
xs: { type: [String, Number, Object] as PropType<string | number | ColSize> },
|
|
sm: { type: [String, Number, Object] as PropType<string | number | ColSize> },
|
|
md: { type: [String, Number, Object] as PropType<string | number | ColSize> },
|
|
lg: { type: [String, Number, Object] as PropType<string | number | ColSize> },
|
|
xl: { type: [String, Number, Object] as PropType<string | number | ColSize> },
|
|
xxl: { type: [String, Number, Object] as PropType<string | number | ColSize> },
|
|
xxxl: { type: [String, Number, Object] as PropType<string | number | ColSize> },
|
|
prefixCls: String,
|
|
flex: [String, Number],
|
|
});
|
|
|
|
export type ColProps = Partial<ExtractPropTypes<ReturnType<typeof colProps>>>;
|
|
|
|
export default defineComponent({
|
|
name: 'ACol',
|
|
props: colProps(),
|
|
setup(props, { slots }) {
|
|
const { gutter, supportFlexGap, wrap } = useInjectRow();
|
|
const { prefixCls, direction } = useConfigInject('col', props);
|
|
const classes = computed(() => {
|
|
const { span, order, offset, push, pull } = props;
|
|
const pre = prefixCls.value;
|
|
let sizeClassObj = {};
|
|
['xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl'].forEach(size => {
|
|
let sizeProps: ColSize = {};
|
|
const propSize = props[size];
|
|
if (typeof propSize === 'number') {
|
|
sizeProps.span = propSize;
|
|
} else if (typeof propSize === 'object') {
|
|
sizeProps = propSize || {};
|
|
}
|
|
|
|
sizeClassObj = {
|
|
...sizeClassObj,
|
|
[`${pre}-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
|
|
[`${pre}-${size}-order-${sizeProps.order}`]: sizeProps.order || sizeProps.order === 0,
|
|
[`${pre}-${size}-offset-${sizeProps.offset}`]: sizeProps.offset || sizeProps.offset === 0,
|
|
[`${pre}-${size}-push-${sizeProps.push}`]: sizeProps.push || sizeProps.push === 0,
|
|
[`${pre}-${size}-pull-${sizeProps.pull}`]: sizeProps.pull || sizeProps.pull === 0,
|
|
[`${pre}-rtl`]: direction.value === 'rtl',
|
|
};
|
|
});
|
|
return classNames(
|
|
pre,
|
|
{
|
|
[`${pre}-${span}`]: span !== undefined,
|
|
[`${pre}-order-${order}`]: order,
|
|
[`${pre}-offset-${offset}`]: offset,
|
|
[`${pre}-push-${push}`]: push,
|
|
[`${pre}-pull-${pull}`]: pull,
|
|
},
|
|
sizeClassObj,
|
|
);
|
|
});
|
|
|
|
const mergedStyle = computed(() => {
|
|
const { flex } = props;
|
|
const gutterVal = gutter.value;
|
|
const style: CSSProperties = {};
|
|
// Horizontal gutter use padding
|
|
if (gutterVal && gutterVal[0] > 0) {
|
|
const horizontalGutter = `${gutterVal[0] / 2}px`;
|
|
style.paddingLeft = horizontalGutter;
|
|
style.paddingRight = horizontalGutter;
|
|
}
|
|
|
|
// Vertical gutter use padding when gap not support
|
|
if (gutterVal && gutterVal[1] > 0 && !supportFlexGap.value) {
|
|
const verticalGutter = `${gutterVal[1] / 2}px`;
|
|
style.paddingTop = verticalGutter;
|
|
style.paddingBottom = verticalGutter;
|
|
}
|
|
|
|
if (flex) {
|
|
style.flex = parseFlex(flex);
|
|
|
|
// Hack for Firefox to avoid size issue
|
|
// https://github.com/ant-design/ant-design/pull/20023#issuecomment-564389553
|
|
if (wrap.value === false && !style.minWidth) {
|
|
style.minWidth = 0;
|
|
}
|
|
}
|
|
return style;
|
|
});
|
|
return () => {
|
|
return (
|
|
<div class={classes.value} style={mergedStyle.value}>
|
|
{slots.default?.()}
|
|
</div>
|
|
);
|
|
};
|
|
},
|
|
});
|