Components/AI

Generated Answer

AI-generated answer component with progressive text reveal, markdown support, and interactive controls

Live Preview
Open in
2:15

Example

export default function GeneratedAnswerExample() {
  const sampleContent = `# React Best Practices

## Component Structure
- Use functional components with hooks
- Keep components small and focused
- Implement proper prop validation

## State Management
- Use useState for local state
- Consider Context API for shared state
- Implement proper error boundaries

## Performance Optimization
- Use React.memo for expensive components
- Implement proper key props in lists
- Avoid unnecessary re-renders

\`\`\`jsx
const MyComponent = ({ data }) => {
  const [state, setState] = useState(null)
  
  useEffect(() => {
    // Handle side effects
  }, [data])
  
  return <div>{data}</div>
}
\`\`\``

  const handleEndAnimation = () => {
    console.log('Text animation ended')
  }

  const handleComplete = () => {
    console.log('Answer generation completed')
  }

  return (
    <GeneratedAnswer
      content={sampleContent}
      timestamp="1:23"
      isLoading={false}
      textSpeed={30}
      markdownMode={true}
      hideControls={false}
      onEndAnimation={handleEndAnimation}
      onComplete={handleComplete}
      className="w-full max-w-2xl"
    />
  )
}

Documentation

PropTypeDefaultDescription
classNamestringundefinedAdditional CSS classes for styling
contentstring""The answer content to display
timestampstring"00:00"Timestamp displayed in the controls
isLoadingbooleanfalseWhether to show loading state
LoaderComponentReact.ReactNodeundefinedCustom loader component
onEndAnimation() => voidundefinedCallback when text animation ends
onComplete() => voidundefinedCallback when answer generation completes
textSpeednumber30Speed of progressive text reveal
markdownModebooleanfalseWhether to render content as markdown
hideControlsbooleanfalseWhether to hide the control buttons

Types

type GeneratedAnswerProps = {
  className?: string
  content?: string
  timestamp?: string
  isLoading?: boolean
  LoaderComponent?: React.ReactNode
  onEndAnimation?: () => void
  onComplete?: () => void
  textSpeed?: number
  markdownMode?: boolean
  hideControls?: boolean
}

Features

  • Progressive Text Reveal: Animated text appearance with configurable speed
  • Markdown Support: Full markdown rendering with syntax highlighting
  • Loading States: Customizable loading indicators and states
  • Interactive Controls: Copy, like, dislike, and regenerate functionality
  • Timestamp Display: Shows when the answer was generated
  • Responsive Design: Adapts to different screen sizes with proper text wrapping
  • Dark Mode Support: Full dark mode compatibility with appropriate styling
  • Accessibility Focused: Proper ARIA labels and keyboard navigation support