@sesionario/blocks 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -456,6 +456,68 @@ function ConfirmDestructiveDialog({
456
456
  ] })
457
457
  ] }) });
458
458
  }
459
+ var COLLAPSED_MAX_HEIGHT_REM = 11;
460
+ function ExpandableText({
461
+ children,
462
+ expandLabel,
463
+ collapseLabel,
464
+ className,
465
+ textClassName
466
+ }) {
467
+ const [expanded, setExpanded] = React6.useState(false);
468
+ const [overflowing, setOverflowing] = React6.useState(false);
469
+ const contentRef = React6.useRef(null);
470
+ React6.useEffect(() => {
471
+ setExpanded(false);
472
+ }, [children]);
473
+ React6.useLayoutEffect(() => {
474
+ const el = contentRef.current;
475
+ if (!el) return;
476
+ const measure = () => {
477
+ const rootFontSize = Number.parseFloat(
478
+ getComputedStyle(document.documentElement).fontSize
479
+ );
480
+ const maxPx = COLLAPSED_MAX_HEIGHT_REM * (rootFontSize || 16);
481
+ setOverflowing(el.scrollHeight > maxPx + 1);
482
+ };
483
+ measure();
484
+ const observer = new ResizeObserver(measure);
485
+ observer.observe(el);
486
+ return () => observer.disconnect();
487
+ }, [children]);
488
+ const collapsed = !expanded && overflowing;
489
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("space-y-1", className), children: [
490
+ /* @__PURE__ */ jsxRuntime.jsx(
491
+ "div",
492
+ {
493
+ className: cn(
494
+ collapsed && "max-h-[11rem] overflow-hidden scroll-fade-b"
495
+ ),
496
+ children: /* @__PURE__ */ jsxRuntime.jsx(
497
+ "p",
498
+ {
499
+ ref: contentRef,
500
+ className: cn(
501
+ "whitespace-pre-wrap text-sm leading-relaxed",
502
+ textClassName
503
+ ),
504
+ children
505
+ }
506
+ )
507
+ }
508
+ ),
509
+ overflowing ? /* @__PURE__ */ jsxRuntime.jsx(
510
+ "button",
511
+ {
512
+ type: "button",
513
+ className: "text-sm font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 rounded-sm",
514
+ "aria-expanded": expanded,
515
+ onClick: () => setExpanded((prev) => !prev),
516
+ children: expanded ? collapseLabel : expandLabel
517
+ }
518
+ ) : null
519
+ ] });
520
+ }
459
521
  var MIN_SCALE = 1;
460
522
  var MAX_SCALE = 4;
461
523
  var DOUBLE_TAP_MS = 300;
@@ -6029,6 +6091,7 @@ exports.EmptyMedia = EmptyMedia;
6029
6091
  exports.EmptyState = EmptyState;
6030
6092
  exports.EmptyTitle = EmptyTitle;
6031
6093
  exports.ErrorState = ErrorState;
6094
+ exports.ExpandableText = ExpandableText;
6032
6095
  exports.ImageLightbox = ImageLightbox;
6033
6096
  exports.LanguageContext = LanguageContext;
6034
6097
  exports.LanguageSwitcher = LanguageSwitcher;