Skip to content

Commit

Permalink
feat: add addonAfter param the blockHeader component (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaoei committed Nov 9, 2022
1 parent 5daace3 commit 8780a46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/blockHeader/__tests__/blockHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const props2 = {
title: '标题2',
beforeTitle: <span>Icon</span>,
afterTitle: '说明文字',
addonAfter: <div className="test-button-after">新增按钮</div>,
isSmall: true,
titleRowClassName: 'test-row-className',
titleClassName: 'test-title-className',
Expand Down Expand Up @@ -54,6 +55,7 @@ describe('test BlockHeader render', () => {
expect(wrap.firstChild).toHaveClass(`test-row-className`);
expect(getByText('标题2')).toHaveClass('test-title-className');
expect(getByText('说明文字')).toHaveClass(`${prefixCls}-after-title`);
expect(getByText('新增按钮')).toHaveClass(`test-button-after`);
expect(getByText('Icon')).toBeTruthy();
});
test('should render BlockHeader test click event', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/blockHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface BlockHeaderProps {
afterTitle?: string | React.ReactNode;
// 默认展示为问号的toolip
tooltip?: React.ReactNode;
// 后缀自定义内容块
addonAfter?: React.ReactNode;
/**
* true 小标题 font-size: 12px; line-height: 32px
* false 大标题 font-size: 14px; line-height: 40px
Expand Down Expand Up @@ -40,6 +42,7 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
titleClassName = '',
showBackground = true,
defaultExpand = true,
addonAfter,
children = '',
onChange,
} = props;
Expand Down Expand Up @@ -74,7 +77,7 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
<div className={`${prefixCls}-after-title`}>{newAfterTitle}</div>
) : null}
</div>

{addonAfter && <div className={`${prefixCls}-addonAfter-box`}>{addonAfter}</div>}
{children && (
<div className={`${prefixCls}-collapse-box`}>
<div className="text">{expand ? '收起' : '展开'}</div>
Expand Down
3 changes: 3 additions & 0 deletions src/stories/blockHeader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ stories.add(
<p style={style}>8、简洁版</p>
<BlockHeader title="分类标题" beforeTitle="" />
<p style={style}>9、自定义后缀元素</p>
<BlockHeader title="分类标题" addonAfter={<Button type="primary" onClick={() => alert('触发了点击事件')} size="small">点击</Button>} />
~~~
`,
TableComponent: () => PropsTable({ propDefinitions }),
Expand Down
5 changes: 4 additions & 1 deletion src/stories/components/blockHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Tooltip } from 'antd';
import { Button, Tooltip } from 'antd';
import { DingdingOutlined, PieChartOutlined } from '@ant-design/icons';
import BlockHeader from '../../../components/blockHeader';

Expand Down Expand Up @@ -50,6 +50,9 @@ export default function BlockHeaderRender() {

<p style={style}>8、简洁版</p>
<BlockHeader title="分类标题" beforeTitle="" />

<p style={style}>9、自定义后缀元素</p>
<BlockHeader title="分类标题" addonAfter={<Button type="primary" onClick={() => alert('触发了点击事件')} size="small">点击</Button>} />
</React.Fragment>
);
}

0 comments on commit 8780a46

Please sign in to comment.