This repository was archived by the owner on Oct 16, 2026. It is now read-only.
Repository navigation
feat(fuselage): extract controlled AudioPlayerControls from AudioPlayer #2052
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
62d0637
feat(fuselage): extract controlled AudioPlayerControls from AudioPlayer
ggazzo 6187dea
chore(fuselage): fix import group spacing
ggazzo bd1a6b2
chore(fuselage): drop Controls story (needs visual-regression baseline)
ggazzo 033b362
Update .changeset/audio-player-controls.md
ggazzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/fuselage': minor | ||
| --- | ||
|
|
||
| Extracted the presentational, fully controlled `AudioPlayerControls` component from `AudioPlayer` and exported it. It renders the play/pause, seek, elapsed time, playback speed and optional download controls without owning an `<audio>` element or any playback state, so it can be driven by an external/shared media element. `AudioPlayer` keeps its previous self-contained behavior and now composes `AudioPlayerControls` internally, so existing usage is unchanged. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/fuselage/src/components/AudioPlayer/AudioPlayerControls.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import type { MouseEvent } from 'react'; | ||
|
|
||
| import { Box, Button, IconButton, Margins } from '../..'; | ||
| import { Slider } from '../Slider'; | ||
|
|
||
| const getMaskTime = (durationTime: number) => | ||
| new Date(durationTime * 1000) | ||
| .toISOString() | ||
| .slice(durationTime > 60 * 60 ? 11 : 14, 19); | ||
|
|
||
| export type AudioPlayerControlsProps = { | ||
| isPlaying: boolean; | ||
| currentTime: number; | ||
| durationTime: number; | ||
| playbackSpeed: number; | ||
| onTogglePlay: () => void; | ||
| onSeek: (time: number) => void; | ||
| onChangePlaybackSpeed: () => void; | ||
| download?: boolean; | ||
| downloadHref?: string; | ||
| onDownload?: (event: MouseEvent<HTMLElement>) => void; | ||
| playLabel?: string; | ||
| pauseLabel?: string; | ||
| audioPlaybackRangeLabel?: string; | ||
| changePlaybackSpeedLabel?: string; | ||
| downloadAudioFileLabel?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Presentational, fully controlled audio controls (play/pause, seek, elapsed | ||
| * time, playback speed and optional download). It owns no `<audio>` element and | ||
| * no playback state, so it can be driven by any source — a local element or a | ||
| * shared/persistent one. `AudioPlayer` wraps this with its own element for the | ||
| * common self-contained case. | ||
| */ | ||
| const AudioPlayerControls = ({ | ||
| isPlaying, | ||
| currentTime, | ||
| durationTime, | ||
| playbackSpeed, | ||
| onTogglePlay, | ||
| onSeek, | ||
| onChangePlaybackSpeed, | ||
| download = false, | ||
| downloadHref, | ||
| onDownload, | ||
| playLabel = 'Play', | ||
| pauseLabel = 'Pause', | ||
| audioPlaybackRangeLabel = 'Audio Playback Range', | ||
| changePlaybackSpeedLabel = 'Change Playback Speed', | ||
| downloadAudioFileLabel = 'Download Audio File', | ||
| }: AudioPlayerControlsProps) => ( | ||
| <Box display='flex' alignItems='center' w='full'> | ||
| <IconButton | ||
| primary | ||
| medium | ||
| onClick={onTogglePlay} | ||
| aria-label={isPlaying ? pauseLabel : playLabel} | ||
| icon={isPlaying ? 'pause-shape-filled' : 'play-shape-filled'} | ||
| /> | ||
| <Margins inline={8}> | ||
| <Box fontScale='p2' color='secondary-info'> | ||
| {isPlaying || currentTime > 0 | ||
| ? getMaskTime(currentTime) | ||
| : getMaskTime(durationTime)} | ||
| </Box> | ||
| <Box mi={16} w='full'> | ||
| <Slider | ||
| aria-label={audioPlaybackRangeLabel} | ||
| showOutput={false} | ||
| value={currentTime} | ||
| maxValue={durationTime} | ||
| onChange={(value) => onSeek(Array.isArray(value) ? value[0] : value)} | ||
| /> | ||
| </Box> | ||
|
|
||
| <Button | ||
| secondary | ||
| small | ||
| onClick={onChangePlaybackSpeed} | ||
| aria-label={changePlaybackSpeedLabel} | ||
| > | ||
| {playbackSpeed}x | ||
| </Button> | ||
| </Margins> | ||
| {download && ( | ||
| <IconButton | ||
| primary | ||
| medium | ||
| is='a' | ||
| href={downloadHref} | ||
| download | ||
| icon='download' | ||
| aria-label={downloadAudioFileLabel} | ||
| onClick={onDownload} | ||
| /> | ||
| )} | ||
| </Box> | ||
| ); | ||
|
|
||
| export default AudioPlayerControls; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| export { default as AudioPlayer, type AudioPlayerProps } from './AudioPlayer'; | ||
| export { | ||
| default as AudioPlayerControls, | ||
| type AudioPlayerControlsProps, | ||
| } from './AudioPlayerControls'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.