import { Component } from 'react'; import cx from 'classnames'; import ConfigContext from './ConfigContext'; import BreakPointHub from './BreakPointHub'; import LayoutBreakpointContext from './BreakPointContext'; import { BREAKPOINTS, getValueForBreakpoint } from './screen-breakpoints'; import { LayoutBreakPoint } from './types'; export interface ILayoutGridProps { className?: string; style?: React.CSSProperties; } interface ILayoutGridState { breakpoints: Partial>; } export class LayoutGrid extends Component { state = { breakpoints: {} as Partial>, }; render() { const { className, style, ...others } = this.props; const { breakpoints } = this.state; return ( {config => { const rowGutter = getValueForBreakpoint( breakpoints, config.rowGutter ); let layoutStyles = style; if (rowGutter > 0) { const height = -(rowGutter / 2); layoutStyles = { ...layoutStyles, marginTop: height, marginBottom: height, }; } return (
{this.props.children}
); }}
); } onBreakpointChange = (name: LayoutBreakPoint, matched: boolean) => { this.setState(prevState => { const { breakpoints } = prevState; return { breakpoints: { ...breakpoints, [name]: matched }, } as ILayoutGridState; }); }; } export default LayoutGrid;