From 31051cd6c48318135b7c487541a64e4fd6c2be91 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Mon, 16 Sep 2024 16:17:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8(frontend)=20improve=20share=20scre?= =?UTF-8?q?en=20UX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced the share screen button by adding a tooltip and improving contrast for better accessibility. Created a temporary icon by combining two from Remix, but it’s bulky and will need refactoring soon. --- .../components/controls/ScreenShareToggle.tsx | 54 +++++++++++++++++++ .../rooms/livekit/prefabs/ControlBar.tsx | 33 ++---------- 2 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 src/frontend/src/features/rooms/livekit/components/controls/ScreenShareToggle.tsx diff --git a/src/frontend/src/features/rooms/livekit/components/controls/ScreenShareToggle.tsx b/src/frontend/src/features/rooms/livekit/components/controls/ScreenShareToggle.tsx new file mode 100644 index 00000000..f66b4838 --- /dev/null +++ b/src/frontend/src/features/rooms/livekit/components/controls/ScreenShareToggle.tsx @@ -0,0 +1,54 @@ +import { Div, ToggleButton } from '@/primitives' +import { RiArrowUpLine, RiCloseFill, RiRectangleLine } from '@remixicon/react' +import { useTranslation } from 'react-i18next' +import { useTrackToggle, UseTrackToggleProps } from '@livekit/components-react' +import { Track } from 'livekit-client' +import React from 'react' + +export const ScreenShareToggle = ( + props: Omit< + UseTrackToggleProps, + 'source' | 'captureOptions' + > +) => { + const { t } = useTranslation('rooms', { keyPrefix: 'controls' }) + const { buttonProps, enabled } = useTrackToggle({ + ...props, + source: Track.Source.ScreenShare, + captureOptions: { audio: true, selfBrowserSurface: 'include' }, + }) + + const Icon = enabled ? RiCloseFill : RiArrowUpLine + + // fixme - remove ToggleButton custom styles when we design a proper icon + return ( + + buttonProps.onClick?.( + e as unknown as React.MouseEvent + ) + } + style={{ + maxWidth: '46px', + maxHeight: '46px', + }} + > +
+ + +
+
+ ) +} diff --git a/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx b/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx index 77a16bd5..f71bc53d 100644 --- a/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx +++ b/src/frontend/src/features/rooms/livekit/prefabs/ControlBar.tsx @@ -4,7 +4,6 @@ import * as React from 'react' import { supportsScreenSharing } from '@livekit/components-core' import { - TrackToggle, useMaybeLayoutContext, usePersistentUserChoices, } from '@livekit/components-react' @@ -12,13 +11,13 @@ import { import { mergeProps } from '@/utils/mergeProps.ts' import { StartMediaButton } from '../components/controls/StartMediaButton' import { useMediaQuery } from '../hooks/useMediaQuery' -import { useTranslation } from 'react-i18next' import { OptionsButton } from '../components/controls/Options/OptionsButton' import { ParticipantsToggle } from '../components/controls/Participants/ParticipantsToggle' import { ChatToggle } from '../components/controls/ChatToggle' import { HandToggle } from '../components/controls/HandToggle' import { SelectToggleDevice } from '../components/controls/SelectToggleDevice' import { LeaveButton } from '../components/controls/LeaveButton' +import { ScreenShareToggle } from '../components/controls/ScreenShareToggle' /** @public */ export type ControlBarControls = { @@ -66,7 +65,6 @@ export function ControlBar({ onDeviceError, ...props }: ControlBarProps) { - const { t } = useTranslation('rooms', { keyPrefix: 'controls' }) const [isChatOpen, setIsChatOpen] = React.useState(false) const layoutContext = useMaybeLayoutContext() React.useEffect(() => { @@ -82,26 +80,8 @@ export function ControlBar({ const defaultVariation = isTooLittleSpace ? 'minimal' : 'verbose' variation ??= defaultVariation - const showIcon = React.useMemo( - () => variation === 'minimal' || variation === 'verbose', - [variation] - ) - const showText = React.useMemo( - () => variation === 'textOnly' || variation === 'verbose', - [variation] - ) - const browserSupportsScreenSharing = supportsScreenSharing() - const [isScreenShareEnabled, setIsScreenShareEnabled] = React.useState(false) - - const onScreenShareChange = React.useCallback( - (enabled: boolean) => { - setIsScreenShareEnabled(enabled) - }, - [setIsScreenShareEnabled] - ) - const htmlProps = mergeProps({ className: 'lk-control-bar' }, props) const { @@ -146,18 +126,11 @@ export function ControlBar({ } /> {browserSupportsScreenSharing && ( - onDeviceError?.({ source: Track.Source.ScreenShare, error }) } - > - {showText && - t(isScreenShareEnabled ? 'stopScreenShare' : 'shareScreen')} - + /> )}