UNPKG

@workday/canvas-kit-react-layout

Version:

Layout module for canvas-kit-react

98 lines (97 loc) 3.66 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; import styled from '@emotion/styled'; import Column from './Column'; import canvas, { spacingNumbers } from '@workday/canvas-kit-react-core'; import isPropValid from '@emotion/is-prop-valid'; var LayoutStyles = { classname: 'layout', styles: { display: 'flex', width: '100%', boxSizing: 'border-box', }, }; var LayoutContainer = styled('div', { shouldForwardProp: function (prop) { return isPropValid(prop) && prop !== 'spacing'; }, })(LayoutStyles.styles, function (_a) { var gutter = _a.gutter; if (gutter === 0) { return; } return { padding: "0 " + gutter }; }, function (_a) { var capWidth = _a.capWidth; if (!capWidth) { return; } return { maxWidth: '1280px', margin: '0 auto', }; }); var Layout = (function (_super) { __extends(Layout, _super); function Layout() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.renderChild = function (child, spacing) { if (!child) { return; } if (child.type === Column) { var childProps = child.props; if (childProps.spacing || childProps.spacing === 0) { return child; } return React.cloneElement(child, { spacing: spacing }); } return child; }; return _this; } Layout.prototype.render = function () { var _this = this; var _a = this.props, _b = _a.gutter, gutter = _b === void 0 ? canvas.spacing.xs : _b, _c = _a.spacing, spacing = _c === void 0 ? spacingNumbers.xs : _c, children = _a.children, capWidth = _a.capWidth, elemProps = __rest(_a, ["gutter", "spacing", "children", "capWidth"]); return (React.createElement(LayoutContainer, __assign({ spacing: spacing, gutter: gutter, capWidth: capWidth }, elemProps), React.Children.map(children, function (child) { return _this.renderChild(child, spacing); }))); }; Layout.Column = Column; return Layout; }(React.Component)); Layout.Column = Column; export default Layout;