Skip to content

Commit

Permalink
add disabled state
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Jul 30, 2024
1 parent 1a7df7a commit 9177f84
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export interface ChatProps extends PropsWithChildren {
*/
isLoading?: boolean;

/**
* Whether to disable the chat.
*/
disabled?: boolean;

/**
* Callback function to handle when a session is selected.
*/
Expand Down Expand Up @@ -84,6 +89,7 @@ export const Chat: FC<ChatProps> = ({
theme: customTheme = chatTheme,
onNewSession,
remarkPlugins,
disabled,
style,
className
}) => {
Expand Down Expand Up @@ -140,6 +146,7 @@ export const Chat: FC<ChatProps> = ({
activeSession,
remarkPlugins,
theme,
disabled,
isLoading,
activeSessionId: internalActiveSessionID,
selectSession: handleSelectSession,
Expand All @@ -148,6 +155,7 @@ export const Chat: FC<ChatProps> = ({
}),
[
isLoading,
disabled,
theme,
remarkPlugins,
sessions,
Expand Down
1 change: 1 addition & 0 deletions src/ChatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PluggableList } from 'react-markdown/lib';

export interface ChatContextProps {
sessions: Session[];
disabled?: boolean;
activeSessionId: string | null;
theme?: ChatTheme;
isLoading?: boolean;
Expand Down
8 changes: 5 additions & 3 deletions src/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const ChatInput: FC<ChatInputProps> = ({
stopIcon = <StopIcon />,
attachIcon = <AttachIcon />
}) => {
const { theme, isLoading } = useContext(ChatContext);
const { theme, isLoading, disabled } = useContext(ChatContext);
const [message, setMessage] = useState<string>('');
const fileInputRef = useRef<HTMLInputElement>(null);

Expand Down Expand Up @@ -107,7 +107,7 @@ export const ChatInput: FC<ChatInputProps> = ({
defaultValue={defaultValue}
onKeyPress={handleKeyPress}
placeholder={placeholder}
disabled={isLoading}
disabled={isLoading || disabled}
/>
{allowedFiles?.length > 0 && (
<>
Expand All @@ -120,6 +120,7 @@ export const ChatInput: FC<ChatInputProps> = ({
/>
<Button
title="Upload"
disabled={isLoading || disabled}
className={cn(theme.input.upload)}
onClick={() => fileInputRef.current?.click()}
>
Expand All @@ -132,6 +133,7 @@ export const ChatInput: FC<ChatInputProps> = ({
title="Stop"
className={cn(theme.input.stop)}
onClick={onStopMessage}
disabled={disabled}
>
{stopIcon}
</Button>
Expand All @@ -140,7 +142,7 @@ export const ChatInput: FC<ChatInputProps> = ({
title="Send"
className={cn(theme.input.send)}
onClick={handleSendMessage}
disabled={isLoading}
disabled={isLoading || disabled}
>
{sendIcon}
</Button>
Expand Down
3 changes: 2 additions & 1 deletion src/SessionsList/NewSessionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const NewSessionButton: FC<NewSessionButtonProps> = ({
children,
newSessionText = 'New Session'
}) => {
const { theme, createSession } = useContext(ChatContext);
const { theme, createSession, disabled } = useContext(ChatContext);
const Comp = children ? Slot : Button;

return (
Expand All @@ -23,6 +23,7 @@ export const NewSessionButton: FC<NewSessionButtonProps> = ({
disableMargins
color="primary"
className={cn(theme.sessions.create)}
disabled={disabled}
onClick={createSession}
>
{children || newSessionText}
Expand Down
1 change: 1 addition & 0 deletions stories/Demos.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ export const OpenAIIntegration = () => {
viewType="console"
sessions={sessions}
isLoading={isLoading}
disabled={!apiKey}
onDeleteSession={handleDeleteSession}
onSendMessage={handleNewMessage}
activeSessionId={activeSessionId}
Expand Down

0 comments on commit 9177f84

Please sign in to comment.