Skip to content

Commit

Permalink
⚡ feat: header & footer config & layout type was dont
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLY-yours committed Dec 18, 2023
1 parent 11c65d8 commit 5dfbdfb
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 38 deletions.
32 changes: 24 additions & 8 deletions src/Layout/components/HeaderAndFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ActionIcon from '@/ActionIcon';
import { MenuUnfoldOutlined } from '@ant-design/icons';
import { DropDownProps, Dropdown, Flex, FlexProps } from 'antd';
import { ReactNode } from 'react';
Expand All @@ -12,7 +13,7 @@ enum typeEnum {
type iconDropdownType = {
icon?: ReactNode;
dropdown?: DropDownProps;
title?: string;
title?: ReactNode;
};

interface HeaderFooterSettings {
Expand All @@ -21,6 +22,8 @@ interface HeaderFooterSettings {
flex?: FlexProps;
hide?: boolean;
render?: (props: HeaderFooterSettings) => ReactNode;
style?: React.CSSProperties;
className?: string;
children?: ReactNode;
type?: typeEnum | string;
}
Expand All @@ -39,11 +42,14 @@ const HeaderAndFooter = (props: HeaderFooterSettings) => {
className: '',
},
type = 'header',
extra,
iconConfig = {
icon: <MenuUnfoldOutlined />,
dropdown: undefined,
title: '',
},
style = {},
className,
} = props || {};
if (hide) {
return null;
Expand All @@ -58,16 +64,23 @@ const HeaderAndFooter = (props: HeaderFooterSettings) => {

if (!dropdown)
return (
<div>
{icon}
<div className={styles.headerAndFooterIcon}>
<ActionIcon icon={icon} />
{title}
</div>
);

return (
<Dropdown trigger={['click']} {...iconConfig.dropdown}>
{iconConfig.icon}
</Dropdown>
<div className={styles.headerAndFooterIcon}>
<Dropdown
trigger={['click']}
placement={type === typeEnum.header ? 'bottomLeft' : 'topLeft'}
{...iconConfig.dropdown}
>
<ActionIcon icon={icon} />
</Dropdown>
{title}
</div>
);
};

Expand All @@ -79,11 +92,14 @@ const HeaderAndFooter = (props: HeaderFooterSettings) => {
type === typeEnum.header ? styles.header : styles.footer,
styles.flexContainer,
flex?.className,
className,
)}
style={style}
>
{/* 虽然是放在 flex 中,但实际上是 absoult 定位到最中间 */}
<div className={styles.headerAndFooterCenterChildren}>{children}</div>
<IconDom />
{children}
<div>Extra</div>
{extra && <div className={styles.headerAndFooterExtra}>{extra}</div>}
</Flex>
);
};
Expand Down
96 changes: 96 additions & 0 deletions src/Layout/components/LayoutTypeContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Flex } from 'antd';
import { ReactNode } from 'react';
import { Flexbox } from 'react-layout-kit';
import { LayoutTypeEnum } from '..';
import { getPrefixCls } from '../../theme';
import { useStyle } from './../style';

type LayoutTypeContainerProps = {
pannels: ReactNode[];
headerandfooter: ReactNode[];
type: LayoutTypeEnum;
};

const LayoutTypeContainer = (props: LayoutTypeContainerProps) => {
const prefixCls = getPrefixCls('layout');
const { styles } = useStyle(prefixCls);

const { type, pannels, headerandfooter, ...rest } = props;

const [LeftPannelDom, RightPannelDom, BottomPannelDom, CenterPannelDom] = pannels;
const [HeaderDom, FooterDom] = headerandfooter;

console.log('type', type);

if (type === 'Left&Right') {
return (
<Flexbox className={styles.layout} {...rest}>
{HeaderDom}
<Flex className={styles.container}>
{LeftPannelDom}
<Flex vertical flex={1}>
{CenterPannelDom}
{BottomPannelDom}
</Flex>
{RightPannelDom}
</Flex>
{FooterDom}
</Flexbox>
);
}

if (type === 'LeftFull') {
return (
<Flexbox className={styles.layout} {...rest}>
{HeaderDom}
<Flex className={styles.container}>
{LeftPannelDom}
<Flex vertical flex={1}>
<Flex flex={1}>
{CenterPannelDom}
{RightPannelDom}
</Flex>
{BottomPannelDom}
</Flex>
</Flex>
{FooterDom}
</Flexbox>
);
}

if (type === 'RightFull') {
return (
<Flexbox className={styles.layout} {...rest}>
{HeaderDom}
<Flex className={styles.container}>
<Flex vertical flex={1}>
<Flex flex={1}>
{LeftPannelDom}
{CenterPannelDom}
</Flex>
{BottomPannelDom}
</Flex>
{RightPannelDom}
</Flex>
{FooterDom}
</Flexbox>
);
}

return (
<>
<Flexbox className={styles.layout} {...rest}>
{HeaderDom}
<Flex className={styles.container}>
{LeftPannelDom}
{CenterPannelDom}
{RightPannelDom}
</Flex>
{BottomPannelDom}
{FooterDom}
</Flexbox>
</>
);
};

