Skip to content

Commit 3499b11

Browse files
committed
refactor: flex components
1 parent dae7262 commit 3499b11

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

components/flex/index.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { defineComponent, shallowRef } from 'vue';
1+
import { computed, defineComponent } from 'vue';
22
import type { CSSProperties } from 'vue';
33
import { useConfigContextInject } from '../config-provider/context';
44
import useConfigInject from '../config-provider/hooks/useConfigInject';
55
import useStyle from './style';
6-
import classNames from '../_util/classNames';
76
import { isPresetSize } from '../_util/gapSize';
87
import omit from '../_util/omit';
98
import { withInstall } from '../_util/type';
@@ -19,26 +18,20 @@ const AFlex = defineComponent({
1918
const { flex: ctxFlex, direction: ctxDirection } = useConfigContextInject();
2019
const { prefixCls } = useConfigInject('flex', props);
2120
const [wrapSSR, hashId] = useStyle(prefixCls);
22-
const flexRef = shallowRef();
23-
21+
const mergedCls = computed(() => [
22+
prefixCls.value,
23+
hashId.value,
24+
createFlexClassNames(prefixCls.value, props),
25+
{
26+
[`${prefixCls.value}-rtl`]: ctxDirection.value === 'rtl',
27+
[`${prefixCls.value}-gap-${props.gap}`]: isPresetSize(props.gap),
28+
[`${prefixCls.value}-vertical`]: props.vertical ?? ctxFlex?.value.vertical,
29+
},
30+
]);
2431
return () => {
25-
const { flex, gap, vertical = false, component: Component = 'div', ...othersProps } = props;
26-
27-
const mergedVertical = vertical ?? ctxFlex?.value.vertical;
28-
29-
const mergedCls = classNames(
30-
attrs.class,
31-
prefixCls.value,
32-
hashId.value,
33-
createFlexClassNames(prefixCls.value, props),
34-
{
35-
[`${prefixCls.value}-rtl`]: ctxDirection.value === 'rtl',
36-
[`${prefixCls.value}-gap-${gap}`]: isPresetSize(gap),
37-
[`${prefixCls.value}-vertical`]: mergedVertical,
38-
},
39-
);
32+
const { flex, gap, component: Component = 'div', ...othersProps } = props;
4033

41-
const mergedStyle = { ...(attrs.style as CSSProperties) };
34+
const mergedStyle: CSSProperties = {};
4235

4336
if (flex) {
4437
mergedStyle.flex = flex;
@@ -50,10 +43,9 @@ const AFlex = defineComponent({
5043

5144
return wrapSSR(
5245
<Component
53-
ref={flexRef.value}
54-
class={mergedCls}
55-
style={mergedStyle}
56-
{...omit(othersProps, ['justify', 'wrap', 'align'])}
46+
class={[attrs.class, mergedCls.value]}
47+
style={[attrs.style as CSSProperties, mergedStyle]}
48+
{...omit(othersProps, ['justify', 'wrap', 'align', 'vertical'])}
5749
>
5850
{slots.default?.()}
5951
</Component>,

components/theme/interface/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export interface ComponentTokenMap {
114114
Tour?: TourComponentToken;
115115
QRCode?: QRCodeComponentToken;
116116
App?: AppComponentToken;
117+
Flex?: FlexToken;
117118

118119
// /** @private Internal TS definition. Do not use. */
119120
Wave?: WaveToken;
120-
Flex?: FlexToken;
121121
}

typings/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ declare module 'vue' {
266266
ABackTop: typeof import('ant-design-vue')['BackTop'];
267267

268268
AWatermark: typeof import('ant-design-vue')['Watermark'];
269+
270+
AFlex: typeof import('ant-design-vue')['Flex'];
269271
}
270272
}
271273
export {};

0 commit comments

Comments
 (0)