2016-12-30 21:41:28 +08:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
export interface BasicProps {
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
2017-01-08 17:03:47 +08:00
|
|
|
name: string;
|
2016-12-30 21:41:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function generator(props) {
|
|
|
|
return (Basic) : any => {
|
|
|
|
return class Adapter extends React.Component<BasicProps, any> {
|
|
|
|
static Header: any;
|
|
|
|
static Footer: any;
|
|
|
|
static Content: any;
|
|
|
|
static Sider: any;
|
|
|
|
render() {
|
|
|
|
const { prefixCls } = props;
|
2017-01-08 17:03:47 +08:00
|
|
|
return <Basic prefixCls={prefixCls} name={props.name} {...this.props}/>;
|
2016-12-30 21:41:28 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class Basic extends React.Component<BasicProps, any> {
|
|
|
|
render() {
|
2017-01-08 17:03:47 +08:00
|
|
|
const { prefixCls, className, children, name, ...others } = this.props;
|
|
|
|
let hasSider;
|
|
|
|
if (name === 'Layout') {
|
|
|
|
React.Children.forEach(children, (ele: React.ReactElement<any>) => {
|
|
|
|
if (ele && ele.props && ele.props.name === 'Sider') {
|
|
|
|
hasSider = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const divCls = classNames(className, prefixCls, {
|
|
|
|
[`${prefixCls}-has-sider`]: hasSider,
|
|
|
|
});
|
2016-12-30 21:41:28 +08:00
|
|
|
return (
|
2017-01-08 17:03:47 +08:00
|
|
|
<div className={divCls} {...others}>{children}</div>
|
2016-12-30 21:41:28 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Layout = generator({
|
|
|
|
prefixCls: 'ant-layout',
|
2017-01-08 17:03:47 +08:00
|
|
|
name: 'Layout',
|
2016-12-30 21:41:28 +08:00
|
|
|
})(Basic);
|
|
|
|
|
|
|
|
const Header = generator({
|
|
|
|
prefixCls: 'ant-layout-header',
|
2017-01-08 17:03:47 +08:00
|
|
|
name: 'Header',
|
2016-12-30 21:41:28 +08:00
|
|
|
})(Basic);
|
|
|
|
|
|
|
|
const Footer = generator({
|
|
|
|
prefixCls: 'ant-layout-footer',
|
2017-01-08 17:03:47 +08:00
|
|
|
name: 'Footer',
|
2016-12-30 21:41:28 +08:00
|
|
|
})(Basic);
|
|
|
|
|
|
|
|
const Content = generator({
|
|
|
|
prefixCls: 'ant-layout-content',
|
2017-01-08 17:03:47 +08:00
|
|
|
name: 'Content',
|
2016-12-30 21:41:28 +08:00
|
|
|
})(Basic);
|
|
|
|
|
|
|
|
Layout.Header = Header;
|
|
|
|
Layout.Footer = Footer;
|
|
|
|
Layout.Content = Content;
|
|
|
|
|
|
|
|
export default Layout;
|