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

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.
@@ -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, useState } from "react";
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 Button from "../button";
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 > 50 ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
49
- style: {
50
- maxHeight: expand ? '100%' : "".concat(collapse, "px"),
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);
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ interface ExpandableProps {
3
+ children: React.ReactNode;
4
+ collapsedHeight: number;
5
+ }
6
+ declare const Expandable: React.FC<ExpandableProps>;
7
+ export default Expandable;
@@ -0,0 +1,67 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import Button from "../button";
3
+ import React, { useEffect, useRef, useState } from "react";
4
+ var Expandable = function Expandable(_ref) {
5
+ var children = _ref.children,
6
+ collapsedHeight = _ref.collapsedHeight;
7
+ var contentRef = useRef(null);
8
+ var _useState = useState(false),
9
+ _useState2 = _slicedToArray(_useState, 2),
10
+ expanded = _useState2[0],
11
+ setExpanded = _useState2[1];
12
+ var _useState3 = useState(0),
13
+ _useState4 = _slicedToArray(_useState3, 2),
14
+ fullHeight = _useState4[0],
15
+ setFullHeight = _useState4[1];
16
+ var _useState5 = useState(false),
17
+ _useState6 = _slicedToArray(_useState5, 2),
18
+ isOverflowing = _useState6[0],
19
+ setIsOverflowing = _useState6[1];
20
+ useEffect(function () {
21
+ var el = contentRef.current;
22
+ if (!el) return;
23
+ var updateHeight = function updateHeight() {
24
+ var scrollHeight = el.scrollHeight;
25
+ setFullHeight(scrollHeight);
26
+ setIsOverflowing(scrollHeight > collapsedHeight);
27
+ };
28
+ updateHeight();
29
+ var observer = new ResizeObserver(updateHeight);
30
+ observer.observe(el);
31
+ return function () {
32
+ return observer.disconnect();
33
+ };
34
+ }, [children, collapsedHeight]);
35
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
36
+ style: {
37
+ height: expanded ? fullHeight : collapsedHeight,
38
+ overflow: "hidden",
39
+ transition: "height 0.3s ease",
40
+ position: "relative"
41
+ }
42
+ }, /*#__PURE__*/React.createElement("div", {
43
+ 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
+ }
53
+ })), isOverflowing && /*#__PURE__*/React.createElement(Button, {
54
+ margin: 0,
55
+ padding: 0,
56
+ onClick: function onClick() {
57
+ return setExpanded(function (prev) {
58
+ return !prev;
59
+ });
60
+ },
61
+ effect: false,
62
+ color: "abort",
63
+ scale: 2 / 3,
64
+ auto: true
65
+ }, /*#__PURE__*/React.createElement("b", null, expanded ? 'Show less' : 'Show more')));
66
+ };
67
+ export default Expandable;
@@ -0,0 +1,2 @@
1
+ import Expandable from "./expand";
2
+ export default Expandable;
@@ -0,0 +1,2 @@
1
+ import Expandable from "./expand";
2
+ export default Expandable;
package/esm/index.d.ts CHANGED
@@ -129,3 +129,4 @@ export type { CarouselProps } from './carousal';
129
129
  export { default as useToasts } from './use-toasts';
130
130
  export type { Toast, ToastInput, ToastAction, ToastLayout } from './use-toasts';
131
131
  export { default as Clipboard } from './copy-to-clipboard';
132
+ export { default as Expandable } from './expandable';
package/esm/index.js CHANGED
@@ -88,4 +88,5 @@ export { default as Carousel } from './carousal';
88
88
  // export type { CurrencyInputProps, CurrencyInputOnChangeValues } from './input/input-currency';
89
89
 
90
90
  export { default as useToasts } from './use-toasts';
91
- export { default as Clipboard } from './copy-to-clipboard';
91
+ export { default as Clipboard } from './copy-to-clipboard';
92
+ export { default as Expandable } from './expandable';
@@ -15,7 +15,6 @@ interface Props {
15
15
  span?: boolean;
16
16
  del?: boolean;
17
17
  em?: boolean;
18
- collapse?: number;
19
18
  blockquote?: boolean;
20
19
  noWrap?: boolean;
21
20
  className?: string;
package/esm/text/text.js CHANGED
@@ -1,12 +1,10 @@
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
- var _excluded = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "b", "small", "i", "span", "del", "em", "blockquote", "noWrap", "collapse", "children", "className", "display", "alignItems", "justify"];
3
+ var _excluded = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "b", "small", "i", "span", "del", "em", "blockquote", "noWrap", "children", "className", "display", "alignItems", "justify"];
5
4
  /* "use client" */;
