@pingux/astro 2.104.0-alpha.0 → 2.104.0-alpha.2
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/lib/cjs/components/AIComponents/Response/Response.d.ts +4 -0
- package/lib/cjs/components/AIComponents/Response/Response.js +52 -0
- package/lib/cjs/components/AIComponents/Response/Response.stories.d.ts +7 -0
- package/lib/cjs/components/AIComponents/Response/Response.stories.js +82 -0
- package/lib/cjs/components/AIComponents/Response/Response.test.jsx +215 -0
- package/lib/cjs/components/AIComponents/Response/ResponseAttachment.d.ts +4 -0
- package/lib/cjs/components/AIComponents/Response/ResponseAttachment.js +54 -0
- package/lib/cjs/components/AIComponents/Response/ResponseList.d.ts +4 -0
- package/lib/cjs/components/AIComponents/Response/ResponseList.js +66 -0
- package/lib/cjs/components/AIComponents/Response/ResponseText.d.ts +4 -0
- package/lib/cjs/components/AIComponents/Response/ResponseText.js +46 -0
- package/lib/cjs/components/AIComponents/Response/ResponseToolbar.d.ts +4 -0
- package/lib/cjs/components/AIComponents/Response/ResponseToolbar.js +79 -0
- package/lib/cjs/components/AIComponents/Response/index.d.ts +5 -0
- package/lib/cjs/components/AIComponents/Response/index.js +42 -0
- package/lib/cjs/components/Image/Image.stories.js +1 -1
- package/lib/cjs/hooks/useTypeAnimation/index.d.ts +1 -0
- package/lib/cjs/hooks/useTypeAnimation/index.js +14 -0
- package/lib/cjs/hooks/useTypeAnimation/useTypeAnimation.d.ts +8 -0
- package/lib/cjs/hooks/useTypeAnimation/useTypeAnimation.js +50 -0
- package/lib/cjs/hooks/useTypeAnimation/useTypeAnimation.test.d.ts +1 -0
- package/lib/cjs/hooks/useTypeAnimation/useTypeAnimation.test.js +66 -0
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +40 -0
- package/lib/cjs/styles/themes/next-gen/convertedComponentList.js +1 -1
- package/lib/cjs/styles/themes/next-gen/next-gen.d.ts +42 -0
- package/lib/cjs/styles/themes/next-gen/variants/response.d.ts +33 -0
- package/lib/cjs/styles/themes/next-gen/variants/response.js +43 -0
- package/lib/cjs/styles/themes/next-gen/variants/text.d.ts +10 -0
- package/lib/cjs/styles/themes/next-gen/variants/text.js +10 -0
- package/lib/cjs/styles/themes/next-gen/variants/variants.d.ts +32 -0
- package/lib/cjs/styles/themes/next-gen/variants/variants.js +3 -1
- package/lib/cjs/types/response.d.ts +48 -0
- package/lib/cjs/types/response.js +6 -0
- package/lib/cjs/utils/devUtils/constants/images.d.ts +1 -0
- package/lib/cjs/utils/devUtils/constants/images.js +4 -2
- package/lib/cjs/utils/devUtils/shouldReturnComingSoon.js +1 -1
- package/lib/components/AIComponents/Response/Response.js +38 -0
- package/lib/components/AIComponents/Response/Response.stories.js +72 -0
- package/lib/components/AIComponents/Response/Response.test.jsx +215 -0
- package/lib/components/AIComponents/Response/ResponseAttachment.js +40 -0
- package/lib/components/AIComponents/Response/ResponseList.js +52 -0
- package/lib/components/AIComponents/Response/ResponseText.js +37 -0
- package/lib/components/AIComponents/Response/ResponseToolbar.js +65 -0
- package/lib/components/AIComponents/Response/index.js +5 -0
- package/lib/components/Image/Image.stories.js +2 -2
- package/lib/hooks/useTypeAnimation/index.js +1 -0
- package/lib/hooks/useTypeAnimation/useTypeAnimation.js +41 -0
- package/lib/hooks/useTypeAnimation/useTypeAnimation.test.js +63 -0
- package/lib/index.js +5 -0
- package/lib/styles/themes/next-gen/convertedComponentList.js +1 -1
- package/lib/styles/themes/next-gen/variants/response.js +35 -0
- package/lib/styles/themes/next-gen/variants/text.js +10 -0
- package/lib/styles/themes/next-gen/variants/variants.js +3 -1
- package/lib/types/response.js +1 -0
- package/lib/utils/devUtils/constants/images.js +2 -1
- package/lib/utils/devUtils/shouldReturnComingSoon.js +1 -1
- package/package.json +1 -1
@@ -0,0 +1,72 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import React from 'react';
|
3
|
+
import CopyIcon from '@pingux/mdi-react/ContentCopyIcon';
|
4
|
+
import TextIcon from '@pingux/mdi-react/TextIcon';
|
5
|
+
import ThumbDownOutlineIcon from '@pingux/mdi-react/ThumbDownOutlineIcon';
|
6
|
+
import ThumbUpOutlineIcon from '@pingux/mdi-react/ThumbUpOutlineIcon';
|
7
|
+
import VolumeHighIcon from '@pingux/mdi-react/VolumeHighIcon';
|
8
|
+
import { AstroWrapper, NextGenTheme } from '../../..';
|
9
|
+
import Response from './Response';
|
10
|
+
import ResponseAttachment from './ResponseAttachment';
|
11
|
+
import ResponseList from './ResponseList';
|
12
|
+
import ResponseText from './ResponseText';
|
13
|
+
import ResponseToolbar from './ResponseToolbar';
|
14
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
15
|
+
export default {
|
16
|
+
title: 'Ai Components/Response',
|
17
|
+
component: Response
|
18
|
+
};
|
19
|
+
var testText = 'Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet';
|
20
|
+
export var Default = function Default(args) {
|
21
|
+
var toolBarProps = {
|
22
|
+
readButtonProps: {
|
23
|
+
title: 'Read aloud',
|
24
|
+
icon: VolumeHighIcon
|
25
|
+
},
|
26
|
+
copyButtonProps: {
|
27
|
+
title: 'Copy',
|
28
|
+
icon: CopyIcon
|
29
|
+
},
|
30
|
+
goodButtonProps: {
|
31
|
+
title: 'Good Response',
|
32
|
+
icon: ThumbUpOutlineIcon
|
33
|
+
},
|
34
|
+
badButtonProps: {
|
35
|
+
title: 'Bad Response',
|
36
|
+
icon: ThumbDownOutlineIcon
|
37
|
+
},
|
38
|
+
rephraseButtonProps: {
|
39
|
+
title: 'Rephrase Answer',
|
40
|
+
icon: TextIcon
|
41
|
+
}
|
42
|
+
};
|
43
|
+
var delay = 20;
|
44
|
+
return ___EmotionJSX(AstroWrapper, _extends({}, args, {
|
45
|
+
themeOverrides: [NextGenTheme]
|
46
|
+
}), ___EmotionJSX(Response, {
|
47
|
+
delay: delay
|
48
|
+
}, ___EmotionJSX(ResponseText, {
|
49
|
+
text: testText
|
50
|
+
}), ___EmotionJSX(ResponseAttachment, null), ___EmotionJSX(ResponseText, {
|
51
|
+
text: testText
|
52
|
+
}), ___EmotionJSX(ResponseText, {
|
53
|
+
text: testText
|
54
|
+
}), ___EmotionJSX(ResponseList, null, ___EmotionJSX(ResponseText, {
|
55
|
+
as: "h5",
|
56
|
+
sx: {
|
57
|
+
fontWeight: 2
|
58
|
+
},
|
59
|
+
text: "heading"
|
60
|
+
}), ___EmotionJSX(ResponseText, {
|
61
|
+
as: "li",
|
62
|
+
text: "list item 1"
|
63
|
+
}), ___EmotionJSX(ResponseText, {
|
64
|
+
as: "li",
|
65
|
+
text: "list item 2"
|
66
|
+
}), ___EmotionJSX(ResponseText, {
|
67
|
+
as: "li",
|
68
|
+
text: "list item 3"
|
69
|
+
})), ___EmotionJSX(ResponseText, {
|
70
|
+
text: "follow up text"
|
71
|
+
}), ___EmotionJSX(ResponseToolbar, toolBarProps)));
|
72
|
+
};
|
@@ -0,0 +1,215 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import AccountGroupIcon from '@pingux/mdi-react/AccountGroupIcon';
|
3
|
+
import AccountIcon from '@pingux/mdi-react/AccountIcon';
|
4
|
+
import LockIcon from '@pingux/mdi-react/LockIcon';
|
5
|
+
import SearchIcon from '@pingux/mdi-react/SearchIcon';
|
6
|
+
import TagIcon from '@pingux/mdi-react/TagIcon';
|
7
|
+
|
8
|
+
import { act, render, screen } from '../../../utils/testUtils/testWrapper';
|
9
|
+
|
10
|
+
import Response from './Response';
|
11
|
+
import ResponseAttachment from './ResponseAttachment';
|
12
|
+
import ResponseList from './ResponseList';
|
13
|
+
import ResponseText from './ResponseText';
|
14
|
+
import ResponseToolbar from './ResponseToolbar';
|
15
|
+
|
16
|
+
const delay = 100;
|
17
|
+
|
18
|
+
const headingText = 'heading';
|
19
|
+
|
20
|
+
const listItem1 = 'list item 1';
|
21
|
+
const listItem2 = 'list item 2';
|
22
|
+
const listItem3 = 'list item 3';
|
23
|
+
const nextText = 'nextText';
|
24
|
+
const attachmentWrapperId = 'wrapper-id';
|
25
|
+
const toolbarId = 'id';
|
26
|
+
|
27
|
+
const customProps = {
|
28
|
+
readButtonProps: {
|
29
|
+
title: 'Read aloud test',
|
30
|
+
icon: AccountGroupIcon,
|
31
|
+
},
|
32
|
+
copyButtonProps: {
|
33
|
+
title: 'Copy test',
|
34
|
+
icon: AccountIcon,
|
35
|
+
},
|
36
|
+
goodButtonProps: {
|
37
|
+
title: 'Good Response test',
|
38
|
+
icon: LockIcon,
|
39
|
+
},
|
40
|
+
badButtonProps: {
|
41
|
+
title: 'Bad Response test',
|
42
|
+
icon: SearchIcon,
|
43
|
+
},
|
44
|
+
rephraseButtonProps: {
|
45
|
+
title: 'Rephrase Answer test',
|
46
|
+
icon: TagIcon,
|
47
|
+
},
|
48
|
+
};
|
49
|
+
|
50
|
+
const defaultProps = {
|
51
|
+
containerProps: {
|
52
|
+
'data-testid': 'container',
|
53
|
+
},
|
54
|
+
text: 'Hello',
|
55
|
+
delay,
|
56
|
+
};
|
57
|
+
|
58
|
+
beforeEach(() => {
|
59
|
+
jest.useFakeTimers();
|
60
|
+
});
|
61
|
+
|
62
|
+
const getComponent = props => render(
|
63
|
+
<Response {...defaultProps} {...props}>
|
64
|
+
<ResponseText text={defaultProps.text} />
|
65
|
+
</Response>,
|
66
|
+
);
|
67
|
+
|
68
|
+
const getComponentWithList = props => render(
|
69
|
+
<Response {...defaultProps} {...props}>
|
70
|
+
<ResponseText text={headingText} delay={delay} />
|
71
|
+
<ResponseList as="ul">
|
72
|
+
<ResponseText as="li" text={listItem1} />
|
73
|
+
<ResponseText as="li" text={listItem2} />
|
74
|
+
<ResponseText as="li" text={listItem3} />
|
75
|
+
</ResponseList>
|
76
|
+
<ResponseText text={nextText} />
|
77
|
+
</Response>,
|
78
|
+
);
|
79
|
+
|
80
|
+
const getComponentWithToolbar = props => render(
|
81
|
+
<Response {...defaultProps} {...props}>
|
82
|
+
<ResponseText text={defaultProps.text} />
|
83
|
+
<ResponseToolbar data-testid={toolbarId} />
|
84
|
+
</Response>,
|
85
|
+
);
|
86
|
+
|
87
|
+
const getComponentWithAttachment = props => render(
|
88
|
+
<Response {...defaultProps} {...props}>
|
89
|
+
<ResponseText text={defaultProps.text} />
|
90
|
+
<ResponseAttachment wrapperProps={{ 'data-testid': attachmentWrapperId }} />
|
91
|
+
<ResponseText text={defaultProps.text} />
|
92
|
+
</Response>,
|
93
|
+
);
|
94
|
+
|
95
|
+
const getComponentWithToolbarCustomProps = props => render(
|
96
|
+
<Response {...defaultProps} {...props}>
|
97
|
+
<ResponseText text={defaultProps.text} />
|
98
|
+
<ResponseToolbar data-testid={toolbarId} {...customProps} />
|
99
|
+
</Response>,
|
100
|
+
);
|
101
|
+
|
102
|
+
test('component renders', () => {
|
103
|
+
getComponent();
|
104
|
+
const container = screen.getByTestId('container');
|
105
|
+
|
106
|
+
expect(container).toBeInTheDocument();
|
107
|
+
});
|
108
|
+
|
109
|
+
test('delay prop works correctly', async () => {
|
110
|
+
getComponent();
|
111
|
+
|
112
|
+
expect(screen.queryByText(defaultProps.text)).not.toBeInTheDocument();
|
113
|
+
for (let i = 1; i < defaultProps.text.length + 1; i += 1) {
|
114
|
+
act(() => { jest.advanceTimersByTime(100); });
|
115
|
+
expect(screen.queryByText(defaultProps.text.slice(0, i))).toBeInTheDocument();
|
116
|
+
}
|
117
|
+
expect(screen.queryByText(defaultProps.text)).toBeInTheDocument();
|
118
|
+
});
|
119
|
+
|
120
|
+
test('delay prop works correctly, with list', async () => {
|
121
|
+
getComponentWithList();
|
122
|
+
|
123
|
+
expect(screen.queryByText(headingText)).not.toBeInTheDocument();
|
124
|
+
for (let i = 1; i < headingText.length + 1; i += 1) {
|
125
|
+
act(() => { jest.advanceTimersByTime(100); });
|
126
|
+
expect(screen.queryByText(headingText.slice(0, i))).toBeInTheDocument();
|
127
|
+
}
|
128
|
+
expect(screen.queryByText(headingText)).toBeInTheDocument();
|
129
|
+
|
130
|
+
// advance through the listItems
|
131
|
+
for (let i = 1; i < (listItem1.length * 3) + 1; i += 1) {
|
132
|
+
act(() => { jest.advanceTimersByTime(100); });
|
133
|
+
}
|
134
|
+
expect(screen.queryByText(nextText)).not.toBeInTheDocument();
|
135
|
+
|
136
|
+
// ensure that the subsequent text renders correctly
|
137
|
+
for (let i = 1; i < nextText.length + 1; i += 1) {
|
138
|
+
act(() => { jest.advanceTimersByTime(100); });
|
139
|
+
expect(screen.queryByText(nextText.slice(0, i))).toBeInTheDocument();
|
140
|
+
}
|
141
|
+
expect(screen.queryByText(nextText)).toBeInTheDocument();
|
142
|
+
});
|
143
|
+
|
144
|
+
test('default delay prop works correctly', async () => {
|
145
|
+
render(
|
146
|
+
<Response {...defaultProps} delay={undefined}>
|
147
|
+
<ResponseText text={defaultProps.text} />
|
148
|
+
</Response>,
|
149
|
+
);
|
150
|
+
|
151
|
+
expect(screen.queryByText(defaultProps.text)).not.toBeInTheDocument();
|
152
|
+
for (let i = 1; i < defaultProps.text.length + 1; i += 1) {
|
153
|
+
act(() => { jest.advanceTimersByTime(10); });
|
154
|
+
expect(screen.queryByText(defaultProps.text.slice(0, i))).toBeInTheDocument();
|
155
|
+
}
|
156
|
+
expect(screen.queryByText(defaultProps.text)).toBeInTheDocument();
|
157
|
+
});
|
158
|
+
|
159
|
+
test('ResponseToolbar renders correctly', async () => {
|
160
|
+
getComponentWithToolbar();
|
161
|
+
|
162
|
+
const toolbar = screen.getByTestId(toolbarId);
|
163
|
+
expect(toolbar).toHaveClass('is-not-loaded');
|
164
|
+
|
165
|
+
for (let i = 1; i < defaultProps.text.length + 1; i += 1) {
|
166
|
+
act(() => { jest.advanceTimersByTime(100); });
|
167
|
+
}
|
168
|
+
expect(toolbar).not.toHaveClass('is-not-loaded');
|
169
|
+
});
|
170
|
+
|
171
|
+
test('ResponseAttachment renders correctly', async () => {
|
172
|
+
getComponentWithAttachment();
|
173
|
+
act(() => { jest.advanceTimersByTime(10); });
|
174
|
+
|
175
|
+
expect(screen.getByText('Attachment text')).toBeInTheDocument();
|
176
|
+
const wrapper = screen.getByTestId(attachmentWrapperId);
|
177
|
+
expect(wrapper).toHaveClass('is-not-loaded');
|
178
|
+
for (let i = 1; i < defaultProps.text.length + 1; i += 1) {
|
179
|
+
act(() => { jest.advanceTimersByTime(100); });
|
180
|
+
}
|
181
|
+
expect(wrapper).not.toHaveClass('is-not-loaded');
|
182
|
+
});
|
183
|
+
|
184
|
+
test('ResponseAttachment renders correctly, with custom props', async () => {
|
185
|
+
getComponentWithToolbarCustomProps();
|
186
|
+
act(() => { jest.advanceTimersByTime(10); });
|
187
|
+
|
188
|
+
expect(screen.getByTitle('Read aloud test')).toBeInTheDocument();
|
189
|
+
expect(screen.getByTitle('Copy test')).toBeInTheDocument();
|
190
|
+
expect(screen.getByTitle('Good Response test')).toBeInTheDocument();
|
191
|
+
expect(screen.getByTitle('Bad Response test')).toBeInTheDocument();
|
192
|
+
expect(screen.getByTitle('Rephrase Answer test')).toBeInTheDocument();
|
193
|
+
});
|
194
|
+
|
195
|
+
test('ResponseToolbar conditional rendering of IconButton based on title prop', async () => {
|
196
|
+
render(
|
197
|
+
<Response {...defaultProps}>
|
198
|
+
<ResponseText text={defaultProps.text} />
|
199
|
+
<ResponseToolbar
|
200
|
+
data-testid={toolbarId}
|
201
|
+
readButtonProps={{ title: 'Read aloud' }}
|
202
|
+
copyButtonProps={{ title: '' }}
|
203
|
+
goodButtonProps={{ title: 'Good Response' }}
|
204
|
+
badButtonProps={{ title: '' }}
|
205
|
+
rephraseButtonProps={{ title: 'Rephrase Answer' }}
|
206
|
+
/>
|
207
|
+
</Response>,
|
208
|
+
);
|
209
|
+
|
210
|
+
expect(screen.getByTitle('Read aloud')).toBeInTheDocument();
|
211
|
+
expect(screen.queryByTitle('Copy')).not.toBeInTheDocument();
|
212
|
+
expect(screen.getByTitle('Good Response')).toBeInTheDocument();
|
213
|
+
expect(screen.queryByTitle('Bad Response')).not.toBeInTheDocument();
|
214
|
+
expect(screen.getByTitle('Rephrase Answer')).toBeInTheDocument();
|
215
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import React, { useEffect, useRef } from 'react';
|
3
|
+
import FileTableOutlineIcon from '@pingux/mdi-react/FileTableOutlineIcon';
|
4
|
+
import { useStatusClasses } from '../../../hooks';
|
5
|
+
import { Box, Icon, Text } from '../../../index';
|
6
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
7
|
+
var ResponseAttachment = function ResponseAttachment(props) {
|
8
|
+
var setAnimationIndex = props.setAnimationIndex,
|
9
|
+
parentIndex = props.parentIndex,
|
10
|
+
wrapperProps = props.wrapperProps,
|
11
|
+
textProps = props.textProps,
|
12
|
+
iconProps = props.iconProps,
|
13
|
+
className = props.className,
|
14
|
+
animationIndex = props.animationIndex,
|
15
|
+
shouldStartAnimation = props.shouldStartAnimation;
|
16
|
+
var isLoaded = useRef(false);
|
17
|
+
useEffect(function () {
|
18
|
+
if (shouldStartAnimation && setAnimationIndex && animationIndex !== undefined && isLoaded.current === false) {
|
19
|
+
isLoaded.current = true;
|
20
|
+
setAnimationIndex(animationIndex + 1);
|
21
|
+
}
|
22
|
+
}, [setAnimationIndex, parentIndex, animationIndex, shouldStartAnimation]);
|
23
|
+
var _useStatusClasses = useStatusClasses(className, {
|
24
|
+
isNotLoaded: !isLoaded.current
|
25
|
+
}),
|
26
|
+
classNames = _useStatusClasses.classNames;
|
27
|
+
return ___EmotionJSX(Box, _extends({
|
28
|
+
isRow: true
|
29
|
+
}, wrapperProps, {
|
30
|
+
className: classNames,
|
31
|
+
variant: "response.attachmentWrapper"
|
32
|
+
}), ___EmotionJSX(Icon, _extends({
|
33
|
+
color: "green",
|
34
|
+
icon: FileTableOutlineIcon,
|
35
|
+
title: {
|
36
|
+
name: 'attachment icon'
|
37
|
+
}
|
38
|
+
}, iconProps)), ___EmotionJSX(Text, textProps, "Attachment text"));
|
39
|
+
};
|
40
|
+
export default ResponseAttachment;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
2
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
3
|
+
var _excluded = ["children", "parentIndex", "setAnimationIndex", "shouldStartAnimation", "delay"];
|
4
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
5
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
6
|
+
import React, { Children, useEffect, useState } from 'react';
|
7
|
+
import { Box } from '../../../index';
|
8
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
9
|
+
var ResponseList = function ResponseList(props) {
|
10
|
+
var _useState = useState(-1),
|
11
|
+
_useState2 = _slicedToArray(_useState, 2),
|
12
|
+
index = _useState2[0],
|
13
|
+
setIndex = _useState2[1];
|
14
|
+
var children = props.children,
|
15
|
+
parentIndex = props.parentIndex,
|
16
|
+
setAnimationIndex = props.setAnimationIndex,
|
17
|
+
shouldStartAnimation = props.shouldStartAnimation,
|
18
|
+
delay = props.delay,
|
19
|
+
others = _objectWithoutProperties(props, _excluded);
|
20
|
+
useEffect(function () {
|
21
|
+
if (children && setAnimationIndex && index === children.length && parentIndex) {
|
22
|
+
setAnimationIndex(parentIndex + 1);
|
23
|
+
}
|
24
|
+
}, [index]);
|
25
|
+
useEffect(function () {
|
26
|
+
if (shouldStartAnimation) {
|
27
|
+
setIndex(0);
|
28
|
+
}
|
29
|
+
}, [shouldStartAnimation]);
|
30
|
+
return ___EmotionJSX(Box, others, ___EmotionJSX(React.Fragment, null, /*#__PURE__*/React.cloneElement(children[0], {
|
31
|
+
shouldStartAnimation: index === 0,
|
32
|
+
setAnimationIndex: setIndex,
|
33
|
+
animationIndex: 0,
|
34
|
+
delay: delay
|
35
|
+
})), ___EmotionJSX(Box, {
|
36
|
+
as: "ul",
|
37
|
+
sx: {
|
38
|
+
pl: 'md',
|
39
|
+
listStyleType: 'disc',
|
40
|
+
listStylePosition: 'inside'
|
41
|
+
}
|
42
|
+
}, _mapInstanceProperty(Children).call(Children, _sliceInstanceProperty(children).call(children, 1, children.length), function (child, i) {
|
43
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
44
|
+
shouldStartAnimation: index === i + 1,
|
45
|
+
setAnimationIndex: setIndex,
|
46
|
+
animationIndex: i + 1,
|
47
|
+
delay: delay,
|
48
|
+
isListItem: true
|
49
|
+
});
|
50
|
+
})));
|
51
|
+
};
|
52
|
+
export default ResponseList;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["delay", "text", "shouldStartAnimation", "setAnimationIndex", "animationIndex", "isListItem", "className"];
|
4
|
+
import React from 'react';
|
5
|
+
import { useStatusClasses } from '../../../hooks';
|
6
|
+
import useTypeAnimation from '../../../hooks/useTypeAnimation/useTypeAnimation';
|
7
|
+
import { Text } from '../../../index';
|
8
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
9
|
+
var ResponseText = function ResponseText(props) {
|
10
|
+
var delay = props.delay,
|
11
|
+
text = props.text,
|
12
|
+
shouldStartAnimation = props.shouldStartAnimation,
|
13
|
+
setAnimationIndex = props.setAnimationIndex,
|
14
|
+
animationIndex = props.animationIndex,
|
15
|
+
isListItem = props.isListItem,
|
16
|
+
className = props.className,
|
17
|
+
others = _objectWithoutProperties(props, _excluded);
|
18
|
+
var animationProps = {
|
19
|
+
delay: delay,
|
20
|
+
text: text,
|
21
|
+
setAnimationIndex: setAnimationIndex,
|
22
|
+
animationIndex: animationIndex,
|
23
|
+
shouldStartAnimation: shouldStartAnimation
|
24
|
+
};
|
25
|
+
var currentText = useTypeAnimation(animationProps);
|
26
|
+
var hasBullet = isListItem && currentText.length > 0;
|
27
|
+
var _useStatusClasses = useStatusClasses(className, {
|
28
|
+
hasBullet: hasBullet
|
29
|
+
}),
|
30
|
+
classNames = _useStatusClasses.classNames;
|
31
|
+
return ___EmotionJSX(Text, _extends({}, others, {
|
32
|
+
role: isListItem ? 'listitem' : '',
|
33
|
+
variant: "response",
|
34
|
+
className: classNames
|
35
|
+
}), currentText);
|
36
|
+
};
|
37
|
+
export default ResponseText;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["parentIndex", "setAnimationIndex", "readButtonProps", "copyButtonProps", "goodButtonProps", "badButtonProps", "rephraseButtonProps", "className", "shouldStartAnimation", "animationIndex"];
|
4
|
+
import React, { useEffect, useRef } from 'react';
|
5
|
+
import CopyIcon from '@pingux/mdi-react/ContentCopyIcon';
|
6
|
+
import TextIcon from '@pingux/mdi-react/TextIcon';
|
7
|
+
import ThumbDownOutlineIcon from '@pingux/mdi-react/ThumbDownOutlineIcon';
|
8
|
+
import ThumbUpOutlineIcon from '@pingux/mdi-react/ThumbUpOutlineIcon';
|
9
|
+
import VolumeHighIcon from '@pingux/mdi-react/VolumeHighIcon';
|
10
|
+
import { useStatusClasses } from '../../../hooks';
|
11
|
+
import { Box, Icon, IconButton } from '../../../index';
|
12
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
13
|
+
var ResponseToolbarIcon = function ResponseToolbarIcon(props) {
|
14
|
+
var title = props.title,
|
15
|
+
icon = props.icon;
|
16
|
+
return ___EmotionJSX(IconButton, {
|
17
|
+
title: title
|
18
|
+
}, ___EmotionJSX(Icon, {
|
19
|
+
icon: icon,
|
20
|
+
title: {
|
21
|
+
name: title
|
22
|
+
}
|
23
|
+
}));
|
24
|
+
};
|
25
|
+
var ResponseToolbar = function ResponseToolbar(props) {
|
26
|
+
var parentIndex = props.parentIndex,
|
27
|
+
setAnimationIndex = props.setAnimationIndex,
|
28
|
+
readButtonProps = props.readButtonProps,
|
29
|
+
copyButtonProps = props.copyButtonProps,
|
30
|
+
goodButtonProps = props.goodButtonProps,
|
31
|
+
badButtonProps = props.badButtonProps,
|
32
|
+
rephraseButtonProps = props.rephraseButtonProps,
|
33
|
+
className = props.className,
|
34
|
+
shouldStartAnimation = props.shouldStartAnimation,
|
35
|
+
animationIndex = props.animationIndex,
|
36
|
+
others = _objectWithoutProperties(props, _excluded);
|
37
|
+
var isLoaded = useRef(false);
|
38
|
+
useEffect(function () {
|
39
|
+
if (shouldStartAnimation && setAnimationIndex && animationIndex !== undefined && isLoaded.current === false) {
|
40
|
+
isLoaded.current = true;
|
41
|
+
setAnimationIndex(animationIndex + 1);
|
42
|
+
}
|
43
|
+
}, [setAnimationIndex, parentIndex, shouldStartAnimation, animationIndex]);
|
44
|
+
var _useStatusClasses = useStatusClasses(className, {
|
45
|
+
isNotLoaded: !isLoaded.current
|
46
|
+
}),
|
47
|
+
classNames = _useStatusClasses.classNames;
|
48
|
+
return ___EmotionJSX(Box, _extends({
|
49
|
+
isRow: true,
|
50
|
+
gap: "sm",
|
51
|
+
variant: "response.toolbar",
|
52
|
+
className: classNames
|
53
|
+
}, others), (readButtonProps === null || readButtonProps === void 0 ? void 0 : readButtonProps.title) && ___EmotionJSX(ResponseToolbarIcon, _extends({
|
54
|
+
icon: VolumeHighIcon
|
55
|
+
}, readButtonProps)), (copyButtonProps === null || copyButtonProps === void 0 ? void 0 : copyButtonProps.title) && ___EmotionJSX(ResponseToolbarIcon, _extends({
|
56
|
+
icon: CopyIcon
|
57
|
+
}, copyButtonProps)), (goodButtonProps === null || goodButtonProps === void 0 ? void 0 : goodButtonProps.title) && ___EmotionJSX(ResponseToolbarIcon, _extends({
|
58
|
+
icon: ThumbUpOutlineIcon
|
59
|
+
}, goodButtonProps)), (badButtonProps === null || badButtonProps === void 0 ? void 0 : badButtonProps.title) && ___EmotionJSX(ResponseToolbarIcon, _extends({
|
60
|
+
icon: ThumbDownOutlineIcon
|
61
|
+
}, badButtonProps)), (rephraseButtonProps === null || rephraseButtonProps === void 0 ? void 0 : rephraseButtonProps.title) && ___EmotionJSX(ResponseToolbarIcon, _extends({
|
62
|
+
icon: TextIcon
|
63
|
+
}, rephraseButtonProps)));
|
64
|
+
};
|
65
|
+
export default ResponseToolbar;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export { default } from './Response';
|
2
|
+
export { default as ResponseAttachment } from './ResponseAttachment';
|
3
|
+
export { default as ResponseList } from './ResponseList';
|
4
|
+
export { default as ResponseText } from './ResponseText';
|
5
|
+
export { default as ResponseToolbar } from './ResponseToolbar';
|
@@ -6,7 +6,7 @@ import isChromatic from 'chromatic/isChromatic';
|
|
6
6
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
7
7
|
import { Box, Button, Image } from '../../index';
|
8
8
|
import { htmlElements } from '../../utils/devUtils/constants/htmlElements';
|
9
|
-
import { chiefIdentityChampions, pingImg } from '../../utils/devUtils/constants/images';
|
9
|
+
import { chiefIdentityChampions, fallbackImg, pingImg } from '../../utils/devUtils/constants/images';
|
10
10
|
import ImageReadme from './Image.mdx';
|
11
11
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
12
12
|
export default {
|
@@ -77,7 +77,7 @@ export var Disabled = function Disabled() {
|
|
77
77
|
};
|
78
78
|
export var FallbackImage = function FallbackImage() {
|
79
79
|
return ___EmotionJSX(Image, {
|
80
|
-
fallbackImage:
|
80
|
+
fallbackImage: fallbackImg,
|
81
81
|
fallbackAlt: "Ping Identity",
|
82
82
|
src: "https://deelay.me/7000/https://picsum.photos/150/150",
|
83
83
|
sx: {
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './useTypeAnimation';
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
2
|
+
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
3
|
+
import { useEffect, useState } from 'react';
|
4
|
+
var useTypeAnimation = function useTypeAnimation(_ref) {
|
5
|
+
var shouldStartAnimation = _ref.shouldStartAnimation,
|
6
|
+
text = _ref.text,
|
7
|
+
delay = _ref.delay,
|
8
|
+
setAnimationIndex = _ref.setAnimationIndex,
|
9
|
+
animationIndex = _ref.animationIndex;
|
10
|
+
var _useState = useState(''),
|
11
|
+
_useState2 = _slicedToArray(_useState, 2),
|
12
|
+
currentText = _useState2[0],
|
13
|
+
setCurrentText = _useState2[1];
|
14
|
+
var _useState3 = useState(0),
|
15
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
16
|
+
currentIndex = _useState4[0],
|
17
|
+
setCurrentIndex = _useState4[1];
|
18
|
+
useEffect(function () {
|
19
|
+
if (shouldStartAnimation && text && currentIndex < text.length) {
|
20
|
+
var timeout = _setTimeout(function () {
|
21
|
+
setCurrentText(function (prevText) {
|
22
|
+
return prevText + text[currentIndex];
|
23
|
+
});
|
24
|
+
setCurrentIndex(function (prevIndex) {
|
25
|
+
return prevIndex + 1;
|
26
|
+
});
|
27
|
+
}, delay);
|
28
|
+
return function () {
|
29
|
+
return clearTimeout(timeout);
|
30
|
+
};
|
31
|
+
}
|
32
|
+
if (text && currentIndex === text.length) {
|
33
|
+
setAnimationIndex(animationIndex + 1);
|
34
|
+
}
|
35
|
+
return function () {
|
36
|
+
return null;
|
37
|
+
};
|
38
|
+
}, [currentIndex, delay, text, shouldStartAnimation, setAnimationIndex, animationIndex]);
|
39
|
+
return currentText;
|
40
|
+
};
|
41
|
+
export default useTypeAnimation;
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
3
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
7
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
12
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
13
|
+
import { act, renderHook } from '@testing-library/react-hooks';
|
14
|
+
import useTypeAnimation from './useTypeAnimation';
|
15
|
+
var setAnimationIndex = jest.fn();
|
16
|
+
var animationIndex = 0;
|
17
|
+
var text = 'Hello';
|
18
|
+
var delay = 100;
|
19
|
+
var defaultProps = {
|
20
|
+
text: text,
|
21
|
+
delay: delay,
|
22
|
+
setAnimationIndex: setAnimationIndex,
|
23
|
+
animationIndex: animationIndex,
|
24
|
+
shouldStartAnimation: true
|
25
|
+
};
|
26
|
+
describe('useTypeAnimation', function () {
|
27
|
+
beforeEach(function () {
|
28
|
+
jest.useFakeTimers();
|
29
|
+
});
|
30
|
+
afterEach(function () {
|
31
|
+
jest.useRealTimers();
|
32
|
+
});
|
33
|
+
it('should type out text with delay', function () {
|
34
|
+
var _renderHook = renderHook(function () {
|
35
|
+
return useTypeAnimation(defaultProps);
|
36
|
+
}),
|
37
|
+
result = _renderHook.result;
|
38
|
+
expect(result.current).toBe('');
|
39
|
+
for (var i = 0; i < text.length; i += 1) {
|
40
|
+
act(function () {
|
41
|
+
jest.advanceTimersByTime(delay);
|
42
|
+
});
|
43
|
+
expect(result.current).toBe(_sliceInstanceProperty(text).call(text, 0, i + 1));
|
44
|
+
}
|
45
|
+
expect(result.current).toBe(text);
|
46
|
+
});
|
47
|
+
it('should NOT render text when shouldStartAnimation = false', function () {
|
48
|
+
var _renderHook2 = renderHook(function () {
|
49
|
+
return useTypeAnimation(_objectSpread(_objectSpread({}, defaultProps), {}, {
|
50
|
+
shouldStartAnimation: false
|
51
|
+
}));
|
52
|
+
}),
|
53
|
+
result = _renderHook2.result;
|
54
|
+
expect(result.current).toBe('');
|
55
|
+
for (var i = 0; i < text.length; i += 1) {
|
56
|
+
act(function () {
|
57
|
+
jest.advanceTimersByTime(delay);
|
58
|
+
});
|
59
|
+
expect(result.current).toBe('');
|
60
|
+
}
|
61
|
+
expect(result.current).toBe('');
|
62
|
+
});
|
63
|
+
});
|
package/lib/index.js
CHANGED
@@ -11,6 +11,11 @@ export * from './components/AccordionGroup';
|
|
11
11
|
export { default as AccordionItem } from './components/AccordionItem';
|
12
12
|
export * from './components/AccordionItem';
|
13
13
|
export { default as Prompt } from './components/AIComponents/Prompt';
|
14
|
+
export { default as Response } from './components/AIComponents/Response';
|
15
|
+
export { default as ResponseAttachment } from './components/AIComponents/Response/ResponseAttachment';
|
16
|
+
export { default as ResponseList } from './components/AIComponents/Response/ResponseList';
|
17
|
+
export { default as ResponseText } from './components/AIComponents/Response/ResponseText';
|
18
|
+
export { default as ResponseToolbar } from './components/AIComponents/Response/ResponseToolbar';
|
14
19
|
export { default as ArrayField } from './components/ArrayField';
|
15
20
|
export * from './components/ArrayField';
|
16
21
|
export { default as AstroWrapper } from './components/AstroProvider';
|
@@ -9,5 +9,5 @@ export var componentSpecificNextGenBlacklist = {
|
|
9
9
|
TextField: ['Success'],
|
10
10
|
OverlayPanel: ['Expandable']
|
11
11
|
};
|
12
|
-
export var nextGenOnlyComponents = ['NavigationHeader', 'Prompt'];
|
12
|
+
export var nextGenOnlyComponents = ['NavigationHeader', 'Prompt', 'Response'];
|
13
13
|
export default nextGenConvertedComponents;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
var iconWrapper = {
|
2
|
+
border: '1px solid',
|
3
|
+
p: 'xs',
|
4
|
+
borderColor: 'gray-200',
|
5
|
+
borderRadius: '50%',
|
6
|
+
alignContent: 'center',
|
7
|
+
alignItems: 'center',
|
8
|
+
justifyContent: 'center',
|
9
|
+
width: '32px',
|
10
|
+
height: '32px',
|
11
|
+
minWidth: '32px',
|
12
|
+
minHeight: '32px'
|
13
|
+
};
|
14
|
+
var attachmentWrapper = {
|
15
|
+
alignItems: 'center',
|
16
|
+
height: '60px',
|
17
|
+
border: '1px solid',
|
18
|
+
borderColor: 'gray-200',
|
19
|
+
p: 'md',
|
20
|
+
gap: 'sm',
|
21
|
+
borderRadius: '4px',
|
22
|
+
'&.is-not-loaded': {
|
23
|
+
display: 'none'
|
24
|
+
}
|
25
|
+
};
|
26
|
+
var toolbar = {
|
27
|
+
'&.is-not-loaded': {
|
28
|
+
display: 'none'
|
29
|
+
}
|
30
|
+
};
|
31
|
+
export default {
|
32
|
+
iconWrapper: iconWrapper,
|
33
|
+
attachmentWrapper: attachmentWrapper,
|
34
|
+
toolbar: toolbar
|
35
|
+
};
|