Skip to content
← UI Library

Product tour switcher

A segmented feature switcher that pairs each feature with a headline metric and an animated trend chart.

Svelte 5 · Version 1.0.0 · Zero extra packages

Connect MCP

Live preview

Understand usage

See how many teams used your product this week and which features they opened.

284 Active teams

Design decision

PostHog’s audit shows feature switching paired with recognisable outcomes. Give every panel an example a prospective user can understand.

PostHog audit ↗ · Site score 5

Source and integration

Supply steps with label, heading, description, metric, metricLabel and an optional series of numbers for the chart. Use verified figures for production metrics. Map the --ui-* variables to your tokens.

You may copy and adapt this original SaaSCrisp implementation in personal and commercial websites.

ProductTour.svelte
<script lang="ts">
	type Step = {
		label: string;
		heading: string;
		description: string;
		metric: string;
		metricLabel: string;
		series?: number[];
	};
	let { steps, label = 'Product tour' }: { steps: Step[]; label?: string } = $props();

	const id = $props.id();
	let selected = $state(0);
	let tabs: HTMLButtonElement[] = $state([]);
	let indicator = $state({ x: 0, width: 0, ready: false });

	const step = $derived(steps[selected] ?? steps[0]);
	const chart = $derived(build(step?.series ?? [3, 5, 4, 7, 6, 9, 11]));

	$effect(() => {
		const tab = tabs[selected];
		if (tab) indicator = { x: tab.offsetLeft, width: tab.offsetWidth, ready: true };
	});

	/** Builds a smooth line and filled area in a 100 x 100 box, leaving room for the end dot. */
	function build(series: number[]) {
		const values = series.length > 1 ? series : [0, series[0] ?? 0];
		const min = Math.min(...values);
		const span = Math.max(...values) - min || 1;
		const points = values.map((value, index) => ({
			x: (index / (values.length - 1)) * 95,
			y: 90 - ((value - min) / span) * 72
		}));
		let line = `M${points[0].x} ${points[0].y}`;
		for (let index = 0; index < points.length - 1; index++) {
			const [p0, p1, p2, p3] = [-1, 0, 1, 2].map((offset) => points[Math.min(Math.max(index + offset, 0), points.length - 1)]);
			const c1 = { x: p1.x + (p2.x - p0.x) / 6, y: p1.y + (p2.y - p0.y) / 6 };
			const c2 = { x: p2.x - (p3.x - p1.x) / 6, y: p2.y - (p3.y - p1.y) / 6 };
			line += ` C${c1.x.toFixed(2)} ${c1.y.toFixed(2)} ${c2.x.toFixed(2)} ${c2.y.toFixed(2)} ${p2.x.toFixed(2)} ${p2.y.toFixed(2)}`;
		}
		const end = points[points.length - 1];
		return { line, area: `${line} L${end.x} 100 L0 100 Z`, end };
	}

	function choose(index: number, focus = false) {
		selected = (index + steps.length) % steps.length;
		if (focus) tabs[selected]?.focus();
	}

	function onkeydown(event: KeyboardEvent) {
		const target: Record<string, number> = {
			ArrowRight: selected + 1,
			ArrowLeft: selected - 1,
			Home: 0,
			End: steps.length - 1
		};
		if (event.key in target) {
			event.preventDefault();
			choose(target[event.key], true);
		}
	}
</script>

