UNPKG

react-antd-admin-panel

Version:

Modern TypeScript-first React admin panel builder with Ant Design 6

188 lines (187 loc) 4.92 kB
"use strict"; var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); const jsxRuntime = require("react/jsx-runtime"); const React = require("react"); const antd = require("antd"); const BaseBuilder = require("./BaseBuilder-ByZeEu3_.cjs"); class Section extends BaseBuilder.BaseBuilder { constructor() { super(...arguments); __publicField(this, "_children", []); __publicField(this, "_rowChildren", []); } /** * Set column span (24-grid system) */ col(span) { this._config.col = span; return this; } /** * Set responsive breakpoints for column span */ responsive(breakpoints) { this._config.responsive = breakpoints; return this; } /** * Enable row layout (horizontal) */ row(value = true) { this._config.row = value; return this; } /** * Wrap in Card component */ card(value = true) { if (typeof value === "boolean") { this._config.card = value; } else { this._config.card = true; this._config.cardProps = value; } return this; } /** * Render in Modal */ modal(value = true) { if (typeof value === "boolean") { this._config.modal = value; } else { this._config.modal = true; this._config.modalProps = value; } return this; } /** * Render in Drawer */ drawer(value = true) { if (typeof value === "boolean") { this._config.drawer = value; } else { this._config.drawer = true; this._config.drawerProps = value; } return this; } /** * Set row justify alignment */ justify(value) { this._config.justify = value; return this; } /** * Set row align */ align(value) { this._config.align = value; return this; } /** * Set gutter (spacing between columns) */ gutter(value) { this._config.gutter = value; return this; } /** * Set custom styles */ style(value) { this._config.style = value; return this; } /** * Add a child component */ add(child) { this._children.push(child); return this; } /** * Add multiple children */ addMore(children) { children.forEach((child) => this.add(child)); return this; } /** * Add child to row-end position */ addRowEnd(child) { this._rowChildren.push(child); return this; } /** * Clear all children */ clear() { this._children = []; this._rowChildren = []; return this; } /** * Get all children */ getChildren() { return [...this._children]; } /** * Render method for compatibility - returns a SectionComponent */ render() { if (this._config.hidden) { return null; } return /* @__PURE__ */ jsxRuntime.jsx(SectionComponent, { section: this }); } } const SectionComponent = React.memo(({ section }) => { if (section._config.hidden) { return null; } const children = [...section._children, ...section._rowChildren]; const renderedChildren = children.map((child, index) => { if (child && typeof child === "object" && "render" in child && typeof child.render === "function") { return /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: child.render() }, index); } return /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: child }, index); }); let content; if (section._config.row) { const rowProps = { justify: section._config.justify, align: section._config.align, gutter: section._config.gutter, style: section._config.style }; content = /* @__PURE__ */ jsxRuntime.jsx(antd.Row, { ...rowProps, children: renderedChildren }); } else { content = /* @__PURE__ */ jsxRuntime.jsx("div", { style: section._config.style, children: renderedChildren }); } if (section._config.card) { content = /* @__PURE__ */ jsxRuntime.jsx(antd.Card, { ...section._config.cardProps, children: content }); } if (section._config.col || section._config.responsive) { const colProps = { span: section._config.col, ...section._config.responsive }; content = /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { ...colProps, children: content }); } if (section._config.modal) { content = /* @__PURE__ */ jsxRuntime.jsx(antd.Modal, { open: true, ...section._config.modalProps, children: content }); } if (section._config.drawer) { content = /* @__PURE__ */ jsxRuntime.jsx(antd.Drawer, { open: true, ...section._config.drawerProps, children: content }); } return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: content }); }); exports.Section = Section; //# sourceMappingURL=Section-QsEya_jl.cjs.map