@stack-spot/ai-chat-widget 0.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/dist/StackspotAIWidget.d.ts +13 -0
- package/dist/StackspotAIWidget.d.ts.map +1 -0
- package/dist/StackspotAIWidget.js +32 -0
- package/dist/StackspotAIWidget.js.map +1 -0
- package/dist/chat-interceptors/quick-commands.d.ts +4 -0
- package/dist/chat-interceptors/quick-commands.d.ts.map +1 -0
- package/dist/chat-interceptors/quick-commands.js +11 -0
- package/dist/chat-interceptors/quick-commands.js.map +1 -0
- package/dist/chat-interceptors/send-message.d.ts +4 -0
- package/dist/chat-interceptors/send-message.d.ts.map +1 -0
- package/dist/chat-interceptors/send-message.js +36 -0
- package/dist/chat-interceptors/send-message.js.map +1 -0
- package/dist/components/Accordion.d.ts +10 -0
- package/dist/components/Accordion.d.ts.map +1 -0
- package/dist/components/Accordion.js +46 -0
- package/dist/components/Accordion.js.map +1 -0
- package/dist/components/AdaptiveTextArea.d.ts +10 -0
- package/dist/components/AdaptiveTextArea.d.ts.map +1 -0
- package/dist/components/AdaptiveTextArea.js +28 -0
- package/dist/components/AdaptiveTextArea.js.map +1 -0
- package/dist/components/Code.d.ts +19 -0
- package/dist/components/Code.d.ts.map +1 -0
- package/dist/components/Code.js +112 -0
- package/dist/components/Code.js.map +1 -0
- package/dist/components/Editor.d.ts +9 -0
- package/dist/components/Editor.d.ts.map +1 -0
- package/dist/components/Editor.js +2 -0
- package/dist/components/Editor.js.map +1 -0
- package/dist/components/FadingOverflow.d.ts +12 -0
- package/dist/components/FadingOverflow.d.ts.map +1 -0
- package/dist/components/FadingOverflow.js +216 -0
- package/dist/components/FadingOverflow.js.map +1 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.d.ts +30 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.js +38 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.js.map +1 -0
- package/dist/components/FallbackBoundary/Loading.d.ts +2 -0
- package/dist/components/FallbackBoundary/Loading.d.ts.map +1 -0
- package/dist/components/FallbackBoundary/Loading.js +12 -0
- package/dist/components/FallbackBoundary/Loading.js.map +1 -0
- package/dist/components/FallbackBoundary/index.d.ts +6 -0
- package/dist/components/FallbackBoundary/index.d.ts.map +1 -0
- package/dist/components/FallbackBoundary/index.js +9 -0
- package/dist/components/FallbackBoundary/index.js.map +1 -0
- package/dist/components/HistoryList.d.ts +13 -0
- package/dist/components/HistoryList.d.ts.map +1 -0
- package/dist/components/HistoryList.js +4 -0
- package/dist/components/HistoryList.js.map +1 -0
- package/dist/components/IconInput.d.ts +7 -0
- package/dist/components/IconInput.d.ts.map +1 -0
- package/dist/components/IconInput.js +58 -0
- package/dist/components/IconInput.js.map +1 -0
- package/dist/components/Markdown.d.ts +9 -0
- package/dist/components/Markdown.d.ts.map +1 -0
- package/dist/components/Markdown.js +17 -0
- package/dist/components/Markdown.js.map +1 -0
- package/dist/components/OverlayMenu.d.ts +9 -0
- package/dist/components/OverlayMenu.d.ts.map +1 -0
- package/dist/components/OverlayMenu.js +2 -0
- package/dist/components/OverlayMenu.js.map +1 -0
- package/dist/components/ProgressBar.d.ts +11 -0
- package/dist/components/ProgressBar.d.ts.map +1 -0
- package/dist/components/ProgressBar.js +126 -0
- package/dist/components/ProgressBar.js.map +1 -0
- package/dist/components/QuickStartButton.d.ts +8 -0
- package/dist/components/QuickStartButton.d.ts.map +1 -0
- package/dist/components/QuickStartButton.js +40 -0
- package/dist/components/QuickStartButton.js.map +1 -0
- package/dist/components/RightPanelForm.d.ts +5 -0
- package/dist/components/RightPanelForm.d.ts.map +1 -0
- package/dist/components/RightPanelForm.js +45 -0
- package/dist/components/RightPanelForm.js.map +1 -0
- package/dist/components/RightPanelTabs.d.ts +10 -0
- package/dist/components/RightPanelTabs.d.ts.map +1 -0
- package/dist/components/RightPanelTabs.js +20 -0
- package/dist/components/RightPanelTabs.js.map +1 -0
- package/dist/components/TabManager.d.ts +34 -0
- package/dist/components/TabManager.d.ts.map +1 -0
- package/dist/components/TabManager.js +158 -0
- package/dist/components/TabManager.js.map +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +11 -0
- package/dist/components/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/components/Tooltip/Tooltip.js +9 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -0
- package/dist/components/Tooltip/TooltipAPI.d.ts +10 -0
- package/dist/components/Tooltip/TooltipAPI.d.ts.map +1 -0
- package/dist/components/Tooltip/TooltipAPI.js +48 -0
- package/dist/components/Tooltip/TooltipAPI.js.map +1 -0
- package/dist/components/Tooltip/context.d.ts +5 -0
- package/dist/components/Tooltip/context.d.ts.map +1 -0
- package/dist/components/Tooltip/context.js +18 -0
- package/dist/components/Tooltip/context.js.map +1 -0
- package/dist/components/Tooltip/index.d.ts +3 -0
- package/dist/components/Tooltip/index.d.ts.map +1 -0
- package/dist/components/Tooltip/index.js +3 -0
- package/dist/components/Tooltip/index.js.map +1 -0
- package/dist/components/Tooltip/style.d.ts +4 -0
- package/dist/components/Tooltip/style.d.ts.map +1 -0
- package/dist/components/Tooltip/style.js +23 -0
- package/dist/components/Tooltip/style.js.map +1 -0
- package/dist/components/Tooltip/types.d.ts +8 -0
- package/dist/components/Tooltip/types.d.ts.map +1 -0
- package/dist/components/Tooltip/types.js +2 -0
- package/dist/components/Tooltip/types.js.map +1 -0
- package/dist/components/form/DescribedCheckboxGroup.d.ts +3 -0
- package/dist/components/form/DescribedCheckboxGroup.d.ts.map +1 -0
- package/dist/components/form/DescribedCheckboxGroup.js +23 -0
- package/dist/components/form/DescribedCheckboxGroup.js.map +1 -0
- package/dist/components/form/DescribedRadioGroup.d.ts +3 -0
- package/dist/components/form/DescribedRadioGroup.d.ts.map +1 -0
- package/dist/components/form/DescribedRadioGroup.js +18 -0
- package/dist/components/form/DescribedRadioGroup.js.map +1 -0
- package/dist/components/form/styled.d.ts +2 -0
- package/dist/components/form/styled.d.ts.map +1 -0
- package/dist/components/form/styled.js +41 -0
- package/dist/components/form/styled.js.map +1 -0
- package/dist/components/form/types.d.ts +19 -0
- package/dist/components/form/types.d.ts.map +1 -0
- package/dist/components/form/types.js +2 -0
- package/dist/components/form/types.js.map +1 -0
- package/dist/context/AIWidgetProvider.d.ts +4 -0
- package/dist/context/AIWidgetProvider.d.ts.map +1 -0
- package/dist/context/AIWidgetProvider.js +4 -0
- package/dist/context/AIWidgetProvider.js.map +1 -0
- package/dist/context/hooks.d.ts +18 -0
- package/dist/context/hooks.d.ts.map +1 -0
- package/dist/context/hooks.js +82 -0
- package/dist/context/hooks.js.map +1 -0
- package/dist/features.d.ts +13 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +6 -0
- package/dist/features.js.map +1 -0
- package/dist/hooks/chat-scroll.d.ts +7 -0
- package/dist/hooks/chat-scroll.d.ts.map +1 -0
- package/dist/hooks/chat-scroll.js +15 -0
- package/dist/hooks/chat-scroll.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.css +119 -0
- package/dist/right-panel/DefaultPanel.d.ts +9 -0
- package/dist/right-panel/DefaultPanel.d.ts.map +1 -0
- package/dist/right-panel/DefaultPanel.js +46 -0
- package/dist/right-panel/DefaultPanel.js.map +1 -0
- package/dist/right-panel/RightPanel.d.ts +2 -0
- package/dist/right-panel/RightPanel.d.ts.map +1 -0
- package/dist/right-panel/RightPanel.js +6 -0
- package/dist/right-panel/RightPanel.js.map +1 -0
- package/dist/right-panel/RightPanelProvider.d.ts +13 -0
- package/dist/right-panel/RightPanelProvider.d.ts.map +1 -0
- package/dist/right-panel/RightPanelProvider.js +10 -0
- package/dist/right-panel/RightPanelProvider.js.map +1 -0
- package/dist/right-panel/hooks.d.ts +13 -0
- package/dist/right-panel/hooks.d.ts.map +1 -0
- package/dist/right-panel/hooks.js +39 -0
- package/dist/right-panel/hooks.js.map +1 -0
- package/dist/state/ChatEntry.d.ts +48 -0
- package/dist/state/ChatEntry.d.ts.map +1 -0
- package/dist/state/ChatEntry.js +55 -0
- package/dist/state/ChatEntry.js.map +1 -0
- package/dist/state/ChatState.d.ts +46 -0
- package/dist/state/ChatState.d.ts.map +1 -0
- package/dist/state/ChatState.js +53 -0
- package/dist/state/ChatState.js.map +1 -0
- package/dist/state/ChatTabsController.d.ts +17 -0
- package/dist/state/ChatTabsController.d.ts.map +1 -0
- package/dist/state/ChatTabsController.js +47 -0
- package/dist/state/ChatTabsController.js.map +1 -0
- package/dist/state/ObservableState.d.ts +10 -0
- package/dist/state/ObservableState.d.ts.map +1 -0
- package/dist/state/ObservableState.js +25 -0
- package/dist/state/ObservableState.js.map +1 -0
- package/dist/state/WidgetState.d.ts +19 -0
- package/dist/state/WidgetState.d.ts.map +1 -0
- package/dist/state/WidgetState.js +29 -0
- package/dist/state/WidgetState.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/chat.d.ts +6 -0
- package/dist/utils/chat.d.ts.map +1 -0
- package/dist/utils/chat.js +26 -0
- package/dist/utils/chat.js.map +1 -0
- package/dist/utils/date.d.ts +6 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +38 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/views/Agents.d.ts +2 -0
- package/dist/views/Agents.d.ts.map +1 -0
- package/dist/views/Agents.js +2 -0
- package/dist/views/Agents.js.map +1 -0
- package/dist/views/Chat/AgentInfo.d.ts +6 -0
- package/dist/views/Chat/AgentInfo.d.ts.map +1 -0
- package/dist/views/Chat/AgentInfo.js +7 -0
- package/dist/views/Chat/AgentInfo.js.map +1 -0
- package/dist/views/Chat/ChatMessage.d.ts +6 -0
- package/dist/views/Chat/ChatMessage.d.ts.map +1 -0
- package/dist/views/Chat/ChatMessage.js +61 -0
- package/dist/views/Chat/ChatMessage.js.map +1 -0
- package/dist/views/Chat/ChatMessages.d.ts +7 -0
- package/dist/views/Chat/ChatMessages.d.ts.map +1 -0
- package/dist/views/Chat/ChatMessages.js +12 -0
- package/dist/views/Chat/ChatMessages.js.map +1 -0
- package/dist/views/Chat/index.d.ts +6 -0
- package/dist/views/Chat/index.d.ts.map +1 -0
- package/dist/views/Chat/index.js +8 -0
- package/dist/views/Chat/index.js.map +1 -0
- package/dist/views/Chat/styled.d.ts +2 -0
- package/dist/views/Chat/styled.d.ts.map +1 -0
- package/dist/views/Chat/styled.js +116 -0
- package/dist/views/Chat/styled.js.map +1 -0
- package/dist/views/ChatTabSelection.d.ts +8 -0
- package/dist/views/ChatTabSelection.d.ts.map +1 -0
- package/dist/views/ChatTabSelection.js +45 -0
- package/dist/views/ChatTabSelection.js.map +1 -0
- package/dist/views/Editor.d.ts +2 -0
- package/dist/views/Editor.d.ts.map +1 -0
- package/dist/views/Editor.js +2 -0
- package/dist/views/Editor.js.map +1 -0
- package/dist/views/Home.d.ts +6 -0
- package/dist/views/Home.d.ts.map +1 -0
- package/dist/views/Home.js +68 -0
- package/dist/views/Home.js.map +1 -0
- package/dist/views/KnowledgeSources.d.ts +2 -0
- package/dist/views/KnowledgeSources.d.ts.map +1 -0
- package/dist/views/KnowledgeSources.js +82 -0
- package/dist/views/KnowledgeSources.js.map +1 -0
- package/dist/views/MessageInput/ButtonGroup.d.ts +12 -0
- package/dist/views/MessageInput/ButtonGroup.d.ts.map +1 -0
- package/dist/views/MessageInput/ButtonGroup.js +22 -0
- package/dist/views/MessageInput/ButtonGroup.js.map +1 -0
- package/dist/views/MessageInput/InfoBar.d.ts +2 -0
- package/dist/views/MessageInput/InfoBar.d.ts.map +1 -0
- package/dist/views/MessageInput/InfoBar.js +28 -0
- package/dist/views/MessageInput/InfoBar.js.map +1 -0
- package/dist/views/MessageInput/dictionary.d.ts +2 -0
- package/dist/views/MessageInput/dictionary.d.ts.map +1 -0
- package/dist/views/MessageInput/dictionary.js +35 -0
- package/dist/views/MessageInput/dictionary.js.map +1 -0
- package/dist/views/MessageInput/index.d.ts +7 -0
- package/dist/views/MessageInput/index.d.ts.map +1 -0
- package/dist/views/MessageInput/index.js +43 -0
- package/dist/views/MessageInput/index.js.map +1 -0
- package/dist/views/MessageInput/styled.d.ts +2 -0
- package/dist/views/MessageInput/styled.d.ts.map +1 -0
- package/dist/views/MessageInput/styled.js +195 -0
- package/dist/views/MessageInput/styled.js.map +1 -0
- package/dist/views/MinimizedHeader.d.ts +3 -0
- package/dist/views/MinimizedHeader.d.ts.map +1 -0
- package/dist/views/MinimizedHeader.js +76 -0
- package/dist/views/MinimizedHeader.js.map +1 -0
- package/dist/views/Stacks.d.ts +2 -0
- package/dist/views/Stacks.d.ts.map +1 -0
- package/dist/views/Stacks.js +73 -0
- package/dist/views/Stacks.js.map +1 -0
- package/dist/views/Workspaces.d.ts +2 -0
- package/dist/views/Workspaces.d.ts.map +1 -0
- package/dist/views/Workspaces.js +59 -0
- package/dist/views/Workspaces.js.map +1 -0
- package/package.json +52 -0
- package/src/StackspotAIWidget.tsx +65 -0
- package/src/chat-interceptors/quick-commands.ts +12 -0
- package/src/chat-interceptors/send-message.ts +35 -0
- package/src/components/Accordion.tsx +64 -0
- package/src/components/AdaptiveTextArea.tsx +34 -0
- package/src/components/Code.tsx +201 -0
- package/src/components/Editor.tsx +12 -0
- package/src/components/FadingOverflow.tsx +234 -0
- package/src/components/FallbackBoundary/ErrorBoundary.tsx +48 -0
- package/src/components/FallbackBoundary/Loading.tsx +14 -0
- package/src/components/FallbackBoundary/index.tsx +15 -0
- package/src/components/HistoryList.tsx +16 -0
- package/src/components/IconInput.tsx +70 -0
- package/src/components/Markdown.tsx +53 -0
- package/src/components/OverlayMenu.tsx +10 -0
- package/src/components/ProgressBar.tsx +153 -0
- package/src/components/QuickStartButton.tsx +51 -0
- package/src/components/RightPanelForm.tsx +55 -0
- package/src/components/RightPanelTabs.tsx +39 -0
- package/src/components/TabManager.tsx +223 -0
- package/src/components/Tooltip/Tooltip.tsx +30 -0
- package/src/components/Tooltip/TooltipAPI.ts +46 -0
- package/src/components/Tooltip/context.tsx +24 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/components/Tooltip/style.tsx +25 -0
- package/src/components/Tooltip/types.ts +8 -0
- package/src/components/form/DescribedCheckboxGroup.tsx +39 -0
- package/src/components/form/DescribedRadioGroup.tsx +33 -0
- package/src/components/form/styled.ts +41 -0
- package/src/components/form/types.ts +21 -0
- package/src/context/AIWidgetProvider.tsx +6 -0
- package/src/context/hooks.ts +93 -0
- package/src/features.ts +18 -0
- package/src/hooks/chat-scroll.ts +14 -0
- package/src/index.ts +8 -0
- package/src/layout.css +119 -0
- package/src/right-panel/DefaultPanel.tsx +67 -0
- package/src/right-panel/RightPanel.tsx +6 -0
- package/src/right-panel/RightPanelProvider.tsx +20 -0
- package/src/right-panel/hooks.tsx +47 -0
- package/src/state/ChatEntry.ts +95 -0
- package/src/state/ChatState.ts +85 -0
- package/src/state/ChatTabsController.ts +55 -0
- package/src/state/ObservableState.ts +35 -0
- package/src/state/WidgetState.ts +42 -0
- package/src/types.ts +20 -0
- package/src/utils/chat.ts +30 -0
- package/src/utils/date.ts +40 -0
- package/src/views/Agents.tsx +1 -0
- package/src/views/Chat/AgentInfo.tsx +17 -0
- package/src/views/Chat/ChatMessage.tsx +89 -0
- package/src/views/Chat/ChatMessages.tsx +16 -0
- package/src/views/Chat/index.tsx +11 -0
- package/src/views/Chat/styled.ts +116 -0
- package/src/views/ChatTabSelection.tsx +65 -0
- package/src/views/Editor.tsx +1 -0
- package/src/views/Home.tsx +109 -0
- package/src/views/KnowledgeSources.tsx +115 -0
- package/src/views/MessageInput/ButtonGroup.tsx +84 -0
- package/src/views/MessageInput/InfoBar.tsx +69 -0
- package/src/views/MessageInput/dictionary.ts +36 -0
- package/src/views/MessageInput/index.tsx +79 -0
- package/src/views/MessageInput/styled.ts +196 -0
- package/src/views/MinimizedHeader.tsx +94 -0
- package/src/views/Stacks.tsx +104 -0
- package/src/views/Workspaces.tsx +88 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Card } from '@citric/ui'
|
|
2
|
+
import { styled } from 'styled-components'
|
|
3
|
+
import { PropsOf } from '../types'
|
|
4
|
+
import { FallbackBoundary } from './FallbackBoundary'
|
|
5
|
+
|
|
6
|
+
const Form = styled.form`
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
flex: 1;
|
|
12
|
+
gap: 20px;
|
|
13
|
+
|
|
14
|
+
> .content {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 8px;
|
|
18
|
+
flex: 1;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
> button {
|
|
23
|
+
margin-right: auto;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.search {
|
|
27
|
+
margin-bottom: 8px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.option-list {
|
|
31
|
+
overflow: auto;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
li.filtered-out {
|
|
35
|
+
opacity: 0.5;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
${Card} svg {
|
|
39
|
+
fill: transparent;
|
|
40
|
+
}
|
|
41
|
+
`
|
|
42
|
+
|
|
43
|
+
export const RightPanelForm = ({ children, onSubmit, ...props }: PropsOf<typeof Form>) => (
|
|
44
|
+
<FallbackBoundary>
|
|
45
|
+
<Form
|
|
46
|
+
{...props}
|
|
47
|
+
onSubmit={(e) => {
|
|
48
|
+
e.preventDefault()
|
|
49
|
+
onSubmit?.(e)
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
</Form>
|
|
54
|
+
</FallbackBoundary>
|
|
55
|
+
)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Tabs, TabsItem } from '@citric/ui'
|
|
2
|
+
import { useMemo, useState } from 'react'
|
|
3
|
+
import styled from 'styled-components'
|
|
4
|
+
import { RightPanelForm } from './RightPanelForm'
|
|
5
|
+
|
|
6
|
+
interface Tab {
|
|
7
|
+
title: string,
|
|
8
|
+
content: React.ReactNode,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
tabs: Tab[],
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const StyledTabs = styled(Tabs)`
|
|
16
|
+
> button {
|
|
17
|
+
flex: 1;
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
const StyledTabsItem = styled(TabsItem)`
|
|
22
|
+
flex: 1;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
export const RightPanelTabs = ({ tabs }: Props) => {
|
|
27
|
+
const [currentTab, setCurrentTab] = useState(0)
|
|
28
|
+
const tabItems = useMemo(() => tabs.map(({ content, title }) => (
|
|
29
|
+
<StyledTabsItem key={title} title={title}>
|
|
30
|
+
<RightPanelForm>{content}</RightPanelForm>
|
|
31
|
+
</StyledTabsItem>
|
|
32
|
+
)), [tabs])
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<StyledTabs activeIndex={currentTab} onChange={setCurrentTab}>
|
|
36
|
+
{tabItems}
|
|
37
|
+
</StyledTabs>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/* Tabs to select chat and add new chats */
|
|
2
|
+
|
|
3
|
+
import { TimesMini } from '@citric/icons'
|
|
4
|
+
import { IconButton } from '@citric/ui'
|
|
5
|
+
import { listToClass, theme } from '@stack-spot/portal-theme'
|
|
6
|
+
import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
|
|
7
|
+
import { last } from 'lodash'
|
|
8
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react'
|
|
9
|
+
import { styled } from 'styled-components'
|
|
10
|
+
import { ButtonAction } from '../types'
|
|
11
|
+
import { FadingOverflow } from './FadingOverflow'
|
|
12
|
+
|
|
13
|
+
interface Props<T, Key extends React.Key> {
|
|
14
|
+
/**
|
|
15
|
+
* The list of tabs.
|
|
16
|
+
*/
|
|
17
|
+
tabs: T[],
|
|
18
|
+
/**
|
|
19
|
+
* Function to generate a unique id for a tab.
|
|
20
|
+
*/
|
|
21
|
+
keygen: (tab: T) => Key,
|
|
22
|
+
/**
|
|
23
|
+
* The key corresponding to the tab currently active.
|
|
24
|
+
*/
|
|
25
|
+
active: Key,
|
|
26
|
+
/**
|
|
27
|
+
* Function to call once a tab is selected.
|
|
28
|
+
*/
|
|
29
|
+
onSelect: (tab: T) => void,
|
|
30
|
+
/**
|
|
31
|
+
* Function to run once a tab is closed.
|
|
32
|
+
*/
|
|
33
|
+
onRemove: (tab: T) => void,
|
|
34
|
+
/**
|
|
35
|
+
* Extra buttons that goes in the far-end of the tab manager.
|
|
36
|
+
*/
|
|
37
|
+
buttons?: ButtonAction[],
|
|
38
|
+
/**
|
|
39
|
+
* Function to render the label inside the tab.
|
|
40
|
+
*/
|
|
41
|
+
renderLabel: (tab: T) => React.ReactElement,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const EXTRA_BTN_SIZE = 24
|
|
45
|
+
const EXTRA_BTN_MARGIN = 8
|
|
46
|
+
|
|
47
|
+
const Tabs = styled.nav<{ $numberOfExtraButtons: number }>`
|
|
48
|
+
width: 100%;
|
|
49
|
+
background-color: ${theme.color.light[400]};
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: row;
|
|
52
|
+
align-items: center;
|
|
53
|
+
border-bottom: 1px solid ${theme.color.light[500]};
|
|
54
|
+
|
|
55
|
+
button {
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
|
|
58
|
+
&.extra {
|
|
59
|
+
padding: 0;
|
|
60
|
+
transition: background-color 0.3s;
|
|
61
|
+
width: ${EXTRA_BTN_SIZE}px;
|
|
62
|
+
height: ${EXTRA_BTN_SIZE}px;
|
|
63
|
+
margin: 0 ${EXTRA_BTN_MARGIN}px;
|
|
64
|
+
|
|
65
|
+
&:hover {
|
|
66
|
+
background-color: ${theme.color.light[500]};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
${IconButton} {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
background-color: transparent;
|
|
76
|
+
border: none;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.list-overflow {
|
|
80
|
+
max-width: ${({ $numberOfExtraButtons }) => `calc(100% - ${$numberOfExtraButtons * (EXTRA_BTN_SIZE + EXTRA_BTN_MARGIN * 2)}px)`};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
ul {
|
|
84
|
+
padding: 0;
|
|
85
|
+
margin: 0;
|
|
86
|
+
list-style: none;
|
|
87
|
+
display: flex;
|
|
88
|
+
flex-direction: row;
|
|
89
|
+
|
|
90
|
+
&::-webkit-scrollbar {
|
|
91
|
+
width: 2px;
|
|
92
|
+
height: 2px;
|
|
93
|
+
opacity: 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
li {
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
overflow-x: clip;
|
|
99
|
+
white-space: nowrap;
|
|
100
|
+
height: 39px;
|
|
101
|
+
padding: 0 12px;
|
|
102
|
+
display: flex;
|
|
103
|
+
flex-direction: row;
|
|
104
|
+
align-items: center;
|
|
105
|
+
gap: 8px;
|
|
106
|
+
border-top: 1px solid transparent;
|
|
107
|
+
border-right: 1px solid ${theme.color.light[500]};
|
|
108
|
+
background-color: ${theme.color.light[400]};
|
|
109
|
+
transition: background-color 0.3s, border-color 0.3s;
|
|
110
|
+
|
|
111
|
+
&.active, &:hover {
|
|
112
|
+
button {
|
|
113
|
+
opacity: 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
&:hover {
|
|
118
|
+
background-color: ${theme.color.light[500]};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
&.active {
|
|
122
|
+
background-color: ${theme.color.light[500]};
|
|
123
|
+
border-top-color: ${theme.color.secondary[400]};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
button {
|
|
127
|
+
opacity: 0.7;
|
|
128
|
+
transition: opacity 0.3s;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
button.label {
|
|
132
|
+
max-width: 100px;
|
|
133
|
+
overflow: hidden;
|
|
134
|
+
text-overflow: clip;
|
|
135
|
+
background-color: transparent;
|
|
136
|
+
border: none;
|
|
137
|
+
padding: 0;
|
|
138
|
+
color: inherit;
|
|
139
|
+
position: relative;
|
|
140
|
+
|
|
141
|
+
&.overflow {
|
|
142
|
+
mask-image: linear-gradient(to right, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 1) 70%, rgba(0, 0, 0, 0) 100%);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
${IconButton} {
|
|
147
|
+
padding: 0;
|
|
148
|
+
width: 18px;
|
|
149
|
+
height: 18px;
|
|
150
|
+
transition: background-color 0.3s;
|
|
151
|
+
|
|
152
|
+
svg {
|
|
153
|
+
height: 14px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
&:hover {
|
|
157
|
+
background-color: ${theme.color.light[600]};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
`
|
|
163
|
+
|
|
164
|
+
export function TabManager<T, Key extends React.Key>(
|
|
165
|
+
{ active, tabs, keygen, onRemove, onSelect, renderLabel, buttons = [] }: Props<T, Key>,
|
|
166
|
+
) {
|
|
167
|
+
const t = useTranslate(dictionary)
|
|
168
|
+
const tabList = useRef<HTMLUListElement>(null)
|
|
169
|
+
const lastNumberOfTabs = useRef(tabs.length)
|
|
170
|
+
|
|
171
|
+
const onClickTab = useCallback((event: React.MouseEvent<HTMLElement, MouseEvent>) => {
|
|
172
|
+
const target = event.target as HTMLElement
|
|
173
|
+
if (target.tagName === 'LI') target.querySelector('button')?.click()
|
|
174
|
+
}, [])
|
|
175
|
+
|
|
176
|
+
const tabItems = useMemo(() => tabs.map((tab) => (
|
|
177
|
+
<li key={keygen(tab)} className={keygen(tab) === active ? 'active' : undefined} onClick={onClickTab}>
|
|
178
|
+
<button className="label" onClick={() => onSelect(tab)}><FadingOverflow>{renderLabel(tab)}</FadingOverflow></button>
|
|
179
|
+
{tabs.length > 1 && <IconButton aria-label={t.close} title={t.close} onClick={() => onRemove(tab)}><TimesMini /></IconButton>}
|
|
180
|
+
</li>
|
|
181
|
+
)), [tabs, active])
|
|
182
|
+
|
|
183
|
+
const extras = useMemo(() => buttons.map(({ label, onClick, icon, className, style }) => (
|
|
184
|
+
<IconButton
|
|
185
|
+
key={label}
|
|
186
|
+
aria-label={label}
|
|
187
|
+
title={label}
|
|
188
|
+
className={listToClass([className, 'extra'])}
|
|
189
|
+
style={style}
|
|
190
|
+
onClick={onClick}
|
|
191
|
+
>
|
|
192
|
+
{icon}
|
|
193
|
+
</IconButton>
|
|
194
|
+
)), [buttons])
|
|
195
|
+
|
|
196
|
+
// when a new tab is added, we should scroll to it if there are more tabs that we can show.
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
if (tabs.length > lastNumberOfTabs.current) {
|
|
199
|
+
const items = tabList.current?.children ?? []
|
|
200
|
+
last(items)?.scrollIntoView({ behavior: 'smooth' })
|
|
201
|
+
}
|
|
202
|
+
lastNumberOfTabs.current = tabs.length
|
|
203
|
+
}, [tabs])
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<Tabs $numberOfExtraButtons={buttons.length}>
|
|
207
|
+
<FadingOverflow className="list-overflow" scroll="arrows" enableHorizontalScrollWithVerticalWheel>
|
|
208
|
+
<ul ref={tabList}>{tabItems}</ul>
|
|
209
|
+
</FadingOverflow>
|
|
210
|
+
{extras}
|
|
211
|
+
</Tabs>
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const dictionary = {
|
|
216
|
+
en: {
|
|
217
|
+
close: 'Close',
|
|
218
|
+
},
|
|
219
|
+
pt: {
|
|
220
|
+
close: 'Fechar',
|
|
221
|
+
},
|
|
222
|
+
} satisfies Dictionary
|
|
223
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Text } from '@citric/core'
|
|
2
|
+
import { WithStyle } from '@stack-spot/portal-theme'
|
|
3
|
+
import { WithChildren } from '../../types'
|
|
4
|
+
import { useTooltip } from './context'
|
|
5
|
+
import { DefaultTooltip } from './style'
|
|
6
|
+
import { TooltipPosition } from './types'
|
|
7
|
+
|
|
8
|
+
interface Props extends WithChildren, WithStyle {
|
|
9
|
+
content: React.ReactNode,
|
|
10
|
+
position?: TooltipPosition,
|
|
11
|
+
custom?: boolean,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Tooltip = ({ content, custom, position = 'bottom', children, className, style }: Props) => {
|
|
15
|
+
const api = useTooltip()
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
onMouseEnter={e => api.show(
|
|
19
|
+
custom ? content : <DefaultTooltip><Text appearance="microtext1">{content}</Text></DefaultTooltip>,
|
|
20
|
+
e.target as HTMLElement,
|
|
21
|
+
position,
|
|
22
|
+
)}
|
|
23
|
+
onMouseLeave={() => api.hide()}
|
|
24
|
+
className={className}
|
|
25
|
+
style={style}
|
|
26
|
+
>
|
|
27
|
+
{children}
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { animationTimeMS } from './style'
|
|
2
|
+
import { TooltipPosition } from './types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class TooltipAPI {
|
|
6
|
+
private tooltipRef: React.RefObject<HTMLDivElement>
|
|
7
|
+
private setContent: React.Dispatch<React.SetStateAction<React.ReactNode>>
|
|
8
|
+
private hideTimeoutId: number | undefined
|
|
9
|
+
|
|
10
|
+
constructor(tooltipRef: React.RefObject<HTMLDivElement>, setContent: React.Dispatch<React.SetStateAction<React.ReactNode>>) {
|
|
11
|
+
this.tooltipRef = tooltipRef
|
|
12
|
+
this.setContent = setContent
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
show(content: React.ReactNode, anchor: HTMLElement, position: TooltipPosition): void {
|
|
16
|
+
window.clearTimeout(this.hideTimeoutId)
|
|
17
|
+
this.hideTimeoutId = undefined
|
|
18
|
+
this.setContent(content)
|
|
19
|
+
setTimeout(() => {
|
|
20
|
+
if (!this.tooltipRef.current) return
|
|
21
|
+
const rect = anchor.getClientRects()[0]
|
|
22
|
+
this.tooltipRef.current.classList.add('visible')
|
|
23
|
+
const tooltipWidth = this.tooltipRef.current.clientWidth
|
|
24
|
+
const tooltipHeight = this.tooltipRef.current.clientHeight
|
|
25
|
+
let top = 0
|
|
26
|
+
let left = 0
|
|
27
|
+
if (position === 'left' || position === 'right') {
|
|
28
|
+
top = rect.top + rect.height / 2 - tooltipHeight / 2
|
|
29
|
+
if (position === 'left') left = rect.left - tooltipWidth
|
|
30
|
+
else left = rect.left + rect.width
|
|
31
|
+
} else {
|
|
32
|
+
left = rect.left + rect.width / 2 - tooltipWidth / 2
|
|
33
|
+
if (position === 'top') top = rect.top - tooltipHeight
|
|
34
|
+
else top = rect.top + rect.height
|
|
35
|
+
}
|
|
36
|
+
this.tooltipRef.current.style.top = `${top}px`
|
|
37
|
+
this.tooltipRef.current.style.left = `${left}px`
|
|
38
|
+
}, 10)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
hide(): void {
|
|
42
|
+
if (!this.tooltipRef.current) return
|
|
43
|
+
this.tooltipRef.current.classList.remove('visible')
|
|
44
|
+
this.hideTimeoutId = window.setTimeout(() => this.setContent(undefined), animationTimeMS)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import { WithChildren } from '../../types'
|
|
3
|
+
import { TooltipBox } from './style'
|
|
4
|
+
import { TooltipAPI } from './TooltipAPI'
|
|
5
|
+
|
|
6
|
+
const Context = createContext<TooltipAPI | undefined>(undefined)
|
|
7
|
+
|
|
8
|
+
export const TooltipProvider = ({ children }: Required<WithChildren>) => {
|
|
9
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
10
|
+
const [content, setContent] = useState<React.ReactNode>()
|
|
11
|
+
const api = useMemo(() => new TooltipAPI(ref, setContent), [])
|
|
12
|
+
return (
|
|
13
|
+
<Context.Provider value={api}>
|
|
14
|
+
{children}
|
|
15
|
+
<TooltipBox ref={ref} aria-hidden>{content}</TooltipBox>
|
|
16
|
+
</Context.Provider>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useTooltip() {
|
|
21
|
+
const api = useContext(Context)
|
|
22
|
+
if (!api) throw new Error('In order to use tooltips, you must wrap your content in a <TooltipProvider>.')
|
|
23
|
+
return api
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { theme } from '@stack-spot/portal-theme'
|
|
2
|
+
import { styled } from 'styled-components'
|
|
3
|
+
|
|
4
|
+
export const animationTimeMS = 300
|
|
5
|
+
|
|
6
|
+
export const TooltipBox = styled.div`
|
|
7
|
+
position: absolute;
|
|
8
|
+
pointer-events: none;
|
|
9
|
+
opacity: 0;
|
|
10
|
+
transition: opacity ${animationTimeMS/ 1000}s;
|
|
11
|
+
top: 0;
|
|
12
|
+
left: 0;
|
|
13
|
+
|
|
14
|
+
&.visible {
|
|
15
|
+
opacity: 1;
|
|
16
|
+
}
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
export const DefaultTooltip = styled.div`
|
|
20
|
+
padding: 4px 8px;
|
|
21
|
+
background-color: ${theme.color.inverse[500]};
|
|
22
|
+
color: ${theme.color.inverse.contrastText};
|
|
23
|
+
border-radius: 6px;
|
|
24
|
+
margin: 6px;
|
|
25
|
+
`
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Checkbox, Text } from '@citric/core'
|
|
2
|
+
import { listToClass } from '@stack-spot/portal-theme'
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import { Accordion } from '../Accordion'
|
|
5
|
+
import { RadioCheckBox } from './styled'
|
|
6
|
+
import { CheckProps } from './types'
|
|
7
|
+
|
|
8
|
+
export function DescribedCheckboxGroup<T>(
|
|
9
|
+
{ keygen, onChange, options, renderDescription, renderLabel, optionClassName, optionStyle, value, className, style }: CheckProps<T>,
|
|
10
|
+
) {
|
|
11
|
+
const items = useMemo(() => options.map((option) => {
|
|
12
|
+
const label = renderLabel(option)
|
|
13
|
+
const description = renderDescription(option)
|
|
14
|
+
const header = (
|
|
15
|
+
<label>
|
|
16
|
+
<Checkbox
|
|
17
|
+
checked={value.includes(option)}
|
|
18
|
+
onChange={(e) => {
|
|
19
|
+
if (e.target.checked && !value.includes(option)) onChange([...value, option])
|
|
20
|
+
else onChange(value.filter(item => item !== option))
|
|
21
|
+
}}
|
|
22
|
+
/>
|
|
23
|
+
{typeof label === 'string' ? <Text>{label}</Text> : label}
|
|
24
|
+
</label>
|
|
25
|
+
)
|
|
26
|
+
return (
|
|
27
|
+
<li key={keygen(option)} className={listToClass(['radio-group-item', optionClassName?.(option)])} style={optionStyle?.(option)}>
|
|
28
|
+
<Accordion header={header}>
|
|
29
|
+
{typeof description === 'string'
|
|
30
|
+
? <Text appearance="microtext1" colorScheme="light.700">{description}</Text>
|
|
31
|
+
: description as any
|
|
32
|
+
}
|
|
33
|
+
</Accordion>
|
|
34
|
+
</li>
|
|
35
|
+
)
|
|
36
|
+
}), [options, value])
|
|
37
|
+
|
|
38
|
+
return <RadioCheckBox style={style} className={className}>{items}</RadioCheckBox>
|
|
39
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Radio, Text } from '@citric/core'
|
|
2
|
+
import { listToClass } from '@stack-spot/portal-theme'
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import { Accordion } from '../Accordion'
|
|
5
|
+
import { RadioCheckBox } from './styled'
|
|
6
|
+
import { RadioProps } from './types'
|
|
7
|
+
|
|
8
|
+
export function DescribedRadioGroup<T>(
|
|
9
|
+
{ keygen, onChange, options, renderDescription, renderLabel, optionClassName, optionStyle, value, className, style }: RadioProps<T>,
|
|
10
|
+
) {
|
|
11
|
+
const items = useMemo(() => options.map((option) => {
|
|
12
|
+
const label = renderLabel(option)
|
|
13
|
+
const description = renderDescription(option)
|
|
14
|
+
const header = (
|
|
15
|
+
<label>
|
|
16
|
+
<Radio checked={option === value} onChange={() => onChange(option)} />
|
|
17
|
+
{typeof label === 'string' ? <Text>{label}</Text> : label}
|
|
18
|
+
</label>
|
|
19
|
+
)
|
|
20
|
+
return (
|
|
21
|
+
<li key={keygen(option)} className={listToClass(['radio-group-item', optionClassName?.(option)])} style={optionStyle?.(option)}>
|
|
22
|
+
<Accordion header={header}>
|
|
23
|
+
{typeof description === 'string'
|
|
24
|
+
? <Text appearance="microtext1" colorScheme="light.700">{description}</Text>
|
|
25
|
+
: description as any
|
|
26
|
+
}
|
|
27
|
+
</Accordion>
|
|
28
|
+
</li>
|
|
29
|
+
)
|
|
30
|
+
}), [options, value])
|
|
31
|
+
|
|
32
|
+
return <RadioCheckBox style={style} className={className}>{items}</RadioCheckBox>
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { theme } from '@stack-spot/portal-theme'
|
|
2
|
+
import { styled } from 'styled-components'
|
|
3
|
+
|
|
4
|
+
export const RadioCheckBox = styled.ul`
|
|
5
|
+
margin: 0;
|
|
6
|
+
padding: 0;
|
|
7
|
+
list-style: none;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
gap: 6px;
|
|
11
|
+
|
|
12
|
+
li {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
gap: 8px;
|
|
16
|
+
border-radius: 6px;
|
|
17
|
+
background-color: ${theme.color.light[400]};
|
|
18
|
+
|
|
19
|
+
label {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: row;
|
|
22
|
+
align-items: center;
|
|
23
|
+
gap: 8px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
input[type="radio"], input[type="checkbox"] {
|
|
27
|
+
border-color: ${theme.color.light[700]};
|
|
28
|
+
background-color: transparent;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
input[type="checkbox"]:checked {
|
|
32
|
+
background-color: ${theme.color.inverse[500]};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
input[type="radio"] {
|
|
36
|
+
&:after {
|
|
37
|
+
background-color: ${theme.color.light[700]};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WithStyle } from '@stack-spot/portal-theme'
|
|
2
|
+
|
|
3
|
+
interface RadioCheckProps<T> extends WithStyle {
|
|
4
|
+
options: T[],
|
|
5
|
+
renderLabel: (option: T) => React.ReactNode,
|
|
6
|
+
renderDescription: (option: T) => React.ReactNode,
|
|
7
|
+
optionClassName?: (option: T) => string | undefined,
|
|
8
|
+
optionStyle?: (option: T) => React.CSSProperties | undefined,
|
|
9
|
+
keygen: (option: T) => React.Key,
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface RadioProps<T> extends RadioCheckProps<T> {
|
|
14
|
+
value: T | undefined,
|
|
15
|
+
onChange: (option: T) => void,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CheckProps<T> extends RadioCheckProps<T> {
|
|
19
|
+
value: T[],
|
|
20
|
+
onChange: (option: T[]) => void,
|
|
21
|
+
}
|