UNPKG

@anoki/fse-ui

Version:

FSE UI components library

78 lines (77 loc) 2.11 kB
import { j as e } from "./index.es237.js"; import o, { useMemo as S } from "react"; import './sections/RichText/RichText.css';/* empty css */ import { HTML as m } from "./index.es148.js"; import { clsx as d } from "./index.es239.js"; import { Section as c } from "./index.es123.js"; import { Col as E } from "./index.es61.js"; const z = ({ title: i, description: t, fontSize: f = "2", mdFontSize: u = "2", classNameTitle: h, additionalClass: g, children: x, maxLines: r = void 0 }) => { const [s, p] = o.useState( typeof r == "number" ), [a, j] = o.useState(!1), l = o.useRef(null), v = () => { p(!s); }; o.useLayoutEffect(() => { const n = () => { if (l.current) { const { scrollHeight: w, clientHeight: y } = l.current; j(w > y); } }; return n(), window.addEventListener("resize", n), () => window.removeEventListener("resize", n); }, [t, r]); const b = S(() => t ? typeof t == "string" && o.isValidElement(t) || !r ? m(t.toString(), "div") : /* @__PURE__ */ e.jsxs(e.Fragment, { children: [ /* @__PURE__ */ e.jsx( "div", { ref: l, className: d( "rich-text-body", s && "rich-text-body--clamped" ), style: { "--max-lines": r }, children: m(t.toString(), "div") } ), a && /* @__PURE__ */ e.jsxs( "a", { "aria-label": "Mostra altro", className: "toggle-clamped-btn", onClick: v, children: [ "Mostra ", s ? "altro" : "meno" ] } ) ] }) : null, [t, s, r, a]); return /* @__PURE__ */ e.jsxs(c, { className: d("base-col ui-rich-text-section", g), children: [ /* @__PURE__ */ e.jsxs(E, { className: "ui-rich-text-content", children: [ i && /* @__PURE__ */ e.jsx( c.Title, { fs: f, mdFs: u, className: h, children: i } ), /* @__PURE__ */ e.jsx(c.Description, { children: b }) ] }), x ] }); }; export { z as RichText }; //# sourceMappingURL=index.es143.js.map