@datarobot/design-system 30.4.0 → 30.5.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.
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import './expandable-content.less';
3
+ export type ExpandableContentProps = {
4
+ /** Content to render */
5
+ children: React.ReactNode;
6
+ /** Maximum height in pixels. When content exceeds this height it is clipped and a Show more/Show less button appears */
7
+ maxHeight: number;
8
+ /** Additional CSS class applied to the wrapper */
9
+ className?: string;
10
+ };
11
+ /** Clips content to a maximum height and shows a Show more/Show less ghost button when the content overflows.
12
+ * @midnight-gray-supported
13
+ * @alpine-light-supported
14
+ */
15
+ declare const ExpandableContent: React.FC<ExpandableContentProps>;
16
+ export { ExpandableContent };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ExpandableContent = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _faChevronDown = require("@fortawesome/free-solid-svg-icons/faChevronDown");
10
+ var _faChevronUp = require("@fortawesome/free-solid-svg-icons/faChevronUp");
11
+ var _button = require("../button");
12
+ var _useTranslation = require("../hooks/use-translation");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
+ /** Clips content to a maximum height and shows a Show more/Show less ghost button when the content overflows.
17
+ * @midnight-gray-supported
18
+ * @alpine-light-supported
19
+ */
20
+ const ExpandableContent = ({
21
+ children,
22
+ maxHeight,
23
+ className
24
+ }) => {
25
+ const [isExpanded, setIsExpanded] = (0, _react.useState)(false);
26
+ const [isOverflowing, setIsOverflowing] = (0, _react.useState)(false);
27
+ const contentRef = (0, _react.useRef)(null);
28
+ const {
29
+ t
30
+ } = (0, _useTranslation.useTranslation)();
31
+ (0, _react.useLayoutEffect)(() => {
32
+ if (contentRef.current) {
33
+ setIsOverflowing(contentRef.current.scrollHeight > maxHeight);
34
+ }
35
+ }, [children, maxHeight]);
36
+ const isClipped = isOverflowing && !isExpanded;
37
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
38
+ className: (0, _classnames.default)('expandable-content', className),
39
+ "test-id": "expandable-content",
40
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
41
+ ref: contentRef,
42
+ className: "expandable-content-body"
43
+ // eslint-disable-next-line react/forbid-dom-props
44
+ ,
45
+ style: isClipped ? {
46
+ maxHeight,
47
+ overflow: 'hidden'
48
+ } : undefined,
49
+ "test-id": "expandable-content-body",
50
+ children: children
51
+ }), isOverflowing && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
52
+ accentType: _button.ACCENT_TYPES.GHOST,
53
+ onClick: () => setIsExpanded(prev => !prev),
54
+ className: "expandable-content-toggle",
55
+ rightIcon: isExpanded ? _faChevronUp.faChevronUp : _faChevronDown.faChevronDown,
56
+ testId: "expandable-content-toggle",
57
+ children: isExpanded ? t('Show less') : t('Show more')
58
+ })]
59
+ });
60
+ };
61
+ exports.ExpandableContent = ExpandableContent;
@@ -0,0 +1,3 @@
1
+ import { ExpandableContent, ExpandableContentProps } from './expandable-content';
2
+ export type { ExpandableContentProps };
3
+ export { ExpandableContent };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "ExpandableContent", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _expandableContent.ExpandableContent;
10
+ }
11
+ });
12
+ var _expandableContent = require("./expandable-content");
package/cjs/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export * from './editable-text';
33
33
  export * from './embedded-steps';
34
34
  export * from './empty-state';
35
35
  export * from './error-boundary';
36
+ export * from './expandable-content';
36
37
  export * from './export-button';
37
38
  export * from './file-tree';
38
39
  export * from './file-upload';
package/cjs/index.js CHANGED
@@ -388,6 +388,17 @@ Object.keys(_errorBoundary).forEach(function (key) {
388
388
  }
389
389
  });
390
390
  });
391
+ var _expandableContent = require("./expandable-content");
392
+ Object.keys(_expandableContent).forEach(function (key) {
393
+ if (key === "default" || key === "__esModule") return;
394
+ if (key in exports && exports[key] === _expandableContent[key]) return;
395
+ Object.defineProperty(exports, key, {
396
+ enumerable: true,
397
+ get: function () {
398
+ return _expandableContent[key];
399
+ }
400
+ });
401
+ });
391
402
  var _exportButton = require("./export-button");
