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

refactor:pageheader #6239

Merged
merged 2 commits into from
Feb 8, 2023
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
35 changes: 24 additions & 11 deletions components/page-header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import useDestroyed from '../_util/hooks/useDestroyed';
import type { MouseEventHandler } from '../_util/EventInterface';
import Space from '../space';

// CSSINJS
import useStyle from './style';

export const pageHeaderProps = () => ({
backIcon: PropTypes.any,
prefixCls: String,
Expand All @@ -35,11 +38,16 @@ export type PageHeaderProps = Partial<ExtractPropTypes<ReturnType<typeof pageHea
const PageHeader = defineComponent({
compatConfig: { MODE: 3 },
name: 'APageHeader',
inheritAttrs: false,
props: pageHeaderProps(),
// emits: ['back'],
slots: ['backIcon', 'avatar', 'breadcrumb', 'title', 'subTitle', 'tags', 'extra', 'footer'],
setup(props, { emit, slots }) {
setup(props, { emit, slots, attrs }) {
const { prefixCls, direction, pageHeader } = useConfigInject('page-header', props);

// style
const [wrapSSR, hashId] = useStyle(prefixCls);

const compact = ref(false);
const isDestroyed = useDestroyed();
const onResize = ({ width }: { width: number }) => {
Expand Down Expand Up @@ -148,22 +156,27 @@ const PageHeader = defineComponent({
const hasBreadcrumb = props.breadcrumb?.routes || slots.breadcrumb;
const hasFooter = props.footer || slots.footer;
const children = flattenChildren(slots.default?.());
const className = classNames(prefixCls.value, {
'has-breadcrumb': hasBreadcrumb,
'has-footer': hasFooter,
[`${prefixCls.value}-ghost`]: ghost.value,
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
[`${prefixCls.value}-compact`]: compact.value,
});
return (
const className = classNames(
prefixCls.value,
{
'has-breadcrumb': hasBreadcrumb,
'has-footer': hasFooter,
[`${prefixCls.value}-ghost`]: ghost.value,
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
[`${prefixCls.value}-compact`]: compact.value,
},
attrs.class,
hashId.value,
);
return wrapSSR(
<ResizeObserver onResize={onResize}>
<div class={className}>
<div {...attrs} class={className}>
{renderBreadcrumb()}
{renderTitle()}
{children.length ? renderChildren(children) : null}
{renderFooter()}
</div>
</ResizeObserver>
</ResizeObserver>,
);
};
},
Expand Down
123 changes: 0 additions & 123 deletions components/page-header/style/index.less

This file was deleted.

160 changes: 155 additions & 5 deletions components/page-header/style/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,156 @@
import './index.less';
import type { CSSObject } from '../../_util/cssinjs';
import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
import { resetComponent, textEllipsis } from '../../_style';
import { operationUnit } from '../../_style';

// style dependencies
import '../../breadcrumb/style';
import '../../avatar/style';
import '../../space/style';
interface PageHeaderToken extends FullToken<'PageHeader'> {
pageHeaderPadding: number;
pageHeaderPaddingVertical: number;
pageHeaderPaddingBreadcrumb: number;
pageHeaderGhostBg: string;
pageHeaderBackColor: string;
pageHeaderHeadingTitle: number;
pageHeaderHeadingSubTitle: number;
pageHeaderContentPaddingVertical: number;
pageHeaderTabFontSize: number;
}

const genPageHeaderStyle: GenerateStyle<PageHeaderToken, CSSObject> = token => {
const { componentCls, antCls } = token;

return {
[componentCls]: {
...resetComponent(token),
position: 'relative',
padding: `${token.pageHeaderPaddingVertical}px ${token.pageHeaderPadding}px`,
backgroundColor: token.colorBgLayout,

[`${componentCls}-ghost`]: {
backgroundColor: token.pageHeaderGhostBg,
},

[`&.has-footer`]: {
paddingBottom: 0,
},

[`${componentCls}-back`]: {
marginRight: token.marginMD,
fontZize: token.fontSizeLG,
lineHeight: 1,

[`&-button`]: {
...operationUnit(token),
color: token.pageHeaderBackColor,
cursor: 'pointer',
},
},

[`${antCls}-divider-vertical`]: {
height: '14px',
margin: `0 ${token.marginSM}`,
verticalAlign: 'middle',
},

[`${antCls}-breadcrumb + &-heading`]: {
marginTop: token.marginXS,
},

[`${componentCls}-heading`]: {
display: 'flex',
justifyContent: 'space-between',

[`&-left`]: {
display: 'flex',
alignItems: 'center',
margin: `${token.marginXS / 2}px 0`,
overflow: 'hidden',
},

[`&-title`]: {
marginRight: token.marginSM,
marginBottom: 0,
color: token.colorTextHeading,
fontWeight: 600,
fontSize: token.pageHeaderHeadingTitle,
lineHeight: `${token.controlHeight}px`,
...textEllipsis,
},

[`${antCls}-avatar`]: {
marginRight: token.marginSM,
},

[`&-sub-title`]: {
marginRight: token.marginSM,
color: token.colorTextDescription,
fontSize: token.pageHeaderHeadingSubTitle,
lineHeight: token.lineHeight,
...textEllipsis,
},

[`&-extra`]: {
margin: `${token.marginXS / 2}px 0`,
whiteSpace: 'nowrap',

[`> *`]: {
marginLeft: token.marginSM,
whiteSpace: 'unset',
},

[`> *:first-child`]: {
marginLeft: 0,
},
},
},

[`${componentCls}-content`]: {
paddingTop: token.pageHeaderContentPaddingVertical,
},

[`${componentCls}-footer`]: {
marginTop: token.marginMD,
[`${antCls}-tabs`]: {
[`> ${antCls}-tabs-nav`]: {
margin: 0,

[`&::before`]: {
border: 'none',
},
},
[`${antCls}-tabs-tab`]: {
paddingTop: token.paddingXS,
paddingBottom: token.paddingXS,
fontSize: token.pageHeaderTabFontSize,
},
},
},

[`${componentCls}-compact ${componentCls}-heading`]: {
flexWrap: 'wrap',
},

// rtl style
[`&${token.componentCls}-rtl`]: {
direction: 'rtl',
},
},
};
};

// ============================== Export ==============================
export default genComponentStyleHook('PageHeader', token => {
const PageHeaderToken = mergeToken<PageHeaderToken>(token, {
pageHeaderPadding: token.paddingLG,
pageHeaderPaddingVertical: token.paddingMD,
pageHeaderPaddingBreadcrumb: token.paddingSM,
pageHeaderContentPaddingVertical: token.paddingSM,
pageHeaderBackColor: token.colorTextBase,
pageHeaderGhostBg: 'inherit',
pageHeaderHeadingTitle: token.fontSizeHeading4,
pageHeaderHeadingSubTitle: token.fontSize,
pageHeaderTabFontSize: token.fontSizeLG,
});

return [genPageHeaderStyle(PageHeaderToken)];
});
Loading