@helpdice/ui 2.6.0-beta.6 → 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/container/index.js +10 -719
- package/dist/expandable/expand.d.ts +5 -2
- package/dist/expandable/index.js +63 -1511
- package/dist/index.js +63 -52
- package/esm/container/box.js +5 -30
- package/esm/expandable/expand.d.ts +5 -2
- package/esm/expandable/expand.js +60 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,11 +6,13 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
var icons = require('@helpdice/icons');
|
|
7
7
|
var framerMotion = require('framer-motion');
|
|
8
8
|
var reactDom = require('react-dom');
|
|
9
|
+
var Expandable$1 = require('components/expandable');
|
|
9
10
|
var reactDom$1 = require('@floating-ui/react-dom');
|
|
10
11
|
var pro = require('@helpdice/pro');
|
|
11
12
|
var reactSyntaxHighlighter = require('react-syntax-highlighter');
|
|
12
13
|
var prism = require('react-syntax-highlighter/dist/cjs/styles/prism');
|
|
13
14
|
var require$$0 = require('react-is');
|
|
15
|
+
var Button$1 = require('components/button');
|
|
14
16
|
var isEqual = require('react-fast-compare');
|
|
15
17
|
|
|
16
18
|
function _interopNamespaceDefault(e) {
|
|
@@ -13403,10 +13405,6 @@ var Container = function Container(_ref) {
|
|
|
13403
13405
|
_ref$className = _ref.className,
|
|
13404
13406
|
className = _ref$className === void 0 ? '' : _ref$className,
|
|
13405
13407
|
props = _objectWithoutProperties(_ref, _excluded$B);
|
|
13406
|
-
var _useState = React.useState(false),
|
|
13407
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
13408
|
-
expand = _useState2[0],
|
|
13409
|
-
setExpand = _useState2[1];
|
|
13410
13408
|
var _useScale = useScale(),
|
|
13411
13409
|
unit = _useScale.unit,
|
|
13412
13410
|
SCALES = _useScale.SCALES;
|
|
@@ -13427,34 +13425,9 @@ var Container = function Container(_ref) {
|
|
|
13427
13425
|
return /*#__PURE__*/jsxRuntime.jsxs(GridBasicItem, _objectSpread2(_objectSpread2({
|
|
13428
13426
|
className: classes
|
|
13429
13427
|
}, props), {}, {
|
|
13430
|
-
children: [collapse >
|
|
13431
|
-
|
|
13432
|
-
|
|
13433
|
-
maxHeight: expand ? '100%' : "".concat(collapse, "px"),
|
|
13434
|
-
overflow: 'hidden',
|
|
13435
|
-
display: 'inline',
|
|
13436
|
-
transition: "max-height 0.3s ease"
|
|
13437
|
-
},
|
|
13438
|
-
children: children
|
|
13439
|
-
}), /*#__PURE__*/jsxRuntime.jsx(Button, {
|
|
13440
|
-
margin: 0,
|
|
13441
|
-
onClick: function onClick() {
|
|
13442
|
-
return setExpand(!expand);
|
|
13443
|
-
},
|
|
13444
|
-
style: {
|
|
13445
|
-
textTransform: 'lowercase',
|
|
13446
|
-
height: '25px'
|
|
13447
|
-
},
|
|
13448
|
-
effect: false,
|
|
13449
|
-
color: "abort",
|
|
13450
|
-
scale: 2 / 3,
|
|
13451
|
-
px: 0.2,
|
|
13452
|
-
py: 0,
|
|
13453
|
-
auto: true,
|
|
13454
|
-
children: /*#__PURE__*/jsxRuntime.jsx("b", {
|
|
13455
|
-
children: expand ? 'less' : 'more'
|
|
13456
|
-
})
|
|
13457
|
-
})]
|
|
13428
|
+
children: [collapse > 10 ? /*#__PURE__*/jsxRuntime.jsx(Expandable$1, {
|
|
13429
|
+
collapsedHeight: collapse,
|
|
13430
|
+
children: children
|
|
13458
13431
|
}) : children, styles]
|
|
13459
13432
|
}));
|
|
13460
13433
|
};
|
|
@@ -42487,27 +42460,45 @@ function Clipboard(props) {
|
|
|
42487
42460
|
|
|
42488
42461
|
var Expandable = function Expandable(_ref) {
|
|
42489
42462
|
var children = _ref.children,
|
|
42490
|
-
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;
|
|
42491
42470
|
var contentRef = React.useRef(null);
|
|
42471
|
+
var containerRef = React.useRef(null);
|
|
42492
42472
|
var _useState = React.useState(false),
|
|
42493
42473
|
_useState2 = _slicedToArray(_useState, 2),
|
|
42494
42474
|
expanded = _useState2[0],
|
|
42495
42475
|
setExpanded = _useState2[1];
|
|
42496
|
-
var _useState3 = React.useState(
|
|
42476
|
+
var _useState3 = React.useState(false),
|
|
42497
42477
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
42498
|
-
|
|
42499
|
-
|
|
42500
|
-
var _useState5 = React.useState(
|
|
42478
|
+
isOverflowing = _useState4[0],
|
|
42479
|
+
setIsOverflowing = _useState4[1];
|
|
42480
|
+
var _useState5 = React.useState(0),
|
|
42501
42481
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
42502
|
-
|
|
42503
|
-
|
|
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
|
|
42504
42490
|
React.useEffect(function () {
|
|
42505
42491
|
var el = contentRef.current;
|
|
42506
42492
|
if (!el) return;
|
|
42507
42493
|
var updateHeight = function updateHeight() {
|
|
42494
|
+
var _containerRef$current;
|
|
42508
42495
|
var scrollHeight = el.scrollHeight;
|
|
42509
|
-
|
|
42496
|
+
setContentHeight(scrollHeight);
|
|
42510
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");
|
|
42511
42502
|
};
|
|
42512
42503
|
updateHeight();
|
|
42513
42504
|
var observer = new ResizeObserver(updateHeight);
|
|
@@ -42516,28 +42507,48 @@ var Expandable = function Expandable(_ref) {
|
|
|
42516
42507
|
return observer.disconnect();
|
|
42517
42508
|
};
|
|
42518
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
|
+
};
|
|
42519
42533
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
42534
|
+
ref: containerRef,
|
|
42535
|
+
className: className,
|
|
42520
42536
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
42521
42537
|
style: {
|
|
42522
|
-
height:
|
|
42538
|
+
height: containerHeight,
|
|
42523
42539
|
overflow: "hidden",
|
|
42524
|
-
transition: "height
|
|
42540
|
+
transition: "height ".concat(transitionDuration, "ms ease"),
|
|
42525
42541
|
position: "relative"
|
|
42526
42542
|
},
|
|
42527
42543
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
42528
42544
|
ref: contentRef,
|
|
42529
42545
|
children: children
|
|
42530
|
-
}),
|
|
42531
|
-
style:
|
|
42532
|
-
position: "absolute",
|
|
42533
|
-
bottom: 0,
|
|
42534
|
-
left: 0,
|
|
42535
|
-
right: 0,
|
|
42536
|
-
height: 40,
|
|
42537
|
-
background: "linear-gradient(to bottom, rgba(255,255,255,0), white)"
|
|
42538
|
-
}
|
|
42546
|
+
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
42547
|
+
style: fadeStyle
|
|
42539
42548
|
})]
|
|
42540
|
-
}), isOverflowing && /*#__PURE__*/jsxRuntime.jsx(Button, {
|
|
42549
|
+
}), isOverflowing && /*#__PURE__*/jsxRuntime.jsx(Button$1, {
|
|
42550
|
+
"aria-expanded": expanded,
|
|
42551
|
+
onKeyDown: handleKey,
|
|
42541
42552
|
margin: 0,
|
|
42542
42553
|
padding: 0,
|
|
42543
42554
|
onClick: function onClick() {
|
package/esm/container/box.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
3
|
var _excluded = ["gap", "children", "direction", "justify", "alignItems", "alignContent", "collapse", "className"];
|
|
5
4
|
import _JSXStyle from "../styled-jsx.es.js";
|
|
6
|
-
import React, { useMemo
|
|
5
|
+
import React, { useMemo } from "react";
|
|
7
6
|
import GridBasicItem from "../grid/basic-item";
|
|
8
7
|
import useScale, { withScale } from '../use-scale';
|
|
9
8
|
import { useClasses } from '@helpdice/theme';
|
|
10
9
|
import { tuple } from '../utils/prop-types';
|
|
11
|
-
import
|
|
10
|
+
import Expandable from "components/expandable";
|
|
12
11
|
var wrap = tuple('nowrap', 'wrap', 'wrap-reverse');
|
|
13
12
|
var Container = function Container(_ref) {
|
|
14
13
|
var _ref$gap = _ref.gap,
|
|
@@ -23,10 +22,6 @@ var Container = function Container(_ref) {
|
|
|
23
22
|
_ref$className = _ref.className,
|
|
24
23
|
className = _ref$className === void 0 ? '' : _ref$className,
|
|
25
24
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
26
|
-
var _useState = useState(false),
|
|
27
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
-
expand = _useState2[0],
|
|
29
|
-
setExpand = _useState2[1];
|
|
30
25
|
var _useScale = useScale(),
|
|
31
26
|
unit = _useScale.unit,
|
|
32
27
|
SCALES = _useScale.SCALES;
|
|
@@ -45,29 +40,9 @@ var Container = function Container(_ref) {
|
|
|
45
40
|
var classes = useClasses(resolveClassName, className);
|
|
46
41
|
return /*#__PURE__*/React.createElement(GridBasicItem, _extends({
|
|
47
42
|
className: classes
|
|
48
|
-
}, props), collapse >
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
overflow: 'hidden',
|
|
52
|
-
display: 'inline',
|
|
53
|
-
transition: "max-height 0.3s ease"
|
|
54
|
-
}
|
|
55
|
-
}, children), /*#__PURE__*/React.createElement(Button, {
|
|
56
|
-
margin: 0,
|
|
57
|
-
onClick: function onClick() {
|
|
58
|
-
return setExpand(!expand);
|
|
59
|
-
},
|
|
60
|
-
style: {
|
|
61
|
-
textTransform: 'lowercase',
|
|
62
|
-
height: '25px'
|
|
63
|
-
},
|
|
64
|
-
effect: false,
|
|
65
|
-
color: "abort",
|
|
66
|
-
scale: 2 / 3,
|
|
67
|
-
px: 0.2,
|
|
68
|
-
py: 0,
|
|
69
|
-
auto: true
|
|
70
|
-
}, /*#__PURE__*/React.createElement("b", null, expand ? 'less' : 'more'))) : children, styles);
|
|
43
|
+
}, props), collapse > 10 ? /*#__PURE__*/React.createElement(Expandable, {
|
|
44
|
+
collapsedHeight: collapse
|
|
45
|
+
}, children) : children, styles);
|
|
71
46
|
};
|
|
72
47
|
Container.displayName = 'Container';
|
|
73
48
|
export default withScale(Container);
|
|
@@ -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;
|
package/esm/expandable/expand.js
CHANGED
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import Button from "
|
|
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(
|
|
19
|
+
var _useState3 = useState(false),
|
|
13
20
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _useState5 = useState(
|
|
21
|
+
isOverflowing = _useState4[0],
|
|
22
|
+
setIsOverflowing = _useState4[1];
|
|
23
|
+
var _useState5 = useState(0),
|
|
17
24
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
81
|
+
height: containerHeight,
|
|
38
82
|
overflow: "hidden",
|
|
39
|
-
transition: "height
|
|
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),
|
|
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() {
|