Skip to content

Commit 6acef46

Browse files
committed
feat(product tours): add banner animations
1 parent 36713c1 commit 6acef46

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

.changeset/wet-hands-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'posthog-js': patch
3+
---
4+
5+
add animation option for tour banners

packages/browser/src/extensions/product-tours/components/ProductTourBanner.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ function StaticWrapper({ class: className, children }: BannerWrapperProps): h.JS
5656
return <div class={className}>{children}</div>
5757
}
5858

59-
export function ProductTourBanner({
59+
export function ProductTourBanner(props: ProductTourBannerProps) {
60+
return (
61+
<div class="ph-tour-banner-wrapper">
62+
<div class="ph-tour-banner-slide">
63+
<ProductTourBannerInner {...props} />
64+
</div>
65+
</div>
66+
)
67+
}
68+
69+
function ProductTourBannerInner({
6070
step,
6171
onDismiss,
6272
onActionClick,

packages/browser/src/extensions/product-tours/product-tour.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,25 @@
560560
}
561561

562562
/* Banner styles */
563+
@keyframes ph-tour-banner-slide-in {
564+
from {
565+
grid-template-rows: 0fr;
566+
}
567+
to {
568+
grid-template-rows: 1fr;
569+
}
570+
}
571+
572+
.ph-tour-banner-wrapper {
573+
display: grid;
574+
animation: ph-tour-banner-slide-in var(--ph-tour-banner-animation-duration, 300ms) ease-out forwards;
575+
}
576+
577+
.ph-tour-banner-slide {
578+
overflow: hidden;
579+
min-height: 0;
580+
}
581+
563582
.ph-tour-banner {
564583
display: flex;
565584
align-items: center;

packages/browser/src/extensions/product-tours/product-tours.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { createLogger } from '../../utils/logger'
2828
import { document as _document, window as _window } from '../../utils/globals'
2929
import { localStore, sessionStore } from '../../storage'
3030
import { addEventListener } from '../../utils'
31-
import { isNull, SurveyMatchType } from '@posthog/core'
31+
import { isNull, isUndefined, SurveyMatchType } from '@posthog/core'
3232
import { propertyComparisons } from '../../utils/property-utils'
3333
import {
3434
TOUR_SHOWN_KEY_PREFIX,
@@ -151,6 +151,10 @@ function retrieveBannerShadow(
151151

152152
addProductTourCSSVariablesToElement(div, tour.appearance)
153153

154+
if (!isUndefined(bannerConfig?.animation?.duration)) {
155+
div.style.setProperty('--ph-tour-banner-animation-duration', `${bannerConfig.animation.duration}ms`)
156+
}
157+
154158
const shadow = div.attachShadow({ mode: 'open' })
155159

156160
const stylesheet = getProductTourStylesheet()

packages/browser/src/posthog-product-tours-types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export interface ProductTourBannerConfig {
2222
link?: string
2323
tourId?: string
2424
}
25+
animation?: {
26+
duration?: number
27+
}
2528
}
2629

2730
/** Button actions available on modal steps */

playground/nextjs/pages/product-tours.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export default function ProductTours() {
5353

5454
return (
5555
<div className="p-6 max-w-4xl mx-auto">
56+
<div id="playground-banner-container"></div>
57+
5658
<h1 className="text-2xl font-bold mb-6">Product Tours Playground</h1>
5759

5860
{/* Tour Controls */}

0 commit comments

Comments
 (0)