Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Audio input button transition (DSN-2581) #375

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface AudioInputButtonProps {
listening?: boolean;
processing?: boolean;
initializing?: boolean;
showButton?: boolean;
}

export const AudioInputButton: React.FC<AudioInputButtonProps> = ({
Expand All @@ -19,13 +20,14 @@ export const AudioInputButton: React.FC<AudioInputButtonProps> = ({
listening,
processing,
initializing,
showButton,
}) => {
return (
<button
className={clsx(
squareButtonStyles({ size: 'medium', isActive: listening }),
SquareButtonTheme.light,
audioInputButton()
audioInputButton({ hidden: !showButton })
)}
onClick={listening ? onStop : onStart}
disabled={processing || initializing}
Expand Down
13 changes: 13 additions & 0 deletions packages/chat/src/components/MessageInput/MessageInput.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,25 @@ export const audioInputButton = recipe({
base: {
display: 'flex',
borderRadius: 100,
overflow: 'hidden', // Ensures smooth shrinking
transition: transition(['opacity', 'width']), // Common transitions
},
variants: {
disabled: {
true: {
cursor: 'not-allowed',
},
},
hidden: {
true: {
opacity: 0,
transition: 'opacity 0.15s, width 0.15s 0.15s', // Delay width transition to occur after opacity
width: 0,
},
false: {
opacity: 1,
transition: 'opacity 0.15s 0.15s, width 0s', // Delay opacity to occur after width expands
},
},
},
});
18 changes: 9 additions & 9 deletions packages/chat/src/components/MessageInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export const MessageInput: React.FC<IMessageInput> = ({
/>
</div>
<div className={buttonContainer}>
{withAudioInput && (
<AudioInputButton
onStop={speechRecognition.stopListening}
onStart={speechRecognition.startListening}
listening={speechRecognition.listening}
processing={speechRecognition.processing}
initializing={speechRecognition.initializing}
/>
)}
<AudioInputButton
onStop={speechRecognition.stopListening}
onStart={speechRecognition.startListening}
listening={speechRecognition.listening}
processing={speechRecognition.processing}
initializing={speechRecognition.initializing}
showButton={withAudioInput}
/>

<SendButton onClick={sendMessage} disabled={!message?.length} />
</div>
</div>
Expand Down
Loading