392
403
  Object.keys(_exportButton).forEach(function (key) {
393
404
  if (key === "default" || key === "__esModule") return;
@@ -3,6 +3,12 @@ import './markdown.less';
3
3
  type Props = {
4
4
  className?: string;
5
5
  children?: React.ReactNode;
6
+ /** If set, content will be clipped to this height and a Show more/Show less button will appear */
7
+ maxHeight?: number;
6
8
  };
9
+ /** Renders markdown content as HTML with support for GFM, math, and syntax highlighting.
10
+ * @midnight-gray-supported
11
+ * @alpine-light-supported
12
+ */
7
13
  declare const Markdown: React.FC<Props>;
8
14
  export { Markdown };
@@ -7,14 +7,20 @@ exports.Markdown = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _classnames = _interopRequireDefault(require("classnames"));
9
9
  var _message = require("../message");
10
+ var _expandableContent = require("../expandable-content");
10
11
  var _markdownUtils = require("./markdown-utils");
11
12
  var _useTranslation = require("../hooks/use-translation");
12
13
  var _jsxRuntime = require("react/jsx-runtime");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
+ /** Renders markdown content as HTML with support for GFM, math, and syntax highlighting.
17
+ * @midnight-gray-supported
18
+ * @alpine-light-supported
19
+ */
15
20
  const Markdown = ({
16
21
  children,
17
- className
22
+ className,
23
+ maxHeight
18
24
  }) => {
19
25
  const [html, setHtml] = (0, _react.useState)('');
20
26
  const [error, setError] = (0, _react.useState)('');
@@ -74,11 +80,18 @@ const Markdown = ({
74
80
  if (!html) {
75
81
  return null;
76
82
  }
77
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
83
+ const content = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
78
84
  className: (0, _classnames.default)('markdown', className),
79
85
  dangerouslySetInnerHTML: {
80
86
  __html: String(html)
81
87
  }
82
88
  });
89
+ if (maxHeight !== undefined) {
90
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_expandableContent.ExpandableContent, {
91
+ maxHeight: maxHeight,
92
+ children: content
93
+ });
94
+ }
95
+ return content;
83
96
  };
84
97
  exports.Markdown = Markdown;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import './expandable-content.less';
3
+ export type ExpandableContentProps = {
4
+ /** Content to render */
5
+ children: React.ReactNode;
6
+ /** Maximum height in pixels. When content exceeds this height it is clipped and a Show more/Show less button appears */
7
+ maxHeight: number;
8
+ /** Additional CSS class applied to the wrapper */
9
+ className?: string;
10
+ };
11
+ /** Clips content to a maximum height and shows a Show more/Show less ghost button when the content overflows.
12
+ * @midnight-gray-supported
13
+ * @alpine-light-supported
14
+ */
15
+ declare const ExpandableContent: React.FC<ExpandableContentProps>;
16
+ export { ExpandableContent };
@@ -0,0 +1,53 @@
1
+ import React, { useLayoutEffect, useRef, useState } from 'react';
2
+ import classNames from 'classnames';
3
+ import { faChevronDown } from '@fortawesome/free-solid-svg-icons/faChevronDown';
4
+ import { faChevronUp } from '@fortawesome/free-solid-svg-icons/faChevronUp';
5
+ import { Button, ACCENT_TYPES } from '../button';
6
+ import { useTranslation } from '../hooks/use-translation';
7
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
+ /** Clips content to a maximum height and shows a Show more/Show less ghost button when the content overflows.
9
+ * @midnight-gray-supported
10
+ * @alpine-light-supported
11
+ */
12
+ const ExpandableContent = ({
13
+ children,
14
+ maxHeight,
15
+ className
16
+ }) => {
17
+ const [isExpanded, setIsExpanded] = useState(false);
18
+ const [isOverflowing, setIsOverflowing] = useState(false);
19
+ const contentRef = useRef(null);
20
+ const {
21
+ t
22
+ } = useTranslation();
23
+ useLayoutEffect(() => {
24
+ if (contentRef.current) {
25
+ setIsOverflowing(contentRef.current.scrollHeight > maxHeight);
26
+ }
27
+ }, [children, maxHeight]);
28
+ const isClipped = isOverflowing && !isExpanded;
29
+ return /*#__PURE__*/_jsxs("div", {
30
+ className: classNames('expandable-content', className),
31
+ "test-id": "expandable-content",
32
+ children: [/*#__PURE__*/_jsx("div", {
33
+ ref: contentRef,
34
+ className: "expandable-content-body"
35
+ // eslint-disable-next-line react/forbid-dom-props
36
+ ,
37
+ style: isClipped ? {
38
+ maxHeight,
39
+ overflow: 'hidden'
40
+ } : undefined,
41
+ "test-id": "expandable-content-body",
42
+ children: children
43
+ }), isOverflowing && /*#__PURE__*/_jsx(Button, {
44
+ accentType: ACCENT_TYPES.GHOST,
45
+ onClick: () => setIsExpanded(prev => !prev),
46
+ className: "expandable-content-toggle",
47
+ rightIcon: isExpanded ? faChevronUp : faChevronDown,
48
+ testId: "expandable-content-toggle",
49
+ children: isExpanded ? t('Show less') : t('Show more')
50
+ })]
51
+ });
52
+ };
53
+ export { ExpandableContent };
@@ -0,0 +1,3 @@
1
+ import { ExpandableContent, ExpandableContentProps } from './expandable-content';
2
+ export type { ExpandableContentProps };
3
+ export { ExpandableContent };
@@ -0,0 +1,2 @@
1
+ import { ExpandableContent } from './expandable-content';
2
+ export { ExpandableContent };
package/esm/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export * from './editable-text';
33
33
  export * from './embedded-steps';
34
34
  export * from './empty-state';
35
35
  export * from './error-boundary';
36
+ export * from './expandable-content';
36
37
  export * from './export-button';
37
38
  export * from './file-tree';
38
39
  export * from './file-upload';
package/esm/index.js CHANGED
@@ -33,6 +33,7 @@ export * from './editable-text';
33
33
  export * from './embedded-steps';
34
34
  export * from './empty-state';
35
35
  export * from './error-boundary';
36
+ export * from './expandable-content';
36
37
  export * from './export-button';
37
38
  export * from './file-tree';
38
39
  export * from './file-upload';
@@ -3,6 +3,12 @@ import './markdown.less';
3
3
  type Props = {
4
4
  className?: string;
5
5
  children?: React.ReactNode;
6
+ /** If set, content will be clipped to this height and a Show more/Show less button will appear */
7
+ maxHeight?: number;
6
8
  };
9
+ /** Renders markdown content as HTML with support for GFM, math, and syntax highlighting.
10
+ * @midnight-gray-supported
11
+ * @alpine-light-supported
12
+ */
7
13
  declare const Markdown: React.FC<Props>;
8
14
  export { Markdown };
@@ -1,12 +1,18 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { Message, MESSAGE_TYPES } from '../message';
4
+ import { ExpandableContent } from '../expandable-content';
4
5
  import { datarobotCSSClasses } from './markdown-utils';
5
6
  import { useTranslation } from '../hooks/use-translation';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
+ /** Renders markdown content as HTML with support for GFM, math, and syntax highlighting.
9
+ * @midnight-gray-supported
10
+ * @alpine-light-supported
11
+ */
7
12
  const Markdown = ({
8
13
  children,
9
- className
14
+ className,
15
+ maxHeight
10
16
  }) => {
11
17
  const [html, setHtml] = useState('');
12
18
  const [error, setError] = useState('');
@@ -66,11 +72,18 @@ const Markdown = ({
66
72
  if (!html) {
67
73
  return null;
68
74
  }
69
- return /*#__PURE__*/_jsx("div", {
75
+ const content = /*#__PURE__*/_jsx("div", {
70
76
  className: classNames('markdown', className),
71
77
  dangerouslySetInnerHTML: {
72
78
  __html: String(html)
73
79
  }
74
80
  });
81
+ if (maxHeight !== undefined) {
82
+ return /*#__PURE__*/_jsx(ExpandableContent, {
83
+ maxHeight: maxHeight,
84
+ children: content
85
+ });
86
+ }
87
+ return content;
75
88
  };
76
89
  export { Markdown };
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@datarobot/design-system/expandable-content",
3
+ "private": true,
4
+ "main": "../cjs/expandable-content",
5
+ "module": "../esm/expandable-content",
6
+ "types": "../esm/index.d.ts"
7
+ }