Skip to content
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

feat: Pageheader new style and props #19100

Merged
merged 14 commits into from Oct 15, 2019
3 changes: 3 additions & 0 deletions components/config-provider/context.ts
Expand Up @@ -14,6 +14,9 @@ export interface ConfigConsumerProps {
csp?: CSPConfig;
autoInsertSpaceInButton?: boolean;
locale?: Locale;
pageHeader?: {
type: 'ghost' | 'default';
};
}

export const ConfigContext = createReactContext<ConfigConsumerProps>({
Expand Down
1 change: 1 addition & 0 deletions components/config-provider/index.en-US.md
Expand Up @@ -43,3 +43,4 @@ Some component use dynamic style to support wave effect. You can config `csp` pr
| getPopupContainer | to set the container of the popup element. The default is to create a `div` element in `body`. | Function(triggerNode) | `() => document.body` | 3.11.0 |
| locale | language package setting, you can find the packages in [antd/es/locale](http://unpkg.com/antd/es/locale/) | object | 3.21.0 |
| prefixCls | set prefix class | string | ant | 3.12.0 |
| pageHeader | Unify the type of pageHeader ,Ref [pageHeader](<(/components/page-header)> | { type: 'ghost'\|'default' } | 'default' | 3.24.0 |
11 changes: 11 additions & 0 deletions components/config-provider/index.tsx
Expand Up @@ -18,6 +18,7 @@ export const configConsumerProps = [
'csp',
'autoInsertSpaceInButton',
'locale',
'pageHeader',
];

export interface ConfigProviderProps {
Expand All @@ -28,6 +29,9 @@ export interface ConfigProviderProps {
csp?: CSPConfig;
autoInsertSpaceInButton?: boolean;
locale?: Locale;
pageHeader?: {
type: 'ghost' | 'default';
};
}

class ConfigProvider extends React.Component<ConfigProviderProps> {
Expand All @@ -47,6 +51,7 @@ class ConfigProvider extends React.Component<ConfigProviderProps> {
csp,
autoInsertSpaceInButton,
locale,
pageHeader,
} = this.props;

const config: ConfigConsumerProps = {
Expand All @@ -63,6 +68,12 @@ class ConfigProvider extends React.Component<ConfigProviderProps> {
config.renderEmpty = renderEmpty;
}

// set pageHeader type
// 防止设置为 null 报错
chenshuai2144 marked this conversation as resolved.
Show resolved Hide resolved
if (pageHeader && pageHeader.type) {
config.pageHeader = pageHeader;
}

return (
<ConfigContext.Provider value={config}>
<LocaleProvider locale={locale || legacyLocale} _ANT_MARK__={ANT_MARK}>
Expand Down
1 change: 1 addition & 0 deletions components/config-provider/index.zh-CN.md
Expand Up @@ -44,3 +44,4 @@ return (
| getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode) | () => document.body | 3.11.0 |
| locale | 语言包配置,语言包可到 [antd/es/locale](http://unpkg.com/antd/es/locale/) 目录下寻找 | object | - | 3.21.0 |
| prefixCls | 设置统一样式前缀 | string | ant | 3.12.0 |
| pageHeader | 统一设置 pageHeader 的 type,参考 [pageHeader](<(/components/page-header)>) | { type: 'ghost' \| 'default' } | 'default' | 3.24.0 |
185 changes: 185 additions & 0 deletions components/page-header/__tests__/__snapshots__/demo.test.js.snap
Expand Up @@ -695,6 +695,191 @@ exports[`renders ./components/page-header/demo/content.md correctly 1`] = `
</div>
`;

exports[`renders ./components/page-header/demo/pure.md correctly 1`] = `
<div
style="background-color:#F5F5F5;padding:24px"
>
<div
class="ant-page-header ghost"
>
<div
class="ant-page-header-heading"
>
<div
class="ant-page-header-back"
>
<div
aria-label="Back"
class="ant-page-header-back-button"
role="button"
style="border:0;background:transparent;padding:0;line-height:inherit;display:inline-block"
tabindex="0"
>
<i
aria-label="icon: arrow-left"
class="anticon anticon-arrow-left"
>
<svg
aria-hidden="true"
class=""
data-icon="arrow-left"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M872 474H286.9l350.2-304c5.6-4.9 2.2-14-5.2-14h-88.5c-3.9 0-7.6 1.4-10.5 3.9L155 487.8a31.96 31.96 0 0 0 0 48.3L535.1 866c1.5 1.3 3.3 2 5.2 2h91.5c7.4 0 10.8-9.2 5.2-14L286.9 550H872c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z"
/>
</svg>
</i>
</div>
</div>
<span
class="ant-page-header-heading-title"
>
Title
</span>
<span
class="ant-page-header-heading-sub-title"
>
This is a subtitle
</span>
<span
class="ant-page-header-heading-extra"
>
<button
class="ant-btn"
type="button"
>
<span>
Operation
</span>
</button>
<button
class="ant-btn"
type="button"
>
<span>
Operation
</span>
</button>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Primary
</span>
</button>
</span>
</div>
<div
class="ant-page-header-content"
>
<div
class="ant-descriptions ant-descriptions-small"
>
<div
class="ant-descriptions-view"
>
<table>
<tbody>
<tr
class="ant-descriptions-row"
>
<td
class="ant-descriptions-item"
colspan="1"
>
<span
class="ant-descriptions-item-label ant-descriptions-item-colon"
>
Created
</span>
<span
class="ant-descriptions-item-content"
>
Lili Qu
</span>
</td>
<td
class="ant-descriptions-item"
colspan="1"
>
<span
class="ant-descriptions-item-label ant-descriptions-item-colon"
>
Association
</span>
<span
class="ant-descriptions-item-content"
>
<a>
421421
</a>
</span>
</td>
<td
class="ant-descriptions-item"
colspan="1"
>
<span
class="ant-descriptions-item-label ant-descriptions-item-colon"
>
Creation Time
</span>
<span
class="ant-descriptions-item-content"
>
2017-01-10
</span>
</td>
</tr>
<tr
class="ant-descriptions-row"
>
<td
class="ant-descriptions-item"
colspan="1"
>
<span
class="ant-descriptions-item-label ant-descriptions-item-colon"
>
Effective Time
</span>
<span
class="ant-descriptions-item-content"
>
2017-10-10
</span>
</td>
<td
class="ant-descriptions-item"
colspan="2"
>
<span
class="ant-descriptions-item-label ant-descriptions-item-colon"
>
Remarks
</span>
<span
class="ant-descriptions-item-content"
>
Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
`;

exports[`renders ./components/page-header/demo/responsive.md correctly 1`] = `
<div>
<div
Expand Down
2 changes: 1 addition & 1 deletion components/page-header/demo/actions.md
@@ -1,5 +1,5 @@
---
order: 4
order: 5
title:
zh-CN: 多种形态的 PageHeader
en-US: Various forms of PageHeader
Expand Down
2 changes: 1 addition & 1 deletion components/page-header/demo/breadcrumb.md
@@ -1,5 +1,5 @@
---
order: 2
order: 3
title:
zh-CN: 带面包屑页头
en-US: Use with breadcrumbs
Expand Down
8 changes: 1 addition & 7 deletions components/page-header/demo/content.md
@@ -1,5 +1,5 @@
---
order: 3
order: 4
title:
zh-CN: 组合示例
en-US: Complete example
Expand Down Expand Up @@ -169,9 +169,3 @@ ReactDOM.render(
mountNode,
);
```

<style>
.ant-page-header {
border: 1px solid rgb(235, 237, 240);
}
<style>
60 changes: 60 additions & 0 deletions components/page-header/demo/pure.md
@@ -0,0 +1,60 @@
---
order: 2
title:
zh-CN: 纯净模式,没有白底
en-US: Pure mode, no white background
---

## zh-CN

在某些情况下,pageHeader 不需要自己的背景颜色。
chenshuai2144 marked this conversation as resolved.
Show resolved Hide resolved

## en-US

In some cases, pageHeader does not require its own background color.

```jsx
import { PageHeader, Button, Descriptions } from 'antd';

ReactDOM.render(
<div
style={{
backgroundColor: '#F5F5F5',
padding: 24,
}}
>
<PageHeader
type="ghost"
onBack={() => window.history.back()}
title="Title"
subTitle="This is a subtitle"
extra={[
<Button key="3">Operation</Button>,
<Button key="2">Operation</Button>,
<Button key="1" type="primary">
Primary
</Button>,
]}
>
<Descriptions size="small" column={3}>
<Descriptions.Item label="Created">Lili Qu</Descriptions.Item>
<Descriptions.Item label="Association">
<a>421421</a>
</Descriptions.Item>
<Descriptions.Item label="Creation Time">2017-01-10</Descriptions.Item>
<Descriptions.Item label="Effective Time">2017-10-10</Descriptions.Item>
<Descriptions.Item label="Remarks">
Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
</Descriptions.Item>
</Descriptions>
</PageHeader>
</div>,
mountNode,
);
```

<style>
#components-page-header-demo-pure .code-box-demo .ant-page-header {
border: 1px solid #ebedf0;
chenshuai2144 marked this conversation as resolved.
Show resolved Hide resolved
}
</style>
4 changes: 2 additions & 2 deletions components/page-header/demo/responsive.md
@@ -1,6 +1,6 @@
---
order: 4
iframe: 240
order: 6
iframe: 210
title:
zh-CN: 响应式
en-US: responsive
Expand Down
1 change: 1 addition & 0 deletions components/page-header/index.en-US.md
Expand Up @@ -18,6 +18,7 @@ It can also be used as inter-page navigation when it is needed to make the user
| --- | --- | --- | --- | --- |
| title | custom title text | ReactNode | - | 3.14.0 |
| subTitle | custom subTitle text | ReactNode | - | 3.14.0 |
| type | pageHeader type, will change background color | `'default' | 'ghost'` | 'default' | 3.24.0 |
| avatar | Avatar next to the title bar | [avatar props](/components/avatar/) | - | 3.22.0 |
| backIcon | custom back icon, if false the back icon will not be displayed | ReactNode | `<Icon type="arrow-left" />` | 3.14.0 |
| tags | Tag list next to title | [Tag](https://ant.design/components/tag-cn/)[] \| [Tag](https://ant.design/components/tag-cn/) | - | 3.14.0 |
Expand Down
6 changes: 5 additions & 1 deletion components/page-header/index.tsx
Expand Up @@ -22,6 +22,7 @@ export interface PageHeaderProps {
avatar?: AvatarProps;
onBack?: (e: React.MouseEvent<HTMLDivElement>) => void;
className?: string;
type?: 'ghost' | 'default';
}

const renderBack = (
Expand Down Expand Up @@ -89,12 +90,13 @@ const renderChildren = (prefixCls: string, children: React.ReactNode) => {

const PageHeader: React.SFC<PageHeaderProps> = props => (
<ConfigConsumer>
{({ getPrefixCls }: ConfigConsumerProps) => {
{({ getPrefixCls, pageHeader = { type: 'default' } }: ConfigConsumerProps) => {
const {
prefixCls: customizePrefixCls,
style,
footer,
children,
type,
breadcrumb,
className: customizeClassName,
} = props;
Expand All @@ -104,6 +106,8 @@ const PageHeader: React.SFC<PageHeaderProps> = props => (
const className = classnames(prefixCls, customizeClassName, {
'has-breadcrumb': breadcrumbDom,
'has-footer': footer,
// 防止设置为 null 报错
ghost: type === 'ghost' || (pageHeader && pageHeader.type === 'ghost'),
});

return (
Expand Down
1 change: 1 addition & 0 deletions components/page-header/index.zh-CN.md
Expand Up @@ -18,6 +18,7 @@ subtitle: 页头
| --- | --- | --- | --- | --- |
| title | 自定义标题文字 | ReactNode | - | 3.14.0 |
| subTitle | 自定义的二级标题文字 | ReactNode | - | 3.14.0 |
| type | pageHeader 的类型,将会改变背景颜色 | `'default' | 'ghost'` | 'default' | 3.24.0 |
| avatar | 标题栏旁的头像 | [avatar props](/components/avatar/) | - | 3.22.0 |
| backIcon | 自定义 back icon ,如果为 false 不渲染 back icon | ReactNode | `<Icon type="arrow-left" />` | 3.14.0 |
| tags | title 旁的 tag 列表 | [Tag](https://ant.design/components/tag-cn/)[] \| [Tag](https://ant.design/components/tag-cn/) | - | 3.14.0 |
Expand Down