react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
189 lines (188 loc) • 4.78 kB
JavaScript
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);
import { jsx, Fragment } from "react/jsx-runtime";
import React from "react";
import { Card, Col, Modal, Drawer, Row } from "antd";
import { B as BaseBuilder } from "./BaseBuilder-dOpE6Uh1.js";
class Section extends 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__ */ 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__ */ jsx(React.Fragment, { children: child.render() }, index);
}
return /* @__PURE__ */ 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__ */ jsx(Row, { ...rowProps, children: renderedChildren });
} else {
content = /* @__PURE__ */ jsx("div", { style: section._config.style, children: renderedChildren });
}
if (section._config.card) {
content = /* @__PURE__ */ jsx(Card, { ...section._config.cardProps, children: content });
}
if (section._config.col || section._config.responsive) {
const colProps = {
span: section._config.col,
...section._config.responsive
};
content = /* @__PURE__ */ jsx(Col, { ...colProps, children: content });
}
if (section._config.modal) {
content = /* @__PURE__ */ jsx(Modal, { open: true, ...section._config.modalProps, children: content });
}
if (section._config.drawer) {
content = /* @__PURE__ */ jsx(Drawer, { open: true, ...section._config.drawerProps, children: content });
}
return /* @__PURE__ */ jsx(Fragment, { children: content });
});
export {
Section as S
};
//# sourceMappingURL=Section-ColPnZCN.js.map