UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

121 lines (120 loc) 3.04 kB
import { jsxs as a, Fragment as p, jsx as i } from "react/jsx-runtime"; import { useState as f } from "react"; import { Markdown as u } from "../Markdown/MarkdownSynapse.js"; import { Link as S } from "@mui/material"; const h = 400, w = "SRC-short-description", m = "SRC-long-description", g = (t, n) => { let e = ""; const r = t.split(" "); let o = 0; for (; e.length < n && o < r.length; ) e += `${r[o]} `, o += 1; return e = e.trim(), { previewText: e }; }; function D(t) { const { description: n, hasClickedShowMore: e, descriptionSubTitle: r, descriptionConfig: o, toggleShowMore: c, charCountCutoff: s = h } = t; let l = n; o?.isMarkdown && (l == null || typeof l == "string") && (l = /* @__PURE__ */ i(u, { markdown: l })); const d = e || o?.showFullDescriptionByDefault, C = c && !o?.showFullDescriptionByDefault && n.length >= s; return /* @__PURE__ */ a("div", { className: d ? "" : "SRC-hidden", children: [ /* @__PURE__ */ i( "span", { "data-search-handle": r, className: `SRC-font-size-base ${m}`, children: l } ), C && /* @__PURE__ */ i( S, { style: { fontSize: "16px", cursor: "pointer", marginLeft: "5px" }, onClick: c, children: "Show Less" } ) ] }); } function R(t) { const { description: n, hasClickedShowMore: e, descriptionSubTitle: r, descriptionConfig: o, toggleShowMore: c, charCountCutoff: s = h } = t; return o?.showFullDescriptionByDefault ? /* @__PURE__ */ i(p, {}) : /* @__PURE__ */ a("div", { className: e ? "SRC-hidden" : "", children: [ /* @__PURE__ */ i( "span", { "data-search-handle": r, className: `SRC-font-size-base ${w} SRC-short-description`, children: g(n, s).previewText } ), n.length >= s && /* @__PURE__ */ i( S, { style: { fontSize: "16px", cursor: "pointer", marginLeft: "5px" }, onClick: c, children: "...Show More" } ) ] }); } function _({ description: t, descriptionSubTitle: n, descriptionConfig: e, charCountCutoff: r = h }) { const [o, c] = f(!1), s = () => c((l) => !l); return /* @__PURE__ */ a(p, { children: [ t && /* @__PURE__ */ i( R, { description: t, hasClickedShowMore: o, descriptionSubTitle: n, descriptionConfig: e, toggleShowMore: s, charCountCutoff: r } ), t && /* @__PURE__ */ i( D, { description: t, hasClickedShowMore: o, descriptionSubTitle: n, descriptionConfig: e, toggleShowMore: s, charCountCutoff: r } ) ] }); } export { m as CARD_LONG_DESCRIPTION_CSS, w as CARD_SHORT_DESCRIPTION_CSS, _ as CollapsibleDescription, D as LongDescription, R as ShortDescription, g as getCutoff }; //# sourceMappingURL=CollapsibleDescription.js.map