-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from ant-design/rc
sparkles: feat: add Editor Layout new Components
- Loading branch information
Showing
21 changed files
with
4,660 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import ActionIcon from '@/ActionIcon'; | ||
import { MenuUnfoldOutlined } from '@ant-design/icons'; | ||
import { DropDownProps, Dropdown, Flex, FlexProps } from 'antd'; | ||
import { ReactNode } from 'react'; | ||
import { ThemeLayoutType } from '..'; | ||
import { getPrefixCls } from '../../theme'; | ||
import { useStyle } from './../style'; | ||
|
||
enum typeEnum { | ||
header = 'header', | ||
footer = 'footer', | ||
} | ||
|
||
type iconDropdownType = { | ||
icon?: ReactNode; | ||
dropdown?: DropDownProps; | ||
title?: ReactNode; | ||
render?: (props: iconDropdownType, defalutDom?: ReactNode) => JSX.Element; | ||
}; | ||
|
||
interface HeaderFooterSettings { | ||
iconConfig?: iconDropdownType | false; | ||
extra?: ReactNode; | ||
flex?: FlexProps; | ||
hide?: boolean; | ||
render?: (props: HeaderFooterSettings) => JSX.Element; | ||
style?: React.CSSProperties; | ||
className?: string; | ||
children?: ReactNode; | ||
type?: typeEnum | string; | ||
themeType?: ThemeLayoutType; | ||
} | ||
|
||
const HeaderAndFooter = (props: HeaderFooterSettings) => { | ||
const { | ||
children, | ||
render, | ||
hide = false, | ||
flex = { | ||
justify: 'space-between', | ||
align: 'center', | ||
className: '', | ||
}, | ||
type = 'header', | ||
extra, | ||
iconConfig = { | ||
icon: <MenuUnfoldOutlined />, | ||
dropdown: undefined, | ||
title: '', | ||
render, | ||
}, | ||
themeType, | ||
style = {}, | ||
className, | ||
} = props || {}; | ||
|
||
const prefixCls = getPrefixCls('layout'); | ||
|
||
const { styles, cx } = useStyle({ prefixCls, themeType }); | ||
|
||
if (hide) { | ||
return null; | ||
} | ||
if (render) { | ||
return render(props); | ||
} | ||
|
||
const IconDom = () => { | ||
if (iconConfig === false) return null; | ||
const { icon, dropdown, title, render } = iconConfig || {}; | ||
|
||
if (!dropdown) | ||
return ( | ||
<div className={styles.headerAndFooterIcon}> | ||
<ActionIcon icon={icon} /> | ||
{title} | ||
</div> | ||
); | ||
|
||
const DefalutIconDom = ( | ||
<> | ||
<Dropdown | ||
trigger={['click']} | ||
placement={type === typeEnum.header ? 'bottomLeft' : 'topLeft'} | ||
{...iconConfig.dropdown} | ||
> | ||
<ActionIcon icon={icon} /> | ||
</Dropdown> | ||
{title} | ||
</> | ||
); | ||
|
||
if (render) { | ||
return render(iconConfig, DefalutIconDom); | ||
} | ||
|
||
return DefalutIconDom; | ||
}; | ||
|
||
return ( | ||
<Flex | ||
key={type === typeEnum.header ? 'editor-layout-header' : 'editor-layout-footer'} | ||
{...flex} | ||
className={cx( | ||
type === typeEnum.header ? styles.header : styles.footer, | ||
styles.flexContainer, | ||
flex?.className, | ||
className, | ||
)} | ||
style={style} | ||
> | ||
{/* 虽然是放在 flex 中,但实际上是 absoult 定位到最中间 */} | ||
<div className={styles.headerAndFooterCenterChildren}>{children}</div> | ||
<div className={styles.headerAndFooterIcon}> | ||
<IconDom /> | ||
</div> | ||
{extra && <div className={styles.headerAndFooterExtra}>{extra}</div>} | ||
</Flex> | ||
); | ||
}; | ||
|
||
export { HeaderAndFooter }; | ||
export type { HeaderFooterSettings, typeEnum }; |
Oops, something went wrong.