refactor: flex components
parent
dae7262f13
commit
3499b11a47
|
@ -1,9 +1,8 @@
|
||||||
import { defineComponent, shallowRef } from 'vue';
|
import { computed, defineComponent } from 'vue';
|
||||||
import type { CSSProperties } from 'vue';
|
import type { CSSProperties } from 'vue';
|
||||||
import { useConfigContextInject } from '../config-provider/context';
|
import { useConfigContextInject } from '../config-provider/context';
|
||||||
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
||||||
import useStyle from './style';
|
import useStyle from './style';
|
||||||
import classNames from '../_util/classNames';
|
|
||||||
import { isPresetSize } from '../_util/gapSize';
|
import { isPresetSize } from '../_util/gapSize';
|
||||||
import omit from '../_util/omit';
|
import omit from '../_util/omit';
|
||||||
import { withInstall } from '../_util/type';
|
import { withInstall } from '../_util/type';
|
||||||
|
@ -19,26 +18,20 @@ const AFlex = defineComponent({
|
||||||
const { flex: ctxFlex, direction: ctxDirection } = useConfigContextInject();
|
const { flex: ctxFlex, direction: ctxDirection } = useConfigContextInject();
|
||||||
const { prefixCls } = useConfigInject('flex', props);
|
const { prefixCls } = useConfigInject('flex', props);
|
||||||
const [wrapSSR, hashId] = useStyle(prefixCls);
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
||||||
const flexRef = shallowRef();
|
const mergedCls = computed(() => [
|
||||||
|
prefixCls.value,
|
||||||
|
hashId.value,
|
||||||
|
createFlexClassNames(prefixCls.value, props),
|
||||||
|
{
|
||||||
|
[`${prefixCls.value}-rtl`]: ctxDirection.value === 'rtl',
|
||||||
|
[`${prefixCls.value}-gap-${props.gap}`]: isPresetSize(props.gap),
|
||||||
|
[`${prefixCls.value}-vertical`]: props.vertical ?? ctxFlex?.value.vertical,
|
||||||
|
},
|
||||||
|
]);
|
||||||
return () => {
|
return () => {
|
||||||
const { flex, gap, vertical = false, component: Component = 'div', ...othersProps } = props;
|
const { flex, gap, component: Component = 'div', ...othersProps } = props;
|
||||||
|
|
||||||
const mergedVertical = vertical ?? ctxFlex?.value.vertical;
|
const mergedStyle: CSSProperties = {};
|
||||||
|
|
||||||
const mergedCls = classNames(
|
|
||||||
attrs.class,
|
|
||||||
prefixCls.value,
|
|
||||||
hashId.value,
|
|
||||||
createFlexClassNames(prefixCls.value, props),
|
|
||||||
{
|
|
||||||
[`${prefixCls.value}-rtl`]: ctxDirection.value === 'rtl',
|
|
||||||
[`${prefixCls.value}-gap-${gap}`]: isPresetSize(gap),
|
|
||||||
[`${prefixCls.value}-vertical`]: mergedVertical,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const mergedStyle = { ...(attrs.style as CSSProperties) };
|
|
||||||
|
|
||||||
if (flex) {
|
if (flex) {
|
||||||
mergedStyle.flex = flex;
|
mergedStyle.flex = flex;
|
||||||
|
@ -50,10 +43,9 @@ const AFlex = defineComponent({
|
||||||
|
|
||||||
return wrapSSR(
|
return wrapSSR(
|
||||||
<Component
|
<Component
|
||||||
ref={flexRef.value}
|
class={[attrs.class, mergedCls.value]}
|
||||||
class={mergedCls}
|
style={[attrs.style as CSSProperties, mergedStyle]}
|
||||||
style={mergedStyle}
|
{...omit(othersProps, ['justify', 'wrap', 'align', 'vertical'])}
|
||||||
{...omit(othersProps, ['justify', 'wrap', 'align'])}
|
|
||||||
>
|
>
|
||||||
{slots.default?.()}
|
{slots.default?.()}
|
||||||
</Component>,
|
</Component>,
|
||||||
|
|
|
@ -114,8 +114,8 @@ export interface ComponentTokenMap {
|
||||||
Tour?: TourComponentToken;
|
Tour?: TourComponentToken;
|
||||||
QRCode?: QRCodeComponentToken;
|
QRCode?: QRCodeComponentToken;
|
||||||
App?: AppComponentToken;
|
App?: AppComponentToken;
|
||||||
|
Flex?: FlexToken;
|
||||||
|
|
||||||
// /** @private Internal TS definition. Do not use. */
|
// /** @private Internal TS definition. Do not use. */
|
||||||
Wave?: WaveToken;
|
Wave?: WaveToken;
|
||||||
Flex?: FlexToken;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,6 +266,8 @@ declare module 'vue' {
|
||||||
ABackTop: typeof import('ant-design-vue')['BackTop'];
|
ABackTop: typeof import('ant-design-vue')['BackTop'];
|
||||||
|
|
||||||
AWatermark: typeof import('ant-design-vue')['Watermark'];
|
AWatermark: typeof import('ant-design-vue')['Watermark'];
|
||||||
|
|
||||||
|
AFlex: typeof import('ant-design-vue')['Flex'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export {};
|
export {};
|
||||||
|
|
Loading…
Reference in New Issue