mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## What kind of change does this PR introduce? Refactor. Follow-up to #49871. ## What is the current behavior? Branded (green) text still uses the `text-brand` classname while the colour comes from `--primary`. ## What is the new behavior? **Rename-only:** `text-brand` → `text-primary` across callsites and docs. Leftover `bg-brand` / `border-brand` alias to `brand-default`. No intentional colour changes in this PR. This better matches how we treat our green in other components and props, like `variant="primary"` for green buttons. ## To test On light mode: smoke-test that branded text still looks like #49871 (readable green, not the bright fill). - [Homepage](https://zone-www-dot-com-git-dnywh-depr-316-text-brand-de2380-supabase.vercel.app/): “Scale to millions” uses `text-primary` - [Docs homepage](https://docs-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/docs): branded links like “More on self-hosting” are still readable - [Typography docs](https://design-system-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/design-system/docs/typography): documents `text-primary` - [Colour usage](https://design-system-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/design-system/docs/color-usage): `text-primary` is visibly darker than `bg-brand-default` _on light mode_ - [Studio auth providers](https://studio-staging-git-dnywh-depr-316-text-brand-to-60fa6c-supabase.vercel.app/dashboard/project/_/auth/providers): enabled provider badge text readable; status dot stays bright green <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Style** * Updated branded text, link hover states, icons, badges, indicators, and highlighted content across the Design System, Docs, Studio, Learn, UI Library, and marketing experiences to use the primary theme color. * Updated syntax highlighting and table-of-contents styling for consistent primary-color presentation. * Refined brand color fallback behavior for bright fills and borders. * **Documentation** * Updated color-usage and typography guidance to recommend the primary text utility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
170 lines
5.8 KiB
TypeScript
170 lines
5.8 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useRef, useState } from 'react'
|
|
|
|
import type { DistributionQuery, SurveyFilters } from '../lib/survey-key'
|
|
import { useDistributionPercent } from './use-distribution'
|
|
import { useYear } from './year-context'
|
|
|
|
const ANIMATION_DURATION = 600
|
|
|
|
export interface StatQuery extends DistributionQuery {
|
|
newIn2026?: boolean
|
|
}
|
|
|
|
interface SurveyStatCardProps {
|
|
label: string
|
|
/** Data-driven percent. Omit when `value` is provided. */
|
|
query?: StatQuery
|
|
/** Static percent to display as-is (for derived/combined figures that don't
|
|
* map to a single column). Overrides `query`. */
|
|
value?: number
|
|
/** Section-level cohort toggle filter, merged on top of the query filters. */
|
|
cohortFilter?: SurveyFilters
|
|
}
|
|
|
|
export function SurveyStatCard({ label, query, value, cohortFilter }: SurveyStatCardProps) {
|
|
const cardRef = useRef<HTMLDivElement>(null)
|
|
const { year } = useYear()
|
|
|
|
const accentBg = 'bg-brand-default'
|
|
const accentText = 'text-primary'
|
|
|
|
// A static `value` wins; otherwise resolve from the embedded dataset for the
|
|
// active year. Returns null when the option/column has no data that year
|
|
// (e.g. a new-in-2026 question viewed at 2025), which renders an em dash.
|
|
const queried = useDistributionPercent(query, cohortFilter)
|
|
const resolvedPercent = value ?? queried
|
|
|
|
const isNewThisYear = resolvedPercent === null && query?.newIn2026 && year < 2026
|
|
|
|
const [displayValue, setDisplayValue] = useState(0)
|
|
const [hasAnimated, setHasAnimated] = useState(false)
|
|
const [shouldAnimateBar, setShouldAnimateBar] = useState(false)
|
|
|
|
// Initial scroll-in animation: count up from 0 to the resolved value the
|
|
// first time the card enters the viewport.
|
|
useEffect(() => {
|
|
if (hasAnimated) return
|
|
if (resolvedPercent === null) return
|
|
|
|
const observer = new IntersectionObserver(
|
|
(entries) => {
|
|
entries.forEach((entry) => {
|
|
if (entry.isIntersecting && !hasAnimated) {
|
|
setHasAnimated(true)
|
|
setShouldAnimateBar(true)
|
|
|
|
const startTime = Date.now()
|
|
const startValue = 0
|
|
const endValue = resolvedPercent
|
|
|
|
const animate = () => {
|
|
const elapsed = Date.now() - startTime
|
|
const progress = Math.min(elapsed / ANIMATION_DURATION, 1)
|
|
const easeOutQuart = 1 - Math.pow(1 - progress, 4)
|
|
setDisplayValue(Math.round(startValue + (endValue - startValue) * easeOutQuart))
|
|
if (progress < 1) requestAnimationFrame(animate)
|
|
}
|
|
|
|
requestAnimationFrame(animate)
|
|
}
|
|
})
|
|
},
|
|
{ threshold: 0.1 }
|
|
)
|
|
|
|
const currentCardRef = cardRef.current
|
|
if (currentCardRef) observer.observe(currentCardRef)
|
|
return () => {
|
|
if (currentCardRef) observer.unobserve(currentCardRef)
|
|
}
|
|
}, [resolvedPercent, hasAnimated])
|
|
|
|
// After the initial animation, snap to the latest resolved value when the
|
|
// year toggle (or cohort toggle) changes.
|
|
useEffect(() => {
|
|
if (!hasAnimated) return
|
|
if (resolvedPercent === null) {
|
|
setDisplayValue(0)
|
|
setShouldAnimateBar(false)
|
|
return
|
|
}
|
|
setDisplayValue(resolvedPercent)
|
|
setShouldAnimateBar(true)
|
|
}, [resolvedPercent, hasAnimated])
|
|
|
|
const hasValue = resolvedPercent !== null
|
|
const renderedBarValue = hasValue ? resolvedPercent : 0
|
|
|
|
return (
|
|
<div ref={cardRef} className="flex-1 px-8 py-8 flex flex-col gap-4">
|
|
{/* Progress bar */}
|
|
<div
|
|
className="h-2 relative overflow-hidden"
|
|
style={
|
|
{
|
|
'--bar-value': renderedBarValue,
|
|
} as React.CSSProperties
|
|
}
|
|
>
|
|
{/* Background pattern for the entire bar */}
|
|
<div
|
|
className="absolute inset-0 pointer-events-none bg-foreground-muted/80"
|
|
style={{
|
|
maskImage: 'url("/images/state-of-startups/pattern-stipple.svg")',
|
|
maskSize: '4px',
|
|
maskRepeat: 'repeat',
|
|
maskPosition: 'center',
|
|
}}
|
|
/>
|
|
|
|
{/* Filled portion of the bar (only when there is a value to show) */}
|
|
{hasValue && (
|
|
<div
|
|
className={`h-full relative bg-surface-100`}
|
|
style={{
|
|
width: `calc(max(0.5%, (var(--bar-value) / 100) * 100%))`,
|
|
clipPath: shouldAnimateBar ? 'inset(0 0 0 0)' : 'inset(0 100% 0 0)',
|
|
transition: `clip-path 0.5s steps(${Math.max(2, Math.floor(((resolvedPercent ?? 0) / 100) * 12))}, end)`,
|
|
}}
|
|
>
|
|
<div
|
|
className={`absolute inset-0 pointer-events-none ${accentBg}`}
|
|
style={{
|
|
maskImage: 'url("/images/state-of-startups/pattern-checker.svg")',
|
|
maskSize: '4px',
|
|
maskRepeat: 'repeat',
|
|
maskPosition: 'top left',
|
|
}}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
{/* Text */}
|
|
<div className="flex flex-col gap-2">
|
|
{hasValue ? (
|
|
<p
|
|
className={`md:-ml-1 md:mt-8 text-2xl md:text-6xl font-mono tracking-tight inline-block flex flex-row items-baseline ${hasAnimated ? accentText : 'text-foreground-muted'} transition-colors duration-1000`}
|
|
>
|
|
{displayValue}
|
|
<span className="md:text-4xl">%</span>
|
|
</p>
|
|
) : (
|
|
<p
|
|
className="md:-ml-1 md:mt-8 text-2xl md:text-6xl font-mono tracking-tight inline-block flex flex-row items-baseline text-foreground-muted"
|
|
aria-label={isNewThisYear ? 'New in 2026' : `No ${year} baseline for this stat`}
|
|
>
|
|
{isNewThisYear ? (
|
|
<span className="text-base md:text-2xl self-center">New in 2026</span>
|
|
) : (
|
|
'—'
|
|
)}
|
|
</p>
|
|
)}
|
|
<p className="text-foreground-light text-sm text-balance md:mr-6">{label}</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|