@plteam/chat-ui
Version:
CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript
26 lines (25 loc) • 1.39 kB
JavaScript
import * as React from 'react';
import { AddIcon } from '../../icons';
import { useObserverValue } from '../hooks/useObserverValue';
import { useHistoryContext } from '../core/history/HistoryContext';
import internalApi from '../core/history/internalApi';
import Box from '@mui/material/Box';
const useDisabled = () => {
const internal = useObserverValue(internalApi);
const thread = useObserverValue(internal?.model?.currentThread);
const isEmpty = useObserverValue(thread?.isEmpty);
return isEmpty;
};
export const NewChatIconButton = ({ openNewThread }) => {
const disabled = useDisabled();
const { slots, slotProps } = useHistoryContext();
return (React.createElement(slots.baseIconButton, { disabled: disabled, size: "small", onClick: openNewThread, ...slotProps.baseIconButton },
React.createElement(AddIcon, null)));
};
const NewChatButton = ({ openNewThread }) => {
const disabled = useDisabled();
const { slots, slotProps, locale } = useHistoryContext();
return (React.createElement(Box, { pt: 1.5, px: 2, width: "100%", boxSizing: "border-box" },
React.createElement(slots.baseButton, { fullWidth: true, disabled: disabled, startIcon: React.createElement(AddIcon, null), variant: "outlined", onClick: openNewThread, ...slotProps.baseButton }, locale.newChat)));
};
export default NewChatButton;