@patternfly/chatbot 2.2.0-prerelease.44 → 2.2.0-prerelease.46
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/Message/Message.d.ts +15 -1
- package/dist/cjs/Message/Message.js +53 -34
- package/dist/cjs/Message/Message.test.js +46 -0
- package/dist/cjs/Message/MessageInput.d.ts +18 -0
- package/dist/cjs/Message/MessageInput.js +34 -0
- package/dist/cjs/SourcesCard/SourcesCard.d.ts +6 -1
- package/dist/cjs/SourcesCard/SourcesCard.js +14 -9
- package/dist/cjs/SourcesCard/SourcesCard.test.js +25 -11
- package/dist/css/main.css +7 -7
- package/dist/css/main.css.map +1 -1
- package/dist/esm/Message/Message.d.ts +15 -1
- package/dist/esm/Message/Message.js +53 -34
- package/dist/esm/Message/Message.test.js +46 -0
- package/dist/esm/Message/MessageInput.d.ts +18 -0
- package/dist/esm/Message/MessageInput.js +29 -0
- package/dist/esm/SourcesCard/SourcesCard.d.ts +6 -1
- package/dist/esm/SourcesCard/SourcesCard.js +15 -10
- package/dist/esm/SourcesCard/SourcesCard.test.js +25 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/BotMessage.tsx +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx +34 -5
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessage.tsx +61 -14
- package/src/Message/Message.scss +4 -0
- package/src/Message/Message.test.tsx +48 -0
- package/src/Message/Message.tsx +107 -53
- package/src/Message/MessageInput.tsx +59 -0
- package/src/SourcesCard/SourcesCard.scss +3 -7
- package/src/SourcesCard/SourcesCard.test.tsx +30 -17
- package/src/SourcesCard/SourcesCard.tsx +41 -11
@@ -12,6 +12,8 @@ import {
|
|
12
12
|
CardFooter,
|
13
13
|
CardProps,
|
14
14
|
CardTitle,
|
15
|
+
ExpandableSection,
|
16
|
+
ExpandableSectionVariant,
|
15
17
|
Icon,
|
16
18
|
pluralize,
|
17
19
|
Truncate
|
@@ -23,12 +25,18 @@ export interface SourcesCardProps extends CardProps {
|
|
23
25
|
className?: string;
|
24
26
|
/** Flag indicating if the pagination is disabled. */
|
25
27
|
isDisabled?: boolean;
|
26
|
-
/** Label for the English word "of"
|
28
|
+
/** @deprecated ofWord has been deprecated. Label for the English word "of." */
|
27
29
|
ofWord?: string;
|
28
30
|
/** Accessible label for the pagination component. */
|
29
31
|
paginationAriaLabel?: string;
|
30
32
|
/** Content rendered inside the paginated card */
|
31
|
-
sources: {
|
33
|
+
sources: {
|
34
|
+
title?: string;
|
35
|
+
link: string;
|
36
|
+
body?: React.ReactNode | string;
|
37
|
+
isExternal?: boolean;
|
38
|
+
hasShowMore?: boolean;
|
39
|
+
}[];
|
32
40
|
/** Label for the English word "source" */
|
33
41
|
sourceWord?: string;
|
34
42
|
/** Plural for sourceWord */
|
@@ -43,12 +51,15 @@ export interface SourcesCardProps extends CardProps {
|
|
43
51
|
onPreviousClick?: (event: React.SyntheticEvent<HTMLButtonElement>, page: number) => void;
|
44
52
|
/** Function called when page is changed. */
|
45
53
|
onSetPage?: (event: React.MouseEvent | React.KeyboardEvent | MouseEvent, newPage: number) => void;
|
54
|
+
/** Label for English words "show more" */
|
55
|
+
showMoreWords?: string;
|
56
|
+
/** Label for English words "show less" */
|
57
|
+
showLessWords?: string;
|
46
58
|
}
|
47
59
|
|
48
60
|
const SourcesCard: React.FunctionComponent<SourcesCardProps> = ({
|
49
61
|
className,
|
50
62
|
isDisabled,
|
51
|
-
ofWord = 'of',
|
52
63
|
paginationAriaLabel = 'Pagination',
|
53
64
|
sources,
|
54
65
|
sourceWord = 'source',
|
@@ -58,9 +69,16 @@ const SourcesCard: React.FunctionComponent<SourcesCardProps> = ({
|
|
58
69
|
onNextClick,
|
59
70
|
onPreviousClick,
|
60
71
|
onSetPage,
|
72
|
+
showMoreWords = 'show more',
|
73
|
+
showLessWords = 'show less',
|
61
74
|
...props
|
62
75
|
}: SourcesCardProps) => {
|
63
76
|
const [page, setPage] = React.useState(1);
|
77
|
+
const [isExpanded, setIsExpanded] = React.useState(false);
|
78
|
+
|
79
|
+
const onToggle = (_event: React.MouseEvent, isExpanded: boolean) => {
|
80
|
+
setIsExpanded(isExpanded);
|
81
|
+
};
|
64
82
|
|
65
83
|
const handleNewPage = (_evt: React.MouseEvent | React.KeyboardEvent | MouseEvent, newPage: number) => {
|
66
84
|
setPage(newPage);
|
@@ -93,10 +111,23 @@ const SourcesCard: React.FunctionComponent<SourcesCardProps> = ({
|
|
93
111
|
</Button>
|
94
112
|
</CardTitle>
|
95
113
|
{sources[page - 1].body && (
|
96
|
-
<CardBody
|
97
|
-
|
98
|
-
|
99
|
-
|
114
|
+
<CardBody className={`pf-chatbot__sources-card-body`}>
|
115
|
+
{sources[page - 1].hasShowMore ? (
|
116
|
+
// prevents extra VO announcements of button text - parent Message has aria-live
|
117
|
+
<div aria-live="off">
|
118
|
+
<ExpandableSection
|
119
|
+
variant={ExpandableSectionVariant.truncate}
|
120
|
+
toggleText={isExpanded ? showLessWords : showMoreWords}
|
121
|
+
onToggle={onToggle}
|
122
|
+
isExpanded={isExpanded}
|
123
|
+
truncateMaxLines={2}
|
124
|
+
>
|
125
|
+
{sources[page - 1].body}
|
126
|
+
</ExpandableSection>
|
127
|
+
</div>
|
128
|
+
) : (
|
129
|
+
<div className="pf-chatbot__sources-card-body-text">{sources[page - 1].body}</div>
|
130
|
+
)}
|
100
131
|
</CardBody>
|
101
132
|
)}
|
102
133
|
{sources.length > 1 && (
|
@@ -129,6 +160,9 @@ const SourcesCard: React.FunctionComponent<SourcesCardProps> = ({
|
|
129
160
|
</svg>
|
130
161
|
</Icon>
|
131
162
|
</Button>
|
163
|
+
<span aria-hidden="true">
|
164
|
+
{page}/{sources.length}
|
165
|
+
</span>
|
132
166
|
<Button
|
133
167
|
variant={ButtonVariant.plain}
|
134
168
|
isDisabled={isDisabled || page === sources.length}
|
@@ -156,10 +190,6 @@ const SourcesCard: React.FunctionComponent<SourcesCardProps> = ({
|
|
156
190
|
</Icon>
|
157
191
|
</Button>
|
158
192
|
</nav>
|
159
|
-
|
160
|
-
<span aria-hidden="true">
|
161
|
-
{page} {ofWord} {sources.length}
|
162
|
-
</span>
|
163
193
|
</div>
|
164
194
|
</CardFooter>
|
165
195
|
)}
|