UNPKG

@devgateway/dvz-ui-react

Version:

A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.

122 lines (121 loc) 4.44 kB
import { jsx as o, jsxs as i, Fragment as R } from "react/jsx-runtime"; import v, { useState as I, useEffect as x } from "react"; import { Container as u, Grid as T, Label as M } from "semantic-ui-react"; import { PostProvider as _, PostConsumer as S, MediaProvider as B, MediaConsumer as H, PostIcon as N, utils as j } from "@devgateway/wp-react-lib"; import E from "../connected-templates/PostIntro.js"; import { useParams as V } from "react-router"; import k from "../connected-templates/PostContent.js"; const q = (f) => { const { posts: c, showIcons: w, showContentToggle: s, contentToggleHPosition: y, locale: C, readMoreLabel: d, readLessLabel: P } = f, [n, b] = I({}), l = v.createRef(), a = (t, e = "Read More") => t && t.trim() !== "" ? t : e; x(() => { window.setTimeout( () => { if (window.location.hash) { const t = document.getElementById(window.location.hash.substr(1)); t && t.scrollIntoView({ behavior: "auto", block: "start" }); } }, 0 ); }, [c]); const h = (t) => { const e = t.content ? t.content.rendered.split("<!--more-->") : []; return e.length > 1 ? e[1] : e[0]; }, m = (t) => { const e = n[t] || !1, r = e ? a(P, "Read less") : a(d, "Read more"); return /* @__PURE__ */ o("div", { children: /* @__PURE__ */ o("div", { style: { position: "relative", left: y + "%" }, children: /* @__PURE__ */ o("a", { className: "link", onClick: () => { l.current && e && (l.current.scrollIntoView({ behavior: "smooth", block: "start" }), l.current.scrollTop = 0), b({ ...n, [t]: !e }); }, children: r }) }) }); }, g = (t) => { const e = t.content ? t.content.rendered.split("<!--more-->") : [], r = e.length > 1 ? e[0] : null; return r ? r.trim() : null; }, p = (t) => { const e = t.content ? t.content.rendered.split("<!--more-->") : []; return e.length > 1 && e[1].trim().length > 0; }; return /* @__PURE__ */ o(u, { fluid: !0, className: "inline list", children: c && c.map((t) => /* @__PURE__ */ i(T, { children: [ w && /* @__PURE__ */ i(T.Column, { textAlign: "center", width: 1, children: [ /* @__PURE__ */ o("a", { id: t.slug }), /* @__PURE__ */ o( B, { id: t.meta_fields && t.meta_fields.icon ? t.meta_fields.icon[0] : null, children: /* @__PURE__ */ o(H, { children: /* @__PURE__ */ o(N, { as: M }) }) } ) ] }), /* @__PURE__ */ i(T.Column, { width: w ? 15 : 16, children: [ g(t) && /* @__PURE__ */ o(E, { as: u, fluid: !0, post: t, ref: l }), !g(t) && /* @__PURE__ */ o( k, { post: { content: { rendered: h(t) } }, style: { clear: "both", display: "block" } } ), p(t) && /* @__PURE__ */ i(u, { children: [ s && /* @__PURE__ */ i(R, { children: [ !n[t.slug] && m(t.slug), /* @__PURE__ */ o( k, { post: { content: { rendered: h(t) } }, style: { clear: "both", display: n[t.slug] ? "block" : "none" } } ), n[t.slug] && m(t.slug) ] }), !s && /* @__PURE__ */ o("a", { href: j.replaceLink(t.link, C), className: "link", children: a(d) }) ] }) ] }) ] })) }); }, K = (f) => { const [c, w] = I(Math.random() * 99998 + 1), { locale: s } = V(), { "data-width": y, "data-height": C, "data-type": d, "data-taxonomy": P, "data-categories": n, "data-items": b, "data-color": l, "data-show-post-icons": a, "data-show-content-toggle": h, "data-content-toggle-h-position": m, //horizontal position "data-read-more-label": g, "data-read-less-label": p, parent: t, editing: e, component: r, unique: L } = f; return /* @__PURE__ */ o(u, { fluid: !0, children: /* @__PURE__ */ o( _, { type: d, locale: s, taxonomy: P, categories: n, store: "inline_list_" + t + "_" + L, page: 1, perPage: b, children: /* @__PURE__ */ o(S, { children: /* @__PURE__ */ o( q, { locale: s ?? "en", showIcons: a === "true", showContentToggle: h === "true", contentToggleHPosition: parseInt(m || "50", 10), readMoreLabel: g, readLessLabel: p } ) }) } ) }); }; export { K as default };