@lanaco/lnc-react-ui
Version:
React component library
43 lines (42 loc) • 1.71 kB
JavaScript
import { jsx as A } from "react/jsx-runtime";
import { forwardRef as W, useState as g, useRef as v, useImperativeHandle as P, Children as B, isValidElement as Y, cloneElement as i } from "react";
import { s as D } from "./emotion-styled.browser.esm-DfbrHHed.js";
import { u as L } from "./useUpdateEffect-CuYWz7EA.js";
const R = D.div``, K = W((V, y) => {
const {
defaultViewType: a,
activeViewType: r,
//------------------
className: f = "",
children: T,
...w
} = V, [p, s] = g(
r || a
), t = v([a]);
P(y, () => ({
changeView(e) {
I(e);
},
goToBackView() {
o();
}
})), L(() => {
s(r);
}, [r]);
const I = (e) => {
s(e), t.current.push(e);
}, o = () => {
var e;
t.current.pop(), ((e = t.current) == null ? void 0 : e.length) > 0 && s(t.current[t.current.length - 1]);
}, N = B.map(T, (e) => {
var n, _, E, m, u;
if (Y(e) && (e.props.__TYPE__ == "TABLE_VIEW" || ((n = e == null ? void 0 : e.type) == null ? void 0 : n.displayName) === "TABLE_VIEW" || e.props.__TYPE__ == "DETAILS_VIEW" || ((_ = e == null ? void 0 : e.type) == null ? void 0 : _.displayName) === "DETAILS_VIEW" || e.props.__TYPE__ == "FORM_VIEW" || ((E = e == null ? void 0 : e.type) == null ? void 0 : E.displayName) === "FORM_VIEW" || e.props.__TYPE__ == "KANBAN_VIEW" || ((m = e == null ? void 0 : e.type) == null ? void 0 : m.displayName) === "KANBAN_VIEW") && (e.props.__TYPE__ == p || ((u = e == null ? void 0 : e.type) == null ? void 0 : u.displayName) === p))
return i(e, {
goToPreviousView: o
});
});
return /* @__PURE__ */ A(R, { className: "lnc-ui-dataview " + f, ...w, children: N });
});
export {
K as default
};