2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2017-11-09 20:04:34 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2016-12-30 21:41:28 +08:00
|
|
|
import classNames from 'classnames';
|
2017-05-28 03:20:05 +08:00
|
|
|
import { SiderProps } from './Sider';
|
2016-12-30 21:41:28 +08:00
|
|
|
|
|
|
|
export interface BasicProps {
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
2017-11-21 19:02:23 +08:00
|
|
|
function generator(props: BasicProps) {
|
|
|
|
return (BasicComponent: React.ComponentClass<BasicProps>): any => {
|
2016-12-30 21:41:28 +08:00
|
|
|
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-11-09 20:04:34 +08:00
|
|
|
return <BasicComponent prefixCls={prefixCls} {...this.props} />;
|
2016-12-30 21:41:28 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class Basic extends React.Component<BasicProps, any> {
|
|
|
|
render() {
|
2017-02-24 16:06:15 +08:00
|
|
|
const { prefixCls, className, children, ...others } = this.props;
|
2017-11-09 20:04:34 +08:00
|
|
|
const divCls = classNames(className, prefixCls);
|
|
|
|
return (
|
|
|
|
<div className={divCls} {...others}>{children}</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BasicLayout extends React.Component<BasicProps, any> {
|
|
|
|
static childContextTypes = {
|
|
|
|
siderHook: PropTypes.object,
|
|
|
|
};
|
|
|
|
state = { siders: [] };
|
|
|
|
|
|
|
|
getChildContext() {
|
|
|
|
return {
|
|
|
|
siderHook: {
|
|
|
|
addSider: (id: string) => {
|
|
|
|
this.setState({
|
2017-11-09 20:14:51 +08:00
|
|
|
siders: [...this.state.siders, id],
|
2017-11-09 20:04:34 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
removeSider: (id: string) => {
|
|
|
|
this.setState({
|
2017-11-09 20:14:51 +08:00
|
|
|
siders: this.state.siders.filter(currentId => currentId !== id),
|
2017-11-09 20:04:34 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { prefixCls, className, children, ...others } = this.props;
|
2017-01-08 17:03:47 +08:00
|
|
|
const divCls = classNames(className, prefixCls, {
|
2017-11-09 20:04:34 +08:00
|
|
|
[`${prefixCls}-has-sider`]: this.state.siders.length > 0,
|
2017-01-08 17:03:47 +08:00
|
|
|
});
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-28 03:20:05 +08:00
|
|
|
const Layout: React.ComponentClass<BasicProps> & {
|
|
|
|
Header: React.ComponentClass<BasicProps>;
|
|
|
|
Footer: React.ComponentClass<BasicProps>;
|
|
|
|
Content: React.ComponentClass<BasicProps>;
|
|
|
|
Sider: React.ComponentClass<SiderProps>;
|
|
|
|
} = generator({
|
2016-12-30 21:41:28 +08:00
|
|
|
prefixCls: 'ant-layout',
|
2017-11-09 20:04:34 +08:00
|
|
|
})(BasicLayout);
|
2016-12-30 21:41:28 +08:00
|
|
|
|
|
|
|
const Header = generator({
|
|
|
|
prefixCls: 'ant-layout-header',
|
|
|
|
})(Basic);
|
|
|
|
|
|
|
|
const Footer = generator({
|
|
|
|
prefixCls: 'ant-layout-footer',
|
|
|
|
})(Basic);
|
|
|
|
|
|
|
|
const Content = generator({
|
|
|
|
prefixCls: 'ant-layout-content',
|
|
|
|
})(Basic);
|
|
|
|
|
|
|
|
Layout.Header = Header;
|
|
|
|
Layout.Footer = Footer;
|
|
|
|
Layout.Content = Content;
|
|
|
|
|
|
|
|
export default Layout;
|