@patternfly/chatbot 6.3.0 → 6.4.0-prerelease.3
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/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +5 -1
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +3 -3
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +17 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.d.ts +18 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.js +25 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.test.js +22 -0
- package/dist/cjs/ChatbotHeader/index.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/index.js +1 -0
- package/dist/cjs/FileDropZone/FileDropZone.d.ts +1 -2
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.js +1 -10
- package/dist/cjs/Message/Message.d.ts +4 -2
- package/dist/cjs/Message/Message.js +4 -4
- package/dist/cjs/Message/Message.test.js +26 -0
- package/dist/cjs/Message/MessageInput.d.ts +3 -1
- package/dist/cjs/Message/MessageInput.js +2 -2
- package/dist/cjs/MessageBar/AttachButton.d.ts +2 -2
- package/dist/cjs/MessageBar/MessageBar.d.ts +2 -2
- package/dist/cjs/MessageBox/MessageBox.js +1 -1
- package/dist/cjs/MessageDivider/MessageDivider.d.ts +9 -0
- package/dist/cjs/MessageDivider/MessageDivider.js +23 -0
- package/dist/cjs/MessageDivider/MessageDivider.test.d.ts +1 -0
- package/dist/cjs/MessageDivider/MessageDivider.test.js +29 -0
- package/dist/cjs/MessageDivider/index.d.ts +2 -0
- package/dist/cjs/MessageDivider/index.js +23 -0
- package/dist/cjs/ResponseActions/ResponseActions.d.ts +1 -0
- package/dist/cjs/ResponseActions/ResponseActions.js +4 -4
- package/dist/cjs/ResponseActions/ResponseActions.test.js +6 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +4 -1
- package/dist/css/main.css +56 -55
- package/dist/css/main.css.map +1 -1
- package/dist/dynamic/MessageDivider/package.json +1 -0
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +5 -1
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +5 -5
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +17 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.d.ts +18 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.js +22 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.test.js +20 -0
- package/dist/esm/ChatbotHeader/index.d.ts +1 -0
- package/dist/esm/ChatbotHeader/index.js +1 -0
- package/dist/esm/FileDropZone/FileDropZone.d.ts +1 -2
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.js +1 -7
- package/dist/esm/Message/Message.d.ts +4 -2
- package/dist/esm/Message/Message.js +4 -4
- package/dist/esm/Message/Message.test.js +26 -0
- package/dist/esm/Message/MessageInput.d.ts +3 -1
- package/dist/esm/Message/MessageInput.js +2 -2
- package/dist/esm/MessageBar/AttachButton.d.ts +2 -2
- package/dist/esm/MessageBar/MessageBar.d.ts +2 -2
- package/dist/esm/MessageBox/MessageBox.js +1 -1
- package/dist/esm/MessageDivider/MessageDivider.d.ts +9 -0
- package/dist/esm/MessageDivider/MessageDivider.js +21 -0
- package/dist/esm/MessageDivider/MessageDivider.test.d.ts +1 -0
- package/dist/esm/MessageDivider/MessageDivider.test.js +24 -0
- package/dist/esm/MessageDivider/index.d.ts +2 -0
- package/dist/esm/MessageDivider/index.js +2 -0
- package/dist/esm/ResponseActions/ResponseActions.d.ts +1 -0
- package/dist/esm/ResponseActions/ResponseActions.js +5 -5
- package/dist/esm/ResponseActions/ResponseActions.test.js +6 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -4
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithDividers.tsx +24 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +15 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessage.tsx +39 -7
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderBasic.tsx +17 -3
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawer.tsx +9 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawerWithPin.tsx +196 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/UI.md +16 -3
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +33 -1
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotDisplayMode.tsx +486 -0
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotTranscripts.tsx +565 -0
- package/src/Chatbot/Chatbot.scss +1 -1
- package/src/ChatbotContent/ChatbotContent.scss +1 -1
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss +14 -2
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx +58 -0
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx +34 -12
- package/src/ChatbotFooter/ChatbotFooter.scss +1 -1
- package/src/ChatbotHeader/ChatbotHeader.scss +3 -3
- package/src/ChatbotHeader/ChatbotHeaderNewChatButton.test.tsx +25 -0
- package/src/ChatbotHeader/ChatbotHeaderNewChatButton.tsx +64 -0
- package/src/ChatbotHeader/index.ts +1 -0
- package/src/ChatbotToggle/ChatbotToggle.scss +2 -2
- package/src/FileDetails/__snapshots__/FileDetails.test.tsx.snap +6 -9
- package/src/FileDetailsLabel/__snapshots__/FileDetailsLabel.test.tsx.snap +6 -9
- package/src/FileDropZone/FileDropZone.tsx +2 -2
- package/src/Message/CodeBlockMessage/CodeBlockMessage.tsx +3 -27
- package/src/Message/Message.scss +9 -7
- package/src/Message/Message.test.tsx +35 -0
- package/src/Message/Message.tsx +8 -4
- package/src/Message/MessageInput.tsx +5 -1
- package/src/MessageBar/AttachButton.tsx +2 -2
- package/src/MessageBar/MessageBar.tsx +2 -2
- package/src/MessageBar/SendButton.scss +3 -3
- package/src/MessageBox/JumpButton.scss +1 -1
- package/src/MessageBox/MessageBox.tsx +1 -1
- package/src/MessageDivider/MessageDivider.scss +45 -0
- package/src/MessageDivider/MessageDivider.test.tsx +24 -0
- package/src/MessageDivider/MessageDivider.tsx +35 -0
- package/src/MessageDivider/index.ts +3 -0
- package/src/ResponseActions/ResponseActions.test.tsx +6 -1
- package/src/ResponseActions/ResponseActions.tsx +24 -3
- package/src/index.ts +3 -0
- package/src/main.scss +1 -52
- package/dist/cjs/Message/CodeBlockMessage/ExpandableSectionForSyntaxHighlighter.d.ts +0 -62
- package/dist/cjs/Message/CodeBlockMessage/ExpandableSectionForSyntaxHighlighter.js +0 -139
- package/dist/esm/Message/CodeBlockMessage/ExpandableSectionForSyntaxHighlighter.d.ts +0 -62
- package/dist/esm/Message/CodeBlockMessage/ExpandableSectionForSyntaxHighlighter.js +0 -133
- package/src/Message/CodeBlockMessage/ExpandableSectionForSyntaxHighlighter.tsx +0 -223
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { Component, createRef } from 'react';
|
|
14
|
-
import styles from '@patternfly/react-styles/css/components/ExpandableSection/expandable-section';
|
|
15
|
-
import { css } from '@patternfly/react-styles';
|
|
16
|
-
import lineClamp from '@patternfly/react-tokens/dist/esm/c_expandable_section_m_truncate__content_LineClamp';
|
|
17
|
-
import { debounce, getResizeObserver, getUniqueId } from '@patternfly/react-core';
|
|
18
|
-
export var ExpandableSectionVariant;
|
|
19
|
-
(function (ExpandableSectionVariant) {
|
|
20
|
-
ExpandableSectionVariant["default"] = "default";
|
|
21
|
-
ExpandableSectionVariant["truncate"] = "truncate";
|
|
22
|
-
})(ExpandableSectionVariant || (ExpandableSectionVariant = {}));
|
|
23
|
-
const setLineClamp = (element, lines, language, isExpanded) => {
|
|
24
|
-
if (!element || !lines || lines < 1 || typeof isExpanded === 'undefined') {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (language) {
|
|
28
|
-
const selector = `.language-${language.toLowerCase()}`;
|
|
29
|
-
const childElement = element.querySelector(selector);
|
|
30
|
-
if (!childElement) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (isExpanded) {
|
|
34
|
-
// Reset all truncation-related styles to their default values
|
|
35
|
-
childElement.style.removeProperty('-webkit-line-clamp');
|
|
36
|
-
childElement.style.removeProperty('display');
|
|
37
|
-
childElement.style.removeProperty('-webkit-box-orient');
|
|
38
|
-
childElement.style.removeProperty('overflow');
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
childElement.style.setProperty('-webkit-line-clamp', lines.toString());
|
|
42
|
-
childElement.style.setProperty('display', '-webkit-box');
|
|
43
|
-
childElement.style.setProperty('-webkit-box-orient', 'vertical');
|
|
44
|
-
childElement.style.setProperty('overflow', 'hidden');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
class ExpandableSectionForSyntaxHighlighter extends Component {
|
|
49
|
-
constructor(props) {
|
|
50
|
-
var _a;
|
|
51
|
-
super(props);
|
|
52
|
-
this.expandableContentRef = createRef();
|
|
53
|
-
/* eslint-disable-next-line */
|
|
54
|
-
this.observer = () => { };
|
|
55
|
-
this.checkToggleVisibility = () => {
|
|
56
|
-
var _a;
|
|
57
|
-
if ((_a = this.expandableContentRef) === null || _a === void 0 ? void 0 : _a.current) {
|
|
58
|
-
const maxLines = this.props.truncateMaxLines || parseInt(lineClamp.value);
|
|
59
|
-
const totalLines = this.expandableContentRef.current.scrollHeight /
|
|
60
|
-
parseInt(getComputedStyle(this.expandableContentRef.current).lineHeight);
|
|
61
|
-
this.setState({
|
|
62
|
-
hasToggle: totalLines > maxLines
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
this.resize = () => {
|
|
67
|
-
if (this.expandableContentRef.current) {
|
|
68
|
-
const { offsetWidth } = this.expandableContentRef.current;
|
|
69
|
-
if (this.state.previousWidth !== offsetWidth) {
|
|
70
|
-
this.setState({ previousWidth: offsetWidth });
|
|
71
|
-
this.checkToggleVisibility();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
this.handleResize = debounce(this.resize, 250);
|
|
76
|
-
this.state = {
|
|
77
|
-
isExpanded: (_a = props.isExpanded) !== null && _a !== void 0 ? _a : false,
|
|
78
|
-
hasToggle: true,
|
|
79
|
-
previousWidth: undefined
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
componentDidMount() {
|
|
83
|
-
if (this.props.variant === ExpandableSectionVariant.truncate) {
|
|
84
|
-
const expandableContent = this.expandableContentRef.current;
|
|
85
|
-
if (expandableContent) {
|
|
86
|
-
this.setState({ previousWidth: expandableContent.offsetWidth });
|
|
87
|
-
this.observer = getResizeObserver(expandableContent, this.handleResize, false);
|
|
88
|
-
if (this.props.truncateMaxLines) {
|
|
89
|
-
setLineClamp(expandableContent, this.props.truncateMaxLines, this.props.language, this.state.isExpanded);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
this.checkToggleVisibility();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
componentDidUpdate(prevProps) {
|
|
96
|
-
if (this.props.variant === ExpandableSectionVariant.truncate &&
|
|
97
|
-
(prevProps.truncateMaxLines !== this.props.truncateMaxLines ||
|
|
98
|
-
prevProps.children !== this.props.children ||
|
|
99
|
-
prevProps.isExpanded !== this.props.isExpanded)) {
|
|
100
|
-
const expandableContent = this.expandableContentRef.current;
|
|
101
|
-
setLineClamp(expandableContent, this.props.truncateMaxLines, this.props.language, this.props.isExpanded);
|
|
102
|
-
this.checkToggleVisibility();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
componentWillUnmount() {
|
|
106
|
-
if (this.props.variant === ExpandableSectionVariant.truncate) {
|
|
107
|
-
this.observer();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
render() {
|
|
111
|
-
const _a = this.props, { className, children, isExpanded, isDetached, displaySize, isWidthLimited, isIndented, contentId, toggleId, variant,
|
|
112
|
-
// Gets rid of console error about it being on a DOM element
|
|
113
|
-
// eslint-disable-next-line
|
|
114
|
-
truncateMaxLines } = _a, props = __rest(_a, ["className", "children", "isExpanded", "isDetached", "displaySize", "isWidthLimited", "isIndented", "contentId", "toggleId", "variant", "truncateMaxLines"]);
|
|
115
|
-
if (isDetached && !toggleId) {
|
|
116
|
-
/* eslint-disable no-console */
|
|
117
|
-
console.warn('ExpandableSection: The toggleId value must be passed in and must match the toggleId of the ExpandableSectionToggle.');
|
|
118
|
-
}
|
|
119
|
-
const uniqueContentId = contentId || getUniqueId('expandable-section-content');
|
|
120
|
-
const uniqueToggleId = toggleId || getUniqueId('expandable-section-toggle');
|
|
121
|
-
return (_jsx("div", Object.assign({ className: css(styles.expandableSection, isExpanded && styles.modifiers.expanded, displaySize === 'lg' && styles.modifiers.displayLg, isWidthLimited && styles.modifiers.limitWidth, isIndented && styles.modifiers.indented, variant === ExpandableSectionVariant.truncate && styles.modifiers.truncate, className) }, props, { children: _jsx("div", { ref: this.expandableContentRef, className: css(styles.expandableSectionContent), hidden: variant !== ExpandableSectionVariant.truncate && !isExpanded, id: uniqueContentId, "aria-labelledby": uniqueToggleId, role: "region", children: children }) })));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
ExpandableSectionForSyntaxHighlighter.displayName = 'ExpandableSection';
|
|
125
|
-
ExpandableSectionForSyntaxHighlighter.defaultProps = {
|
|
126
|
-
className: '',
|
|
127
|
-
isDetached: false,
|
|
128
|
-
displaySize: 'default',
|
|
129
|
-
isWidthLimited: false,
|
|
130
|
-
isIndented: false,
|
|
131
|
-
variant: 'default'
|
|
132
|
-
};
|
|
133
|
-
export { ExpandableSectionForSyntaxHighlighter };
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { Component, createRef } from 'react';
|
|
2
|
-
import styles from '@patternfly/react-styles/css/components/ExpandableSection/expandable-section';
|
|
3
|
-
import { css } from '@patternfly/react-styles';
|
|
4
|
-
import lineClamp from '@patternfly/react-tokens/dist/esm/c_expandable_section_m_truncate__content_LineClamp';
|
|
5
|
-
import { debounce, getResizeObserver, getUniqueId, PickOptional } from '@patternfly/react-core';
|
|
6
|
-
|
|
7
|
-
export enum ExpandableSectionVariant {
|
|
8
|
-
default = 'default',
|
|
9
|
-
truncate = 'truncate'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** The main expandable section component. */
|
|
13
|
-
|
|
14
|
-
export interface ExpandableSectionProps extends Omit<React.HTMLProps<HTMLDivElement>, 'onToggle'> {
|
|
15
|
-
/** Content rendered inside the expandable section. */
|
|
16
|
-
children?: React.ReactNode;
|
|
17
|
-
/** Additional classes added to the expandable section. */
|
|
18
|
-
className?: string;
|
|
19
|
-
/** Id of the content of the expandable section. When passing in the isDetached property, this
|
|
20
|
-
* property's value should match the contentId property of the expandable section toggle sub-component.
|
|
21
|
-
*/
|
|
22
|
-
contentId?: string;
|
|
23
|
-
/** Id of the toggle of the expandable section, which provides an accessible name to the
|
|
24
|
-
* expandable section content via the aria-labelledby attribute. When the isDetached property
|
|
25
|
-
* is also passed in, the value of this property must match the toggleId property of the
|
|
26
|
-
* expandable section toggle sub-component.
|
|
27
|
-
*/
|
|
28
|
-
toggleId?: string;
|
|
29
|
-
/** Display size variant. Set to "lg" for disclosure styling. */
|
|
30
|
-
displaySize?: 'default' | 'lg';
|
|
31
|
-
/** Indicates the expandable section has a detached toggle. */
|
|
32
|
-
isDetached?: boolean;
|
|
33
|
-
/** Flag to indicate if the content is expanded. */
|
|
34
|
-
isExpanded?: boolean;
|
|
35
|
-
/** Flag to indicate if the content is indented. */
|
|
36
|
-
isIndented?: boolean;
|
|
37
|
-
/** Flag to indicate the width of the component is limited. Set to "true" for disclosure styling. */
|
|
38
|
-
isWidthLimited?: boolean;
|
|
39
|
-
/** Truncates the expandable content to the specified number of lines when using the
|
|
40
|
-
* "truncate" variant.
|
|
41
|
-
*/
|
|
42
|
-
truncateMaxLines?: number;
|
|
43
|
-
/** Determines the variant of the expandable section. When passing in "truncate" as the
|
|
44
|
-
* variant, the expandable content will be truncated after 3 lines by default.
|
|
45
|
-
*/
|
|
46
|
-
variant?: 'default' | 'truncate';
|
|
47
|
-
language?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface ExpandableSectionState {
|
|
51
|
-
isExpanded: boolean;
|
|
52
|
-
hasToggle: boolean;
|
|
53
|
-
previousWidth: number | undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const setLineClamp = (element: HTMLDivElement | null, lines?: number, language?: string, isExpanded?: boolean) => {
|
|
57
|
-
if (!element || !lines || lines < 1 || typeof isExpanded === 'undefined') {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (language) {
|
|
62
|
-
const selector = `.language-${language.toLowerCase()}`;
|
|
63
|
-
const childElement = element.querySelector(selector) as HTMLDivElement;
|
|
64
|
-
|
|
65
|
-
if (!childElement) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (isExpanded) {
|
|
69
|
-
// Reset all truncation-related styles to their default values
|
|
70
|
-
childElement.style.removeProperty('-webkit-line-clamp');
|
|
71
|
-
childElement.style.removeProperty('display');
|
|
72
|
-
childElement.style.removeProperty('-webkit-box-orient');
|
|
73
|
-
childElement.style.removeProperty('overflow');
|
|
74
|
-
} else {
|
|
75
|
-
childElement.style.setProperty('-webkit-line-clamp', lines.toString());
|
|
76
|
-
childElement.style.setProperty('display', '-webkit-box');
|
|
77
|
-
childElement.style.setProperty('-webkit-box-orient', 'vertical');
|
|
78
|
-
childElement.style.setProperty('overflow', 'hidden');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
class ExpandableSectionForSyntaxHighlighter extends Component<ExpandableSectionProps, ExpandableSectionState> {
|
|
84
|
-
static displayName = 'ExpandableSection';
|
|
85
|
-
constructor(props: ExpandableSectionProps) {
|
|
86
|
-
super(props);
|
|
87
|
-
|
|
88
|
-
this.state = {
|
|
89
|
-
isExpanded: props.isExpanded ?? false,
|
|
90
|
-
hasToggle: true,
|
|
91
|
-
previousWidth: undefined
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
expandableContentRef = createRef<HTMLDivElement>();
|
|
96
|
-
/* eslint-disable-next-line */
|
|
97
|
-
observer: any = () => {};
|
|
98
|
-
|
|
99
|
-
static defaultProps: PickOptional<ExpandableSectionProps> = {
|
|
100
|
-
className: '',
|
|
101
|
-
isDetached: false,
|
|
102
|
-
displaySize: 'default',
|
|
103
|
-
isWidthLimited: false,
|
|
104
|
-
isIndented: false,
|
|
105
|
-
variant: 'default'
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
componentDidMount() {
|
|
109
|
-
if (this.props.variant === ExpandableSectionVariant.truncate) {
|
|
110
|
-
const expandableContent = this.expandableContentRef.current;
|
|
111
|
-
if (expandableContent) {
|
|
112
|
-
this.setState({ previousWidth: expandableContent.offsetWidth });
|
|
113
|
-
this.observer = getResizeObserver(expandableContent, this.handleResize, false);
|
|
114
|
-
|
|
115
|
-
if (this.props.truncateMaxLines) {
|
|
116
|
-
setLineClamp(expandableContent, this.props.truncateMaxLines, this.props.language, this.state.isExpanded);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.checkToggleVisibility();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
componentDidUpdate(prevProps: ExpandableSectionProps) {
|
|
125
|
-
if (
|
|
126
|
-
this.props.variant === ExpandableSectionVariant.truncate &&
|
|
127
|
-
(prevProps.truncateMaxLines !== this.props.truncateMaxLines ||
|
|
128
|
-
prevProps.children !== this.props.children ||
|
|
129
|
-
prevProps.isExpanded !== this.props.isExpanded)
|
|
130
|
-
) {
|
|
131
|
-
const expandableContent = this.expandableContentRef.current;
|
|
132
|
-
setLineClamp(expandableContent, this.props.truncateMaxLines, this.props.language, this.props.isExpanded);
|
|
133
|
-
this.checkToggleVisibility();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
componentWillUnmount() {
|
|
138
|
-
if (this.props.variant === ExpandableSectionVariant.truncate) {
|
|
139
|
-
this.observer();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
checkToggleVisibility = () => {
|
|
144
|
-
if (this.expandableContentRef?.current) {
|
|
145
|
-
const maxLines = this.props.truncateMaxLines || parseInt(lineClamp.value);
|
|
146
|
-
const totalLines =
|
|
147
|
-
this.expandableContentRef.current.scrollHeight /
|
|
148
|
-
parseInt(getComputedStyle(this.expandableContentRef.current).lineHeight);
|
|
149
|
-
|
|
150
|
-
this.setState({
|
|
151
|
-
hasToggle: totalLines > maxLines
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
resize = () => {
|
|
157
|
-
if (this.expandableContentRef.current) {
|
|
158
|
-
const { offsetWidth } = this.expandableContentRef.current;
|
|
159
|
-
if (this.state.previousWidth !== offsetWidth) {
|
|
160
|
-
this.setState({ previousWidth: offsetWidth });
|
|
161
|
-
this.checkToggleVisibility();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
handleResize = debounce(this.resize, 250);
|
|
166
|
-
|
|
167
|
-
render() {
|
|
168
|
-
const {
|
|
169
|
-
className,
|
|
170
|
-
children,
|
|
171
|
-
isExpanded,
|
|
172
|
-
isDetached,
|
|
173
|
-
displaySize,
|
|
174
|
-
isWidthLimited,
|
|
175
|
-
isIndented,
|
|
176
|
-
contentId,
|
|
177
|
-
toggleId,
|
|
178
|
-
variant,
|
|
179
|
-
// Gets rid of console error about it being on a DOM element
|
|
180
|
-
// eslint-disable-next-line
|
|
181
|
-
truncateMaxLines,
|
|
182
|
-
...props
|
|
183
|
-
} = this.props;
|
|
184
|
-
|
|
185
|
-
if (isDetached && !toggleId) {
|
|
186
|
-
/* eslint-disable no-console */
|
|
187
|
-
console.warn(
|
|
188
|
-
'ExpandableSection: The toggleId value must be passed in and must match the toggleId of the ExpandableSectionToggle.'
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const uniqueContentId = contentId || getUniqueId('expandable-section-content');
|
|
193
|
-
const uniqueToggleId = toggleId || getUniqueId('expandable-section-toggle');
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
<div
|
|
197
|
-
className={css(
|
|
198
|
-
styles.expandableSection,
|
|
199
|
-
isExpanded && styles.modifiers.expanded,
|
|
200
|
-
displaySize === 'lg' && styles.modifiers.displayLg,
|
|
201
|
-
isWidthLimited && styles.modifiers.limitWidth,
|
|
202
|
-
isIndented && styles.modifiers.indented,
|
|
203
|
-
variant === ExpandableSectionVariant.truncate && styles.modifiers.truncate,
|
|
204
|
-
className
|
|
205
|
-
)}
|
|
206
|
-
{...props}
|
|
207
|
-
>
|
|
208
|
-
<div
|
|
209
|
-
ref={this.expandableContentRef}
|
|
210
|
-
className={css(styles.expandableSectionContent)}
|
|
211
|
-
hidden={variant !== ExpandableSectionVariant.truncate && !isExpanded}
|
|
212
|
-
id={uniqueContentId}
|
|
213
|
-
aria-labelledby={uniqueToggleId}
|
|
214
|
-
role="region"
|
|
215
|
-
>
|
|
216
|
-
{children}
|
|
217
|
-
</div>
|
|
218
|
-
</div>
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export { ExpandableSectionForSyntaxHighlighter };
|