@helpdice/ui 2.6.0-beta.7 → 2.6.0-beta.9
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/container/index.js +143 -1
- package/dist/expandable/expand.d.ts +5 -2
- package/dist/expandable/index.js +63 -1511
- package/dist/index.js +111 -73
- package/esm/container/box.js +1 -1
- package/esm/expandable/expand.d.ts +5 -2
- package/esm/expandable/expand.js +60 -21
- package/package.json +1 -1
package/dist/container/index.js
CHANGED
|
@@ -5,13 +5,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var theme = require('@helpdice/theme');
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
-
var
|
|
8
|
+
var Button = require('components/button');
|
|
9
9
|
|
|
10
10
|
function _arrayLikeToArray(r, a) {
|
|
11
11
|
(null == a || a > r.length) && (a = r.length);
|
|
12
12
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
13
13
|
return n;
|
|
14
14
|
}
|
|
15
|
+
function _arrayWithHoles(r) {
|
|
16
|
+
if (Array.isArray(r)) return r;
|
|
17
|
+
}
|
|
15
18
|
function _createForOfIteratorHelper(r, e) {
|
|
16
19
|
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
17
20
|
if (!t) {
|
|
@@ -68,6 +71,33 @@ function _defineProperty(e, r, t) {
|
|
|
68
71
|
writable: true
|
|
69
72
|
}) : e[r] = t, e;
|
|
70
73
|
}
|
|
74
|
+
function _iterableToArrayLimit(r, l) {
|
|
75
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
76
|
+
if (null != t) {
|
|
77
|
+
var e,
|
|
78
|
+
n,
|
|
79
|
+
i,
|
|
80
|
+
u,
|
|
81
|
+
a = [],
|
|
82
|
+
f = true,
|
|
83
|
+
o = false;
|
|
84
|
+
try {
|
|
85
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
86
|
+
} catch (r) {
|
|
87
|
+
o = true, n = r;
|
|
88
|
+
} finally {
|
|
89
|
+
try {
|
|
90
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
91
|
+
} finally {
|
|
92
|
+
if (o) throw n;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return a;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function _nonIterableRest() {
|
|
99
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
100
|
+
}
|
|
71
101
|
function ownKeys(e, r) {
|
|
72
102
|
var t = Object.keys(e);
|
|
73
103
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -109,6 +139,9 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
109
139
|
}
|
|
110
140
|
return t;
|
|
111
141
|
}
|
|
142
|
+
function _slicedToArray(r, e) {
|
|
143
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
144
|
+
}
|
|
112
145
|
function _toPrimitive(t, r) {
|
|
113
146
|
if ("object" != typeof t || !t) return t;
|
|
114
147
|
var e = t[Symbol.toPrimitive];
|
|
@@ -953,6 +986,115 @@ tuple('hover', 'click');
|
|
|
953
986
|
tuple('top', 'topStart', 'topEnd', 'left', 'leftStart', 'leftEnd', 'bottom', 'bottomStart', 'bottomEnd', 'right', 'rightStart', 'rightEnd');
|
|
954
987
|
tuple('start', 'center', 'end', 'left', 'right');
|
|
955
988
|
|
|
989
|
+
var Expandable = function Expandable(_ref) {
|
|
990
|
+
var children = _ref.children,
|
|
991
|
+
_ref$collapsedHeight = _ref.collapsedHeight,
|
|
992
|
+
collapsedHeight = _ref$collapsedHeight === void 0 ? 150 : _ref$collapsedHeight,
|
|
993
|
+
_ref$fadeHeight = _ref.fadeHeight,
|
|
994
|
+
fadeHeight = _ref$fadeHeight === void 0 ? 40 : _ref$fadeHeight,
|
|
995
|
+
className = _ref.className,
|
|
996
|
+
_ref$transitionDurati = _ref.transitionDuration,
|
|
997
|
+
transitionDuration = _ref$transitionDurati === void 0 ? 300 : _ref$transitionDurati;
|
|
998
|
+
var contentRef = React.useRef(null);
|
|
999
|
+
var containerRef = React.useRef(null);
|
|
1000
|
+
var _useState = React.useState(false),
|
|
1001
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1002
|
+
expanded = _useState2[0],
|
|
1003
|
+
setExpanded = _useState2[1];
|
|
1004
|
+
var _useState3 = React.useState(false),
|
|
1005
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
1006
|
+
isOverflowing = _useState4[0],
|
|
1007
|
+
setIsOverflowing = _useState4[1];
|
|
1008
|
+
var _useState5 = React.useState(0),
|
|
1009
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
1010
|
+
contentHeight = _useState6[0],
|
|
1011
|
+
setContentHeight = _useState6[1];
|
|
1012
|
+
var _useState7 = React.useState("#fff"),
|
|
1013
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
1014
|
+
fadeColor = _useState8[0],
|
|
1015
|
+
setFadeColor = _useState8[1];
|
|
1016
|
+
|
|
1017
|
+
// Measure content height and detect overflow
|
|
1018
|
+
React.useEffect(function () {
|
|
1019
|
+
var el = contentRef.current;
|
|
1020
|
+
if (!el) return;
|
|
1021
|
+
var updateHeight = function updateHeight() {
|
|
1022
|
+
var _containerRef$current;
|
|
1023
|
+
var scrollHeight = el.scrollHeight;
|
|
1024
|
+
setContentHeight(scrollHeight);
|
|
1025
|
+
setIsOverflowing(scrollHeight > collapsedHeight);
|
|
1026
|
+
|
|
1027
|
+
// Detect background color dynamically
|
|
1028
|
+
var parentBg = window.getComputedStyle((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 ? _containerRef$current : el).backgroundColor;
|
|
1029
|
+
setFadeColor(parentBg || "#fff");
|
|
1030
|
+
};
|
|
1031
|
+
updateHeight();
|
|
1032
|
+
var observer = new ResizeObserver(updateHeight);
|
|
1033
|
+
observer.observe(el);
|
|
1034
|
+
return function () {
|
|
1035
|
+
return observer.disconnect();
|
|
1036
|
+
};
|
|
1037
|
+
}, [children, collapsedHeight]);
|
|
1038
|
+
var containerHeight = !isOverflowing ? contentHeight : expanded ? contentHeight : collapsedHeight;
|
|
1039
|
+
var fadeStyle = {
|
|
1040
|
+
position: "absolute",
|
|
1041
|
+
bottom: 0,
|
|
1042
|
+
left: 0,
|
|
1043
|
+
right: 0,
|
|
1044
|
+
height: fadeHeight,
|
|
1045
|
+
background: "linear-gradient(to bottom, rgba(255,255,255,0), ".concat(fadeColor, ")"),
|
|
1046
|
+
pointerEvents: "none",
|
|
1047
|
+
transition: "opacity ".concat(transitionDuration, "ms ease"),
|
|
1048
|
+
opacity: !expanded && isOverflowing ? 1 : 0
|
|
1049
|
+
};
|
|
1050
|
+
var toggleExpanded = function toggleExpanded() {
|
|
1051
|
+
return setExpanded(function (prev) {
|
|
1052
|
+
return !prev;
|
|
1053
|
+
});
|
|
1054
|
+
};
|
|
1055
|
+
var handleKey = function handleKey(e) {
|
|
1056
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1057
|
+
e.preventDefault();
|
|
1058
|
+
toggleExpanded();
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
1062
|
+
ref: containerRef,
|
|
1063
|
+
className: className,
|
|
1064
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
1065
|
+
style: {
|
|
1066
|
+
height: containerHeight,
|
|
1067
|
+
overflow: "hidden",
|
|
1068
|
+
transition: "height ".concat(transitionDuration, "ms ease"),
|
|
1069
|
+
position: "relative"
|
|
1070
|
+
},
|
|
1071
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
1072
|
+
ref: contentRef,
|
|
1073
|
+
children: children
|
|
1074
|
+
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
1075
|
+
style: fadeStyle
|
|
1076
|
+
})]
|
|
1077
|
+
}), isOverflowing && /*#__PURE__*/jsxRuntime.jsx(Button, {
|
|
1078
|
+
"aria-expanded": expanded,
|
|
1079
|
+
onKeyDown: handleKey,
|
|
1080
|
+
margin: 0,
|
|
1081
|
+
padding: 0,
|
|
1082
|
+
onClick: function onClick() {
|
|
1083
|
+
return setExpanded(function (prev) {
|
|
1084
|
+
return !prev;
|
|
1085
|
+
});
|
|
1086
|
+
},
|
|
1087
|
+
effect: false,
|
|
1088
|
+
color: "abort",
|
|
1089
|
+
scale: 2 / 3,
|
|
1090
|
+
auto: true,
|
|
1091
|
+
children: /*#__PURE__*/jsxRuntime.jsx("b", {
|
|
1092
|
+
children: expanded ? 'Show less' : 'Show more'
|
|
1093
|
+
})
|
|
1094
|
+
})]
|
|
1095
|
+
});
|
|
1096
|
+
};
|
|
1097
|
+
|
|
956
1098
|
var _excluded = ["gap", "children", "direction", "justify", "alignItems", "alignContent", "collapse", "className"];
|
|
957
1099
|
var wrap = tuple('nowrap', 'wrap', 'wrap-reverse');
|
|
958
1100
|
var Container = function Container(_ref) {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
interface ExpandableProps {
|
|
2
|
+
export interface ExpandableProps {
|
|
3
3
|
children: React.ReactNode;
|
|
4
|
-
collapsedHeight
|
|
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;
|