Skip to content

Commit adbc39b

Browse files
committed
style: some code
1 parent 8f20fd5 commit adbc39b

File tree

10 files changed

+53
-29
lines changed

10 files changed

+53
-29
lines changed

components/_util/hooks/useBreakpoint.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import type { Ref } from 'vue';
2-
import { onMounted, onUnmounted, ref } from 'vue';
2+
import { getCurrentInstance, onMounted, onUnmounted, ref } from 'vue';
33
import type { ScreenMap } from '../../_util/responsiveObserve';
44
import ResponsiveObserve from '../../_util/responsiveObserve';
55

6-
function useBreakpoint(): Ref<ScreenMap> {
6+
function useBreakpoint(refreshOnChange = ref(true)): Ref<ScreenMap> {
77
const screens = ref<ScreenMap>({});
88
let token = null;
9-
9+
const instance = getCurrentInstance();
1010
onMounted(() => {
1111
token = ResponsiveObserve.subscribe(supportScreens => {
1212
screens.value = supportScreens;
13+
if (refreshOnChange?.value) {
14+
instance.update();
15+
}
1316
});
1417
});
1518

components/avatar/Avatar.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ const Avatar = defineComponent({
5151
const { prefixCls } = useConfigInject('avatar', props);
5252

5353
const groupSize = useInjectSize();
54-
55-
const screens = useBreakpoint();
54+
const size = computed(() => {
55+
return props.size === 'default' ? groupSize.value : props.size;
56+
});
57+
const needResponsive = computed(() =>
58+
Object.keys(typeof size.value === 'object' ? size.value || {} : {}).some(key =>
59+
['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].includes(key),
60+
),
61+
);
62+
const screens = useBreakpoint(needResponsive);
5663
const responsiveSize = computed(() => {
5764
if (typeof props.size !== 'object') {
5865
return undefined;
@@ -126,27 +133,26 @@ const Avatar = defineComponent({
126133
});
127134

128135
return () => {
129-
const { shape, size: customSize, src, alt, srcset, draggable, crossOrigin } = props;
136+
const { shape, src, alt, srcset, draggable, crossOrigin } = props;
130137
const icon = getPropsSlot(slots, props, 'icon');
131138
const pre = prefixCls.value;
132-
const size = customSize === 'default' ? groupSize.value : customSize;
133139
const classString = {
134140
[`${attrs.class}`]: !!attrs.class,
135141
[pre]: true,
136-
[`${pre}-lg`]: size === 'large',
137-
[`${pre}-sm`]: size === 'small',
142+
[`${pre}-lg`]: size.value === 'large',
143+
[`${pre}-sm`]: size.value === 'small',
138144
[`${pre}-${shape}`]: shape,
139145
[`${pre}-image`]: src && isImgExist.value,
140146
[`${pre}-icon`]: icon,
141147
};
142148

143149
const sizeStyle: CSSProperties =
144-
typeof size === 'number'
150+
typeof size.value === 'number'
145151
? {
146-
width: `${size}px`,
147-
height: `${size}px`,
148-
lineHeight: `${size}px`,
149-
fontSize: icon ? `${size / 2}px` : '18px',
152+
width: `${size.value}px`,
153+
height: `${size.value}px`,
154+
lineHeight: `${size.value}px`,
155+
fontSize: icon ? `${size.value / 2}px` : '18px',
150156
}
151157
: {};
152158

@@ -173,9 +179,9 @@ const Avatar = defineComponent({
173179
transform: transformString,
174180
};
175181
const sizeChildrenStyle =
176-
typeof size === 'number'
182+
typeof size.value === 'number'
177183
? {
178-
lineHeight: `${size}px`,
184+
lineHeight: `${size.value}px`,
179185
}
180186
: {};
181187
childrenToRender = (

components/button/button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import Wave from '../_util/wave';
1313
import buttonTypes from './buttonTypes';
1414
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
15-
import { flattenChildren, getPropsSlot } from '../_util/props-util';
15+
import { flattenChildren, getPropsSlot, initDefaultProps } from '../_util/props-util';
1616
import useConfigInject from '../_util/hooks/useConfigInject';
1717
import devWarning from '../vc-util/devWarning';
1818

@@ -32,7 +32,7 @@ export default defineComponent({
3232
name: 'AButton',
3333
inheritAttrs: false,
3434
__ANT_BUTTON: true,
35-
props: buttonTypes(),
35+
props: initDefaultProps(buttonTypes(), { type: 'default' }),
3636
slots: ['icon'],
3737
emits: ['click', 'mousedown'],
3838
setup(props, { slots, attrs, emit }) {

components/cascader/demo/multiple.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Select multiple options
1818
<template>
1919
<a-cascader
2020
v-model:value="value"
21-
style="width: 233px"
21+
style="width: 100%"
2222
multiple
2323
max-tag-count="responsive"
2424
:options="options"

components/cascader/index.en-US.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ interface Option {
7676
label?: VNode;
7777
disabled?: boolean;
7878
children?: Option[];
79+
// Determines if this is a leaf node(effective when `loadData` is specified).
80+
// `false` will force trade TreeNode as a parent node.
81+
// Show expand icon even if the current node has no children.
82+
isLeaf?: boolean;
7983
}
8084
```
8185

components/cascader/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ShowSearchType, FieldNames, BaseOptionType, DefaultOptionType } from '../vc-cascader';
22
import VcCascader, { cascaderProps as vcCascaderProps } from '../vc-cascader';
33
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
4-
import RedoOutlined from '@ant-design/icons-vue/RedoOutlined';
4+
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
55
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
66
import getIcons from '../select/utils/iconUtil';
77
import type { VueNode } from '../_util/type';
@@ -215,7 +215,7 @@ const Cascader = defineComponent({
215215

216216
const loadingIcon = (
217217
<span class={`${prefixCls.value}-menu-item-loading-icon`}>
218-
<RedoOutlined spin />
218+
<LoadingOutlined spin />
219219
</span>
220220
);
221221

components/cascader/index.zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ interface Option {
7878
label?: any;
7979
disabled?: boolean;
8080
children?: Option[];
81+
// 标记是否为叶子节点,设置了 `loadData` 时有效
82+
// 设为 `false` 时会强制标记为父节点,即使当前节点没有 children,也会显示展开图标
83+
isLeaf?: boolean;
8184
}
8285
```
8386

components/config-provider/cssVariables.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { TinyColor } from '@ctrl/tinycolor';
44
import { generate } from '@ant-design/colors';
55
import type { Theme } from './context';
66
import { updateCSS } from '../vc-util/Dom/dynamicCSS';
7+
import canUseDom from '../_util/canUseDom';
8+
import devWarning from '../vc-util/devWarning';
79

810
const dynamicStyleMark = `-ant-${Date.now()}-${Math.random()}`;
911

@@ -86,12 +88,16 @@ export function registerTheme(globalPrefixCls: string, theme: Theme) {
8688
key => `--${globalPrefixCls}-${key}: ${variables[key]};`,
8789
);
8890

89-
updateCSS(
90-
`
91+
if (canUseDom()) {
92+
updateCSS(
93+
`
9194
:root {
9295
${cssList.join('\n')}
9396
}
9497
`,
95-
`${dynamicStyleMark}-dynamic-theme`,
96-
);
98+
`${dynamicStyleMark}-dynamic-theme`,
99+
);
100+
} else {
101+
devWarning(false, 'ConfigProvider', 'SSR do not support dynamic theme with css variables.');
102+
}
97103
}

components/config-provider/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ const ConfigProvider = defineComponent({
152152
}
153153
const validateMessagesRef = computed(() => {
154154
// Additional Form provider
155-
let validateMessages: ValidateMessages = {
156-
...defaultLocale.Form?.defaultValidateMessages,
157-
};
155+
let validateMessages: ValidateMessages = {};
158156

159157
if (props.locale) {
160158
validateMessages =

components/grid/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import Row from './Row';
22
import Col from './Col';
3-
import useBreakpoint from '../_util/hooks/useBreakpoint';
3+
import useInternalBreakpoint from '../_util/hooks/useBreakpoint';
44

5+
// Do not export params
6+
function useBreakpoint() {
7+
return useInternalBreakpoint();
8+
}
59
export type { RowProps } from './Row';
610

711
export type { ColProps, ColSize } from './Col';

0 commit comments

Comments
 (0)