Skip to content

Commit

Permalink
feat: keyboard shortcut component (#26658)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Dec 4, 2024
1 parent 8b483e2 commit 70f234b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ function FullScreen(): JSX.Element {
<LemonButton
size="xsmall"
onClick={() => setIsFullScreen(!isFullScreen)}
tooltip={`${!isFullScreen ? 'Go' : 'Exit'} full screen (F)`}
tooltip={
<>
{!isFullScreen ? 'Go' : 'Exit'} full screen <KeyboardShortcut f />
</>
}
>
<IconFullScreen className={clsx('text-2xl', isFullScreen ? 'text-link' : 'text-primary-alt')} />
</LemonButton>
Expand Down Expand Up @@ -194,7 +198,11 @@ function Maximise(): JSX.Element {
<LemonButton
size="xsmall"
onClick={onChangeMaximise}
tooltip={`${isMaximised ? 'Open' : 'Close'} other panels (M)`}
tooltip={
<>
{isMaximised ? 'Open' : 'Close'} other panels <KeyboardShortcut m />
</>
}
icon={isMaximised ? <IconCollapse45 className="text-lg" /> : <IconExpand45 className="text-lg" />}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { capitalizeFirstLetter, colonDelimitedDuration } from 'lib/utils'
import { SimpleTimeLabel } from 'scenes/session-recordings/components/SimpleTimeLabel'
import { ONE_FRAME_MS, sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'

import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardShortcut'
import { HotKeyOrModifier } from '~/types'

import { playerSettingsLogic, TimestampFormat } from '../playerSettingsLogic'
import { seekbarLogic } from './seekbarLogic'

Expand Down Expand Up @@ -44,10 +47,14 @@ export function SeekSkip({ direction }: { direction: 'forward' | 'backward' }):

const altKeyHeld = useKeyHeld('Alt')
const jumpTimeSeconds = altKeyHeld ? 1 : jumpTimeMs / 1000
const altKeyName = navigator.platform.includes('Mac') ? '⌥' : 'Alt'

const arrowSymbol = direction === 'forward' ? '→' : '←'
const arrowName = direction === 'forward' ? 'right' : 'left'
const arrowKey: Partial<Record<HotKeyOrModifier, true>> = {}
if (direction === 'forward') {
arrowKey.arrowright = true
}
if (direction === 'backward') {
arrowKey.arrowleft = true
}

return (
<Tooltip
Expand All @@ -56,18 +63,12 @@ export function SeekSkip({ direction }: { direction: 'forward' | 'backward' }):
<div className="text-center">
{!altKeyHeld ? (
<>
{capitalizeFirstLetter(direction)} {jumpTimeSeconds}s (
<kbd>
{arrowSymbol} {arrowName} arrow
</kbd>
) <br />
{capitalizeFirstLetter(direction)} {jumpTimeSeconds}s <KeyboardShortcut {...arrowKey} />
<br />
</>
) : null}
{capitalizeFirstLetter(direction)} 1 frame ({ONE_FRAME_MS}ms) (
<kbd>
{altKeyName} + {arrowSymbol}
</kbd>
)
{capitalizeFirstLetter(direction)} 1 frame ({ONE_FRAME_MS}ms){' '}
<KeyboardShortcut option {...arrowKey} />
</div>
}
>
Expand Down

0 comments on commit 70f234b

Please sign in to comment.