@gravity-ui/aikit 1.3.1 → 1.3.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/LICENSE +1 -1
- package/dist/components/pages/ChatContainer/ChatContainer.js +7 -3
- package/dist/components/pages/ChatContainer/__stories__/ChatContainer.stories.js +7 -1
- package/dist/components/pages/ChatContainer/types.d.ts +9 -1
- package/dist/components/pages/ChatContainer/useChatContainer.d.ts +1 -0
- package/dist/components/pages/ChatContainer/useChatContainer.js +9 -2
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -44,12 +44,13 @@ export function ChatContainer(props) {
|
|
|
44
44
|
return true;
|
|
45
45
|
}, [hideTitleOnEmptyChat, isChatEmpty, headerProps.showTitle]);
|
|
46
46
|
// Build props for Header
|
|
47
|
-
const finalHeaderProps = useMemo(() => (Object.assign(Object.assign({}, headerProps), { title: headerTitle, showTitle, baseActions: hookState.baseActions, handleNewChat: hookState.handleNewChat, handleHistoryToggle: hookState.handleHistoryToggle, handleClose: hookState.handleClose, historyButtonRef: hookState.historyButtonRef })), [
|
|
47
|
+
const finalHeaderProps = useMemo(() => (Object.assign(Object.assign({}, headerProps), { title: headerTitle, showTitle, baseActions: hookState.baseActions, handleNewChat: hookState.handleNewChat, handleHistoryToggle: hookState.handleHistoryToggle, handleFolding: hookState.handleFolding, handleClose: hookState.handleClose, historyButtonRef: hookState.historyButtonRef })), [
|
|
48
48
|
headerTitle,
|
|
49
49
|
showTitle,
|
|
50
50
|
hookState.baseActions,
|
|
51
51
|
hookState.handleNewChat,
|
|
52
52
|
hookState.handleHistoryToggle,
|
|
53
|
+
hookState.handleFolding,
|
|
53
54
|
hookState.handleClose,
|
|
54
55
|
hookState.historyButtonRef,
|
|
55
56
|
headerProps,
|
|
@@ -57,9 +58,12 @@ export function ChatContainer(props) {
|
|
|
57
58
|
// Build props for EmptyContainer
|
|
58
59
|
const finalEmptyContainerProps = useMemo(() => {
|
|
59
60
|
var _a, _b, _c, _d;
|
|
60
|
-
|
|
61
|
+
const { showDefaultTitle = true, showDefaultDescription = true } = welcomeConfig || {};
|
|
62
|
+
return Object.assign(Object.assign({}, emptyContainerProps), { image: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.image, title: (welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.title) ||
|
|
63
|
+
((_a = i18nConfig.emptyState) === null || _a === void 0 ? void 0 : _a.title) ||
|
|
64
|
+
(showDefaultTitle ? i18n('empty-state-title') : undefined), description: (welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.description) ||
|
|
61
65
|
((_b = i18nConfig.emptyState) === null || _b === void 0 ? void 0 : _b.description) ||
|
|
62
|
-
i18n('empty-state-description'), suggestionTitle: (welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.suggestionTitle) || ((_c = i18nConfig.emptyState) === null || _c === void 0 ? void 0 : _c.suggestionsTitle), suggestions: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.suggestions, alignment: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.alignment, layout: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.layout, wrapText: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.wrapText, showMore: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.showMore, showMoreText: (welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.showMoreText) ||
|
|
66
|
+
(showDefaultDescription ? i18n('empty-state-description') : undefined), suggestionTitle: (welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.suggestionTitle) || ((_c = i18nConfig.emptyState) === null || _c === void 0 ? void 0 : _c.suggestionsTitle), suggestions: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.suggestions, alignment: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.alignment, layout: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.layout, wrapText: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.wrapText, showMore: welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.showMore, showMoreText: (welcomeConfig === null || welcomeConfig === void 0 ? void 0 : welcomeConfig.showMoreText) ||
|
|
63
67
|
((_d = i18nConfig.emptyState) === null || _d === void 0 ? void 0 : _d.showMoreText) ||
|
|
64
68
|
i18n('empty-state-show-more'), onSuggestionClick: async (clickedTitle) => {
|
|
65
69
|
await onSendMessage({ content: clickedTitle });
|
|
@@ -211,6 +211,7 @@ export const Playground = {
|
|
|
211
211
|
chats: mockChats,
|
|
212
212
|
showHistory: true,
|
|
213
213
|
showNewChat: true,
|
|
214
|
+
showFolding: false,
|
|
214
215
|
showClose: false,
|
|
215
216
|
welcomeConfig: {
|
|
216
217
|
title: 'Welcome to AI Chat',
|
|
@@ -225,6 +226,7 @@ export const Playground = {
|
|
|
225
226
|
const [messages, setMessages] = useState(addActionsToMessages(mockChatMessages[initialChat.id] || []));
|
|
226
227
|
const [status, setStatus] = useState(args.status || 'ready');
|
|
227
228
|
const [activeChat, setActiveChat] = useState(initialChat);
|
|
229
|
+
const [foldingState, setFoldingState] = useState('opened');
|
|
228
230
|
const handleSendMessage = async (data) => {
|
|
229
231
|
const userMessage = {
|
|
230
232
|
id: Date.now().toString(),
|
|
@@ -261,7 +263,9 @@ export const Playground = {
|
|
|
261
263
|
const handleCancel = async () => {
|
|
262
264
|
setStatus('ready');
|
|
263
265
|
};
|
|
264
|
-
return (_jsx(ChatContainer, Object.assign({}, args, {
|
|
266
|
+
return (_jsx(ChatContainer, Object.assign({}, args, { headerProps: {
|
|
267
|
+
foldingState,
|
|
268
|
+
}, messages: messages, activeChat: activeChat, onSendMessage: handleSendMessage, onCancel: handleCancel, onSelectChat: handleSelectChat, onCreateChat: handleCreateChat, onFold: setFoldingState, status: status })));
|
|
265
269
|
},
|
|
266
270
|
decorators: defaultDecorators,
|
|
267
271
|
};
|
|
@@ -277,6 +281,8 @@ export const EmptyState = {
|
|
|
277
281
|
description: 'Start a conversation by typing a message or selecting a suggestion.',
|
|
278
282
|
suggestionTitle: 'Try asking:',
|
|
279
283
|
suggestions: mockSuggestions,
|
|
284
|
+
showDefaultTitle: false,
|
|
285
|
+
showDefaultDescription: false,
|
|
280
286
|
},
|
|
281
287
|
},
|
|
282
288
|
render: (args) => {
|
|
@@ -82,6 +82,10 @@ export interface WelcomeConfig {
|
|
|
82
82
|
layout?: 'grid' | 'list';
|
|
83
83
|
/** Enable text wrapping inside suggestion buttons instead of ellipsis */
|
|
84
84
|
wrapText?: boolean;
|
|
85
|
+
/** Show default title when neither title nor i18nConfig.emptyState.title are provided */
|
|
86
|
+
showDefaultTitle?: boolean;
|
|
87
|
+
/** Show default description when neither description nor i18nConfig.emptyState.description are provided */
|
|
88
|
+
showDefaultDescription?: boolean;
|
|
85
89
|
/** Show more suggestions callback */
|
|
86
90
|
showMore?: () => void;
|
|
87
91
|
/** Show more button text */
|
|
@@ -111,6 +115,8 @@ export interface ChatContainerProps {
|
|
|
111
115
|
onDeleteChat?: (chat: ChatType) => void;
|
|
112
116
|
/** Callback when user deletes all chats */
|
|
113
117
|
onDeleteAllChats?: () => Promise<void>;
|
|
118
|
+
/** Callback when user folds or unfolds the chat */
|
|
119
|
+
onFold?: (value: 'collapsed' | 'opened') => void;
|
|
114
120
|
/** Callback when user closes the chat */
|
|
115
121
|
onClose?: () => void;
|
|
116
122
|
/** Callback when user cancels streaming */
|
|
@@ -132,7 +138,7 @@ export interface ChatContainerProps {
|
|
|
132
138
|
/** MessageList configuration for actions and loader behavior */
|
|
133
139
|
messageListConfig?: MessageListConfig;
|
|
134
140
|
/** Props override for Header component */
|
|
135
|
-
headerProps?: Partial<Omit<HeaderProps, 'handleNewChat' | 'handleHistoryToggle' | 'handleClose'>>;
|
|
141
|
+
headerProps?: Partial<Omit<HeaderProps, 'handleNewChat' | 'handleHistoryToggle' | 'handleFolding' | 'handleClose'>>;
|
|
136
142
|
/** Props override for ChatContent component */
|
|
137
143
|
contentProps?: Partial<Omit<ChatContentProps, 'view' | 'messageListProps'>>;
|
|
138
144
|
/** Props override for EmptyContainer (welcome screen) */
|
|
@@ -151,6 +157,8 @@ export interface ChatContainerProps {
|
|
|
151
157
|
showHistory?: boolean;
|
|
152
158
|
/** Show new chat button */
|
|
153
159
|
showNewChat?: boolean;
|
|
160
|
+
/** Show folding button */
|
|
161
|
+
showFolding?: boolean;
|
|
154
162
|
/** Show close button */
|
|
155
163
|
showClose?: boolean;
|
|
156
164
|
/** Hide header title when chat is empty */
|
|
@@ -13,6 +13,7 @@ export declare function useChatContainer(props: ChatContainerProps): {
|
|
|
13
13
|
historyButtonRef: import("react").RefObject<HTMLElement>;
|
|
14
14
|
handleNewChat: () => void;
|
|
15
15
|
handleHistoryToggle: () => void;
|
|
16
|
+
handleFolding: (value: "collapsed" | "opened") => void;
|
|
16
17
|
handleClose: () => void;
|
|
17
18
|
handleSelectChat: (chat: ChatContainerProps["activeChat"]) => void;
|
|
18
19
|
handleHistoryOpenChange: (open: boolean) => void;
|
|
@@ -7,7 +7,7 @@ import { HeaderAction } from '../../organisms/Header';
|
|
|
7
7
|
* @returns object with state and handlers
|
|
8
8
|
*/
|
|
9
9
|
export function useChatContainer(props) {
|
|
10
|
-
const { messages = [], activeChat, onCreateChat, onClose, onSelectChat, showHistory = true, showNewChat = true, showClose = false, } = props;
|
|
10
|
+
const { messages = [], activeChat, onCreateChat, onClose, onFold, onSelectChat, showHistory = true, showNewChat = true, showFolding = false, showClose = false, } = props;
|
|
11
11
|
// Refs for History integration with Header
|
|
12
12
|
const historyButtonRef = useRef(null);
|
|
13
13
|
const [isHistoryOpen, setIsHistoryOpen] = useState(false);
|
|
@@ -29,6 +29,9 @@ export function useChatContainer(props) {
|
|
|
29
29
|
const handleHistoryToggle = useCallback(() => {
|
|
30
30
|
setIsHistoryOpen((prev) => !prev);
|
|
31
31
|
}, []);
|
|
32
|
+
const handleFolding = useCallback((value) => {
|
|
33
|
+
onFold === null || onFold === void 0 ? void 0 : onFold(value);
|
|
34
|
+
}, [onFold]);
|
|
32
35
|
// Handler for closing
|
|
33
36
|
const handleClose = useCallback(() => {
|
|
34
37
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
@@ -53,11 +56,14 @@ export function useChatContainer(props) {
|
|
|
53
56
|
if (showHistory) {
|
|
54
57
|
actions.push(HeaderAction.History);
|
|
55
58
|
}
|
|
59
|
+
if (showFolding) {
|
|
60
|
+
actions.push(HeaderAction.Folding);
|
|
61
|
+
}
|
|
56
62
|
if (showClose) {
|
|
57
63
|
actions.push(HeaderAction.Close);
|
|
58
64
|
}
|
|
59
65
|
return actions;
|
|
60
|
-
}, [showNewChat, showHistory, showClose, chatContentView]);
|
|
66
|
+
}, [showNewChat, showHistory, showFolding, showClose, chatContentView]);
|
|
61
67
|
return {
|
|
62
68
|
// State
|
|
63
69
|
chatContentView,
|
|
@@ -68,6 +74,7 @@ export function useChatContainer(props) {
|
|
|
68
74
|
// Handlers
|
|
69
75
|
handleNewChat,
|
|
70
76
|
handleHistoryToggle,
|
|
77
|
+
handleFolding,
|
|
71
78
|
handleClose,
|
|
72
79
|
handleSelectChat,
|
|
73
80
|
handleHistoryOpenChange,
|