{#if step}
	<div class="pt">
		<div class="pt-tabs" role="tablist" aria-label={label}>
			<span
				class="pt-indicator"
				class:ready={indicator.ready}
				style:transform="translateX({indicator.x}px)"
				style:width="{indicator.width}px"
				aria-hidden="true"
			></span>
			{#each steps as item, index (item.label)}
				<button
					bind:this={tabs[index]}
					type="button"
					role="tab"
					id="{id}-tab-{index}"
					aria-selected={index === selected}
					aria-controls="{id}-panel"
					tabindex={index === selected ? 0 : -1}
					onclick={() => choose(index)}
					{onkeydown}>{item.label}</button
				>
			{/each}
		</div>

		<div class="pt-panel" role="tabpanel" id="{id}-panel" aria-labelledby="{id}-tab-{selected}">
			{#key selected}
				<div class="pt-grid">
					<div class="pt-copy">
						<h3>{step.heading}</h3>
						<p>{step.description}</p>
						<div class="pt-metric">
							<strong>{step.metric}</strong>
							<span>{step.metricLabel}</span>
						</div>
					</div>
					<div class="pt-chart" aria-hidden="true">
						<div class="pt-chart-head">
							<span>{step.metricLabel}</span>
							<span class="pt-live"><i></i>Last 7 days</span>
						</div>
						<div class="pt-plot">
							<svg viewBox="0 0 100 100" preserveAspectRatio="none">
								<defs>
									<linearGradient id="{id}-fill" x1="0" x2="0" y1="0" y2="1">
										<stop offset="0" stop-color="currentColor" stop-opacity="0.32" />
										<stop offset="1" stop-color="currentColor" stop-opacity="0" />
									</linearGradient>
								</defs>
								{#each [25, 50, 75] as y (y)}<line x1="0" x2="100" y1={y} y2={y} />{/each}
								<path class="pt-area" d={chart.area} fill="url(#{id}-fill)" />
								<path class="pt-line" d={chart.line} />
							</svg>
							<span class="pt-dot" style:left="{chart.end.x}%" style:top="{chart.end.y}%"></span>
						</div>
					</div>
				</div>
			{/key}
		</div>
	</div>
{/if}

<style>
	.pt {
		--_bg: var(--ui-bg, #ffffff);
		--_border: var(--ui-border, rgb(15 23 42 / 0.1));
		--_text: var(--ui-text, #0f172a);
		--_muted: var(--ui-muted, #64748b);
		--_accent: var(--ui-accent, #4f46e5);
		container-type: inline-size;
		display: grid;
		gap: 16px;
		padding: 16px;
		border: 1px solid var(--_border);
		border-radius: var(--ui-radius, 18px);
		background:
			radial-gradient(90% 70% at 100% 0%, color-mix(in srgb, var(--_accent) 7%, transparent), transparent 60%),
			var(--_bg);
		color: var(--_text);
		font-family: var(--ui-font, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif);
		text-align: left;
		box-shadow:
			inset 0 1px 0 rgb(255 255 255 / 0.04),
			0 16px 40px -16px rgb(15 23 42 / 0.12);
	}
	.pt-tabs {
		position: relative;
		display: flex;
		width: fit-content;
		max-width: 100%;
		padding: 3px;
		overflow-x: auto;
		border: 1px solid var(--_border);
		border-radius: 999px;
		background: rgb(15 23 42 / 0.03);
		scrollbar-width: none;
	}
	.pt-indicator {
		position: absolute;
		inset: 3px auto 3px 0;
		border-radius: 999px;
		background: #fff;
		box-shadow:
			0 1px 2px rgb(15 23 42 / 0.12),
			0 0 0 1px rgb(15 23 42 / 0.06);
	}
	.pt-indicator.ready {
		transition:
			transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1),
			width 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
	}
	.pt-tabs button {
		position: relative;
		border: 0;
		border-radius: 999px;
		padding: 7px 16px;
		background: none;
		color: var(--_muted);
		font-family: inherit;
		font-size: 13px;
		font-weight: 500;
		white-space: nowrap;
		cursor: pointer;
		transition: color 0.15s;
	}
	.pt-tabs button:hover,
	.pt-tabs button[aria-selected='true'] {
		color: var(--_text);
	}
	.pt-tabs button:focus-visible {
		outline: 2px solid var(--_accent);
		outline-offset: 1px;
	}
	.pt-grid {
		display: grid;
		gap: 16px;
		animation: pt-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
	}
	@container (min-width: 560px) {
		.pt-grid {
			grid-template-columns: 1fr 1.15fr;
			align-items: center;
			gap: 28px;
		}
		.pt-copy {
			padding-left: 6px;
		}
	}
	h3 {
		margin: 0;
		color: var(--_text);
		font-size: 19px;
		font-weight: 600;
		letter-spacing: -0.015em;
		line-height: 1.3;
	}
	.pt-copy p {
		margin: 8px 0 0;
		color: var(--_muted);
		font-size: 14px;
		line-height: 1.55;
	}
	.pt-metric {
		display: grid;
		gap: 2px;
		margin-top: 20px;
	}
	.pt-metric strong {
		font-size: 36px;
		font-weight: 600;
		font-variant-numeric: tabular-nums;
		letter-spacing: -0.03em;
		line-height: 1.1;
	}
	.pt-metric span {
		color: var(--_muted);
		font-size: 13px;
	}
	.pt-chart {
		margin: 0;
		padding: 14px 14px 0;
		overflow: hidden;
		border: 1px solid var(--_border);
		border-radius: 14px;
		background: rgb(15 23 42 / 0.02);
	}
	.pt-chart-head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 8px;
		color: var(--_muted);
		font-size: 12px;
	}
	.pt-live {
		display: inline-flex;
		align-items: center;
		gap: 6px;
	}
	.pt-live i {
		width: 6px;
		height: 6px;
		border-radius: 50%;
		background: var(--_accent);
		box-shadow: 0 0 0 3px color-mix(in srgb, var(--_accent) 20%, transparent);
	}
	.pt-plot {
		position: relative;
		height: 132px;
		margin: 8px -14px 0;
		color: var(--_accent);
	}
	svg {
		display: block;
		width: 100%;
		height: 100%;
		overflow: visible;
		animation: pt-reveal 0.9s cubic-bezier(0.4, 0, 0.2, 1);
	}
	line {
		stroke: rgb(15 23 42 / 0.06);
		stroke-dasharray: 2 3;
		vector-effect: non-scaling-stroke;
	}
	.pt-line {
		fill: none;
		stroke: currentColor;
		stroke-width: 2;
		stroke-linecap: round;
		vector-effect: non-scaling-stroke;
	}
	.pt-dot {
		position: absolute;
		width: 9px;
		height: 9px;
		margin: -4.5px 0 0 -4.5px;
		border: 2px solid var(--_bg);
		border-radius: 50%;
		background: currentColor;
		box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 22%, transparent);
		animation: pt-fade 0.3s ease-out 0.7s backwards;
	}
	@keyframes pt-in {
		from {
			opacity: 0;
			transform: translateY(4px);
		}
	}
	@keyframes pt-reveal {
		from {
			clip-path: inset(0 100% 0 0);
		}
		to {
			clip-path: inset(0 0 0 0);
		}
	}
	@keyframes pt-fade {
		from {
			opacity: 0;
		}
	}
	@media (prefers-reduced-motion: reduce) {
		.pt-grid,
		svg,
		.pt-dot {
			animation: none;
		}
		.pt-indicator.ready {
			transition: none;
		}
	}
</style>
Agent prompt

Use the SaaSCrisp UI Library MCP at https://www.saascrisp.com/api/library/mcp. Retrieve product-tour version 1.0.0 for svelte with get_ui_asset. Preview: https://www.saascrisp.com/library/product-tour. Confirm the project's stack, reuse local primitives and map CSS variables to existing design tokens. Integrate the files and run the project's checks. Report changed files and additional dependencies.