Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

6.2 KB
Raw Blame
@import '../../../../frontend/src/lib/components/ProductEmptyState/previewMixins';

.InsightPreview {
    --insight-preview-accent: var(--empty-state-accent, var(--color-product-product-analytics-light));

    display: flex;
    flex-direction: column;

    // Hidden breakdown state. A direct child of .InsightPreview so `:checked ~` reaches the card.
    &__checkbox {
        position: absolute;
        width: 0;
        height: 0;
        pointer-events: none;
        opacity: 0;
    }

    &__card {
        overflow: hidden;
        background: var(--color-bg-surface-primary);
        border: 1px solid var(--color-border-primary);
        border-radius: var(--radius);
    }

    // Before/after pairs are stacked on one grid cell and crossfaded, so turning the
    // breakdown on never changes any element's size (no layout shift).
    &__swap {
        display: grid;
    }

    &__swap > * {
        grid-area: 1 / 1;
        min-width: 0;
    }

    &__when-after {
        @include preview-swap-hidden;
    }

    &__when-before {
        @include preview-swap-visible;
    }

    &__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.5rem 0.75rem;
        border-bottom: 1px solid var(--color-border-primary);
    }

    &__title {
        font-size: 0.75rem;
        font-weight: 600;
    }

    // Query row

    &__query {
        display: flex;
        gap: 0.5rem;
        align-items: center;
        padding: 0.5rem 0.75rem;
    }

    &__series-dot {
        width: 7px;
        height: 7px;
        background: var(--insight-preview-accent);
        border-radius: 50%;
    }

    &__series {
        font-size: 0.6875rem;
        font-weight: 600;
    }

    &__breakdown {
        padding: 0.1875rem 0.5rem;
        margin-left: auto;
        font-size: 0.625rem;
        font-weight: 600;
        cursor: pointer;
        user-select: none;
        border: 1px dashed color-mix(in oklab, var(--insight-preview-accent) 45%, transparent);
        border-radius: var(--radius);
        transition: background 150ms ease;

        @include preview-accent-text(var(--insight-preview-accent));
    }

    &__breakdown:hover {
        background: color-mix(in oklab, var(--insight-preview-accent) 10%, transparent);
    }

    // Chart

    &__plot {
        padding: 0 0.75rem;
    }

    &__spark-area {
        fill: color-mix(in oklab, var(--insight-preview-accent) 13%, transparent);
        stroke: none;
    }

    &__spark-line {
        fill: none;
        stroke: color-mix(in oklab, var(--insight-preview-accent) 32%, transparent);
        stroke-width: 2;
    }

    // The three breakdown series step down in weight, so they read as parts of the total.
    &__spark-line--chrome {
        stroke: var(--insight-preview-accent);
    }

    &__spark-line--safari {
        stroke: color-mix(in oklab, var(--insight-preview-accent) 62%, var(--color-text-primary));
    }

    &__spark-line--firefox {
        stroke: color-mix(in oklab, var(--insight-preview-accent) 38%, var(--color-text-primary));
    }

    // The moving bit: a short bright segment cycling along the top line.
    &__spark-trace {
        fill: none;
        stroke: var(--insight-preview-accent);
        stroke-dasharray: 16 84;
        stroke-linecap: round;
        stroke-width: 2;
        animation: InsightPreview__trace 3.2s linear infinite;
    }

    // Legend

    &__legend {
        padding: 0.375rem 0.75rem 0;
    }

    &__legend-slot,
    &__legend-spacer {
        min-height: 3rem;
    }

    &__legend-rows {
        display: flex;
        flex-direction: column;
        gap: 0.1875rem;
    }

    &__legend-row {
        display: flex;
        gap: 0.375rem;
        align-items: center;
        font-size: 0.625rem;
    }

    &__key {
        width: 8px;
        height: 3px;
        border-radius: 999px;
    }

    &__key--chrome {
        background: var(--insight-preview-accent);
    }

    &__key--safari {
        background: color-mix(in oklab, var(--insight-preview-accent) 62%, var(--color-text-primary));
    }

    &__key--firefox {
        background: color-mix(in oklab, var(--insight-preview-accent) 38%, var(--color-text-primary));
    }

    &__legend-value {
        margin-left: auto;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
        color: var(--color-text-secondary);
    }

    &__hint {
        padding: 0.375rem 0.75rem 0.625rem;
        font-size: 0.625rem;
        color: var(--color-text-tertiary);
        text-align: center;
    }

    @include preview-sparkline;
}

// Broken-down state (user turned the breakdown on)

.InsightPreview__checkbox:checked ~ * .InsightPreview__when-after {
    @include preview-swap-visible;
}

.InsightPreview__checkbox:checked ~ * .InsightPreview__when-before {
    @include preview-swap-hidden;
}

.InsightPreview__checkbox:checked ~ .InsightPreview__card .InsightPreview__breakdown {
    background: color-mix(in oklab, var(--insight-preview-accent) 12%, transparent);
    border-style: solid;
}

// The checkbox stays keyboard-focusable while visually hidden, so the control it labels
// needs a visible focus indicator (WCAG 2.4.7).
.InsightPreview__checkbox:focus-visible ~ .InsightPreview__card .InsightPreview__breakdown {
    outline: 2px solid var(--insight-preview-accent);
    outline-offset: 1px;
}

// Nudge attention at the breakdown control until it's used.
.InsightPreview:not(.InsightPreview--static)
    .InsightPreview__checkbox:not(:checked)
    ~ .InsightPreview__card
    .InsightPreview__breakdown {
    animation: InsightPreview__nudge 2.4s ease-in-out infinite;
}

@keyframes InsightPreview__nudge {
    0%,
    100% {
        box-shadow: 0 0 0 0 color-mix(in oklab, var(--insight-preview-accent) 45%, transparent);
    }

    50% {
        box-shadow: 0 0 0 4px color-mix(in oklab, var(--insight-preview-accent) 18%, transparent);
    }
}

// pathLength is normalized to 100, so the dash offset loops cleanly regardless of length.
@keyframes InsightPreview__trace {
    to {
        stroke-dashoffset: -100;
    }
}

// Storybook snapshots and reduced motion drop all ambient motion; turning the
// breakdown on still splits the series (transitions only).
@include preview-motion-guards('InsightPreview');