UNPKG

@instructure/ui-grid

Version:
94 lines (93 loc) 3.96 kB
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; const _excluded = ["styles", "makeStyles"], _excluded2 = ["styles"]; var _dec, _class, _GridRow; /* * The MIT License (MIT) * * Copyright (c) 2015 - present Instructure, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import { Component, Children } from 'react'; import { safeCloneElement, matchComponentTypes, omitProps, pickProps } from '@instructure/ui-react-utils'; import { GridCol } from '../GridCol'; import { withStyle } from '@instructure/emotion'; import generateStyle from './styles'; import generateComponentTheme from './theme'; import { propTypes, allowedProps } from './props'; import { jsx as _jsx } from "@emotion/react/jsx-runtime"; /** --- parent: Grid id: Grid.Row --- **/ let GridRow = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_GridRow = class GridRow extends Component { constructor(...args) { super(...args); this.ref = null; this.handleRef = el => { this.ref = el; }; } componentDidMount() { var _this$props$makeStyle, _this$props; (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props); } componentDidUpdate() { var _this$props$makeStyle2, _this$props2; (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2); } renderChildren() { const _this$props3 = this.props, styles = _this$props3.styles, makeStyles = _this$props3.makeStyles, props = _objectWithoutProperties(_this$props3, _excluded); return Children.map(this.props.children, (child, index) => { if (matchComponentTypes(child, [GridCol])) { return safeCloneElement(child, { ...pickProps(props, GridRow.allowedProps), ...child.props /* child props should override parent */, isLastRow: props.isLastRow, isLastCol: index + 1 === Children.count(this.props.children) }); } else { return child; // PropType validation should handle errors } }); } render() { const _this$props4 = this.props, styles = _this$props4.styles, restProps = _objectWithoutProperties(_this$props4, _excluded2); const props = omitProps(restProps, GridRow.allowedProps); return _jsx("span", { ...props, css: styles === null || styles === void 0 ? void 0 : styles.gridRow, ref: this.handleRef, children: this.renderChildren() }); } }, _GridRow.displayName = "GridRow", _GridRow.componentId = 'Grid.Row', _GridRow.propTypes = propTypes, _GridRow.allowedProps = allowedProps, _GridRow.defaultProps = { children: null, isLastRow: false }, _GridRow)) || _class); export default GridRow; export { GridRow };