6
- import React, { useMemo, useState } from 'react';
5
+ import React, { useMemo } from 'react';
7
6
  import TextChild from './child';
8
7
  import { withScale } from '../use-scale';
9
- import Button from '../button';
10
8
  var _getModifierChild = function getModifierChild(tags, children) {
11
9
  if (!tags.length) return children;
12
10
  var nextTag = tags.slice(1, tags.length);
@@ -45,8 +43,6 @@ var TextComponent = function TextComponent(_ref) {
45
43
  blockquote = _ref$blockquote === void 0 ? false : _ref$blockquote,
46
44
  _ref$noWrap = _ref.noWrap,
47
45
  noWrap = _ref$noWrap === void 0 ? false : _ref$noWrap,
48
- _ref$collapse = _ref.collapse,
49
- collapse = _ref$collapse === void 0 ? 0 : _ref$collapse,
50
46
  children = _ref.children,
51
47
  _ref$className = _ref.className,
52
48
  className = _ref$className === void 0 ? '' : _ref$className,
@@ -90,10 +86,6 @@ var TextComponent = function TextComponent(_ref) {
90
86
  *
91
87
  */
92
88
 
93
- var _useState = useState(false),
94
- _useState2 = _slicedToArray(_useState, 2),
95
- expand = _useState2[0],
96
- setExpand = _useState2[1];
97
89
  var tag = useMemo(function () {
98
90
  if (names[0]) return names[0];
99
91
  if (inlineNames[0]) return inlineNames[0];
@@ -115,21 +107,7 @@ var TextComponent = function TextComponent(_ref) {
115
107
  },
116
108
  className: "".concat(className, " ").concat(noWrap ? 'no-wrap' : ''),
117
109
  tag: tag
118
- }, props), typeof children === 'string' && collapse > 50 ? /*#__PURE__*/React.createElement(React.Fragment, null, expand ? modifers : (modifers === null || modifers === void 0 ? void 0 : modifers.toString().substring(0, collapse)) + '...', /*#__PURE__*/React.createElement(Button, {
119
- margin: 0,
120
- onClick: function onClick() {
121
- return setExpand(!expand);
122
- },
123
- style: {
124
- textTransform: 'lowercase'
125
- },
126
- effect: false,
127
- color: "abort",
128
- scale: 2 / 3,
129
- px: 0.2,
130
- py: 0,
131
- auto: true
132
- }, /*#__PURE__*/React.createElement("b", null, expand ? 'less' : 'more'))) : modifers);
110
+ }, props), modifers);
133
111
  };
134
112
  TextComponent.displayName = 'Text';
135
113
  var Text = withScale(TextComponent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helpdice/ui",
3
- "version": "2.6.0-beta.5",
3
+ "version": "2.6.0-beta.7",
4
4
  "main": "dist/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "unpkg": "dist/index.min.js",
@@ -275,6 +275,11 @@
275
275
  "require": "./dist/drawer/index.js",
276
276
  "types": "./dist/drawer/index.d.ts"
277
277
  },
278
+ "./Expandable": {
279
+ "import": "./esm/expandable/index.js",
280
+ "require": "./dist/expandable/index.js",
281
+ "types": "./dist/expandable/index.d.ts"
282
+ },
278
283
  "./Fieldset": {
279
284
  "import": "./esm/fieldset/index.js",
280
285
  "require": "./dist/fieldset/index.js",
@@ -589,6 +594,9 @@
589
594
  "Drawer": [
590
595
  "dist/drawer/index.d.ts"
591
596
  ],
597
+ "Expandable": [
598
+ "dist/expandable/index.d.ts"
599
+ ],
592
600
  "Fieldset": [
593
601
  "dist/fieldset/index.d.ts"
594
602
  ],