export { LayoutTypeContainer };
108 changes: 108 additions & 0 deletions src/Layout/demos/_defaultProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import {
AndroidOutlined,
ChromeOutlined,
CloudOutlined,
CodeSandboxOutlined,
FacebookOutlined,
GithubOutlined,
LinkedinOutlined,
MenuUnfoldOutlined,
SmileOutlined,
TwitterOutlined,
YoutubeOutlined,
} from '@ant-design/icons';
import { Space, Tag } from 'antd';

const DefaultLayoutProps = {
header: {
iconConfig: {
icon: <MenuUnfoldOutlined />,
title: 'EditorLayout',
dropdown: {
menu: {
items: [
{
key: '1',
label: (
<a
target="_blank"
rel="noopener noreferrer"
href="https://pro-editor.antdigital.dev/"
>
关于 Ant Desgin Pro Editor
</a>
),
},
{
key: '2',
label: (
<a target="_blank" rel="noopener noreferrer">
全部显示
</a>
),
icon: <SmileOutlined />,
disabled: true,
},
{
key: 'github',
label: (
<a
target="_blank"
rel="noopener noreferrer"
href="https://github.com/ant-design/pro-editor"
>
GitHub
</a>
),
icon: <GithubOutlined />,
},
],
},
},
},
},
footer: {
extra: (
<Space size={[0, 8]} wrap>
<Tag icon={<TwitterOutlined />} color="#55acee">
Twitter
</Tag>
<Tag icon={<YoutubeOutlined />} color="#cd201f">
Youtube
</Tag>
<Tag icon={<FacebookOutlined />} color="#3b5999">
Facebook
</Tag>
<Tag icon={<LinkedinOutlined />} color="#55acee">
LinkedIn
</Tag>
</Space>
),
iconConfig: {
icon: <CloudOutlined />,
dropdown: {
menu: {
items: [
{
key: '1',
label: 'Build with Android',
icon: <AndroidOutlined />,
},
{
key: '2',
label: 'Run in Chrome',
icon: <ChromeOutlined />,
},
{
key: 'github',
label: 'CodeSandBox',
icon: <CodeSandboxOutlined />,
},
],
},
},
},
},
};

export { DefaultLayoutProps };
24 changes: 23 additions & 1 deletion src/Layout/demos/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import { EditorLayout } from '@ant-design/pro-editor';
import { Button, EditorLayout, Input } from '@ant-design/pro-editor';
import { Space } from 'antd';
import { DefaultLayoutProps } from './_defaultProps';

export default () => {
return (
<EditorLayout
style={{
maxWidth: '100%',
height: '600px',
}}
header={{
...DefaultLayoutProps.header,
children: (
<Input
addonBefore="Options"
placeholder="Search For Some Little Options"
style={{ width: 250 }}
/>
),
extra: (
<Space>
<Button type="primary">Save</Button>
<Button type="dashed">Export</Button>
</Space>
),
}}
footer={{
...DefaultLayoutProps.footer,
}}
leftPannel={{
children: <div>Left Pannel</div>,
Expand Down
47 changes: 47 additions & 0 deletions src/Layout/demos/types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { EditorLayout, Input } from '@ant-design/pro-editor';
import { Segmented, Space } from 'antd';
import { useState } from 'react';
import { DefaultLayoutProps } from './_defaultProps';

export default () => {
const [value, setValue] = useState<string>('Bottom');

return (
<Space
direction="vertical"
style={{
maxWidth: '100%',
}}
>
<Segmented
options={['Left&Right', 'LeftFull', 'RightFull', 'Bottom']}
value={value}
onChange={(e) => setValue(e.toString())}
/>
<EditorLayout
style={{
maxWidth: '100%',
height: '600px',
}}
header={{
...DefaultLayoutProps.header,
children: (
<Input
addonBefore="Options"
placeholder="Search For Some Options"
style={{ width: 250 }}
/>
),
}}
type={value}
footer={{
...DefaultLayoutProps.footer,
children: <div>Footer</div>,
}}
leftPannel={{
children: <div>Left Pannel</div>,
}}
/>
</Space>
);
};

0 comments on commit 5dfbdfb

Please sign in to comment.