-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: add Editor Layout new Components
- Loading branch information
1 parent
172b64d
commit 927cc46
Showing
6 changed files
with
247 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Layout } from '@ant-design/pro-editor'; | ||
|
||
export default () => { | ||
return ( | ||
<Layout | ||
leftPannel={{ | ||
children: <div>Left Pannel</div>, | ||
}} | ||
/> | ||
); | ||
}; |
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,144 @@ | ||
import { DraggablePanel } from '@ant-design/pro-editor'; | ||
import { FlexProps, TabsProps } from 'antd'; | ||
import { ReactNode } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
import { getPrefixCls } from '../theme'; | ||
import { useStyle } from './style'; | ||
|
||
interface HeaderFooterSettings { | ||
Icon?: ReactNode; | ||
extra?: ReactNode; | ||
flex?: FlexProps; | ||
hide?: boolean; | ||
render?: (props: HeaderFooterSettings) => ReactNode; | ||
children?: ReactNode; | ||
} | ||
|
||
interface LayoutProps { | ||
header?: HeaderFooterSettings; | ||
footer?: HeaderFooterSettings; | ||
leftPannel?: PannelSettings; | ||
rightPannel?: PannelSettings; | ||
bottomPannel?: PannelSettings; | ||
centerPannel?: PannelSettings; | ||
type?: string; | ||
} | ||
|
||
interface PannelSettings { | ||
children: ReactNode | ReactNode[]; | ||
direction?: 'horizontal' | 'vertical'; | ||
tabs?: TabsProps; | ||
icon?: ReactNode; | ||
extra?: ReactNode; | ||
hide?: boolean; | ||
minWidth?: number; | ||
minHeight?: number; | ||
style?: React.CSSProperties; | ||
className?: string; | ||
} | ||
|
||
const getPannelProps = ( | ||
index: number, | ||
): | ||
| { | ||
placement: 'left' | 'right' | 'bottom'; | ||
className?: string; | ||
} | ||
| false => { | ||
switch (['left', 'right', 'bottom', 'center'][index]) { | ||
case 'left': | ||
return { | ||
placement: 'left', | ||
}; | ||
case 'right': | ||
return { | ||
placement: 'right', | ||
}; | ||
case 'bottom': | ||
return { | ||
placement: 'bottom', | ||
}; | ||
case 'center': | ||
return false; | ||
default: | ||
return false; | ||
} | ||
}; | ||
|
||
const BasicLayout = (props: LayoutProps) => { | ||
const { header, footer, leftPannel, rightPannel, bottomPannel, centerPannel, type, ...rest } = | ||
props; | ||
|
||
const prefixCls = getPrefixCls('layout'); | ||
const { styles, cx } = useStyle(prefixCls); | ||
|
||
const DraggablePanelRender = (props: PannelSettings, index: number) => { | ||
const { | ||
children = '', | ||
className, | ||
style, | ||
minHeight = 200, | ||
minWidth = 200, | ||
...rest | ||
} = props || {}; | ||
const pannelProps = getPannelProps(index); | ||
if (!pannelProps) { | ||
return ( | ||
<div className={cx(styles.centerPannel)}> | ||
<div className={cx(styles.pannel, className)}>{children}</div> | ||
</div> | ||
); | ||
} | ||
const { placement } = pannelProps; | ||
return ( | ||
<DraggablePanel | ||
expandable={false} | ||
style={{ border: 'none', ...style }} | ||
placement={placement} | ||
minHeight={minHeight} | ||
minWidth={minWidth} | ||
{...pannelProps} | ||
{...rest} | ||
> | ||
<div className={cx(styles.pannel, className)}>{children}</div> | ||
</DraggablePanel> | ||
); | ||
}; | ||
|
||
const [LeftPannelDom, RightPannelDom, BottomPannelDom, CenterPannelDom] = [ | ||
leftPannel, | ||
rightPannel, | ||
bottomPannel, | ||
centerPannel, | ||
].map(DraggablePanelRender); | ||
|
||
const HeaderDom = (props: HeaderFooterSettings) => { | ||
const { children, render } = props || {}; | ||
if (render) { | ||
return render(props); | ||
} | ||
return <div className={styles.header}>{children}</div>; | ||
}; | ||
|
||
const FooterDom = (props: HeaderFooterSettings) => { | ||
const { children } = props || {}; | ||
return <div className={styles.footer}>{children}</div>; | ||
}; | ||
|
||
return ( | ||
<> | ||
<Flexbox className={styles.layout} {...rest}> | ||
<HeaderDom /> | ||
<div className={styles.container}> | ||
{LeftPannelDom} | ||
{CenterPannelDom} | ||
{RightPannelDom} | ||
</div> | ||
{BottomPannelDom} | ||
<FooterDom /> | ||
</Flexbox> | ||
</> | ||
); | ||
}; | ||
|
||
export { BasicLayout as Layout }; |
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,13 @@ | ||
--- | ||
title: Layout 基础布局 | ||
atomId: Layout | ||
group: 基础组件 | ||
--- | ||
|
||
# Layout 基础布局 | ||
|
||
## 代码演示 | ||
|
||
### 基础用法 | ||
|
||
<code src="./demos/basic.tsx" ></code> |
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,77 @@ | ||
import { STUDIO_UI_PREFIX, createStyles } from '../theme'; | ||
|
||
export const useStyle = createStyles(({ css, token, cx }, prefixCls: string) => { | ||
return { | ||
layout: cx( | ||
prefixCls, | ||
css` | ||
height: 100vh; | ||
width: 100vw; | ||
background-color: ${token.colorBgContainer}; | ||
overflow: hidden; | ||
border-radius: ${token.borderRadius}px; | ||
.${STUDIO_UI_PREFIX}-draggable-panel { | ||
border: none; | ||
} | ||
`, | ||
), | ||
header: cx( | ||
`${prefixCls}-header`, | ||
css` | ||
height: 48px; | ||
border-radius: ${token.borderRadius}px; | ||
background-color: ${token.colorFillQuaternary}; | ||
margin-bottom: ${token.margin / 4}px; | ||
`, | ||
), | ||
footer: cx( | ||
`${prefixCls}-footer`, | ||
css` | ||
height: 28px; | ||
width: 100%; | ||
margin-top: ${token.margin / 4}px; | ||
background-color: ${token.colorFillQuaternary}; | ||
`, | ||
), | ||
|
||
centerPannel: cx( | ||
`${prefixCls}-center-pannel`, | ||
css` | ||
flex: 1; | ||
.${prefixCls}-pannel { | ||
height: calc(100% - ${token.margin / 2 + 1}px); | ||
width: calc(100% - ${token.margin / 2 - 2}px); | ||
margin: ${token.margin / 4 + 2}px ${token.margin / 4 - 1}px; | ||
} | ||
`, | ||
), | ||
|
||
container: cx( | ||
`${prefixCls}-container`, | ||
css` | ||
flex: 1; | ||
display: flex; | ||
`, | ||
), | ||
pannel: cx( | ||
`${prefixCls}-pannel`, | ||
css` | ||
border-radius: ${token.borderRadius}px; | ||
background-color: ${token.colorFillQuaternary}; | ||
margin: ${token.margin / 4 + 2}px; | ||
height: calc(100% - ${token.margin / 2 + 1}px); | ||
width: calc(100% - ${token.margin / 2 + 1}px); | ||
`, | ||
), | ||
tip: cx( | ||
`${prefixCls}-tip`, | ||
css` | ||
position: absolute; | ||
left: 50%; | ||
transform: translate(-50%); | ||
`, | ||
), | ||
}; | ||
}); |
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