UNPKG

@onesy/ui-react

Version:
185 lines (183 loc) 7.72 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _compilerRuntime = require("react/compiler-runtime"); var _react = _interopRequireDefault(require("react")); var _utils = require("@onesy/utils"); var _styleReact = require("@onesy/style-react"); var _Line = _interopRequireDefault(require("../Line")); var _Type = _interopRequireDefault(require("../Type")); var _utils2 = require("../utils"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["name", "description", "start", "end", "row", "footer", "responsive", "Component", "HeaderProps", "MainProps", "TextProps", "AsideProps", "StartProps", "EndProps", "className", "children"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } const useStyle = (0, _styleReact.style)(theme => ({ root: {}, aside: { flex: '0 0 auto' }, row: { '& > *': { flex: '1 1 auto' } // '& .onesy-TextField-root, & .onesy-TextField-wrapper': { // width: '100%' // } }, footer: { marginTop: '8px' } }), { name: 'onesy-FormRow' }); const FormRow = props_ => { var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2; const $ = (0, _compilerRuntime.c)(17); const theme = (0, _styleReact.useOnesyTheme)(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesyFormRow) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_); const Line = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default; const Type = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Type) || _Type.default; const { name, description, start, end, row, footer, responsive: t0, Component: t1, HeaderProps, MainProps, TextProps, AsideProps, StartProps, EndProps, className, children } = props, other = (0, _objectWithoutProperties2.default)(props, _excluded); const responsive = t0 === undefined ? true : t0; const Component = t1 === undefined ? Line : t1; const { classes } = useStyle(); const text = name || description; const actions = start || end; const header = text || actions; let justify = "unset"; if (start && end && !text) { justify = "space-between"; } if (!start && !text && end) { justify = "flex-end"; } const t2 = 1; const t3 = "column"; const t4 = "unset"; const t5 = "unset"; const t6 = true; const t7 = (0, _styleReact.classNames)([(0, _utils2.staticClassName)("FormRow", theme) && ["onesy-FormRow-root"], className, classes.root]); const t8 = header && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({ direction: "row", align: "center", justify: justify, fullWidth: true }, HeaderProps), {}, { children: [start && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread(_objectSpread({}, AsideProps), StartProps), {}, { className: (0, _styleReact.classNames)([AsideProps === null || AsideProps === void 0 ? void 0 : AsideProps.className, StartProps === null || StartProps === void 0 ? void 0 : StartProps.className, classes.aside]), children: start })), text && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({ gap: 0.5, direction: "column", flex: true }, TextProps), {}, { children: [name && ((0, _utils.is)("string", name) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, { version: "l2", children: name }) : name), description && ((0, _utils.is)("string", description) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, { version: "b3", children: description }) : description)] })), end && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread(_objectSpread({ gap: 0, direction: "row", align: "center" }, AsideProps), EndProps), {}, { className: (0, _styleReact.classNames)([AsideProps === null || AsideProps === void 0 ? void 0 : AsideProps.className, EndProps === null || EndProps === void 0 ? void 0 : EndProps.className, classes.aside]), children: end }))] })); const t9 = 2; const t10 = row ? responsive ? { default: "row", 1400: "column" } : "row" : "column"; const t11 = true; const t12 = (0, _styleReact.classNames)([(0, _utils2.staticClassName)("FormRow", theme) && ["onesy-FormRow-main"], MainProps === null || MainProps === void 0 ? void 0 : MainProps.className, row && classes.row]); let t13; if ($[0] !== Line || $[1] !== MainProps || $[2] !== children || $[3] !== t10 || $[4] !== t12) { t13 = /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread({ gap: t9, direction: t10, fullWidth: t11, className: t12 }, MainProps), {}, { children: children })); $[0] = Line; $[1] = MainProps; $[2] = children; $[3] = t10; $[4] = t12; $[5] = t13; } else { t13 = $[5]; } let t14; if ($[6] !== Line || $[7] !== classes.footer || $[8] !== footer) { t14 = footer && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, { direction: "row", justify: "flex-end", fullWidth: true, className: classes.footer, children: footer }); $[6] = Line; $[7] = classes.footer; $[8] = footer; $[9] = t14; } else { t14 = $[9]; } let t15; if ($[10] !== Component || $[11] !== other || $[12] !== t13 || $[13] !== t14 || $[14] !== t7 || $[15] !== t8) { t15 = /*#__PURE__*/(0, _jsxRuntime.jsxs)(Component, _objectSpread(_objectSpread({ gap: t2, direction: t3, justify: t4, align: t5, fullWidth: t6, className: t7 }, other), {}, { children: [t8, t13, t14] })); $[10] = Component; $[11] = other; $[12] = t13; $[13] = t14; $[14] = t7; $[15] = t8; $[16] = t15; } else { t15 = $[16]; } return t15; }; FormRow.displayName = 'onesy-FormRow'; var _default = exports.default = FormRow;