|
1 |
| -import React, { useState } from "react"; |
| 1 | +import React, { useState, useEffect, useRef } from "react"; |
| 2 | +import Table from "../common/table/Table"; |
| 3 | +import TableHeader from "../common/table/TableHeader"; |
| 4 | +import TableHeaderCell from "../common/table/TableHeaderCell"; |
| 5 | +import TableBody from "../common/table/TableBody"; |
| 6 | +import TableRow from "../common/table/TableRow"; |
| 7 | +import TableRowCell from "../common/table/TableRowCell"; |
2 | 8 | import Tab from "../common/Tab";
|
| 9 | +import useWindowWidth from "../../hooks/useviewport"; |
3 | 10 |
|
4 | 11 | export default function SdvInNumbersSection() {
|
| 12 | + const metricKeys = ["toDate", "monthly", "yearToDate"]; |
| 13 | + const metricLabels = ["To date", "Monthly", "Year to date"]; |
| 14 | + const [tableColDimensions, setTableColDimensions] = useState( |
| 15 | + "minmax(204px, 204px) minmax(181px, 348px) minmax(181px, 348px) minmax(181px, 348px)" |
| 16 | + ); |
| 17 | + const data = [ |
| 18 | + { name: "SDV", toDate: "8M", monthly: "131K", yearToDate: "10M" }, |
| 19 | + { name: "Gretle", toDate: "998K", monthly: "16K", yearToDate: "1M" }, |
| 20 | + { name: "Synthesized", toDate: "269K", monthly: "4K", yearToDate: "323K" }, |
| 21 | + { name: "YData", toDate: "221K", monthly: "3K", yearToDate: "405K" }, |
| 22 | + { name: "SynthCity", toDate: "84K", monthly: "1,413", yearToDate: "106K" }, |
| 23 | + { |
| 24 | + name: "Realtabformer", |
| 25 | + toDate: "78K", |
| 26 | + monthly: "1,304", |
| 27 | + yearToDate: "97K", |
| 28 | + }, |
| 29 | + { name: "Datomize", toDate: "73K", monthly: "1,216", yearToDate: "81K" }, |
| 30 | + { |
| 31 | + name: "Smartnoise", |
| 32 | + toDate: "68K", |
| 33 | + monthly: "1,134", |
| 34 | + yearToDate: "92K", |
| 35 | + }, |
| 36 | + { name: "Be-great", toDate: "66K", monthly: "1,101", yearToDate: "90K" }, |
| 37 | + { name: "Mostly-AI", toDate: "22K", monthly: "373", yearToDate: "62K" }, |
| 38 | + ]; |
| 39 | + const width = useWindowWidth(); |
| 40 | + const isMobile = width < 768; |
| 41 | + |
| 42 | + const [activeMetricIndex, setActiveMetricIndex] = useState(0); |
| 43 | + const touchStartX = useRef(null); |
| 44 | + |
| 45 | + useEffect(() => { |
| 46 | + setTableColDimensions( |
| 47 | + isMobile |
| 48 | + ? "minmax(204px, 204px) minmax(181px, 348px)" |
| 49 | + : "minmax(204px, 204px) minmax(181px, 348px) minmax(181px, 348px) minmax(181px, 348px)" |
| 50 | + ); |
| 51 | + }, [isMobile]); |
| 52 | + |
| 53 | + const handleSwipeStart = (e) => { |
| 54 | + touchStartX.current = e.touches[0].clientX; |
| 55 | + }; |
| 56 | + |
| 57 | + const handleSwipeMove = (e) => { |
| 58 | + if (touchStartX.current === null) return; |
| 59 | + const deltaX = e.touches[0].clientX - touchStartX.current; |
| 60 | + const threshold = 50; |
| 61 | + |
| 62 | + if (deltaX > threshold) { |
| 63 | + setActiveMetricIndex((prev) => Math.max(prev - 1, 0)); |
| 64 | + touchStartX.current = null; |
| 65 | + } else if (deltaX < -threshold) { |
| 66 | + setActiveMetricIndex((prev) => Math.min(prev + 1, metricKeys.length - 1)); |
| 67 | + touchStartX.current = null; |
| 68 | + } |
| 69 | + }; |
| 70 | + |
5 | 71 | const [tabs, setTabs] = useState([
|
6 | 72 | { label: "Downloads", isActive: true },
|
7 | 73 | { label: "Users", isActive: false },
|
@@ -42,6 +108,130 @@ export default function SdvInNumbersSection() {
|
42 | 108 | </Tab>
|
43 | 109 | ))}
|
44 | 110 | </div>
|
| 111 | + <Table tableColDimensions={tableColDimensions}> |
| 112 | + <TableHeader> |
| 113 | + <div className="relative"> |
| 114 | + <TableHeaderCell /> |
| 115 | + |
| 116 | + {isMobile && ( |
| 117 | + <div className="absolute right-0 top-0 h-full w-6 z-50 pointer-events-none"> |
| 118 | + <div |
| 119 | + className="h-full w-full" |
| 120 | + style={{ |
| 121 | + background: |
| 122 | + "linear-gradient(270deg, rgba(255, 255, 255, 0.00) 0%, rgba(255, 255, 255, 0.01) 100%)", |
| 123 | + boxShadow: "7px 0px 20px -10px rgba(0, 0, 54, 0.14)", |
| 124 | + }} |
| 125 | + /> |
| 126 | + </div> |
| 127 | + )} |
| 128 | + </div> |
| 129 | + {isMobile ? ( |
| 130 | + <div |
| 131 | + onTouchStart={handleSwipeStart} |
| 132 | + onTouchMove={handleSwipeMove} |
| 133 | + className="touch-pan-x w-full" |
| 134 | + > |
| 135 | + <TableHeaderCell> |
| 136 | + {metricLabels[activeMetricIndex]} |
| 137 | + </TableHeaderCell> |
| 138 | + </div> |
| 139 | + ) : ( |
| 140 | + <> |
| 141 | + <TableHeaderCell>To date</TableHeaderCell> |
| 142 | + <TableHeaderCell>Monthly</TableHeaderCell> |
| 143 | + <TableHeaderCell>Year to date</TableHeaderCell> |
| 144 | + </> |
| 145 | + )} |
| 146 | + </TableHeader> |
| 147 | + |
| 148 | + <TableBody> |
| 149 | + {data.map((row, idx) => { |
| 150 | + const isLast = idx === data.length - 1; |
| 151 | + |
| 152 | + return ( |
| 153 | + <TableRow key={row.name} index={idx} isLast={isLast}> |
| 154 | + <div className="relative"> |
| 155 | + <TableRowCell> |
| 156 | + <div className="flex font-semibold text-midnight-950"> |
| 157 | + {row.name} |
| 158 | + </div> |
| 159 | + </TableRowCell> |
| 160 | + |
| 161 | + {isMobile && ( |
| 162 | + <div className="absolute right-0 top-0 h-full w-6 z-50 pointer-events-none"> |
| 163 | + <div |
| 164 | + className="h-full w-full" |
| 165 | + style={{ |
| 166 | + background: |
| 167 | + "linear-gradient(270deg, rgba(255, 255, 255, 0.00) 0%, rgba(255, 255, 255, 0.01) 100%)", |
| 168 | + boxShadow: |
| 169 | + "7px 0px 20px -10px rgba(0, 0, 54, 0.14)", |
| 170 | + }} |
| 171 | + /> |
| 172 | + </div> |
| 173 | + )} |
| 174 | + </div> |
| 175 | + {isMobile ? ( |
| 176 | + <div |
| 177 | + onTouchStart={handleSwipeStart} |
| 178 | + onTouchMove={handleSwipeMove} |
| 179 | + className="w-full touch-pan-x" |
| 180 | + > |
| 181 | + <TableRowCell> |
| 182 | + <div |
| 183 | + className={`flex justify-end ${ |
| 184 | + isLast |
| 185 | + ? "font-bold text-midnight-950" |
| 186 | + : "font-normal" |
| 187 | + }`} |
| 188 | + > |
| 189 | + {row[metricKeys[activeMetricIndex]]} |
| 190 | + </div> |
| 191 | + </TableRowCell> |
| 192 | + </div> |
| 193 | + ) : ( |
| 194 | + <> |
| 195 | + <TableRowCell> |
| 196 | + <div |
| 197 | + className={`flex justify-end ${ |
| 198 | + isLast |
| 199 | + ? "font-bold text-midnight-950" |
| 200 | + : "font-normal" |
| 201 | + }`} |
| 202 | + > |
| 203 | + {row.toDate} |
| 204 | + </div> |
| 205 | + </TableRowCell> |
| 206 | + <TableRowCell> |
| 207 | + <div |
| 208 | + className={`flex justify-end ${ |
| 209 | + isLast |
| 210 | + ? "font-bold text-midnight-950" |
| 211 | + : "font-normal" |
| 212 | + }`} |
| 213 | + > |
| 214 | + {row.monthly} |
| 215 | + </div> |
| 216 | + </TableRowCell> |
| 217 | + <TableRowCell> |
| 218 | + <div |
| 219 | + className={`flex justify-end ${ |
| 220 | + isLast |
| 221 | + ? "font-bold text-midnight-950" |
| 222 | + : "font-normal" |
| 223 | + }`} |
| 224 | + > |
| 225 | + {row.yearToDate} |
| 226 | + </div> |
| 227 | + </TableRowCell> |
| 228 | + </> |
| 229 | + )} |
| 230 | + </TableRow> |
| 231 | + ); |
| 232 | + })} |
| 233 | + </TableBody> |
| 234 | + </Table> |
45 | 235 | </div>
|
46 | 236 | </div>
|
47 | 237 | );
|
|
0 commit comments