@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
14 lines (13 loc) • 727 B
JavaScript
import { ChatViewConstants } from '../ChatViewConstants';
import { useChatContext } from './ChatGlobalContext';
// Resolves the public `speed` object (with the deprecated `typingSpeed` fallback) into
// concrete numbers, applying defaults. Single source of truth so the CSS fade duration,
// the stagger, and the button trigger all agree.
export const resolveSpeed = (speed, typingSpeed) => ({
typing: speed?.typing ?? typingSpeed ?? ChatViewConstants.TEXT_SMOOTH_ANIMATION_DURATION_MS,
stagger: speed?.stagger ?? ChatViewConstants.TEXT_SMOOTH_STAGGER_STEP_MS,
});
export const useResolvedSpeed = () => {
const { speed, typingSpeed } = useChatContext();
return resolveSpeed(speed, typingSpeed);
};