UNPKG

@instructure/ui-grid

Version:
106 lines (105 loc) 4.13 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.GridCol = void 0; var _react = require("react"); var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js"); var _emotion = require("@instructure/emotion"); var _console = require("@instructure/console"); var _styles = _interopRequireDefault(require("./styles")); var _theme = _interopRequireDefault(require("./theme")); var _props = require("./props"); var _jsxRuntime = require("@emotion/react/jsx-runtime"); var _dec, _class, _GridCol; /* * 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. */ /** --- parent: Grid id: Grid.Col --- **/ let GridCol = exports.GridCol = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_GridCol = class GridCol extends _react.Component { constructor(...args) { super(...args); this.ref = null; this.handleRef = el => { const elementRef = this.props.elementRef; this.ref = el; if (typeof elementRef === 'function') { elementRef(el); } }; } widthCheck() { const width = this.props.width; let shouldWarn = false; if (width) { if (typeof width === 'number' && width <= 0) { shouldWarn = true; } if (typeof width === 'object') { Object.keys(width).forEach(breakpoint => { //@ts-expect-error Ts doesn't understand Object.keys properly if (typeof width[breakpoint] === 'number' && width[breakpoint] <= 0) { shouldWarn = true; } }); } } if (shouldWarn) { (0, _console.logWarn)(false, 'Col width must be positive!'); } } 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); this.widthCheck(); } 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); this.widthCheck(); } render() { const _this$props3 = this.props, children = _this$props3.children, styles = _this$props3.styles; const props = (0, _omitProps.omitProps)(this.props, GridCol.allowedProps); return (0, _jsxRuntime.jsx)("span", { ...props, ref: this.handleRef, css: styles === null || styles === void 0 ? void 0 : styles.gridCol, children: children }); } }, _GridCol.displayName = "GridCol", _GridCol.componentId = 'Grid.Col', _GridCol.propTypes = _props.propTypes, _GridCol.allowedProps = _props.allowedProps, _GridCol.defaultProps = { textAlign: 'inherit', children: null, isLastCol: false, isLastRow: false }, _GridCol)) || _class); var _default = exports.default = GridCol;