UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

89 lines (78 loc) 3.72 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkMPQZUD42js = require('./chunk-MPQZUD42.js'); var _chunkTN3AYOMVjs = require('./chunk-TN3AYOMV.js'); // src/components/shared/ReportLayout.tsx var _react = require('react'); // src/components/shared/ReportGridUtils.ts var getGridColumnsClass = (count) => { if (count >= 5) return "lg:grid-cols-5"; if (count === 4) return "lg:grid-cols-4"; if (count === 3) return "lg:grid-cols-3"; if (count === 2) return "lg:grid-cols-2"; return ""; }; // src/components/shared/ReportLayout.tsx var _jsxruntime = require('react/jsx-runtime'); var ReportLayout = ({ tabs, defaultTab, activeTab: controlledTab, onTabChange, renderCard, gridTestId, className, ...props }) => { const firstTabValue = _nullishCoalesce(_optionalChain([tabs, 'access', _ => _[0], 'optionalAccess', _2 => _2.value]), () => ( "")); const [internalTab, setInternalTab] = _react.useState.call(void 0, _nullishCoalesce(defaultTab, () => ( firstTabValue))); const isControlled = controlledTab !== void 0; const activeTabValue = isControlled ? controlledTab : internalTab; const activeTabData = tabs.find((t) => t.value === activeTabValue); const cards = _nullishCoalesce(_optionalChain([activeTabData, 'optionalAccess', _3 => _3.cards]), () => ( [])); const handleTabChange = (value) => { if (!isControlled) { setInternalTab(value); } _optionalChain([onTabChange, 'optionalCall', _4 => _4(value)]); }; if (tabs.length === 0) { return null; } return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunkTN3AYOMVjs.cn.call(void 0, "flex flex-col gap-4", className), ...props, children: [ tabs.length > 1 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkMPQZUD42js.Menu_default, { defaultValue: _nullishCoalesce(defaultTab, () => ( firstTabValue)), value: controlledTab, variant: "menu2", onValueChange: handleTabChange, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkMPQZUD42js.MenuContent, { variant: "menu2", children: tabs.map((tab) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkMPQZUD42js.MenuItem, { value: tab.value, variant: "menu-overflow", className: "!text-sm !leading-[100%] !tracking-[0.2px]", children: [ tab.icon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "[&>svg]:w-[21px] [&>svg]:h-[21px]", children: tab.icon }), tab.label ] }, tab.value )) }) } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _chunkTN3AYOMVjs.cn.call(void 0, "grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4", getGridColumnsClass(cards.length) ), "data-testid": gridTestId, children: cards.map((card) => renderCard(card)) } ) ] }); }; exports.ReportLayout = ReportLayout; //# sourceMappingURL=chunk-HJTAGNGS.js.map