Skip to content

Commit f6975fc

Browse files
authored
feat(settings): add video tooltip previews for canvas settings (#3749)
* feat(settings): add video tooltip previews for canvas settings * fix(tooltip): add preload=none and handle query strings in video detection
1 parent 59182d5 commit f6975fc

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

apps/sim/app/workspace/[workspaceId]/settings/components/general/general.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ModalFooter,
1717
ModalHeader,
1818
Switch,
19+
Tooltip,
1920
} from '@/components/emcn'
2021
import { signOut, useSession } from '@/lib/auth/auth-client'
2122
import { ANONYMOUS_USER_ID } from '@/lib/auth/constants'
@@ -375,7 +376,20 @@ export function General() {
375376
</div>
376377

377378
<div className='flex items-center justify-between'>
378-
<Label htmlFor='auto-connect'>Auto-connect on drop</Label>
379+
<Tooltip.Root>
380+
<Tooltip.Trigger asChild>
381+
<Label htmlFor='auto-connect' className='cursor-help'>
382+
Auto-connect on drop
383+
</Label>
384+
</Tooltip.Trigger>
385+
<Tooltip.Content side='bottom' align='start'>
386+
<p>Automatically connect blocks when dropped near each other</p>
387+
<Tooltip.Preview
388+
src='/tooltips/auto-connect-on-drop.mp4'
389+
alt='Auto-connect on drop example'
390+
/>
391+
</Tooltip.Content>
392+
</Tooltip.Root>
379393
<Switch
380394
id='auto-connect'
381395
checked={settings?.autoConnect ?? true}
@@ -384,7 +398,20 @@ export function General() {
384398
</div>
385399

386400
<div className='flex items-center justify-between'>
387-
<Label htmlFor='error-notifications'>Workflow error notifications</Label>
401+
<Tooltip.Root>
402+
<Tooltip.Trigger asChild>
403+
<Label htmlFor='error-notifications' className='cursor-help'>
404+
Canvas error notifications
405+
</Label>
406+
</Tooltip.Trigger>
407+
<Tooltip.Content side='bottom' align='start'>
408+
<p>Show error popups on blocks when a workflow run fails</p>
409+
<Tooltip.Preview
410+
src='/tooltips/canvas-error-notification.mp4'
411+
alt='Canvas error notification example'
412+
/>
413+
</Tooltip.Content>
414+
</Tooltip.Root>
388415
<Switch
389416
id='error-notifications'
390417
checked={settings?.errorNotificationsEnabled ?? true}

apps/sim/components/emcn/components/tooltip/tooltip.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,71 @@ const Shortcut = ({ keys, className, children }: ShortcutProps) => (
8989
)
9090
Shortcut.displayName = 'Tooltip.Shortcut'
9191

92+
interface PreviewProps {
93+
/** The URL of the image, GIF, or video to display */
94+
src: string
95+
/** Alt text for the media */
96+
alt?: string
97+
/** Width of the preview in pixels */
98+
width?: number
99+
/** Height of the preview in pixels */
100+
height?: number
101+
/** Optional additional class names */
102+
className?: string
103+
}
104+
105+
const VIDEO_EXTENSIONS = ['.mp4', '.webm', '.ogg', '.mov'] as const
106+
107+
/**
108+
* Displays a preview image, GIF, or video within tooltip content.
109+
*
110+
* @example
111+
* ```tsx
112+
* <Tooltip.Content>
113+
* <p>Canvas error notifications</p>
114+
* <Tooltip.Preview src="/tooltips/canvas-error-notification.mp4" alt="Error notification example" />
115+
* </Tooltip.Content>
116+
* ```
117+
*/
118+
const Preview = ({ src, alt = '', width = 240, height, className }: PreviewProps) => {
119+
const pathname = src.toLowerCase().split('?')[0].split('#')[0]
120+
const isVideo = VIDEO_EXTENSIONS.some((ext) => pathname.endsWith(ext))
121+
122+
return (
123+
<div className={cn('mt-[4px] overflow-hidden rounded-[3px]', className)}>
124+
{isVideo ? (
125+
<video
126+
src={src}
127+
width={width}
128+
height={height}
129+
className='block max-w-full'
130+
autoPlay
131+
loop
132+
muted
133+
playsInline
134+
preload='none'
135+
aria-label={alt}
136+
/>
137+
) : (
138+
<img
139+
src={src}
140+
alt={alt}
141+
width={width}
142+
height={height}
143+
className='block max-w-full'
144+
loading='lazy'
145+
/>
146+
)}
147+
</div>
148+
)
149+
}
150+
Preview.displayName = 'Tooltip.Preview'
151+
92152
export const Tooltip = {
93153
Root,
94154
Trigger,
95155
Content,
96156
Provider,
97157
Shortcut,
158+
Preview,
98159
}
16.6 KB
Binary file not shown.
58.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)