forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCohortTable.tsx
More file actions
135 lines (129 loc) · 3.64 KB
/
Copy pathCohortTable.tsx
File metadata and controls
135 lines (129 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'use client';
export interface CohortRow {
cohort: string; // e.g. "2024-W01"
size: number;
retention: (number | null)[]; // weeks 0-12, percentage 0-100
}
interface CohortTableProps {
rows: CohortRow[];
}
function retentionColor(pct: number): string {
if (pct >= 80) return '#166534';
if (pct >= 60) return '#15803d';
if (pct >= 40) return '#4ade80';
if (pct >= 20) return '#bbf7d0';
return '#f0fdf4';
}
function textColor(pct: number): string {
return pct >= 40 ? '#ffffff' : '#166534';
}
const WEEKS = Array.from({ length: 13 }, (_, i) => i); // 0-12
export default function CohortTable({ rows }: CohortTableProps) {
return (
<div style={{ overflowX: 'auto' }}>
<table
style={{
borderCollapse: 'collapse',
fontSize: 13,
minWidth: 900,
width: '100%',
}}
>
<thead>
<tr>
<th
style={{
position: 'sticky',
left: 0,
background: '#f8fafc',
zIndex: 1,
padding: '10px 14px',
textAlign: 'left',
fontWeight: 700,
borderBottom: '2px solid #e2e8f0',
whiteSpace: 'nowrap',
}}
>
Cohort
</th>
<th
style={{
padding: '10px 14px',
textAlign: 'right',
fontWeight: 700,
borderBottom: '2px solid #e2e8f0',
whiteSpace: 'nowrap',
}}
>
Users
</th>
{WEEKS.map((w) => (
<th
key={w}
style={{
padding: '10px 10px',
textAlign: 'center',
fontWeight: 700,
borderBottom: '2px solid #e2e8f0',
whiteSpace: 'nowrap',
color: '#64748b',
}}
>
Wk {w}
</th>
))}
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.cohort}>
<td
style={{
position: 'sticky',
left: 0,
background: '#ffffff',
zIndex: 1,
padding: '8px 14px',
fontWeight: 600,
borderBottom: '1px solid #f1f5f9',
whiteSpace: 'nowrap',
}}
>
{row.cohort}
</td>
<td
style={{
padding: '8px 14px',
textAlign: 'right',
borderBottom: '1px solid #f1f5f9',
color: '#475569',
}}
>
{row.size.toLocaleString()}
</td>
{WEEKS.map((w) => {
const pct = row.retention[w];
return (
<td
key={w}
style={{
padding: '8px 10px',
textAlign: 'center',
borderBottom: '1px solid #f1f5f9',
background: pct != null ? retentionColor(pct) : 'transparent',
color: pct != null ? textColor(pct) : '#cbd5e1',
fontWeight: pct != null ? 600 : 400,
borderRadius: 6,
}}
>
{pct != null ? `${pct}%` : '—'}
</td>
);
})}
</tr>
))}
</tbody>
</table>
</div>
);
}