Skip to content

Commit

Permalink
refactor:list (#6241)
Browse files Browse the repository at this point in the history
* refactor:list

* fix inheritAttrs: false & attrs.class
  • Loading branch information
shifeng1993 authored Feb 8, 2023
1 parent 26f98b7 commit de77b01
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 505 deletions.
29 changes: 21 additions & 8 deletions components/list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { App, Plugin, ExtractPropTypes, PropType, HTMLAttributes } from 'vue';
import { provide, defineComponent, ref, watch, computed, toRef } from 'vue';
import PropTypes from '../_util/vue-types';
import classNames from '../_util/classNames';

import type { SpinProps } from '../spin';
import Spin from '../spin';
Expand All @@ -19,6 +20,9 @@ import type { Breakpoint } from '../_util/responsiveObserve';
import { responsiveArray } from '../_util/responsiveObserve';
import eagerComputed from '../_util/eagerComputed';

// CSSINJS
import useStyle from './style';

export type { ListItemProps } from './Item';
export type { ListItemMetaProps } from './ItemMeta';

Expand Down Expand Up @@ -79,6 +83,7 @@ import type { RenderEmptyHandler } from '../config-provider/renderEmpty';
const List = defineComponent({
compatConfig: { MODE: 3 },
name: 'AList',
inheritAttrs: false,
Item,
props: initDefaultProps(listProps(), {
dataSource: [],
Expand All @@ -88,7 +93,7 @@ const List = defineComponent({
pagination: false,
}),
slots: ['extra', 'loadMore', 'renderItem', 'header', 'footer'],
setup(props, { slots }) {
setup(props, { slots, attrs }) {
provide(ListContextKey, {
grid: toRef(props, 'grid'),
itemLayout: toRef(props, 'itemLayout'),
Expand All @@ -98,6 +103,10 @@ const List = defineComponent({
total: 0,
};
const { prefixCls, direction, renderEmpty } = useConfigInject('list', props);

// Style
const [wrapSSR, hashId] = useStyle(prefixCls);

const paginationObj = computed(() =>
props.pagination && typeof props.pagination === 'object' ? props.pagination : {},
);
Expand Down Expand Up @@ -260,10 +269,14 @@ const List = defineComponent({
const header = props.header ?? slots.header?.();
const children = flattenChildren(slots.default?.());
const isSomethingAfterLastItem = !!(loadMore || props.pagination || footer);
const classString = {
...classObj.value,
[`${prefixCls.value}-something-after-last-item`]: isSomethingAfterLastItem,
};
const classString = classNames(
{
...classObj.value,
[`${prefixCls.value}-something-after-last-item`]: isSomethingAfterLastItem,
},
attrs.class,
hashId.value,
);
const paginationContent = props.pagination ? (
<div class={`${prefixCls.value}-pagination`}>
<Pagination
Expand Down Expand Up @@ -295,8 +308,8 @@ const List = defineComponent({
}

const paginationPosition = paginationProps.value.position || 'bottom';
return (
<div class={classString}>
return wrapSSR(
<div {...attrs} class={classString}>
{(paginationPosition === 'top' || paginationPosition === 'both') && paginationContent}
{header && <div class={`${prefixCls.value}-header`}>{header}</div>}
<Spin {...loadingProp.value}>
Expand All @@ -307,7 +320,7 @@ const List = defineComponent({
{loadMore ||
((paginationPosition === 'bottom' || paginationPosition === 'both') &&
paginationContent)}
</div>
</div>,
);
};
},
Expand Down
44 changes: 0 additions & 44 deletions components/list/style/bordered.less

This file was deleted.

13 changes: 0 additions & 13 deletions components/list/style/customize.less

This file was deleted.

249 changes: 0 additions & 249 deletions components/list/style/index.less

This file was deleted.

Loading

0 comments on commit de77b01

Please sign in to comment.