Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
feat: 增加 header 高度自定义 API (#590)
Browse files Browse the repository at this point in the history
* fix: 增加自定义header 样式

* fix: 修复top 模式下的height 处理问题

* fix: 修复top 模式下的height 处理问题

* doc: 完善API 文档

* fix: 删除example 中的一些配置

* fix: 放弃了自定义颜色的需求

* fix: code review issue
  • Loading branch information
WynterDing authored Jul 27, 2020
1 parent 28fa344 commit 9cc5182
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ProLayout 提供了丰富的 API 来自定义各种行为,我们可以在下
| splitMenus | 是否自动切分 menuData,只有 mix 模式会生效 | boolean | false |
| contentWidth | layout 的内容模式,Fluid:定宽 1200px,Fixed:自适应 | 'Fluid' \| 'Fixed' | `'Fluid'` |
| navTheme | 导航的主题 | 'light' \| 'dark' | `'dark'` |
| headerHeight | header 自定义高度 | number | 48 |
| fixedHeader | 是否固定 header 到顶部 | boolean | `false` |
| fixSiderbar | 是否固定导航 | boolean | `false` |
| breakpoint | 触发响应式布局的[断点](https://ant.design/components/grid-cn/#Col) | `Enum { 'xs', 'sm', 'md', 'lg', 'xl', 'xxl' }` | `lg` |
Expand Down
1 change: 1 addition & 0 deletions example/config/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export default {
title: 'Ant Design Pro',
pwa: false,
iconfontUrl: '',
headerHeight: 64,
} as Settings;
2 changes: 0 additions & 2 deletions example/src/components/RightContent/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
.right {
display: flex;
float: right;
height: 48px;
margin-left: auto;
overflow: hidden;
.action {
display: flex;
align-items: center;
height: 48px;
padding: 0 12px;
cursor: pointer;
transition: all 0.3s;
Expand Down
5 changes: 2 additions & 3 deletions src/GlobalHeader/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
position: relative;
display: flex;
align-items: center;
height: @pro-layout-header-height;
height: 100%;
padding: 0 16px;
background: @pro-layout-header-bg;
box-shadow: @pro-layout-header-box-shadow;
Expand Down Expand Up @@ -43,11 +43,10 @@
&-logo {
position: relative;
overflow: hidden;
line-height: @pro-layout-header-height;
a {
display: flex;
align-items: center;
height: @pro-layout-header-height;
height: 100%;
img {
height: 28px;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GlobalHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class GlobalHeader extends Component<GlobalHeaderProps> {
children,
splitMenus,
menuData,
prefixCls,
prefixCls
} = this.props;
const baseClassName = `${prefixCls}-global-header`;
const className = classNames(propClassName, baseClassName, {
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class GlobalHeader extends Component<GlobalHeaderProps> {
);

return (
<div className={className} style={style}>
<div className={className} style={{ ...style }}>
{isMobile && renderLogo(menuHeaderRender, logoDom)}
{isMobile && collapsedButtonRender && (
<span
Expand Down
9 changes: 5 additions & 4 deletions src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class HeaderView extends Component<HeaderViewProps, HeaderViewState> {
headerRender,
isMobile,
prefixCls,
headerHeight
} = this.props;
const needFixedHeader = fixedHeader || layout === 'mix';
const isTop = layout === 'top';
Expand Down Expand Up @@ -105,17 +106,17 @@ class HeaderView extends Component<HeaderViewProps, HeaderViewState> {
{needFixedHeader && (
<Header
style={{
height: 48,
lineHeight: '48px',
height: headerHeight,
lineHeight: `${headerHeight}px`,
background: 'transparent',
}}
/>
)}
<Header
style={{
padding: 0,
height: 48,
lineHeight: '48px',
height: headerHeight,
lineHeight: `${headerHeight}px`,
width,
zIndex: layout === 'mix' ? 100 : 9,
right,
Expand Down
2 changes: 2 additions & 0 deletions src/SiderMenu/SiderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const SiderMenu: React.FC<SiderMenuProps> = (props) => {
menuContentRender,
prefixCls = 'ant-pro',
onOpenChange,
headerHeight
} = props;
const baseClassName = `${prefixCls}-sider`;
const { flatMenuKeys } = MenuCounter.useContainer();
Expand Down Expand Up @@ -153,6 +154,7 @@ const SiderMenu: React.FC<SiderMenuProps> = (props) => {
collapsedWidth={48}
style={{
overflow: 'hidden',
paddingTop: layout === 'mix' ? headerHeight : undefined,
...style,
}}
width={siderWidth}
Expand Down
8 changes: 2 additions & 6 deletions src/SiderMenu/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
}
}

&-layout-mix {
padding-top: 48px;
}

.@{ant-prefix}-menu-inline-collapsed
> .@{ant-prefix}-menu-item
.anticon
Expand Down Expand Up @@ -254,8 +250,8 @@
}

.top-nav-menu li.@{ant-prefix}-menu-item {
height: @nav-header-height;
line-height: @nav-header-height;
height: 100%;
line-height: 1;
}
.drawer .drawer-content {
background: @layout-sider-background;
Expand Down
3 changes: 2 additions & 1 deletion src/SiderMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SiderMenuWrapper: React.FC<SiderMenuProps> = (props) => {
style,
className,
hide,
prefixCls,
prefixCls
} = props;
const { setFlatMenuKeys } = MenuCounter.useContainer();

Expand Down Expand Up @@ -49,6 +49,7 @@ const SiderMenuWrapper: React.FC<SiderMenuProps> = (props) => {
if (hide) {
return null;
}

return isMobile ? (
<Drawer
visible={!collapsed}
Expand Down
11 changes: 4 additions & 7 deletions src/TopNavHeader/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.@{top-nav-header-prefix-cls} {
position: relative;
width: 100%;
height: @pro-layout-header-height;
height: 100%;
box-shadow: 0 1px 4px 0 rgba(0, 21, 41, 0.12);
transition: background 0.3s, width 0.2s;

Expand All @@ -19,7 +19,6 @@

.@{ant-prefix}-menu-submenu.@{ant-prefix}-menu-submenu-horizontal {
height: 100%;
line-height: @pro-layout-header-height;
.@{ant-prefix}-menu-submenu-title {
height: 100%;
}
Expand All @@ -39,7 +38,7 @@

&-main {
display: flex;
height: @pro-layout-header-height;
height: 100%;
padding-left: 16px;
&-left {
display: flex;
Expand All @@ -54,9 +53,8 @@
&-logo {
position: relative;
min-width: 165px;
height: @pro-layout-header-height;
height: 100%;
overflow: hidden;
line-height: @pro-layout-header-height;
transition: all 0.3s;
img {
display: inline-block;
Expand All @@ -75,8 +73,7 @@
&-menu {
min-width: 0;
.@{ant-prefix}-menu.@{ant-prefix}-menu-horizontal {
height: @pro-layout-header-height;
line-height: @pro-layout-header-height;
height: 100%;
border: none;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ export interface PureSettings {
/**
* nav menu position: `side` or `top`
*/
headerHeight?: number;
/**
* customize header height
*/
layout: 'side' | 'top' | 'mix';
/**
* layout of content: `Fluid` or `Fixed`, only works when layout is top
*/
contentWidth: ContentWidth;

/**
* sticky header
*/
Expand Down Expand Up @@ -53,6 +56,7 @@ const defaultSettings: ProSettings = {
menu: {
locale: true,
},
headerHeight: 48,
title: 'Ant Design Pro',
iconfontUrl: '',
primaryColor: '#1890ff',
Expand Down

0 comments on commit 9cc5182

Please sign in to comment.