Skip to content

Commit

Permalink
feat: update blockHeader margin-bottom (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyFBB committed Dec 30, 2022
1 parent e7bb941 commit 2962911
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/components/blockHeader/__tests__/blockHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,18 @@ describe('test BlockHeader render', () => {
const titleBoxWrap1 = container1.firstChild.firstChild.firstChild;
expect(titleBoxWrap1.childNodes.length).toEqual(3);
});
test('should render BlockHeader correct margin-bottom', () => {
const { container: noStyle } = render(<BlockHeader title="分类级别" beforeTitle="" />);
expect(noStyle.querySelector('.dtc-block-header')).not.toHaveAttribute('style');
const { container: defaultBottom } = render(
<BlockHeader title="分类级别" beforeTitle="" />
);
expect(defaultBottom.querySelector('.dtc-block-header')).toHaveStyle({ marginBottom: 16 });
const { container: customizeBottom } = render(
<BlockHeader title="分类级别" beforeTitle="" hasBottom spaceBottom={10} />
);
expect(customizeBottom.querySelector('.dtc-block-header')).toHaveStyle({
marginBottom: 10,
});
});
});
9 changes: 8 additions & 1 deletion src/components/blockHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface BlockHeaderProps {
* 默认 false
*/
isSmall?: boolean;
hasBottom?: boolean;
spaceBottom?: number;
// 标题一行的样式类名
titleRowClassName?: string;
// 标题的样式类名
Expand All @@ -38,6 +40,8 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
afterTitle = '',
tooltip = '',
isSmall = false,
hasBottom = false,
spaceBottom = 0,
titleRowClassName = '',
titleClassName = '',
showBackground = true,
Expand All @@ -53,6 +57,9 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
</Tooltip>
);
const newAfterTitle = afterTitle || questionTooltip;
let bottomStyle;
if (hasBottom) bottomStyle = { marginBottom: 16 };
if (spaceBottom) bottomStyle = { marginBottom: spaceBottom };
const [expand, setExpand] = useState(defaultExpand);

const handleExpand = (expand) => {
Expand All @@ -61,7 +68,7 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
onChange?.(expand);
};
return (
<div className={`${prefixCls}`}>
<div className={`${prefixCls}`} style={bottomStyle}>
<div
className={`${prefixCls}-title-row ${isSmall ? 'small' : 'default'} ${
showBackground ? 'background' : ''
Expand Down
14 changes: 14 additions & 0 deletions src/stories/blockHeader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ const propDefinitions = [
description: '是否默认展开内容',
defaultValue: 'true',
},
{
property: 'hasBottom',
propType: 'boolean',
required: false,
description: '是否有默认下边距16px',
defaultValue: 'false',
},
{
property: 'spaceBottom',
propType: 'number',
required: false,
description: '自定义下边距,优先级高于 hasBottom',
defaultValue: 0,
},
{
property: 'children',
propType: 'React.ReactNode',
Expand Down

0 comments on commit 2962911

Please sign in to comment.