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