mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-29 13:47:02 +08:00
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import React from 'react';
|
|
import classNames from 'classnames';
|
|
import { SiderProps } from './Sider';
|
|
|
|
export interface BasicProps {
|
|
style?: React.CSSProperties;
|
|
prefixCls?: string;
|
|
className?: string;
|
|
}
|
|
|
|
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;
|
|
return <Basic prefixCls={prefixCls} {...this.props}/>;
|
|
}
|
|
};
|
|
};
|
|
}
|
|
|
|
class Basic extends React.Component<BasicProps, any> {
|
|
render() {
|
|
const { prefixCls, className, children, ...others } = this.props;
|
|
let hasSider;
|
|
React.Children.forEach(children, (element: any) => {
|
|
if (element && element.type && element.type.__ANT_LAYOUT_SIDER) {
|
|
hasSider = true;
|
|
}
|
|
});
|
|
const divCls = classNames(className, prefixCls, {
|
|
[`${prefixCls}-has-sider`]: hasSider,
|
|
});
|
|
return (
|
|
<div className={divCls} {...others}>{children}</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
const Layout: React.ComponentClass<BasicProps> & {
|
|
Header: React.ComponentClass<BasicProps>;
|
|
Footer: React.ComponentClass<BasicProps>;
|
|
Content: React.ComponentClass<BasicProps>;
|
|
Sider: React.ComponentClass<SiderProps>;
|
|
} = generator({
|
|
prefixCls: 'ant-layout',
|
|
})(Basic);
|
|
|
|
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;
|