forked from patternfly/chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBotMessage.tsx
More file actions
297 lines (259 loc) · 8.39 KB
/
BotMessage.tsx
File metadata and controls
297 lines (259 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import React from 'react';
import Message from '@patternfly/chatbot/dist/dynamic/Message';
import patternflyAvatar from './patternfly_avatar.jpg';
import squareImg from './PF-social-color-square.svg';
import { AlertActionLink, Form, FormGroup, Radio } from '@patternfly/react-core';
export const BotMessageExample: React.FunctionComponent = () => {
const [variant, setVariant] = React.useState('code');
/* eslint-disable indent */
const renderContent = () => {
switch (variant) {
case 'code':
return code;
case 'heading':
return heading;
case 'emphasis':
return emphasis;
case 'blockQuotes':
return blockQuotes;
case 'orderedList':
return orderedList;
case 'unorderedList':
return unorderedList;
case 'moreComplexList':
return moreComplexList;
case 'inlineCode':
return inlineCode;
case 'link':
return link;
case 'table':
return table;
case 'image':
return image;
default:
return;
}
};
/* eslint-enable indent */
const code = `
Here is some YAML code:
~~~yaml
apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo0oooo00ooo
spec:
connectionConfig:
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs
~~~
Here is some JavaScript code:
~~~js
import React from 'react';
const MessageLoading = () => (
<div className="pf-chatbot__message-loading">
<span className="pf-chatbot__message-loading-dots">
<span className="pf-v6-screen-reader">Loading message</span>
</span>
</div>
);
export default MessageLoading;
~~~
`;
const heading = `
# h1 Heading
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading
`;
const emphasis = `
**Bold text, formatted with double asterisks**
__Bold text, formatted with double underscores__
*Italic text, formatted with single asterisks*
_Italic text, formatted with single underscores_
~~Strikethrough~~
`;
const blockQuotes = `> Blockquotes can also be nested...
>> ...by using additional greater-than signs (>) right next to each other...
> > > ...or with spaces between each sign.`;
const orderedList = `
Here is an ordered list:
1. Item 1
2. Item 2
3. Item 3`;
const unorderedList = `
Here is an unordered list:
* Item 1
* Item 2
* Item 3`;
const moreComplexList = `You may be wondering whether you can display more complex lists with formatting. In response to your question, I will explain how to spread butter on toast.
1. **Using a \`toaster\`:**
- Place \`bread\` in a \`toaster\`.
- Once \`bread\` is lightly browned, remove from \`toaster\`.
2. **Using a \`knife\`:**
Acquire 1 tablespoon of room temperature \`butter\`. Use \`knife\` to spread butter on \`toast\`. Bon appétit!
`;
const link = `A paragraph with a URL: https://reactjs.org.`;
const inlineCode = `Here is an inline code - \`() => void\``;
const table = `To customize your table, you can use [PatternFly TableProps](/components/table#table)
| Version | GA date | User role
|-|-|-|
| 2.5 | September 30, 2024 | Administrator |
| 2.5 | June 27, 2023 | Editor |
| 3.0 | April 1, 2025 | Administrator
`;
const image = ``;
const error = {
title: 'Could not load chat',
children: 'Wait a few minutes and check your network settings. If the issue persists: ',
actionLinks: (
<React.Fragment>
<AlertActionLink component="a" href="#">
Start a new chat
</AlertActionLink>
<AlertActionLink component="a" href="#">
Contact support
</AlertActionLink>
</React.Fragment>
)
};
return (
<>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content={`This is a text-based message from a bot named "Bot."`}
/>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content={`This is a text-based message from "Bot," with an updated timestamp.`}
timestamp="1 hour ago"
/>
<Message name="Bot" role="bot" avatar={patternflyAvatar} content="Example content" isLoading />
<Message role="bot" avatar={patternflyAvatar} content="This message is from a nameless bot." />
<Message
name="Default Openshift Container Platform Assistant That Can Help With Any Query You Might Need Help With"
role="bot"
avatar={patternflyAvatar}
content="This is a message from a bot with really long name: it's truncated!"
/>
<Message
name="Bot"
role="bot"
avatar={squareImg}
content="This bot has a square avatar. You can further customize the avatar by applying an additional class or passing [PatternFly avatar props](/components/avatar) to the `<Message>` component via `avatarProps`."
hasRoundAvatar={false}
/>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content={`Text-based message from a bot named "Bot," with updated timestamp`}
timestamp="1 hour ago"
/>
<Message name="Bot" role="bot" avatar={patternflyAvatar} content="Example content" isLoading />
<Form>
<FormGroup role="radiogroup" isInline fieldId="bot-message-type" label="Message content type">
<Radio
isChecked={variant === 'code'}
onChange={() => setVariant('code')}
name="bot-message-type"
label="Code"
id="code"
/>
<Radio
isChecked={variant === 'inlineCode'}
onChange={() => setVariant('inlineCode')}
name="bot-message-type"
label="Inline code"
id="inline-code"
/>
<Radio
isChecked={variant === 'heading'}
onChange={() => setVariant('heading')}
name="bot-message-type"
label="Heading"
id="heading"
/>
<Radio
isChecked={variant === 'blockQuotes'}
onChange={() => setVariant('blockQuotes')}
name="bot-message-type"
label="Block quote"
id="block-quotes"
/>
<Radio
isChecked={variant === 'emphasis'}
onChange={() => setVariant('emphasis')}
name="bot-message-type"
label="Emphasis"
id="emphasis"
/>
<Radio
isChecked={variant === 'link'}
onChange={() => setVariant('link')}
name="bot-message-type"
label="Link"
id="link"
/>
<Radio
isChecked={variant === 'unorderedList'}
onChange={() => setVariant('unorderedList')}
name="bot-message-type"
label="Unordered list"
id="unordered-list"
/>
<Radio
isChecked={variant === 'orderedList'}
onChange={() => setVariant('orderedList')}
name="bot-message-type"
label="Ordered list"
id="ordered-list"
/>
<Radio
isChecked={variant === 'moreComplexList'}
onChange={() => setVariant('moreComplexList')}
name="bot-message-type"
label="More complex list"
id="more-complex-list"
/>
<Radio
isChecked={variant === 'table'}
onChange={() => setVariant('table')}
name="bot-message-type"
label="Table"
id="table"
/>
<Radio
isChecked={variant === 'image'}
onChange={() => setVariant('image')}
name="bot-message-type"
label="Image"
id="image"
/>
<Radio
isChecked={variant === 'error'}
onChange={() => setVariant('error')}
name="bot-message-error"
label="Error"
id="error"
/>
</FormGroup>
</Form>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content={renderContent()}
tableProps={
variant === 'table' ? { 'aria-label': 'App information and user roles for bot messages' } : undefined
}
error={variant === 'error' ? error : undefined}
/>
</>
);
};