Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports[`test BlockHeader render should render BlockHeader success render 1`] =
<div>
<div
class="dtc-block-header"
style="margin-bottom: 16px;"
>
<div
class="dtc-block-header__title dtc-block-header__title--middle dtc-block-header__title--background"
Expand Down Expand Up @@ -34,6 +35,7 @@ exports[`test BlockHeader render should render BlockHeader success render 1`] =
"container": <div>
<div
class="dtc-block-header"
style="margin-bottom: 16px;"
>
<div
class="dtc-block-header__title dtc-block-header__title--middle dtc-block-header__title--background"
Expand Down
7 changes: 3 additions & 4 deletions src/blockHeader/__tests__/blockHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
size: 'small' as SizeType,
className: 'test__className',
style: { height: '100px' },
hasBottom: true,
};
const props3: IBlockHeaderProps = {
title: 'hover',
Expand Down Expand Up @@ -45,7 +44,7 @@
test('should render BlockHeader props default in BlockHeader', () => {
const { container } = render(<BlockHeader title="测试" background />);
const wrap = container.firstChild;
expect(wrap!.firstChild!.firstChild!.firstChild).toHaveClass('title__addon-before');

Check warning on line 47 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion

Check warning on line 47 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion

Check warning on line 47 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion
fireEvent.click(document.getElementsByClassName(`${prefixCls}__title`)[0]);
});
test('should render BlockHeader test click event', () => {
Expand Down Expand Up @@ -83,11 +82,11 @@
const props = { title: '测试1', background: false };
const { container } = render(<BlockHeader {...props} />);
const wrap = container.firstChild;
expect(wrap!.firstChild).not.toHaveClass(`dtc-block-header__title--background`);

Check warning on line 85 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion
});
test('should render BlockHeader className when size is small', () => {
const { container, getByText } = render(<BlockHeader {...props2} />);
const wrap = container.firstChild!;

Check warning on line 89 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion
expect(wrap).toHaveClass(`${prefixCls} test__className`);
expect(wrap.firstChild).toHaveClass(
`dtc-block-header__title dtc-block-header__title--small dtc-block-header__title--background`
Expand All @@ -99,14 +98,14 @@

test('should render BlockHeader tooltip success', () => {
const { container } = render(<BlockHeader {...props3} />);
const wrap = container.firstChild!;

Check warning on line 101 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion
const tooltipWrap = wrap.firstChild!.firstChild!.lastChild;

Check warning on line 102 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion

Check warning on line 102 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion
expect(tooltipWrap!.firstChild).toHaveClass('anticon-question-circle');

Check warning on line 103 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion
});

test('should render BlockHeader description success', () => {
const { container } = render(<BlockHeader {...props4} />);
const wrap = container.firstChild!;

Check warning on line 108 in src/blockHeader/__tests__/blockHeader.test.tsx

View workflow job for this annotation

GitHub Actions / setup

Forbidden non-null assertion
const description = wrap.firstChild!.firstChild!.lastChild;
expect(description).toHaveTextContent('说明文字');
});
Expand All @@ -124,14 +123,14 @@
});

test('should render BlockHeader correct margin-bottom', () => {
const { container: noStyle } = render(<BlockHeader title="分类级别" addonBefore="" />);
expect(noStyle.querySelector('.dtc-block-header')).not.toHaveAttribute('style');
const { container: haveStyle } = render(<BlockHeader title="分类级别" addonBefore="" />);
expect(haveStyle.querySelector('.dtc-block-header')).toHaveAttribute('style');
const { container: defaultBottom } = render(
<BlockHeader title="分类级别" addonBefore="" />
);
expect(defaultBottom.querySelector('.dtc-block-header')).toHaveStyle({ marginBottom: 16 });
const { container: customizeBottom } = render(
<BlockHeader title="分类级别" addonBefore="" hasBottom spaceBottom={10} />
<BlockHeader title="分类级别" addonBefore="" spaceBottom={10} />
);
expect(customizeBottom.querySelector('.dtc-block-header')).toHaveStyle({
marginBottom: 10,
Expand Down
3 changes: 0 additions & 3 deletions src/blockHeader/demos/addonBefore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ export default () => {
return (
<>
<BlockHeader title="分类标题" />
<br />
<BlockHeader title="分类标题" addonBefore={''} />
<br />
<BlockHeader title="分类标题" addonBefore={<PieChartOutlined />} />
<br />
<BlockHeader title="分类标题" addonBefore={<PauseCircleOutlined />} />
</>
);
Expand Down
1 change: 0 additions & 1 deletion src/blockHeader/demos/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default () => {
<BlockHeader
size={size}
title="分类标题"
hasBottom
addonBefore={<PieChartOutlined />}
background={showBackground}
tooltip={tooltip ? '这里展示问号提示' : ''}
Expand Down
3 changes: 1 addition & 2 deletions src/blockHeader/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ demo:
| background | 是否显示背景 | `boolean` | `true` |
| expand | 当前展开状态 | `boolean` | |
| defaultExpand | 是否默认展开内容 | `boolean` | `true` |
| hasBottom | 是否有默认下边距 16px | `boolean` | `false` |
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `0` |
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `16` |
| children | 展开/收起的内容 | `React.ReactNode` | - |
| onExpand | 展开/收起时的回调 | `(expand: boolean) => void` | - |
6 changes: 1 addition & 5 deletions src/blockHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface IBlockHeaderProps {
* 默认 中标题
*/
size?: SizeType;
/** 是否展示 Bottom,默认 false,Bottom 值 16px */
hasBottom?: boolean;
/** 自定义 Bottom 值 */
spaceBottom?: number;
/** 标题一行的样式类名 */
Expand Down Expand Up @@ -59,8 +57,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
description = '',
tooltip,
size = 'middle',
hasBottom = false,
spaceBottom = 0,
spaceBottom = 16,
className = '',
style = {},
background = true,
Expand All @@ -79,7 +76,6 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
const tooltipProps = toTooltipProps(tooltip);

let bottomStyle;
if (hasBottom) bottomStyle = { marginBottom: 16 };
if (spaceBottom) bottomStyle = { marginBottom: spaceBottom };

const handleExpand = (expand: boolean) => {
Expand Down