Skip to content

fix(blockheader): support different size to show different custom icon size #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 31, 2024
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 @@ -15,10 +15,10 @@ exports[`test BlockHeader render should render BlockHeader success render 1`] =
class="title__box"
>
<div
class="title__addon-before"
class="title__addon-before title__addon-before--middle"
>
<div
class="title__addon-before--middle"
class="addon-before--default"
/>
</div>
<div
Expand All @@ -42,10 +42,10 @@ exports[`test BlockHeader render should render BlockHeader success render 1`] =
class="title__box"
>
<div
class="title__addon-before"
class="title__addon-before title__addon-before--middle"
>
<div
class="title__addon-before--middle"
class="addon-before--default"
/>
</div>
<div
Expand Down
12 changes: 4 additions & 8 deletions src/blockHeader/demos/addonBefore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ export default () => {
<>
<BlockHeader title="分类标题" />
<br />
<BlockHeader
title="分类标题"
addonBefore={<PieChartOutlined style={{ fontSize: '14px' }} />}
/>
<BlockHeader title="分类标题" addonBefore={''} />
<br />
<BlockHeader
title="分类标题"
addonBefore={<PauseCircleOutlined style={{ fontSize: '14px' }} />}
/>
<BlockHeader title="分类标题" addonBefore={<PieChartOutlined />} />
<br />
<BlockHeader title="分类标题" addonBefore={<PauseCircleOutlined />} />
</>
);
};
10 changes: 10 additions & 0 deletions src/blockHeader/demos/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import { PieChartOutlined } from '@ant-design/icons';
import { Radio, Space, Switch } from 'antd';
import { BlockHeader } from 'dt-react-component';
import { SizeType } from 'dt-react-component/blockHeader';
Expand Down Expand Up @@ -40,6 +41,15 @@ export default () => {
</Space>
<br />
<br />
<BlockHeader
size={size}
title="分类标题"
hasBottom
addonBefore={<PieChartOutlined />}
background={showBackground}
tooltip={tooltip ? '这里展示问号提示' : ''}
description={description ? '提示说明文字' : ''}
/>
<BlockHeader
size={size}
title="分类标题"
Expand Down
32 changes: 16 additions & 16 deletions src/blockHeader/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ demo:
## 示例

<code src="./demos/basic.tsx" description="配置大小、tooltip、描述">基础使用</code>
<code src="./demos/addonBefore.tsx" description="通过 `addonBefore` 可以设置标题前的图标,不设置时默认是一个色块">自定义 icon</code>
<code src="./demos/addonBefore.tsx" description="通过 `addonBefore` 可以设置标题前的图标,不设置时默认是一个色块,设置为假值(`undefined` 除外)不展示图标">自定义 icon</code>
<code src="./demos/addonAfter.tsx" description="通过 `addonAfter` 可以设置后缀自定义内容块">带提示信息的标题</code>
<code src="./demos/expand.tsx" description="若存在 `children` 则支持展开">展开/收起内容</code>

## API

### BlockHeader

| 参数 | 说明 | 类型 | 默认值 |
| ----------------- | ---------------------------------- | --------------------------- | -------- |
| title | 标题 | `string` | - |
| addonBefore | 标题前的图标,默认是一个色块 | `React.ReactNode` | - |
| description | 标题提示文案 | `React.ReactNode` | - |
| tooltip | 默认展示问号提示 | `TooltipProps \| TooltipProps['title']` | - |
| addonAfter | 标题后的内容 | `React.ReactNode` | - |
| size | 小标题、中标题,默认为中标题 | `small \| middle \| large` | `middle` |
| 参数 | 说明 | 类型 | 默认值 |
| ------------- | ---------------------------------- | --------------------------------------- | -------- |
| title | 标题 | `string` | - |
| addonBefore | 标题前的图标,默认是一个色块 | `React.ReactNode` | - |
| description | 标题提示文案 | `React.ReactNode` | - |
| tooltip | 默认展示问号提示 | `TooltipProps \| TooltipProps['title']` | - |
| addonAfter | 标题后的内容 | `React.ReactNode` | - |
| size | 小标题、中标题,默认为中标题 | `small \| middle \| large` | `middle` |
| className | 标题一行的样式类名 | `string` | - |
| style | 标题的样式 | `React.CSSProperties` | - |
| background | 是否显示背景 | `boolean` | `true` |
| expand | 当前展开状态 | `boolean` | |
| defaultExpand | 是否默认展开内容 | `boolean` | `true` |
| hasBottom | 是否有默认下边距 16px | `boolean` | `false` |
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `0` |
| children | 展开/收起的内容 | `React.ReactNode` | - |
| onExpand | 展开/收起时的回调 | `(expand: boolean) => void` | - |
| background | 是否显示背景 | `boolean` | `true` |
| expand | 当前展开状态 | `boolean` | |
| defaultExpand | 是否默认展开内容 | `boolean` | `true` |
| hasBottom | 是否有默认下边距 16px | `boolean` | `false` |
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `0` |
| children | 展开/收起的内容 | `React.ReactNode` | - |
| onExpand | 展开/收起时的回调 | `(expand: boolean) => void` | - |
8 changes: 6 additions & 2 deletions src/blockHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
addonAfter,
expand,
children = '',
addonBefore = <div className={`title__addon-before--${size}`} />,
addonBefore = <div className="addon-before--default" />,
onExpand,
} = props;

Expand Down Expand Up @@ -98,7 +98,11 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
onClick={() => handleExpand(!currentExpand)}
>
<div className="title__box">
{addonBefore ? <div className="title__addon-before">{addonBefore}</div> : null}
{addonBefore ? (
<div className={`title__addon-before title__addon-before--${size}`}>
{addonBefore}
</div>
) : null}
<div className="title__text">{title}</div>
{tooltipProps?.title ? (
<div className={`title__tooltip`}>
Expand Down
27 changes: 20 additions & 7 deletions src/blockHeader/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,29 @@ $card_prefix: "dtc-block-header";
&__addon-before {
margin-right: 8px;
color: #1D78FF;
&--middle,
&--middle {
.addon-before--default {
width: 4px;
height: 16px;
background-color: #1D78FF;
}
font-size: 20px;
}
&--small {
width: 4px;
height: 16px;
background-color: #1D78FF;
.addon-before--default {
width: 4px;
height: 16px;
background-color: #1D78FF;
}
font-size: 16px;
}
&--large {
width: 4px;
height: 20px;
background-color: #1D78FF;
.addon-before--default {
width: 4px;
height: 20px;
background-color: #1D78FF;
}
font-size: 24px;
}
}
&__tooltip {
Expand Down
Loading