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.

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

.SurveysPreview {
    --surveys-preview-accent: var(--empty-state-accent, var(--color-primary-500));

    display: flex;
    flex-direction: column;
    gap: 0.75rem;

    // Hidden answered state. A direct child of .SurveysPreview so `:checked ~` reaches both cards.
    &__checkbox {
        position: absolute;
        width: 0;
        height: 0;
        pointer-events: none;
        opacity: 0;
    }

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

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

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

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

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

    // Mini app with the survey popover

    &__chrome {
        display: flex;
        gap: 0.375rem;
        align-items: center;
        padding: 0.4375rem 0.75rem;
        border-bottom: 1px solid var(--color-border-primary);
    }

    &__url {
        margin-left: 0.375rem;
        font-family: var(--font-mono);
        font-size: 0.625rem;
        color: var(--color-text-secondary);
    }

    &__screen {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem;
    }

    &__page {
        display: flex;
        flex-direction: column;
        gap: 0.375rem;
    }

    &__page-line {
        height: 0.5rem;
        background: var(--color-bg-fill-tertiary);
        border-radius: 999px;
    }

    &__page-line--short {
        width: 55%;
    }

    // The in-app survey popover, bottom-right like the real widget.
    &__popover {
        align-self: flex-end;
        width: 88%;
        padding: 0.625rem 0.75rem;
        background: var(--color-bg-surface-primary);
        border: 1px solid var(--color-border-primary);
        border-radius: var(--radius);
        box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
    }

    &__question {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

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

    &__scale {
        display: grid;
        grid-template-columns: repeat(11, 1fr);
        gap: 0.1875rem;
    }

    &__score {
        padding: 0.25rem 0;
        font-size: 0.625rem;
        font-variant-numeric: tabular-nums;
        text-align: center;
        border: 1px solid var(--color-border-primary);
        border-radius: var(--radius);
    }

    &__score--hero {
        cursor: pointer;
        user-select: none;
        transition:
            background-color 150ms ease,
            color 150ms ease;
    }

    &__score--hero:hover {
        background: var(--color-bg-fill-highlight-50);
    }

    &__scale-labels {
        display: flex;
        justify-content: space-between;
        font-size: 0.5625rem;
        color: var(--color-text-tertiary);
    }

    &__thanks {
        align-self: center;
        font-size: 0.75rem;
        font-weight: 600;
        text-align: center;

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

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

    // Results card

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

    &__title {
        display: flex;
        gap: 0.375rem;
        align-items: center;
        font-size: 0.75rem;
        font-weight: 600;
    }

    &__live-dot {
        width: 7px;
        height: 7px;
        background: var(--surveys-preview-accent);
        border-radius: 50%;
        animation: SurveysPreview__pulse 2s ease-in-out infinite;
    }

    &__stats {
        display: flex;
        gap: 2rem;
        padding: 0.625rem 0.75rem 0.25rem;
    }

    &__stat {
        display: flex;
        flex-direction: column;
    }

    &__stat-label {
        font-size: 0.625rem;
        font-weight: 600;
        color: var(--color-text-secondary);
    }

    &__stat-value {
        font-size: 1.25rem;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        line-height: 1.2;
    }

    &__stat-value--bumped {
        @include preview-accent-text(var(--surveys-preview-accent));
    }

    // Detractors/passives/promoters distribution. The promoter share grows on answer.
    &__bar {
        display: flex;
        gap: 2px;
        height: 8px;
        margin: 0.375rem 0.75rem 0.25rem;
        overflow: hidden;
        border-radius: 999px;
    }

    &__bar-detractors {
        width: 18%;
        background: color-mix(in oklab, var(--danger) 55%, transparent);
        transition: width 400ms ease;
    }

    &__bar-passives {
        width: 30%;
        background: var(--color-bg-fill-tertiary);
        transition: width 400ms ease;
    }

    &__bar-promoters {
        flex: 1;
        background: var(--surveys-preview-accent);
    }

    &__legend {
        display: flex;
        gap: 0.75rem;
        padding: 0 0.75rem;
        font-size: 0.5625rem;
        color: var(--color-text-tertiary);
    }

    &__quote {
        padding: 0.5rem 0.75rem 0.625rem;
        font-size: 0.6875rem;
        color: var(--color-text-secondary);
    }

    &__quote--fresh {
        font-weight: 600;

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

    @include preview-chrome-dot;
}

// Answered state (user clicked a score)

.SurveysPreview__checkbox:checked ~ * .SurveysPreview__when-answered {
    @include preview-swap-visible;
}

.SurveysPreview__checkbox:checked ~ * .SurveysPreview__when-unanswered {
    @include preview-swap-hidden;
}

.SurveysPreview__checkbox:checked ~ .SurveysPreview__app .SurveysPreview__score--hero {
    color: var(--color-bg-surface-primary);
    background: var(--surveys-preview-accent);
}

// One more promoter shifts the distribution.
.SurveysPreview__checkbox:checked ~ .SurveysPreview__results .SurveysPreview__bar-detractors {
    width: 16%;
}

.SurveysPreview__checkbox:checked ~ .SurveysPreview__results .SurveysPreview__bar-passives {
    width: 28%;
}

// The checkbox stays keyboard-focusable while visually hidden, so the score it labels
// needs a visible focus indicator (WCAG 2.4.7).
.SurveysPreview__checkbox:focus-visible ~ .SurveysPreview__app .SurveysPreview__score--hero {
    outline: 2px solid var(--surveys-preview-accent);
    outline-offset: 1px;
}

// Nudge attention at the hero score until it's clicked.
.SurveysPreview:not(.SurveysPreview--static)
    .SurveysPreview__checkbox:not(:checked)
    ~ .SurveysPreview__app
    .SurveysPreview__score--hero {
    animation: SurveysPreview__nudge 2.4s ease-in-out infinite;
}

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

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

@keyframes SurveysPreview__pulse {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

// Storybook snapshots and reduced motion drop all ambient motion; clicking the
// score still flips the state (transitions only).
@include preview-motion-guards('SurveysPreview');