@podoba/react 0.0.18 → 0.0.19
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/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.19",
|
|
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.19",
|
|
29
|
+
"@podoba/tailwind": "^0.0.19",
|
|
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
|
+
}
|
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";
|