@stack-spot/ai-chat-widget 0.11.0 → 1.1.0
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/CHANGELOG.md +9 -0
- package/dist/StackspotAIWidget.d.ts +20 -0
- package/dist/StackspotAIWidget.d.ts.map +1 -1
- package/dist/StackspotAIWidget.js +7 -3
- package/dist/StackspotAIWidget.js.map +1 -1
- package/dist/chat-interceptors/CustomInputs.d.ts +4 -1
- package/dist/chat-interceptors/CustomInputs.d.ts.map +1 -1
- package/dist/chat-interceptors/CustomInputs.js +10 -1
- package/dist/chat-interceptors/CustomInputs.js.map +1 -1
- package/dist/chat-interceptors/quick-command-questions.d.ts +10 -0
- package/dist/chat-interceptors/quick-command-questions.d.ts.map +1 -1
- package/dist/chat-interceptors/quick-command-questions.js +12 -2
- package/dist/chat-interceptors/quick-command-questions.js.map +1 -1
- package/dist/chat-interceptors/quick-commands.d.ts +11 -0
- package/dist/chat-interceptors/quick-commands.d.ts.map +1 -1
- package/dist/chat-interceptors/quick-commands.js +65 -25
- package/dist/chat-interceptors/quick-commands.js.map +1 -1
- package/dist/chat-interceptors/send-message.d.ts +10 -0
- package/dist/chat-interceptors/send-message.d.ts.map +1 -1
- package/dist/chat-interceptors/send-message.js +32 -10
- package/dist/chat-interceptors/send-message.js.map +1 -1
- package/dist/components/Accordion.d.ts +10 -0
- package/dist/components/Accordion.d.ts.map +1 -1
- package/dist/components/Accordion.js +3 -0
- package/dist/components/Accordion.js.map +1 -1
- package/dist/components/AdaptiveTextArea.d.ts +13 -1
- package/dist/components/AdaptiveTextArea.d.ts.map +1 -1
- package/dist/components/AdaptiveTextArea.js +9 -4
- package/dist/components/AdaptiveTextArea.js.map +1 -1
- package/dist/components/AutoFocus.d.ts +23 -0
- package/dist/components/AutoFocus.d.ts.map +1 -0
- package/dist/components/AutoFocus.js +16 -0
- package/dist/components/AutoFocus.js.map +1 -0
- package/dist/components/Fading.d.ts +32 -0
- package/dist/components/Fading.d.ts.map +1 -0
- package/dist/components/Fading.js +33 -0
- package/dist/components/Fading.js.map +1 -0
- package/dist/components/FadingOverflow.d.ts +25 -0
- package/dist/components/FadingOverflow.d.ts.map +1 -1
- package/dist/components/FadingOverflow.js +11 -2
- package/dist/components/FadingOverflow.js.map +1 -1
- package/dist/components/FallbackBoundary/ErrorBoundary.d.ts +3 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.d.ts.map +1 -1
- package/dist/components/FallbackBoundary/ErrorBoundary.js +18 -4
- package/dist/components/FallbackBoundary/ErrorBoundary.js.map +1 -1
- package/dist/components/FallbackBoundary/Loading.js +1 -1
- package/dist/components/FallbackBoundary/Loading.js.map +1 -1
- package/dist/components/FallbackBoundary/index.d.ts +12 -1
- package/dist/components/FallbackBoundary/index.d.ts.map +1 -1
- package/dist/components/FallbackBoundary/index.js +1 -1
- package/dist/components/FallbackBoundary/index.js.map +1 -1
- package/dist/components/HistoryList.d.ts +15 -0
- package/dist/components/HistoryList.d.ts.map +1 -1
- package/dist/components/HistoryList.js +3 -1
- package/dist/components/HistoryList.js.map +1 -1
- package/dist/components/IconInput.d.ts +3 -0
- package/dist/components/IconInput.d.ts.map +1 -1
- package/dist/components/IconInput.js +3 -0
- package/dist/components/IconInput.js.map +1 -1
- package/dist/components/OverlayMenu.d.ts +12 -1
- package/dist/components/OverlayMenu.d.ts.map +1 -1
- package/dist/components/OverlayMenu.js +31 -10
- package/dist/components/OverlayMenu.js.map +1 -1
- package/dist/components/ProgressBar.d.ts +22 -0
- package/dist/components/ProgressBar.d.ts.map +1 -1
- package/dist/components/ProgressBar.js +5 -0
- package/dist/components/ProgressBar.js.map +1 -1
- package/dist/components/QuickStartButton.d.ts.map +1 -1
- package/dist/components/QuickStartButton.js +3 -0
- package/dist/components/QuickStartButton.js.map +1 -1
- package/dist/components/RightPanelForm.d.ts +3 -0
- package/dist/components/RightPanelForm.d.ts.map +1 -1
- package/dist/components/RightPanelForm.js +8 -4
- package/dist/components/RightPanelForm.js.map +1 -1
- package/dist/components/RightPanelTabs.d.ts +3 -0
- package/dist/components/RightPanelTabs.d.ts.map +1 -1
- package/dist/components/RightPanelTabs.js +3 -0
- package/dist/components/RightPanelTabs.js.map +1 -1
- package/dist/components/TabManager.d.ts +6 -0
- package/dist/components/TabManager.d.ts.map +1 -1
- package/dist/components/TabManager.js +8 -0
- package/dist/components/TabManager.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +26 -1
- package/dist/components/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/components/Tooltip/Tooltip.js +18 -5
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tooltip/TooltipAPI.d.ts +18 -2
- package/dist/components/Tooltip/TooltipAPI.d.ts.map +1 -1
- package/dist/components/Tooltip/TooltipAPI.js +68 -51
- package/dist/components/Tooltip/TooltipAPI.js.map +1 -1
- package/dist/components/Tooltip/types.d.ts +13 -0
- package/dist/components/Tooltip/types.d.ts.map +1 -1
- package/dist/components/form/DescribedCheckboxGroup.d.ts +4 -0
- package/dist/components/form/DescribedCheckboxGroup.d.ts.map +1 -1
- package/dist/components/form/DescribedCheckboxGroup.js +4 -0
- package/dist/components/form/DescribedCheckboxGroup.js.map +1 -1
- package/dist/components/form/DescribedRadioGroup.d.ts +4 -0
- package/dist/components/form/DescribedRadioGroup.d.ts.map +1 -1
- package/dist/components/form/DescribedRadioGroup.js +4 -0
- package/dist/components/form/DescribedRadioGroup.js.map +1 -1
- package/dist/components/form/types.d.ts +34 -0
- package/dist/components/form/types.d.ts.map +1 -1
- package/dist/context/AIWidgetProvider.d.ts +19 -0
- package/dist/context/AIWidgetProvider.d.ts.map +1 -1
- package/dist/context/AIWidgetProvider.js +19 -0
- package/dist/context/AIWidgetProvider.js.map +1 -1
- package/dist/context/hooks.d.ts +56 -0
- package/dist/context/hooks.d.ts.map +1 -1
- package/dist/context/hooks.js +56 -1
- package/dist/context/hooks.js.map +1 -1
- package/dist/features.d.ts +28 -0
- package/dist/features.d.ts.map +1 -1
- package/dist/features.js +1 -0
- package/dist/features.js.map +1 -1
- package/dist/layout.css +5 -0
- package/dist/regex.d.ts +2 -0
- package/dist/regex.d.ts.map +1 -0
- package/dist/regex.js +2 -0
- package/dist/regex.js.map +1 -0
- package/dist/right-panel/DefaultPanel.d.ts +3 -0
- package/dist/right-panel/DefaultPanel.d.ts.map +1 -1
- package/dist/right-panel/DefaultPanel.js +3 -0
- package/dist/right-panel/DefaultPanel.js.map +1 -1
- package/dist/right-panel/RightPanel.d.ts +3 -0
- package/dist/right-panel/RightPanel.d.ts.map +1 -1
- package/dist/right-panel/RightPanel.js +3 -0
- package/dist/right-panel/RightPanel.js.map +1 -1
- package/dist/right-panel/RightPanelProvider.d.ts +15 -0
- package/dist/right-panel/RightPanelProvider.d.ts.map +1 -1
- package/dist/right-panel/RightPanelProvider.js.map +1 -1
- package/dist/right-panel/constants.d.ts +2 -0
- package/dist/right-panel/constants.d.ts.map +1 -0
- package/dist/right-panel/constants.js +2 -0
- package/dist/right-panel/constants.js.map +1 -0
- package/dist/right-panel/hooks.d.ts +6 -0
- package/dist/right-panel/hooks.d.ts.map +1 -1
- package/dist/right-panel/hooks.js +8 -1
- package/dist/right-panel/hooks.js.map +1 -1
- package/dist/state/ChatEntry.d.ts +58 -2
- package/dist/state/ChatEntry.d.ts.map +1 -1
- package/dist/state/ChatEntry.js +20 -1
- package/dist/state/ChatEntry.js.map +1 -1
- package/dist/state/ChatState.d.ts +73 -8
- package/dist/state/ChatState.d.ts.map +1 -1
- package/dist/state/ChatState.js +24 -7
- package/dist/state/ChatState.js.map +1 -1
- package/dist/state/ChatTabsController.d.ts +31 -0
- package/dist/state/ChatTabsController.d.ts.map +1 -1
- package/dist/state/ChatTabsController.js +31 -0
- package/dist/state/ChatTabsController.js.map +1 -1
- package/dist/state/ObservableState.d.ts +14 -0
- package/dist/state/ObservableState.d.ts.map +1 -1
- package/dist/state/ObservableState.js +14 -0
- package/dist/state/ObservableState.js.map +1 -1
- package/dist/state/WidgetState.d.ts +5 -0
- package/dist/state/WidgetState.d.ts.map +1 -1
- package/dist/state/WidgetState.js +5 -0
- package/dist/state/WidgetState.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/chat.d.ts +13 -0
- package/dist/utils/chat.d.ts.map +1 -1
- package/dist/utils/chat.js +15 -1
- package/dist/utils/chat.js.map +1 -1
- package/dist/utils/date.d.ts +25 -0
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/date.js +25 -0
- package/dist/utils/date.js.map +1 -1
- package/dist/utils/download.d.ts +5 -0
- package/dist/utils/download.d.ts.map +1 -1
- package/dist/utils/download.js +5 -0
- package/dist/utils/download.js.map +1 -1
- package/dist/utils/knowledge-source.d.ts +10 -0
- package/dist/utils/knowledge-source.d.ts.map +1 -1
- package/dist/utils/knowledge-source.js +16 -0
- package/dist/utils/knowledge-source.js.map +1 -1
- package/dist/utils/string.d.ts +5 -0
- package/dist/utils/string.d.ts.map +1 -1
- package/dist/utils/string.js +5 -1
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/url.d.ts +2 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +8 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/views/Agents.js +3 -0
- package/dist/views/Agents.js.map +1 -1
- package/dist/views/Chat/AgentInfo.d.ts +3 -0
- package/dist/views/Chat/AgentInfo.d.ts.map +1 -1
- package/dist/views/Chat/AgentInfo.js +3 -0
- package/dist/views/Chat/AgentInfo.js.map +1 -1
- package/dist/views/Chat/ChatMessage.d.ts +17 -2
- package/dist/views/Chat/ChatMessage.d.ts.map +1 -1
- package/dist/views/Chat/ChatMessage.js +9 -13
- package/dist/views/Chat/ChatMessage.js.map +1 -1
- package/dist/views/Chat/ChatMessages.d.ts +3 -0
- package/dist/views/Chat/ChatMessages.d.ts.map +1 -1
- package/dist/views/Chat/ChatMessages.js +3 -0
- package/dist/views/Chat/ChatMessages.js.map +1 -1
- package/dist/views/Chat/chat-scroll.d.ts +1 -1
- package/dist/views/Chat/chat-scroll.js +1 -1
- package/dist/views/Chat/events.d.ts +22 -0
- package/dist/views/Chat/events.d.ts.map +1 -0
- package/dist/views/Chat/events.js +66 -0
- package/dist/views/Chat/events.js.map +1 -0
- package/dist/views/Chat/index.d.ts +6 -0
- package/dist/views/Chat/index.d.ts.map +1 -1
- package/dist/views/Chat/index.js +3 -0
- package/dist/views/Chat/index.js.map +1 -1
- package/dist/views/ChatHistory/ChatHistoryPanel.d.ts +3 -0
- package/dist/views/ChatHistory/ChatHistoryPanel.d.ts.map +1 -1
- package/dist/views/ChatHistory/ChatHistoryPanel.js +5 -1
- package/dist/views/ChatHistory/ChatHistoryPanel.js.map +1 -1
- package/dist/views/ChatHistory/HistoryItem.d.ts +3 -0
- package/dist/views/ChatHistory/HistoryItem.d.ts.map +1 -1
- package/dist/views/ChatHistory/HistoryItem.js +13 -1
- package/dist/views/ChatHistory/HistoryItem.js.map +1 -1
- package/dist/views/ChatHistory/index.d.ts +10 -2
- package/dist/views/ChatHistory/index.d.ts.map +1 -1
- package/dist/views/ChatHistory/index.js +3 -0
- package/dist/views/ChatHistory/index.js.map +1 -1
- package/dist/views/ChatHistory/utils.d.ts +14 -0
- package/dist/views/ChatHistory/utils.d.ts.map +1 -1
- package/dist/views/ChatHistory/utils.js +14 -0
- package/dist/views/ChatHistory/utils.js.map +1 -1
- package/dist/views/ChatTabSelection.d.ts +3 -0
- package/dist/views/ChatTabSelection.d.ts.map +1 -1
- package/dist/views/ChatTabSelection.js +3 -0
- package/dist/views/ChatTabSelection.js.map +1 -1
- package/dist/views/Editor.d.ts +3 -0
- package/dist/views/Editor.d.ts.map +1 -1
- package/dist/views/Editor.js +4 -0
- package/dist/views/Editor.js.map +1 -1
- package/dist/views/Home.d.ts +8 -0
- package/dist/views/Home.d.ts.map +1 -1
- package/dist/views/Home.js +5 -0
- package/dist/views/Home.js.map +1 -1
- package/dist/views/KSDocument.d.ts +3 -0
- package/dist/views/KSDocument.d.ts.map +1 -1
- package/dist/views/KSDocument.js +3 -0
- package/dist/views/KSDocument.js.map +1 -1
- package/dist/views/KnowledgeSources.js +3 -0
- package/dist/views/KnowledgeSources.js.map +1 -1
- package/dist/views/MessageInput/ButtonGroup.d.ts +22 -0
- package/dist/views/MessageInput/ButtonGroup.d.ts.map +1 -1
- package/dist/views/MessageInput/ButtonGroup.js +4 -0
- package/dist/views/MessageInput/ButtonGroup.js.map +1 -1
- package/dist/views/MessageInput/InfoBar.d.ts +7 -0
- package/dist/views/MessageInput/InfoBar.d.ts.map +1 -1
- package/dist/views/MessageInput/InfoBar.js +7 -0
- package/dist/views/MessageInput/InfoBar.js.map +1 -1
- package/dist/views/MessageInput/QuickCommandSelector.d.ts +13 -0
- package/dist/views/MessageInput/QuickCommandSelector.d.ts.map +1 -0
- package/dist/views/MessageInput/QuickCommandSelector.js +141 -0
- package/dist/views/MessageInput/QuickCommandSelector.js.map +1 -0
- package/dist/views/MessageInput/index.d.ts +8 -0
- package/dist/views/MessageInput/index.d.ts.map +1 -1
- package/dist/views/MessageInput/index.js +11 -4
- package/dist/views/MessageInput/index.js.map +1 -1
- package/dist/views/MessageInput/styled.d.ts.map +1 -1
- package/dist/views/MessageInput/styled.js +137 -0
- package/dist/views/MessageInput/styled.js.map +1 -1
- package/dist/views/MinimizedHeader.d.ts +4 -0
- package/dist/views/MinimizedHeader.d.ts.map +1 -1
- package/dist/views/MinimizedHeader.js +4 -0
- package/dist/views/MinimizedHeader.js.map +1 -1
- package/dist/views/Stacks.d.ts +3 -0
- package/dist/views/Stacks.d.ts.map +1 -1
- package/dist/views/Stacks.js +3 -0
- package/dist/views/Stacks.js.map +1 -1
- package/dist/views/Workspaces.d.ts +3 -0
- package/dist/views/Workspaces.d.ts.map +1 -1
- package/dist/views/Workspaces.js +3 -0
- package/dist/views/Workspaces.js.map +1 -1
- package/package.json +6 -6
- package/src/StackspotAIWidget.tsx +23 -2
- package/src/chat-interceptors/CustomInputs.ts +14 -1
- package/src/chat-interceptors/quick-command-questions.ts +12 -2
- package/src/chat-interceptors/quick-commands.ts +66 -26
- package/src/chat-interceptors/send-message.ts +41 -11
- package/src/components/Accordion.tsx +10 -0
- package/src/components/AdaptiveTextArea.tsx +21 -4
- package/src/components/AutoFocus.tsx +34 -0
- package/src/components/Fading.tsx +66 -0
- package/src/components/FadingOverflow.tsx +31 -3
- package/src/components/FallbackBoundary/ErrorBoundary.tsx +26 -3
- package/src/components/FallbackBoundary/Loading.tsx +1 -1
- package/src/components/FallbackBoundary/index.tsx +13 -2
- package/src/components/HistoryList.tsx +15 -1
- package/src/components/IconInput.tsx +3 -0
- package/src/components/OverlayMenu.tsx +76 -20
- package/src/components/ProgressBar.tsx +23 -0
- package/src/components/QuickStartButton.tsx +3 -0
- package/src/components/RightPanelForm.tsx +15 -9
- package/src/components/RightPanelTabs.tsx +3 -0
- package/src/components/TabManager.tsx +8 -0
- package/src/components/Tooltip/Tooltip.tsx +47 -5
- package/src/components/Tooltip/TooltipAPI.ts +59 -42
- package/src/components/Tooltip/types.ts +13 -0
- package/src/components/form/DescribedCheckboxGroup.tsx +4 -0
- package/src/components/form/DescribedRadioGroup.tsx +4 -0
- package/src/components/form/types.ts +34 -0
- package/src/context/AIWidgetProvider.tsx +19 -0
- package/src/context/hooks.ts +56 -1
- package/src/features.ts +29 -0
- package/src/layout.css +5 -0
- package/src/regex.ts +1 -0
- package/src/right-panel/DefaultPanel.tsx +4 -0
- package/src/right-panel/RightPanel.tsx +3 -0
- package/src/right-panel/RightPanelProvider.tsx +15 -0
- package/src/right-panel/constants.ts +1 -0
- package/src/right-panel/hooks.tsx +8 -1
- package/src/state/ChatEntry.ts +60 -2
- package/src/state/ChatState.ts +74 -9
- package/src/state/ChatTabsController.ts +31 -0
- package/src/state/ObservableState.ts +14 -0
- package/src/state/WidgetState.ts +5 -0
- package/src/types.ts +10 -0
- package/src/utils/chat.ts +15 -1
- package/src/utils/date.ts +25 -1
- package/src/utils/download.ts +5 -0
- package/src/utils/knowledge-source.ts +16 -0
- package/src/utils/string.ts +5 -1
- package/src/utils/url.ts +8 -0
- package/src/views/Agents.tsx +3 -0
- package/src/views/Chat/AgentInfo.tsx +3 -0
- package/src/views/Chat/ChatMessage.tsx +31 -18
- package/src/views/Chat/ChatMessages.tsx +3 -0
- package/src/views/Chat/chat-scroll.ts +1 -1
- package/src/views/Chat/events.ts +69 -0
- package/src/views/Chat/index.tsx +6 -0
- package/src/views/ChatHistory/ChatHistoryPanel.tsx +6 -2
- package/src/views/ChatHistory/HistoryItem.tsx +14 -2
- package/src/views/ChatHistory/index.tsx +11 -1
- package/src/views/ChatHistory/utils.ts +14 -0
- package/src/views/ChatTabSelection.tsx +3 -0
- package/src/views/Editor.tsx +4 -0
- package/src/views/Home.tsx +8 -0
- package/src/views/KSDocument.tsx +3 -0
- package/src/views/KnowledgeSources.tsx +3 -0
- package/src/views/MessageInput/ButtonGroup.tsx +22 -0
- package/src/views/MessageInput/InfoBar.tsx +7 -0
- package/src/views/MessageInput/QuickCommandSelector.tsx +217 -0
- package/src/views/MessageInput/index.tsx +16 -4
- package/src/views/MessageInput/styled.ts +137 -0
- package/src/views/MinimizedHeader.tsx +4 -0
- package/src/views/Stacks.tsx +3 -0
- package/src/views/Workspaces.tsx +3 -0
|
@@ -41,7 +41,9 @@ interface Props<T, Key extends React.Key> {
|
|
|
41
41
|
renderLabel: (tab: T) => React.ReactElement,
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// The size of extra buttons placed after the tabs.
|
|
44
45
|
const EXTRA_BTN_SIZE = 24
|
|
46
|
+
// The margin of extra buttons placed after the tabs.
|
|
45
47
|
const EXTRA_BTN_MARGIN = 8
|
|
46
48
|
|
|
47
49
|
const Tabs = styled.nav<{ $numberOfExtraButtons: number }>`
|
|
@@ -161,6 +163,12 @@ const Tabs = styled.nav<{ $numberOfExtraButtons: number }>`
|
|
|
161
163
|
}
|
|
162
164
|
`
|
|
163
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Renders and manages a list of tabs. With this, tabs can be selected and removed. Furthermore, extra buttons can be placed after all tabs,
|
|
168
|
+
* e.g. a button to add more tabs.
|
|
169
|
+
*
|
|
170
|
+
* Used for the chat tabs.
|
|
171
|
+
*/
|
|
164
172
|
export function TabManager<T, Key extends React.Key>(
|
|
165
173
|
{ active, tabs, keygen, onRemove, onSelect, renderLabel, buttons = [] }: Props<T, Key>,
|
|
166
174
|
) {
|
|
@@ -1,36 +1,78 @@
|
|
|
1
|
+
/* eslint-disable react/display-name */
|
|
1
2
|
import { Text } from '@citric/core'
|
|
2
3
|
import { WithStyle } from '@stack-spot/portal-theme'
|
|
4
|
+
import { forwardRef } from 'react'
|
|
3
5
|
import { WithChildren } from '../../types'
|
|
4
6
|
import { useTooltip } from './context'
|
|
5
7
|
import { DefaultTooltip } from './style'
|
|
6
8
|
import { TooltipPosition } from './types'
|
|
7
9
|
|
|
8
10
|
interface Props extends WithChildren, WithStyle {
|
|
11
|
+
/**
|
|
12
|
+
* The content of the tooltip. Can be either a string or a Rect Element.
|
|
13
|
+
*/
|
|
9
14
|
content: React.ReactNode,
|
|
15
|
+
/**
|
|
16
|
+
* Where to position the tooltip relative to the element that triggered it.
|
|
17
|
+
*/
|
|
10
18
|
position?: TooltipPosition,
|
|
19
|
+
/**
|
|
20
|
+
* A tooltip can be triggered either by hovering an element or by clicking it.
|
|
21
|
+
* @default 'hover'
|
|
22
|
+
*/
|
|
11
23
|
triggeredBy?: 'click' | 'hover',
|
|
24
|
+
/**
|
|
25
|
+
* If true, no style is applied to the tooltip, letting you customize it however you want to.
|
|
26
|
+
*/
|
|
12
27
|
custom?: boolean,
|
|
28
|
+
/**
|
|
29
|
+
* Function to run whenever the tooltip is shown.
|
|
30
|
+
*/
|
|
31
|
+
onShow?: () => void,
|
|
32
|
+
/**
|
|
33
|
+
* Function to run whenever the tooltip is hidden.
|
|
34
|
+
*/
|
|
35
|
+
onHide?: () => void,
|
|
13
36
|
}
|
|
14
37
|
|
|
15
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Shows a tooltip for its children. This tooltip element is always reused and placed at a root level in order to not be cut out by
|
|
40
|
+
* hidden overflows in the children and its ascendants.
|
|
41
|
+
*/
|
|
42
|
+
export const Tooltip = forwardRef<HTMLDivElement, Props>((
|
|
43
|
+
{ content, custom, position, triggeredBy = 'hover', onHide, onShow, children, className, style },
|
|
44
|
+
ref,
|
|
45
|
+
) => {
|
|
16
46
|
const api = useTooltip()
|
|
17
47
|
|
|
18
|
-
function show(e: React.
|
|
19
|
-
api.show({
|
|
48
|
+
async function show(e: React.UIEvent, hideOnClickOutside?: boolean) {
|
|
49
|
+
await api.show({
|
|
20
50
|
content: custom ? content : <DefaultTooltip><Text appearance="microtext1">{content}</Text></DefaultTooltip>,
|
|
21
51
|
anchor: e.target as HTMLElement,
|
|
22
52
|
position,
|
|
23
53
|
hideOnClickOutside,
|
|
24
54
|
})
|
|
55
|
+
onShow?.()
|
|
25
56
|
}
|
|
57
|
+
|
|
58
|
+
function hide() {
|
|
59
|
+
api.hide()
|
|
60
|
+
onHide?.()
|
|
61
|
+
}
|
|
62
|
+
|
|
26
63
|
return (
|
|
27
64
|
<div
|
|
28
|
-
{...(triggeredBy === 'hover'
|
|
65
|
+
{...(triggeredBy === 'hover'
|
|
66
|
+
? { onMouseEnter: show, onMouseLeave: hide }
|
|
67
|
+
: { onClick: (e) => show(e, true), onKeyDown: (e) => e.key === 'Enter' && show(e, true) }
|
|
68
|
+
)}
|
|
29
69
|
className={className}
|
|
30
70
|
style={style}
|
|
31
71
|
tabIndex={triggeredBy === 'click' ? 0 : undefined}
|
|
72
|
+
role={triggeredBy === 'click' ? 'button' : undefined}
|
|
73
|
+
ref={ref}
|
|
32
74
|
>
|
|
33
75
|
{children}
|
|
34
76
|
</div>
|
|
35
77
|
)
|
|
36
|
-
}
|
|
78
|
+
})
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
+
import { delay } from '@stack-spot/portal-components'
|
|
1
2
|
import { animationTimeMS } from './style'
|
|
2
3
|
import { ShowOptions } from './types'
|
|
3
4
|
|
|
5
|
+
// the maximum amount of pixels a tooltip can get close to the screen edges.
|
|
4
6
|
const MARGIN_TO_CORNERS_PX = 10
|
|
5
7
|
|
|
6
8
|
function isRelative(element: HTMLElement) {
|
|
7
9
|
return ['relative', 'absolute', 'fixed'].includes(element.computedStyleMap().get('position')?.toString() ?? '')
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Allows interaction with the tooltip element.
|
|
14
|
+
*
|
|
15
|
+
* This places the tooltip element at the correct place, shows it, hides it and manages its contents.
|
|
16
|
+
*
|
|
17
|
+
* This also takes into account the screen edges, making adjustments to the tooltip position if it would overflow the screen.
|
|
18
|
+
*/
|
|
10
19
|
export class TooltipAPI {
|
|
11
|
-
|
|
20
|
+
/**
|
|
21
|
+
* A reference to the tooltip element in the HTML tree.
|
|
22
|
+
*/
|
|
23
|
+
tooltipRef: React.RefObject<HTMLDivElement>
|
|
12
24
|
private setContent: React.Dispatch<React.SetStateAction<React.ReactNode>>
|
|
13
25
|
private hideTimeoutId: number | undefined
|
|
14
26
|
private clickListener: ((e: MouseEvent) => void) | undefined
|
|
@@ -27,54 +39,59 @@ export class TooltipAPI {
|
|
|
27
39
|
}
|
|
28
40
|
}
|
|
29
41
|
|
|
30
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Shows the tooltip with `content`. Its position is based on `position` and the position of the element referred by `anchor`.
|
|
44
|
+
*/
|
|
45
|
+
async show({ content, anchor, position = 'bottom', hideOnClickOutside }: ShowOptions) {
|
|
31
46
|
window.clearTimeout(this.hideTimeoutId)
|
|
32
47
|
this.hideTimeoutId = undefined
|
|
33
48
|
if (this.clickListener) document.removeEventListener('click', this.clickListener)
|
|
34
49
|
this.setContent(content)
|
|
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
|
-
document.addEventListener('click', this.clickListener)
|
|
50
|
+
await delay(10)
|
|
51
|
+
if (!this.tooltipRef.current) return
|
|
52
|
+
const anchorRect = anchor.getClientRects()[0]
|
|
53
|
+
this.tooltipRef.current.classList.add('visible')
|
|
54
|
+
const tooltipWidth = this.tooltipRef.current.clientWidth
|
|
55
|
+
const tooltipHeight = this.tooltipRef.current.clientHeight
|
|
56
|
+
let top = 0
|
|
57
|
+
let left = 0
|
|
58
|
+
if (position === 'left' || position === 'right') {
|
|
59
|
+
top = anchorRect.top + anchorRect.height / 2 - tooltipHeight / 2
|
|
60
|
+
if (position === 'left') left = anchorRect.left - tooltipWidth
|
|
61
|
+
else left = anchorRect.left + anchorRect.width
|
|
62
|
+
} else {
|
|
63
|
+
left = anchorRect.left + anchorRect.width / 2 - tooltipWidth / 2
|
|
64
|
+
if (position === 'top') top = anchorRect.top - tooltipHeight
|
|
65
|
+
else top = anchorRect.top + anchorRect.height
|
|
66
|
+
}
|
|
67
|
+
// takes the parent the tooltip is positioned relative to into consideration
|
|
68
|
+
this.computeRelativeTo()
|
|
69
|
+
const relativeRect = this.relativeTo?.getClientRects()[0] ?? { top: 0, left: 0 }
|
|
70
|
+
top -= relativeRect.top
|
|
71
|
+
left -= relativeRect.left
|
|
72
|
+
// adjusts positions in order to avoid overflowing the window and leaving a margin to the corners
|
|
73
|
+
if (top <= 0) top += MARGIN_TO_CORNERS_PX
|
|
74
|
+
else if (top + tooltipHeight >= document.body.clientHeight - MARGIN_TO_CORNERS_PX) {
|
|
75
|
+
top = document.body.clientHeight - MARGIN_TO_CORNERS_PX + tooltipHeight
|
|
76
|
+
}
|
|
77
|
+
if (left <= 0) left += MARGIN_TO_CORNERS_PX
|
|
78
|
+
else if (left + tooltipWidth >= document.body.clientWidth - MARGIN_TO_CORNERS_PX) {
|
|
79
|
+
left = document.body.clientWidth - MARGIN_TO_CORNERS_PX - tooltipWidth
|
|
80
|
+
}
|
|
81
|
+
this.tooltipRef.current.style.top = `${top}px`
|
|
82
|
+
this.tooltipRef.current.style.left = `${left}px`
|
|
83
|
+
if (hideOnClickOutside) {
|
|
84
|
+
this.clickListener = (e: MouseEvent) => {
|
|
85
|
+
if (this.tooltipRef.current?.contains(e.target as HTMLElement)) return
|
|
86
|
+
this.hide()
|
|
74
87
|
}
|
|
75
|
-
|
|
88
|
+
document.addEventListener('click', this.clickListener)
|
|
89
|
+
}
|
|
76
90
|
}
|
|
77
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Hides the tooltip. After the animation, the content is removed.
|
|
94
|
+
*/
|
|
78
95
|
hide(): void {
|
|
79
96
|
if (!this.tooltipRef.current) return
|
|
80
97
|
this.tooltipRef.current.classList.remove('visible')
|
|
@@ -8,8 +8,21 @@ export interface BoxPosition {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface ShowOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The content of the tooltip. Can be either a string or a React Element.
|
|
13
|
+
*/
|
|
11
14
|
content: React.ReactNode,
|
|
15
|
+
/**
|
|
16
|
+
* The anchor to the tooltip. This is part of what defines the position where the tooltip will appear.
|
|
17
|
+
*/
|
|
12
18
|
anchor: HTMLElement,
|
|
19
|
+
/**
|
|
20
|
+
* The position relative to the element referred by `anchor`.
|
|
21
|
+
* @default bottom
|
|
22
|
+
*/
|
|
13
23
|
position?: TooltipPosition,
|
|
24
|
+
/**
|
|
25
|
+
* Whether or not to hide the tooltip when a click is detected outside of it.
|
|
26
|
+
*/
|
|
14
27
|
hideOnClickOutside?: boolean,
|
|
15
28
|
}
|
|
@@ -5,6 +5,10 @@ import { Accordion } from '../Accordion'
|
|
|
5
5
|
import { RadioCheckBox } from './styled'
|
|
6
6
|
import { CheckProps } from './types'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Renders a checkbox group where each option has a label and a description.
|
|
10
|
+
* The description in placed under the label and checkbox as an accordion.
|
|
11
|
+
*/
|
|
8
12
|
export function DescribedCheckboxGroup<T>(
|
|
9
13
|
{ keygen, onChange, options, renderDescription, renderLabel, optionClassName, optionStyle, value, className, style }: CheckProps<T>,
|
|
10
14
|
) {
|
|
@@ -5,6 +5,10 @@ import { Accordion } from '../Accordion'
|
|
|
5
5
|
import { RadioCheckBox } from './styled'
|
|
6
6
|
import { RadioProps } from './types'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Renders a radio button group where each option has a label and a description.
|
|
10
|
+
* The description in placed under the label and radio button as an accordion.
|
|
11
|
+
*/
|
|
8
12
|
export function DescribedRadioGroup<T>(
|
|
9
13
|
{ keygen, onChange, options, renderDescription, renderLabel, optionClassName, optionStyle, value, className, style }: RadioProps<T>,
|
|
10
14
|
) {
|
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
import { WithStyle } from '@stack-spot/portal-theme'
|
|
2
2
|
|
|
3
3
|
interface RadioCheckProps<T> extends WithStyle {
|
|
4
|
+
/**
|
|
5
|
+
* The options available.
|
|
6
|
+
*/
|
|
4
7
|
options: T[],
|
|
8
|
+
/**
|
|
9
|
+
* A function that renders an option as a label. This can either return a string or a React Element.
|
|
10
|
+
*/
|
|
5
11
|
renderLabel: (option: T) => React.ReactNode,
|
|
12
|
+
/**
|
|
13
|
+
* A function that renders an option as a description. This can either return a string or a React Element.
|
|
14
|
+
*/
|
|
6
15
|
renderDescription: (option: T) => React.ReactNode,
|
|
16
|
+
/**
|
|
17
|
+
* A function that gives a custom className to the rendered option.
|
|
18
|
+
*/
|
|
7
19
|
optionClassName?: (option: T) => string | undefined,
|
|
20
|
+
/**
|
|
21
|
+
* A function that gives a custom style to the rendered option.
|
|
22
|
+
*/
|
|
8
23
|
optionStyle?: (option: T) => React.CSSProperties | undefined,
|
|
24
|
+
/**
|
|
25
|
+
* A function that generates a unique id for the option.
|
|
26
|
+
*/
|
|
9
27
|
keygen: (option: T) => React.Key,
|
|
10
28
|
|
|
11
29
|
}
|
|
12
30
|
|
|
13
31
|
export interface RadioProps<T> extends RadioCheckProps<T> {
|
|
32
|
+
/**
|
|
33
|
+
* The current value of the radio group. This is one of the options.
|
|
34
|
+
*
|
|
35
|
+
* Comparisons use the same-value-zero algorithm (`===`).
|
|
36
|
+
*/
|
|
14
37
|
value: T | undefined,
|
|
38
|
+
/**
|
|
39
|
+
* A function to call whenever the value changes.
|
|
40
|
+
*/
|
|
15
41
|
onChange: (option: T) => void,
|
|
16
42
|
}
|
|
17
43
|
|
|
18
44
|
export interface CheckProps<T> extends RadioCheckProps<T> {
|
|
45
|
+
/**
|
|
46
|
+
* The current value of the checkbox group. This is sub-array of the array of options.
|
|
47
|
+
*
|
|
48
|
+
* Comparisons use the same-value-zero algorithm (`===`).
|
|
49
|
+
*/
|
|
19
50
|
value: T[],
|
|
51
|
+
/**
|
|
52
|
+
* A function to call whenever the value changes.
|
|
53
|
+
*/
|
|
20
54
|
onChange: (option: T[]) => void,
|
|
21
55
|
}
|
|
@@ -3,4 +3,23 @@ import { WidgetState } from '../state/WidgetState'
|
|
|
3
3
|
|
|
4
4
|
export const AIWidgetContext = createContext<WidgetState | undefined>(undefined)
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new context for the AI Chat Widget.
|
|
8
|
+
*
|
|
9
|
+
* This is not required, but makes it much easier to control the chat and is the only way to have multiple instances of the chat model in
|
|
10
|
+
* the same application.
|
|
11
|
+
*
|
|
12
|
+
* To control the chat widget in any component descendant from the `AIWidgetProvider`, you can call the hook `useWidget()`.
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
* ```
|
|
16
|
+
* const widget = useMemo(() => new WidgetState(), [])
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <AIWidgetProvider value={widget}>
|
|
20
|
+
* {children}
|
|
21
|
+
* </AIWidgetProvider>
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
6
25
|
export const AIWidgetProvider = AIWidgetContext.Provider
|
package/src/context/hooks.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
1
|
import { useContext, useEffect, useState } from 'react'
|
|
3
2
|
import { ChatEntry } from '../state/ChatEntry'
|
|
4
3
|
import { ChatProperties, ChatState, MessageInterceptor } from '../state/ChatState'
|
|
@@ -9,6 +8,9 @@ import { AIWidgetContext } from './AIWidgetProvider'
|
|
|
9
8
|
|
|
10
9
|
let globalWidgetState: WidgetState | undefined
|
|
11
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Returns the closest instance of a WidgetState (React Context). If no context is available, uses a global instance of the chat widget.
|
|
13
|
+
*/
|
|
12
14
|
export function useWidget(): WidgetState {
|
|
13
15
|
const fromContext = useContext(AIWidgetContext)
|
|
14
16
|
if (fromContext) return fromContext
|
|
@@ -25,11 +27,19 @@ function useObservableState<T, K extends keyof T>(state: ObservableState<T>, key
|
|
|
25
27
|
return value
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Watches one of the widget states.
|
|
32
|
+
* @param key the key watch changes for.
|
|
33
|
+
* @returns the value of the state referred by the key.
|
|
34
|
+
*/
|
|
28
35
|
export function useWidgetState<K extends keyof WidgetProperties>(key: K): WidgetProperties[K] {
|
|
29
36
|
const widget = useWidget()
|
|
30
37
|
return useObservableState(widget, key)
|
|
31
38
|
}
|
|
32
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Watches the tabs of a ChatState. The value is updated whenever a tab is added, removed or selected.
|
|
42
|
+
*/
|
|
33
43
|
export function useChatTabs(): { chats: ChatState[], active: string } {
|
|
34
44
|
const widget = useWidget()
|
|
35
45
|
const [tabs, setTabs] = useState<{ chats: ChatState[], active: string }>({
|
|
@@ -40,6 +50,13 @@ export function useChatTabs(): { chats: ChatState[], active: string } {
|
|
|
40
50
|
return tabs
|
|
41
51
|
}
|
|
42
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Gets a chat according to its identifier (conversation id).
|
|
55
|
+
*
|
|
56
|
+
* An error is thrown if the id doesn't correspond to any chat currently opened.
|
|
57
|
+
*
|
|
58
|
+
* @returns the chat state.
|
|
59
|
+
*/
|
|
43
60
|
export function useChat(chatId: string): ChatState {
|
|
44
61
|
const widget = useWidget()
|
|
45
62
|
const chat = widget.chatTabs.get(chatId)
|
|
@@ -47,21 +64,44 @@ export function useChat(chatId: string): ChatState {
|
|
|
47
64
|
return chat
|
|
48
65
|
}
|
|
49
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Watches the current chat (selected in the chat tabs.)
|
|
69
|
+
*
|
|
70
|
+
* The value changes whenever a new chat is selected.
|
|
71
|
+
*
|
|
72
|
+
* @returns the currently active chat.
|
|
73
|
+
*/
|
|
50
74
|
export function useCurrentChat(): ChatState {
|
|
51
75
|
const { active } = useChatTabs()
|
|
52
76
|
return useChat(active)
|
|
53
77
|
}
|
|
54
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Watches one of the chat states.
|
|
81
|
+
* @param chatId the id of chat to watch.
|
|
82
|
+
* @param key the key of the state to watch.
|
|
83
|
+
* @returns the value of the state referred by the key.
|
|
84
|
+
*/
|
|
55
85
|
export function useChatState<K extends keyof ChatProperties>(chatId: string, key: K): ChatProperties[K] {
|
|
56
86
|
const chat = useChat(chatId)
|
|
57
87
|
return useObservableState(chat, key)
|
|
58
88
|
}
|
|
59
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Watches one of the current chat states. This is the same as calling `useChatState` with the id of the current chat.
|
|
92
|
+
* @param key the key of the state to watch.
|
|
93
|
+
* @returns the value of the state referred by the key.
|
|
94
|
+
*/
|
|
60
95
|
export function useCurrentChatState<K extends keyof ChatProperties>(key: K): ChatProperties[K] {
|
|
61
96
|
const chat = useCurrentChat()
|
|
62
97
|
return useObservableState(chat, key)
|
|
63
98
|
}
|
|
64
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Watches a chat state for changes in the list of messages (chat entries).
|
|
102
|
+
* @param chatId the id of the chat to watch.
|
|
103
|
+
* @returns the list of messages in the chat.
|
|
104
|
+
*/
|
|
65
105
|
export function useChatMessages(chatId: string): ChatEntry[] {
|
|
66
106
|
const chat = useChat(chatId)
|
|
67
107
|
const [entries, setEntries] = useState(chat.getMessages())
|
|
@@ -72,17 +112,32 @@ export function useChatMessages(chatId: string): ChatEntry[] {
|
|
|
72
112
|
return entries
|
|
73
113
|
}
|
|
74
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Watches the chat state currently active for changes in the list of messages (chat entries). This is the same as calling `useChatMessages`
|
|
117
|
+
* with the id of the current chat.
|
|
118
|
+
* @returns the list of messages in the chat.
|
|
119
|
+
*/
|
|
75
120
|
export function useCurrentChatMessages(): ChatEntry[] {
|
|
76
121
|
const { active } = useChatTabs()
|
|
77
122
|
return useChatMessages(active)
|
|
78
123
|
}
|
|
79
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Watches a chat message (chat entry) for changes in its composition. This allows messages to be streamed: each part of the stream will
|
|
127
|
+
* change the current value of the entry.
|
|
128
|
+
* @param entry the message to watch.
|
|
129
|
+
* @returns the current value of the message.
|
|
130
|
+
*/
|
|
80
131
|
export function useChatEntry(entry: ChatEntry) {
|
|
81
132
|
const [content, setContent] = useState(entry.getValue())
|
|
82
133
|
useEffect(() => entry.onChange(setContent), [])
|
|
83
134
|
return content
|
|
84
135
|
}
|
|
85
136
|
|
|
137
|
+
/**
|
|
138
|
+
* This will create a new chat if none exists.
|
|
139
|
+
* @param interceptors the interceptors to add to the new chat.
|
|
140
|
+
*/
|
|
86
141
|
export function useFirstChat(interceptors: MessageInterceptor[]) {
|
|
87
142
|
const widget = useWidget()
|
|
88
143
|
const tabs = widget.chatTabs
|
package/src/features.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
export interface MessageInputFeatures {
|
|
2
|
+
/**
|
|
3
|
+
* Enables stack selection.
|
|
4
|
+
* @default true
|
|
5
|
+
*/
|
|
2
6
|
stack?: boolean,
|
|
7
|
+
/**
|
|
8
|
+
* Enables workspace selection.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
3
11
|
workspace?: boolean,
|
|
12
|
+
/**
|
|
13
|
+
* Enables knowledge source selection.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
4
16
|
knowledgeSource?: boolean,
|
|
17
|
+
/**
|
|
18
|
+
* Enables agent selection.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
5
21
|
agent?: boolean,
|
|
22
|
+
/**
|
|
23
|
+
* Enables quick commands.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
6
26
|
quickCommands?: boolean,
|
|
27
|
+
/**
|
|
28
|
+
* Enables the editor.
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
7
31
|
editor?: boolean,
|
|
8
32
|
}
|
|
9
33
|
|
|
10
34
|
export interface AIWidgetFeatures extends MessageInputFeatures {
|
|
35
|
+
/**
|
|
36
|
+
* Enables the chat history.
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
11
39
|
chatHistory?: boolean,
|
|
12
40
|
}
|
|
13
41
|
|
|
@@ -18,4 +46,5 @@ export const defaultFeatures: AIWidgetFeatures = {
|
|
|
18
46
|
agent: true,
|
|
19
47
|
chatHistory: true,
|
|
20
48
|
editor: true,
|
|
49
|
+
quickCommands: true,
|
|
21
50
|
}
|
package/src/layout.css
CHANGED
package/src/regex.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const quickCommandRegex = /^\/[\w\d-_]+$/
|
|
@@ -40,8 +40,12 @@ const PanelBox = styled.div`
|
|
|
40
40
|
}
|
|
41
41
|
`
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Default layout for a right panel.
|
|
45
|
+
*/
|
|
43
46
|
export const DefaultPanel = ({ description, onClose, title, children }: Props) => {
|
|
44
47
|
const t = useTranslate(dictionary)
|
|
48
|
+
|
|
45
49
|
return (
|
|
46
50
|
<PanelBox>
|
|
47
51
|
<header>
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { createContext, useMemo, useRef, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
interface ContextValue {
|
|
4
|
+
/**
|
|
5
|
+
* The current content of the right panel.
|
|
6
|
+
*/
|
|
4
7
|
content?: React.ReactNode,
|
|
8
|
+
/**
|
|
9
|
+
* Sets the current content of the right panel.
|
|
10
|
+
*/
|
|
5
11
|
setContent?: (content: React.ReactNode) => void,
|
|
12
|
+
/**
|
|
13
|
+
* A reference to the right panel HTML Element.
|
|
14
|
+
*/
|
|
6
15
|
panel?: React.RefObject<HTMLDivElement>,
|
|
16
|
+
/**
|
|
17
|
+
* A reference to the chat window at the left of the right panel.
|
|
18
|
+
*/
|
|
7
19
|
chatWindow?: React.RefObject<HTMLDivElement>,
|
|
20
|
+
/**
|
|
21
|
+
* A function to run when the right panel is closed for the next time.
|
|
22
|
+
*/
|
|
8
23
|
onCloseNext: React.MutableRefObject<(() => void) | undefined>,
|
|
9
24
|
}
|
|
10
25
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const panelAnimationTime = 300
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useContext, useMemo } from 'react'
|
|
2
2
|
import { DefaultPanel } from './DefaultPanel'
|
|
3
3
|
import { RightPanelContext } from './RightPanelProvider'
|
|
4
|
+
import { panelAnimationTime } from './constants'
|
|
4
5
|
|
|
5
6
|
interface RightPanelOptions {
|
|
6
7
|
title: React.ReactNode,
|
|
@@ -8,11 +9,17 @@ interface RightPanelOptions {
|
|
|
8
9
|
onClose?: () => void,
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @returns teh current content of the right panel
|
|
14
|
+
*/
|
|
11
15
|
export function useRightPanelContent() {
|
|
12
16
|
const { content } = useContext(RightPanelContext)
|
|
13
17
|
return content
|
|
14
18
|
}
|
|
15
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Opens, closes or checks the visibility of the right panel.
|
|
22
|
+
*/
|
|
16
23
|
export function useRightPanel() {
|
|
17
24
|
const ctx = useContext(RightPanelContext)
|
|
18
25
|
const { panel, chatWindow, setContent } = ctx
|
|
@@ -35,7 +42,7 @@ export function useRightPanel() {
|
|
|
35
42
|
ctx.onCloseNext.current?.()
|
|
36
43
|
setTimeout(() => {
|
|
37
44
|
setContent(null)
|
|
38
|
-
},
|
|
45
|
+
}, panelAnimationTime)
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
function isOpen() {
|