(front) option to hide menu on SelectToggleDevice

On mobile we want to be able to hide the chevron and menu.
This commit is contained in:
Nathan Vasse
2024-12-20 11:57:06 +01:00
committed by NathanVss
parent 6587863afb
commit c380ff5e1d
3 changed files with 45 additions and 25 deletions

View File

@@ -67,11 +67,13 @@ type SelectToggleDeviceProps<T extends ToggleSource> =
UseTrackToggleProps<T> & { UseTrackToggleProps<T> & {
onActiveDeviceChange: (deviceId: string) => void onActiveDeviceChange: (deviceId: string) => void
source: SelectToggleSource source: SelectToggleSource
hideMenu?: boolean
variant?: 'dark' | 'light' variant?: 'dark' | 'light'
} }
export const SelectToggleDevice = <T extends ToggleSource>({ export const SelectToggleDevice = <T extends ToggleSource>({
onActiveDeviceChange, onActiveDeviceChange,
hideMenu,
variant = 'light', variant = 'light',
...props ...props
}: SelectToggleDeviceProps<T>) => { }: SelectToggleDeviceProps<T>) => {
@@ -94,30 +96,42 @@ export const SelectToggleDevice = <T extends ToggleSource>({
gap: '1px', gap: '1px',
})} })}
> >
<ToggleDevice {...trackProps} config={config} /> <ToggleDevice
<Menu variant={variant}> {...trackProps}
<Button config={config}
tooltip={selectLabel} toggleButtonProps={{
aria-label={selectLabel} ...(hideMenu
groupPosition="right" ? {
square groupPosition: undefined,
variant={trackProps.enabled ? 'primaryDark' : 'error2'} }
> : {}),
<RiArrowDownSLine /> }}
</Button> />
<MenuList {!hideMenu && (
items={devices.map((d) => ({ <Menu variant={variant}>
value: d.deviceId, <Button
label: d.label, tooltip={selectLabel}
}))} aria-label={selectLabel}
selectedItem={activeDeviceId} groupPosition="right"
onAction={(value) => { square
setActiveMediaDevice(value as string) variant={trackProps.enabled ? 'primaryDark' : 'error2'}
onActiveDeviceChange(value as string) >
}} <RiArrowDownSLine />
variant={variant} </Button>
/> <MenuList
</Menu> items={devices.map((d) => ({
value: d.deviceId,
label: d.label,
}))}
selectedItem={activeDeviceId}
onAction={(value) => {
setActiveMediaDevice(value as string)
onActiveDeviceChange(value as string)
}}
variant={variant}
/>
</Menu>
)}
</div> </div>
) )
} }

View File

@@ -7,17 +7,20 @@ import { SelectToggleDeviceConfig } from './SelectToggleDevice'
import useLongPress from '@/features/shortcuts/useLongPress' import useLongPress from '@/features/shortcuts/useLongPress'
import { ActiveSpeaker } from '@/features/rooms/components/ActiveSpeaker' import { ActiveSpeaker } from '@/features/rooms/components/ActiveSpeaker'
import { useIsSpeaking, useLocalParticipant } from '@livekit/components-react' import { useIsSpeaking, useLocalParticipant } from '@livekit/components-react'
import { ToggleButtonProps } from '@/primitives/ToggleButton'
export type ToggleDeviceProps = { export type ToggleDeviceProps = {
enabled: boolean enabled: boolean
toggle: () => void toggle: () => void
config: SelectToggleDeviceConfig config: SelectToggleDeviceConfig
toggleButtonProps?: Partial<ToggleButtonProps>
} }
export const ToggleDevice = ({ export const ToggleDevice = ({
config, config,
enabled, enabled,
toggle, toggle,
toggleButtonProps,
}: ToggleDeviceProps) => { }: ToggleDeviceProps) => {
const { t } = useTranslation('rooms', { keyPrefix: 'join' }) const { t } = useTranslation('rooms', { keyPrefix: 'join' })
@@ -64,6 +67,7 @@ export const ToggleDevice = ({
aria-label={toggleLabel} aria-label={toggleLabel}
tooltip={toggleLabel} tooltip={toggleLabel}
groupPosition="left" groupPosition="left"
{...toggleButtonProps}
> >
<Icon /> <Icon />
</ToggleButton> </ToggleButton>

View File

@@ -55,7 +55,7 @@ export function MobileControlBar({
className={css({ className={css({
display: 'flex', display: 'flex',
justifyContent: 'space-between', justifyContent: 'space-between',
width: '422px', width: '330px',
})} })}
> >
<LeaveButton /> <LeaveButton />
@@ -68,6 +68,7 @@ export function MobileControlBar({
onActiveDeviceChange={(deviceId) => onActiveDeviceChange={(deviceId) =>
saveAudioInputDeviceId(deviceId ?? '') saveAudioInputDeviceId(deviceId ?? '')
} }
hideMenu={true}
/> />
<SelectToggleDevice <SelectToggleDevice
source={Track.Source.Camera} source={Track.Source.Camera}
@@ -78,6 +79,7 @@ export function MobileControlBar({
onActiveDeviceChange={(deviceId) => onActiveDeviceChange={(deviceId) =>
saveVideoInputDeviceId(deviceId ?? '') saveVideoInputDeviceId(deviceId ?? '')
} }
hideMenu={true}
/> />
<HandToggle /> <HandToggle />
<Button <Button