import { Component } from 'react'; import cx from 'classnames'; import ConfigContext from './ConfigContext'; import LayoutBreakpointContext from './BreakPointContext'; import { getValueForBreakpoint } from './screen-breakpoints'; import { ILayoutResponsiveValue } from './types'; export interface ILayoutColProps { span: number | ILayoutResponsiveValue; offset: number | ILayoutResponsiveValue; order: number | ILayoutResponsiveValue; style?: React.CSSProperties; className?: string; } export class LayoutCol extends Component { static defaultProps = { offset: 0, order: 0, }; render() { return ( {breakpoints => ( {config => { const { span, offset, order, className, style, ...others } = this.props; let colStyles = style; const colGutter = getValueForBreakpoint( breakpoints, config.colGutter ); if (colGutter > 0) { const width = colGutter / 2; colStyles = { ...colStyles, paddingLeft: width, paddingRight: width, }; } const spanValue = getValueForBreakpoint(breakpoints, span); const offsetValue = getValueForBreakpoint(breakpoints, offset); const orderValue = getValueForBreakpoint(breakpoints, order); const classes = cx( 'zent-col', { [`zent-col-offset-${offset}`]: offsetValue, [`zent-col-order-${order}`]: orderValue, }, // 0 相当于 display: none `zent-col-${spanValue}`, className ); return (
{this.props.children}
); }}
)}
); } } export default LayoutCol;