Skip to content

Commit

Permalink
feat(list): list support using the componentSize configuration size f…
Browse files Browse the repository at this point in the history
…rom ConfigProvider (ant-design#44267)

* feat(list): list support using the componentSize configuration size from ConfigProvider

* chore: update snapshot
  • Loading branch information
Yuiai01 authored Aug 17, 2023
1 parent 030f385 commit 2e18b63
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17472,7 +17472,7 @@ exports[`ConfigProvider components List configProvider componentDisabled 1`] = `

exports[`ConfigProvider components List configProvider componentSize large 1`] = `
<div
class="config-list config-list-split"
class="config-list config-list-lg config-list-split"
>
<div
class="config-spin-nested-loading"
Expand Down Expand Up @@ -17576,7 +17576,7 @@ exports[`ConfigProvider components List configProvider componentSize middle 1`]

exports[`ConfigProvider components List configProvider componentSize small 1`] = `
<div
class="config-list config-list-split"
class="config-list config-list-sm config-list-split"
>
<div
class="config-spin-nested-loading"
Expand Down
17 changes: 17 additions & 0 deletions components/list/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import type { ListProps } from '..';
import List from '..';
import ConfigProvider from '../../config-provider';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render } from '../../../tests/utils';
Expand All @@ -22,4 +23,20 @@ describe('List', () => {
);
expect(container.querySelector('div.ant-list')?.getAttribute('locale')).toBe(null);
});

it('should apply the componentSize of ConfigProvider', () => {
const { container } = render(
<>
<ConfigProvider componentSize="small">
<List />,
</ConfigProvider>
<ConfigProvider componentSize="large">
<List />,
</ConfigProvider>
</>,
);

expect(container.querySelector('.ant-list-sm')).toBeTruthy();
expect(container.querySelector('.ant-list-lg')).toBeTruthy();
});
});
7 changes: 5 additions & 2 deletions components/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Item from './Item';
// CSSINJS
import { ListContext } from './context';
import useStyle from './style';
import useSize from '../config-provider/hooks/useSize';

export type { ListItemMetaProps, ListItemProps } from './Item';
export type { ListConsumerProps } from './context';
Expand Down Expand Up @@ -83,7 +84,7 @@ function List<T>({
loadMore,
grid,
dataSource = [],
size,
size: customizeSize,
header,
footer,
loading = false,
Expand Down Expand Up @@ -154,10 +155,12 @@ function List<T>({
}
const isLoading = loadingProp && loadingProp.spinning;

const mergedSize = useSize(customizeSize);

// large => lg
// small => sm
let sizeCls = '';
switch (size) {
switch (mergedSize) {
case 'large':
sizeCls = 'lg';
break;
Expand Down

0 comments on commit 2e18b63

Please sign in to comment.