Skip to content

Commit b5fdc6e

Browse files
authored
feat(product tours): add animation toggle to banners (#47980)
## Problem banners cause a pretty jarring layout shift when they appear <!-- Who are we building for, what are their needs, why is this important? --> <!-- Does this fix an issue? Uncomment the line below with the issue ID to automatically close it when merged --> <!-- Closes #ISSUE_ID --> ## Changes adds an animation toggle for banners :) | normal sticky/static banners | custom injection banners | | --- | --- | | [banner-animations.mp4 <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.com/user-attachments/thumbnails/ea020f88-2a9b-4dd5-9dae-34441ee4bd03.mp4" />](https://app.graphite.com/user-attachments/video/ea020f88-2a9b-4dd5-9dae-34441ee4bd03.mp4)<br> | [injected-banner-animation.mp4 <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.com/user-attachments/thumbnails/e54d2862-44de-400a-966d-c4eef45c232d.mp4" />](https://app.graphite.com/user-attachments/video/e54d2862-44de-400a-966d-c4eef45c232d.mp4)<br> | depends on PostHog/posthog-js#3098 technically supports a custom animation duration, but only exposing it as a toggle right now -- don't wanna clutter the UI until we have to 😛 <!-- If there are frontend changes, please include screenshots. --> <!-- If a reference design was involved, include a link to the relevant Figma frame! --> ## How did you test this code? <!-- Briefly describe the steps you took. --> <!-- Include automated tests if possible, otherwise describe the manual testing routine. --> <!-- Docs reminder: If this change requires updated docs, please do that! Engineers are the primary people responsible for their documentation. 🙌 --> 👉 _Stay up-to-date with_ [_PostHog coding conventions_](https://posthog.com/docs/contribute/coding-conventions) _for a smoother review._ ## Publish to changelog? <!-- For features only --> <!-- If publishing, you must provide changelog details in the #changelog Slack channel. You will receive a follow-up PR comment or notification. --> <!-- If not, write "no" or "do not publish to changelog" to explicitly opt-out of posting to #changelog. Removing this entire section will not prevent posting. -->
1 parent dd46aa3 commit b5fdc6e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

frontend/src/scenes/product-tours/editor/BannerSettingsPanel.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useActions, useValues } from 'kea'
22

3-
import { LemonInput, LemonSegmentedButton, LemonSelect } from '@posthog/lemon-ui'
3+
import { LemonInput, LemonSegmentedButton, LemonSelect, LemonSwitch, Tooltip } from '@posthog/lemon-ui'
44

55
import { ProductTourBannerConfig } from '~/types'
66

@@ -20,6 +20,7 @@ export function BannerSettingsPanel({ tourId }: BannerSettingsPanelProps): JSX.E
2020

2121
const behavior = step.bannerConfig?.behavior ?? 'sticky'
2222
const actionType = step.bannerConfig?.action?.type ?? 'none'
23+
const animateIn = (step.bannerConfig?.animation?.duration ?? 0) > 0
2324

2425
const updateBannerConfig = (updates: Partial<ProductTourBannerConfig>): void => {
2526
updateSelectedStep({
@@ -45,7 +46,7 @@ export function BannerSettingsPanel({ tourId }: BannerSettingsPanelProps): JSX.E
4546
<div className="py-3 px-4">
4647
<div className="flex gap-10">
4748
<div className="flex-1 min-w-0 space-y-4">
48-
<div className="flex items-center justify-between gap-4">
49+
<div className="flex flex-col items-start gap-2">
4950
<div>
5051
<div className="font-medium text-sm">Position</div>
5152
<div className="text-muted text-xs">
@@ -81,6 +82,20 @@ export function BannerSettingsPanel({ tourId }: BannerSettingsPanelProps): JSX.E
8182
fullWidth
8283
/>
8384
)}
85+
<div className="flex items-center gap-2">
86+
<Tooltip title="Banner slides in from the top of the page with a brief animation. When disabled, the banner will appear suddenly after page load, potentially causing a layout shift.">
87+
<div className="font-medium text-sm">Animate in</div>
88+
</Tooltip>
89+
<LemonSwitch
90+
data-attr="product-tours-banner-animation-toggle"
91+
checked={animateIn}
92+
onChange={(checked) =>
93+
updateBannerConfig({
94+
animation: { duration: checked ? 300 : 0 },
95+
})
96+
}
97+
/>
98+
</div>
8499
</div>
85100

86101
<div className="flex-1 min-w-0 space-y-3">

frontend/src/scenes/product-tours/productToursLogic.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ function createDefaultBannerContent(): ProductTourContent {
184184
action: {
185185
type: 'none',
186186
},
187+
animation: {
188+
duration: 300,
189+
},
187190
},
188191
},
189192
],

frontend/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,9 @@ export interface ProductTourBannerConfig {
33773377
link?: string
33783378
tourId?: string
33793379
}
3380+
animation?: {
3381+
duration: number
3382+
}
33803383
}
33813384

33823385
export type ProductTourButtonAction = 'dismiss' | 'link' | 'next_step' | 'previous_step' | 'trigger_tour'

0 commit comments

Comments
 (0)