Skip to content

Commit de77b01

Browse files
authored
refactor:list (#6241)
* refactor:list * fix inheritAttrs: false & attrs.class
1 parent 26f98b7 commit de77b01

File tree

9 files changed

+377
-505
lines changed

9 files changed

+377
-505
lines changed

components/list/index.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { App, Plugin, ExtractPropTypes, PropType, HTMLAttributes } from 'vue';
22
import { provide, defineComponent, ref, watch, computed, toRef } from 'vue';
33
import PropTypes from '../_util/vue-types';
4+
import classNames from '../_util/classNames';
45

56
import type { SpinProps } from '../spin';
67
import Spin from '../spin';
@@ -19,6 +20,9 @@ import type { Breakpoint } from '../_util/responsiveObserve';
1920
import { responsiveArray } from '../_util/responsiveObserve';
2021
import eagerComputed from '../_util/eagerComputed';
2122

23+
// CSSINJS
24+
import useStyle from './style';
25+
2226
export type { ListItemProps } from './Item';
2327
export type { ListItemMetaProps } from './ItemMeta';
2428

@@ -79,6 +83,7 @@ import type { RenderEmptyHandler } from '../config-provider/renderEmpty';
7983
const List = defineComponent({
8084
compatConfig: { MODE: 3 },
8185
name: 'AList',
86+
inheritAttrs: false,
8287
Item,
8388
props: initDefaultProps(listProps(), {
8489
dataSource: [],
@@ -88,7 +93,7 @@ const List = defineComponent({
8893
pagination: false,
8994
}),
9095
slots: ['extra', 'loadMore', 'renderItem', 'header', 'footer'],
91-
setup(props, { slots }) {
96+
setup(props, { slots, attrs }) {
9297
provide(ListContextKey, {
9398
grid: toRef(props, 'grid'),
9499
itemLayout: toRef(props, 'itemLayout'),
@@ -98,6 +103,10 @@ const List = defineComponent({
98103
total: 0,
99104
};
100105
const { prefixCls, direction, renderEmpty } = useConfigInject('list', props);
106+
107+
// Style
108+
const [wrapSSR, hashId] = useStyle(prefixCls);
109+
101110
const paginationObj = computed(() =>
102111
props.pagination && typeof props.pagination === 'object' ? props.pagination : {},
103112
);
@@ -260,10 +269,14 @@ const List = defineComponent({
260269
const header = props.header ?? slots.header?.();
261270
const children = flattenChildren(slots.default?.());
262271
const isSomethingAfterLastItem = !!(loadMore || props.pagination || footer);
263-
const classString = {
264-
...classObj.value,
265-
[`${prefixCls.value}-something-after-last-item`]: isSomethingAfterLastItem,
266-
};
272+
const classString = classNames(
273+
{
274+
...classObj.value,
275+
[`${prefixCls.value}-something-after-last-item`]: isSomethingAfterLastItem,
276+
},
277+
attrs.class,
278+
hashId.value,
279+
);
267280
const paginationContent = props.pagination ? (
268281
<div class={`${prefixCls.value}-pagination`}>
269282
<Pagination
@@ -295,8 +308,8 @@ const List = defineComponent({
295308
}
296309

297310
const paginationPosition = paginationProps.value.position || 'bottom';
298-
return (
299-
<div class={classString}>
311+
return wrapSSR(
312+
<div {...attrs} class={classString}>
300313
{(paginationPosition === 'top' || paginationPosition === 'both') && paginationContent}
301314
{header && <div class={`${prefixCls.value}-header`}>{header}</div>}
302315
<Spin {...loadingProp.value}>
@@ -307,7 +320,7 @@ const List = defineComponent({
307320
{loadMore ||
308321
((paginationPosition === 'bottom' || paginationPosition === 'both') &&
309322
paginationContent)}
310-
</div>
323+
</div>,
311324
);
312325
};
313326
},

components/list/style/bordered.less

Lines changed: 0 additions & 44 deletions
This file was deleted.

components/list/style/customize.less

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/list/style/index.less

Lines changed: 0 additions & 249 deletions
This file was deleted.

0 commit comments

Comments
 (0)