Skip to content

Commit

Permalink
docs: add doc comments to code
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnsandy committed Oct 4, 2024
1 parent b8af50f commit 8b88dc5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface TextToSpeechComponentProps {
*/
export const TextToSpeech: React.FC<TextToSpeechComponentProps> = ({
initialText = '',
showTextInput = true,
showTextInput = false,
voice,
pitch = 1,
rate = 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,81 @@
import React from 'react'
import Button from '#components/buttons/button'
import Icon from '#components/icons/icon'
import UI from '#components/ui'
import { FC } from 'react'

/**
* Props for the TextToSpeechControls component.
* @interface TextToSpeechControlsProps
*/
interface TextToSpeechControlsProps {
/** Optional label for the controls */
label?: string | React.ReactNode
/** Indicates if the text-to-speech is currently speaking */
isSpeaking: boolean
/** Indicates if the text-to-speech is paused */
isPaused: boolean
/** Function to start speaking */
onSpeak: () => void
/** Function to pause speaking */
onPause: () => void
/** Function to resume speaking */
onResume: () => void
/** Function to cancel speaking */
onCancel: () => void
}

const TTSButtonComponent = ({
children,
onClick,
}: {
/**
* TTSButtonComponent props
* @interface TTSButtonComponentProps
*/
interface TTSButtonComponentProps {
/** The content of the button */
children: React.ReactNode
/** Function to call when the button is clicked */
onClick: () => void
}

/**
* TTSButtonComponent is a reusable button component for text-to-speech controls.
* @param {TTSButtonComponentProps} props - The component props
* @returns {React.ReactElement} The rendered button
*/
export const TTSButtonComponent: React.FC<TTSButtonComponentProps> = ({
children,
onClick,
}) => {
return (
<button
<UI
as="button"
type="button"
className="tts-border"
data-btn="sm text pill"
onClick={onClick}
>
{children}
</button>
</UI>
)
}

export const TTSButton = React.memo(TTSButtonComponent)

const TextToSpeechControls: React.FC<TextToSpeechControlsProps> = ({
/**
* TextToSpeechControlsComponent interface extends FC<TextToSpeechControlsProps>
* and includes a TTSButton property.
* @interface TextToSpeechControlsComponent
* @extends {FC<TextToSpeechControlsProps>}
*/
interface TextToSpeechControlsComponent extends FC<TextToSpeechControlsProps> {
/** The TTSButton component used within TextToSpeechControls */
TTSButton: typeof TTSButton
}

/**
* TextToSpeechControls component provides a user interface for controlling text-to-speech functionality.
* @param {TextToSpeechControlsProps} props - The component props
* @returns {React.ReactElement} The rendered TextToSpeechControls component
*/
const TextToSpeechControls: TextToSpeechControlsComponent = ({
label,
isSpeaking,
isPaused,
Expand All @@ -45,7 +87,7 @@ const TextToSpeechControls: React.FC<TextToSpeechControlsProps> = ({
const iconSize = 16

return (
<div data-tts>
<UI as="div" data-tts>
{label && <p>{label}</p>}
{!isSpeaking && (
<TTSButton aria-label="Speak" onClick={onSpeak}>
Expand All @@ -65,10 +107,11 @@ const TextToSpeechControls: React.FC<TextToSpeechControlsProps> = ({
<TTSButton aria-label="Stop" onClick={onCancel}>
<Icon.StopSolid size={iconSize} />
</TTSButton>
</div>
</UI>
)
}

export default TextToSpeechControls
TextToSpeechControls.displayName = 'TextToSpeechControls'
// TextToSpeechControls.Button = TTSButton
TextToSpeechControls.TTSButton = TTSButton

export default TextToSpeechControls

0 comments on commit 8b88dc5

Please sign in to comment.