@podoba/react 0.0.18 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/count-up.tsx +59 -0
- package/src/components/stat-stack.tsx +61 -0
- package/src/components/stats-card.tsx +34 -13
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podoba/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
|
|
6
6
|
"repository": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"typecheck": "tsc --build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@podoba/tokens": "^0.0.
|
|
29
|
-
"@podoba/tailwind": "^0.0.
|
|
28
|
+
"@podoba/tokens": "^0.0.20",
|
|
29
|
+
"@podoba/tailwind": "^0.0.20",
|
|
30
30
|
"react-aria-components": "1.18.0",
|
|
31
31
|
"class-variance-authority": "0.7.1",
|
|
32
32
|
"clsx": "2.1.1",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, type ElementType } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CountUp — animates a number from 0 up to `value` on mount (and whenever `value`
|
|
5
|
+
* changes), for the subtle "counting up" effect on dashboard stats. easeOutCubic over
|
|
6
|
+
* ~900ms by default. Respects `prefers-reduced-motion` (renders the final value
|
|
7
|
+
* immediately). Presentational only — pass formatting via `format`.
|
|
8
|
+
*/
|
|
9
|
+
export interface CountUpProps {
|
|
10
|
+
/** Target value to count up to. */
|
|
11
|
+
value: number
|
|
12
|
+
/** Animation duration in ms (default 900). */
|
|
13
|
+
durationMs?: number
|
|
14
|
+
/** Format the displayed number (default `toLocaleString`). */
|
|
15
|
+
format?: (n: number) => string
|
|
16
|
+
/** Element to render as (default `span`). */
|
|
17
|
+
as?: ElementType
|
|
18
|
+
className?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const easeOutCubic = (t: number): number => 1 - Math.pow(1 - t, 3)
|
|
22
|
+
|
|
23
|
+
export function CountUp({
|
|
24
|
+
value,
|
|
25
|
+
durationMs = 900,
|
|
26
|
+
format = (n) => n.toLocaleString(),
|
|
27
|
+
as: Tag = 'span',
|
|
28
|
+
className,
|
|
29
|
+
}: CountUpProps) {
|
|
30
|
+
const [display, setDisplay] = useState(value)
|
|
31
|
+
const rafRef = useRef<number | null>(null)
|
|
32
|
+
const startRef = useRef<number | null>(null)
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (typeof window === 'undefined') return
|
|
36
|
+
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
37
|
+
if (reduce || durationMs <= 0) {
|
|
38
|
+
setDisplay(value)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
startRef.current = null
|
|
42
|
+
const tick = (now: number) => {
|
|
43
|
+
if (startRef.current === null) startRef.current = now
|
|
44
|
+
const progress = Math.min(1, (now - startRef.current) / durationMs)
|
|
45
|
+
setDisplay(Math.round(value * easeOutCubic(progress)))
|
|
46
|
+
if (progress < 1) rafRef.current = requestAnimationFrame(tick)
|
|
47
|
+
}
|
|
48
|
+
rafRef.current = requestAnimationFrame(tick)
|
|
49
|
+
return () => {
|
|
50
|
+
if (rafRef.current !== null) cancelAnimationFrame(rafRef.current)
|
|
51
|
+
}
|
|
52
|
+
}, [value, durationMs])
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Tag className={className} aria-label={format(value)}>
|
|
56
|
+
{format(display)}
|
|
57
|
+
</Tag>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { CountUp } from './count-up'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* StatStack — a "production compass" infographic: a fanned deck of coloured rounded
|
|
6
|
+
* bars, each showing an animated count + label (e.g. 55 Progress · 36 Done · 26
|
|
7
|
+
* Review). Bars cascade with a left inset that shrinks top→bottom and overlap
|
|
8
|
+
* vertically, later bars in front. The counts animate up via <CountUp>. Sits inside a
|
|
9
|
+
* dark data tile. Presentational only.
|
|
10
|
+
*/
|
|
11
|
+
export type StatStackTone = 'neutral' | 'green' | 'mint' | 'yellow' | 'pink' | 'blue'
|
|
12
|
+
|
|
13
|
+
const TONE: Record<StatStackTone, string> = {
|
|
14
|
+
// Fixed decorative chip colours (they sit on a dark tile in both themes, so they
|
|
15
|
+
// do NOT theme-flip); dark text reads on all of them.
|
|
16
|
+
neutral: 'bg-[#eae7e0] text-fg',
|
|
17
|
+
green: 'bg-brand-green text-fg',
|
|
18
|
+
mint: 'bg-accent-mint text-fg',
|
|
19
|
+
yellow: 'bg-accent-yellow text-fg',
|
|
20
|
+
pink: 'bg-accent-pink text-fg',
|
|
21
|
+
blue: 'bg-accent-blue text-white',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface StatStackSegment {
|
|
25
|
+
value: number
|
|
26
|
+
label: ReactNode
|
|
27
|
+
tone: StatStackTone
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface StatStackProps {
|
|
31
|
+
segments: StatStackSegment[]
|
|
32
|
+
className?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function StatStack({ segments, className }: StatStackProps) {
|
|
36
|
+
const n = segments.length
|
|
37
|
+
return (
|
|
38
|
+
<div className={['flex flex-col', className].filter(Boolean).join(' ')}>
|
|
39
|
+
{segments.map((s, i) => (
|
|
40
|
+
<div
|
|
41
|
+
key={i}
|
|
42
|
+
className={[
|
|
43
|
+
'flex items-baseline gap-2 rounded-lg px-5 py-4 shadow-sm',
|
|
44
|
+
TONE[s.tone],
|
|
45
|
+
].join(' ')}
|
|
46
|
+
style={{
|
|
47
|
+
// Cascade: most-inset at the top, flush-left at the bottom; overlap the
|
|
48
|
+
// bar above; later bars sit in front.
|
|
49
|
+
marginLeft: `${(n - 1 - i) * 1.75}rem`,
|
|
50
|
+
marginRight: `${i * 1.25}rem`,
|
|
51
|
+
marginTop: i === 0 ? 0 : '-1rem',
|
|
52
|
+
zIndex: i + 1,
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<CountUp value={s.value} className="text-heading1 font-medium leading-none" />
|
|
56
|
+
<span className="text-heading3 font-medium leading-none">{s.label}</span>
|
|
57
|
+
</div>
|
|
58
|
+
))}
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
@@ -40,6 +40,15 @@ export type StatsCardProps = {
|
|
|
40
40
|
children?: ReactNode
|
|
41
41
|
/** Dark/inverted surface (gs's dark "Cloud" tile). */
|
|
42
42
|
dark?: boolean
|
|
43
|
+
/**
|
|
44
|
+
* Vertical placement of the value band. `center` (default) is gs's
|
|
45
|
+
* `contentAlign="center"` hero-count tile (value fills + centres, footer pinned
|
|
46
|
+
* bottom). `top` sits the value directly under the eyebrow (gs's dark "Summary"
|
|
47
|
+
* data tile) with the footer pushed to the bottom.
|
|
48
|
+
*/
|
|
49
|
+
align?: 'center' | 'top'
|
|
50
|
+
/** Mute the value colour (gs's Summary tile — a descriptive title, not a hero count). */
|
|
51
|
+
subtleValue?: boolean
|
|
43
52
|
/** Accessible label for the clickable card (defaults to nothing — title is read). */
|
|
44
53
|
'aria-label'?: string
|
|
45
54
|
className?: string
|
|
@@ -61,7 +70,11 @@ function StatsCardBody({
|
|
|
61
70
|
badge,
|
|
62
71
|
description,
|
|
63
72
|
dark,
|
|
64
|
-
|
|
73
|
+
align = 'center',
|
|
74
|
+
subtleValue = false,
|
|
75
|
+
}: Pick<StatsCardProps, 'title' | 'value' | 'footer' | 'badge' | 'description' | 'dark' | 'align' | 'subtleValue'>) {
|
|
76
|
+
const isTop = align === 'top'
|
|
77
|
+
const valueTone = dark ? (subtleValue ? 'text-white/60' : 'text-white') : subtleValue ? 'text-fg-muted' : 'text-fg'
|
|
65
78
|
return (
|
|
66
79
|
<>
|
|
67
80
|
<div className="flex items-center justify-between gap-2">
|
|
@@ -76,21 +89,27 @@ function StatsCardBody({
|
|
|
76
89
|
</span>
|
|
77
90
|
) : null}
|
|
78
91
|
{/*
|
|
79
|
-
* gs
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* (1.875rem / 500 / 2rem line). Letter-spacing tracks gs 1:1: light
|
|
84
|
-
* -0.56px via `tracking-wide`; the dark
|
|
92
|
+
* `center` (gs `contentAlign="center"`): the value sits in the CENTRE band —
|
|
93
|
+
* `flex-1` grows to fill the tile and vertically centres it, pushing any footer
|
|
94
|
+
* to the bottom. `top`: the value sits directly under the eyebrow (no grow) and
|
|
95
|
+
* the footer takes `mt-auto` to stay pinned at the bottom. Value ramp = gs
|
|
96
|
+
* label-1 (1.875rem / 500 / 2rem line). Letter-spacing tracks gs 1:1: light
|
|
97
|
+
* tiles use -0.56px via `tracking-wide`; the dark count tile uses gs's em-based
|
|
85
98
|
* `-0.02em` (`AssetsTile.module.scss .count`).
|
|
86
99
|
*/}
|
|
87
100
|
<span
|
|
88
|
-
className={`flex flex-1 items-center text-display font-medium leading-[2rem] ${dark ? 'tracking-normal
|
|
101
|
+
className={`flex ${isTop ? 'items-start pt-6' : 'flex-1 items-center'} text-display font-medium leading-[2rem] ${dark ? 'tracking-normal' : 'tracking-wide'} ${valueTone}`}
|
|
89
102
|
>
|
|
90
|
-
{
|
|
103
|
+
{/*
|
|
104
|
+
* Inner wrapper is deliberate: the band is a flex container, and flex
|
|
105
|
+
* TRIMS the leading whitespace of an anonymous text run — so a value of
|
|
106
|
+
* `<CountUp/> {' '} unit` collapses to "1version". Nesting the value in one
|
|
107
|
+
* inline span makes it a single flex item, preserving the internal space.
|
|
108
|
+
*/}
|
|
109
|
+
<span>{value}</span>
|
|
91
110
|
</span>
|
|
92
111
|
{footer ? (
|
|
93
|
-
<span className={
|
|
112
|
+
<span className={`${isTop ? 'mt-auto ' : ''}pt-4 text-small leading-5 ${dark ? 'text-white/50' : 'text-fg-muted'}`}>
|
|
94
113
|
{footer}
|
|
95
114
|
</span>
|
|
96
115
|
) : null}
|
|
@@ -126,6 +145,8 @@ export function StatsCard({
|
|
|
126
145
|
asChild,
|
|
127
146
|
children,
|
|
128
147
|
dark,
|
|
148
|
+
align,
|
|
149
|
+
subtleValue,
|
|
129
150
|
className,
|
|
130
151
|
...rest
|
|
131
152
|
}: StatsCardProps) {
|
|
@@ -136,7 +157,7 @@ export function StatsCard({
|
|
|
136
157
|
const cardClass = [baseSurface, dark ? darkSkin : lightSkin, anchorInteractive, child.props.className, className]
|
|
137
158
|
.filter(Boolean)
|
|
138
159
|
.join(' ')
|
|
139
|
-
return cloneElement(child, { className: cardClass } as { className: string }, <StatsCardBody title={title} value={value} footer={footer} badge={badge} description={description} dark={dark} />)
|
|
160
|
+
return cloneElement(child, { className: cardClass } as { className: string }, <StatsCardBody title={title} value={value} footer={footer} badge={badge} description={description} dark={dark} align={align} subtleValue={subtleValue} />)
|
|
140
161
|
}
|
|
141
162
|
|
|
142
163
|
if (onPress) {
|
|
@@ -148,13 +169,13 @@ export function StatsCard({
|
|
|
148
169
|
className={[dark ? darkSkin : '', className].filter(Boolean).join(' ')}
|
|
149
170
|
aria-label={rest['aria-label']}
|
|
150
171
|
>
|
|
151
|
-
<StatsCardBody title={title} value={value} footer={footer} badge={badge} description={description} dark={dark} />
|
|
172
|
+
<StatsCardBody title={title} value={value} footer={footer} badge={badge} description={description} dark={dark} align={align} subtleValue={subtleValue} />
|
|
152
173
|
</PressableCard>
|
|
153
174
|
)
|
|
154
175
|
}
|
|
155
176
|
return (
|
|
156
177
|
<div className={[baseSurface, dark ? darkSkin : lightSkin, className].filter(Boolean).join(' ')}>
|
|
157
|
-
<StatsCardBody title={title} value={value} footer={footer} badge={badge} description={description} dark={dark} />
|
|
178
|
+
<StatsCardBody title={title} value={value} footer={footer} badge={badge} description={description} dark={dark} align={align} subtleValue={subtleValue} />
|
|
158
179
|
</div>
|
|
159
180
|
)
|
|
160
181
|
}
|
package/src/index.ts
CHANGED
|
@@ -52,8 +52,10 @@ export * from "./layout/persistent-page-shell";
|
|
|
52
52
|
|
|
53
53
|
// --- product patterns (label-driven; no domain coupling) ---
|
|
54
54
|
export * from "./components/brand-page-header";
|
|
55
|
+
export * from "./components/count-up";
|
|
55
56
|
export * from "./components/cta-pill";
|
|
56
57
|
export * from "./components/feature-tile";
|
|
58
|
+
export * from "./components/stat-stack";
|
|
57
59
|
export * from "./components/icons";
|
|
58
60
|
export * from "./components/subtle";
|
|
59
61
|
export * from "./components/stats-card";
|