@helpdice/ui 2.6.0-beta.7 → 2.6.0-beta.8

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.js CHANGED
@@ -12,6 +12,7 @@ var pro = require('@helpdice/pro');
12
12
  var reactSyntaxHighlighter = require('react-syntax-highlighter');
13
13
  var prism = require('react-syntax-highlighter/dist/cjs/styles/prism');
14
14
  var require$$0 = require('react-is');
15
+ var Button$1 = require('components/button');
15
16
  var isEqual = require('react-fast-compare');
16
17
 
17
18
  function _interopNamespaceDefault(e) {
@@ -42459,27 +42460,45 @@ function Clipboard(props) {
42459
42460
 
42460
42461
  var Expandable = function Expandable(_ref) {
42461
42462
  var children = _ref.children,
42462
- collapsedHeight = _ref.collapsedHeight;
42463
+ _ref$collapsedHeight = _ref.collapsedHeight,
42464
+ collapsedHeight = _ref$collapsedHeight === void 0 ? 150 : _ref$collapsedHeight,
42465
+ _ref$fadeHeight = _ref.fadeHeight,
42466
+ fadeHeight = _ref$fadeHeight === void 0 ? 40 : _ref$fadeHeight,
42467
+ className = _ref.className,
42468
+ _ref$transitionDurati = _ref.transitionDuration,
42469
+ transitionDuration = _ref$transitionDurati === void 0 ? 300 : _ref$transitionDurati;
42463
42470
  var contentRef = React.useRef(null);
42471
+ var containerRef = React.useRef(null);
42464
42472
  var _useState = React.useState(false),
42465
42473
  _useState2 = _slicedToArray(_useState, 2),
42466
42474
  expanded = _useState2[0],
42467
42475
  setExpanded = _useState2[1];
42468
- var _useState3 = React.useState(0),
42476
+ var _useState3 = React.useState(false),
42469
42477
  _useState4 = _slicedToArray(_useState3, 2),
42470
- fullHeight = _useState4[0],
42471
- setFullHeight = _useState4[1];
42472
- var _useState5 = React.useState(false),
42478
+ isOverflowing = _useState4[0],
42479
+ setIsOverflowing = _useState4[1];
42480
+ var _useState5 = React.useState(0),
42473
42481
  _useState6 = _slicedToArray(_useState5, 2),
42474
- isOverflowing = _useState6[0],
42475
- setIsOverflowing = _useState6[1];
42482
+ contentHeight = _useState6[0],
42483
+ setContentHeight = _useState6[1];
42484
+ var _useState7 = React.useState("#fff"),
42485
+ _useState8 = _slicedToArray(_useState7, 2),
42486
+ fadeColor = _useState8[0],
42487
+ setFadeColor = _useState8[1];
42488
+
42489
+ // Measure content height and detect overflow
42476
42490
  React.useEffect(function () {
42477
42491
  var el = contentRef.current;
42478
42492
  if (!el) return;
42479
42493
  var updateHeight = function updateHeight() {
42494
+ var _containerRef$current;
42480
42495
  var scrollHeight = el.scrollHeight;
42481
- setFullHeight(scrollHeight);
42496
+ setContentHeight(scrollHeight);
42482
42497
  setIsOverflowing(scrollHeight > collapsedHeight);
42498
+
42499
+ // Detect background color dynamically
42500
+ var parentBg = window.getComputedStyle((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 ? _containerRef$current : el).backgroundColor;
42501
+ setFadeColor(parentBg || "#fff");
42483
42502
  };
42484
42503
  updateHeight();
42485
42504
  var observer = new ResizeObserver(updateHeight);
@@ -42488,28 +42507,48 @@ var Expandable = function Expandable(_ref) {
42488
42507
  return observer.disconnect();
42489
42508
  };
42490
42509
  }, [children, collapsedHeight]);
42510
+ var containerHeight = !isOverflowing ? contentHeight : expanded ? contentHeight : collapsedHeight;
42511
+ var fadeStyle = {
42512
+ position: "absolute",
42513
+ bottom: 0,
42514
+ left: 0,
42515
+ right: 0,
42516
+ height: fadeHeight,
42517
+ background: "linear-gradient(to bottom, rgba(255,255,255,0), ".concat(fadeColor, ")"),
42518
+ pointerEvents: "none",
42519
+ transition: "opacity ".concat(transitionDuration, "ms ease"),
42520
+ opacity: !expanded && isOverflowing ? 1 : 0
42521
+ };
42522
+ var toggleExpanded = function toggleExpanded() {
42523
+ return setExpanded(function (prev) {
42524
+ return !prev;
42525
+ });
42526
+ };
42527
+ var handleKey = function handleKey(e) {
42528
+ if (e.key === "Enter" || e.key === " ") {
42529
+ e.preventDefault();
42530
+ toggleExpanded();
42531
+ }
42532
+ };
42491
42533
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
42534
+ ref: containerRef,
42535
+ className: className,
42492
42536
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
42493
42537
  style: {
42494
- height: expanded ? fullHeight : collapsedHeight,
42538
+ height: containerHeight,
42495
42539
  overflow: "hidden",
42496
- transition: "height 0.3s ease",
42540
+ transition: "height ".concat(transitionDuration, "ms ease"),
42497
42541
  position: "relative"
42498
42542
  },
42499
42543
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
42500
42544
  ref: contentRef,
42501
42545
  children: children
42502
- }), !expanded && isOverflowing && /*#__PURE__*/jsxRuntime.jsx("div", {
42503
- style: {
42504
- position: "absolute",
42505
- bottom: 0,
42506
- left: 0,
42507
- right: 0,
42508
- height: 40,
42509
- background: "linear-gradient(to bottom, rgba(255,255,255,0), white)"
42510
- }
42546
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
42547
+ style: fadeStyle
42511
42548
  })]
42512
- }), isOverflowing && /*#__PURE__*/jsxRuntime.jsx(Button, {
42549
+ }), isOverflowing && /*#__PURE__*/jsxRuntime.jsx(Button$1, {
42550
+ "aria-expanded": expanded,
42551
+ onKeyDown: handleKey,
42513
42552
  margin: 0,
42514
42553
  padding: 0,
42515
42554
  onClick: function onClick() {
@@ -1,7 +1,10 @@
1
1
  import React from "react";
2
- interface ExpandableProps {
2
+ export interface ExpandableProps {
3
3
  children: React.ReactNode;
4
- collapsedHeight: number;
4
+ collapsedHeight?: number;
5
+ fadeHeight?: number;
6
+ className?: string;
7
+ transitionDuration?: number;
5
8
  }
6
9
  declare const Expandable: React.FC<ExpandableProps>;
7
10
  export default Expandable;
@@ -1,29 +1,47 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import Button from "../button";
2
+ import Button from "components/button";
3
3
  import React, { useEffect, useRef, useState } from "react";
4
4
  var Expandable = function Expandable(_ref) {
5
5
  var children = _ref.children,
6
- collapsedHeight = _ref.collapsedHeight;
6
+ _ref$collapsedHeight = _ref.collapsedHeight,
7
+ collapsedHeight = _ref$collapsedHeight === void 0 ? 150 : _ref$collapsedHeight,
8
+ _ref$fadeHeight = _ref.fadeHeight,
9
+ fadeHeight = _ref$fadeHeight === void 0 ? 40 : _ref$fadeHeight,
10
+ className = _ref.className,
11
+ _ref$transitionDurati = _ref.transitionDuration,
12
+ transitionDuration = _ref$transitionDurati === void 0 ? 300 : _ref$transitionDurati;
7
13
  var contentRef = useRef(null);
14
+ var containerRef = useRef(null);
8
15
  var _useState = useState(false),
9
16
  _useState2 = _slicedToArray(_useState, 2),
10
17
  expanded = _useState2[0],
11
18
  setExpanded = _useState2[1];
12
- var _useState3 = useState(0),
19
+ var _useState3 = useState(false),
13
20
  _useState4 = _slicedToArray(_useState3, 2),
14
- fullHeight = _useState4[0],
15
- setFullHeight = _useState4[1];
16
- var _useState5 = useState(false),
21
+ isOverflowing = _useState4[0],
22
+ setIsOverflowing = _useState4[1];
23
+ var _useState5 = useState(0),
17
24
  _useState6 = _slicedToArray(_useState5, 2),
18
- isOverflowing = _useState6[0],
19
- setIsOverflowing = _useState6[1];
25
+ contentHeight = _useState6[0],
26
+ setContentHeight = _useState6[1];
27
+ var _useState7 = useState("#fff"),
28
+ _useState8 = _slicedToArray(_useState7, 2),
29
+ fadeColor = _useState8[0],
30
+ setFadeColor = _useState8[1];
31
+
32
+ // Measure content height and detect overflow
20
33
  useEffect(function () {
21
34
  var el = contentRef.current;
22
35
  if (!el) return;
23
36
  var updateHeight = function updateHeight() {
37
+ var _containerRef$current;
24
38
  var scrollHeight = el.scrollHeight;
25
- setFullHeight(scrollHeight);
39
+ setContentHeight(scrollHeight);
26
40
  setIsOverflowing(scrollHeight > collapsedHeight);
41
+
42
+ // Detect background color dynamically
43
+ var parentBg = window.getComputedStyle((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 ? _containerRef$current : el).backgroundColor;
44
+ setFadeColor(parentBg || "#fff");
27
45
  };
28
46
  updateHeight();
29
47
  var observer = new ResizeObserver(updateHeight);
@@ -32,25 +50,46 @@ var Expandable = function Expandable(_ref) {
32
50
  return observer.disconnect();
33
51
  };
34
52
  }, [children, collapsedHeight]);
35
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
53
+ var containerHeight = !isOverflowing ? contentHeight : expanded ? contentHeight : collapsedHeight;
54
+ var fadeStyle = {
55
+ position: "absolute",
56
+ bottom: 0,
57
+ left: 0,
58
+ right: 0,
59
+ height: fadeHeight,
60
+ background: "linear-gradient(to bottom, rgba(255,255,255,0), ".concat(fadeColor, ")"),
61
+ pointerEvents: "none",
62
+ transition: "opacity ".concat(transitionDuration, "ms ease"),
63
+ opacity: !expanded && isOverflowing ? 1 : 0
64
+ };
65
+ var toggleExpanded = function toggleExpanded() {
66
+ return setExpanded(function (prev) {
67
+ return !prev;
68
+ });
69
+ };
70
+ var handleKey = function handleKey(e) {
71
+ if (e.key === "Enter" || e.key === " ") {
72
+ e.preventDefault();
73
+ toggleExpanded();
74
+ }
75
+ };
76
+ return /*#__PURE__*/React.createElement("div", {
77
+ ref: containerRef,
78
+ className: className
79
+ }, /*#__PURE__*/React.createElement("div", {
36
80
  style: {
37
- height: expanded ? fullHeight : collapsedHeight,
81
+ height: containerHeight,
38
82
  overflow: "hidden",
39
- transition: "height 0.3s ease",
83
+ transition: "height ".concat(transitionDuration, "ms ease"),
40
84
  position: "relative"
41
85
  }
42
86
  }, /*#__PURE__*/React.createElement("div", {
43
87
  ref: contentRef
44
- }, children), !expanded && isOverflowing && /*#__PURE__*/React.createElement("div", {
45
- style: {
46
- position: "absolute",
47
- bottom: 0,
48
- left: 0,
49
- right: 0,
50
- height: 40,
51
- background: "linear-gradient(to bottom, rgba(255,255,255,0), white)"
52
- }
88
+ }, children), /*#__PURE__*/React.createElement("div", {
89
+ style: fadeStyle
53
90
  })), isOverflowing && /*#__PURE__*/React.createElement(Button, {
91
+ "aria-expanded": expanded,
92
+ onKeyDown: handleKey,
54
93
  margin: 0,
55
94
  padding: 0,
56
95
  onClick: function onClick() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helpdice/ui",
3
- "version": "2.6.0-beta.7",
3
+ "version": "2.6.0-beta.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "unpkg": "dist/index.min.js",