Skip to content

Commit 97c6860

Browse files
authored
Merge pull request #13807 from ethereum/walletTableAbstraction
Product table refactor
2 parents 5d130d2 + ba803de commit 97c6860

File tree

154 files changed

+3420
-3013
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+3420
-3013
lines changed

.storybook/i18next.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export const ns = [
2323
"page-developers-index",
2424
"page-what-is-ethereum",
2525
"page-upgrades-index",
26+
"page-wallets-find-wallet",
2627
"page-developers-docs",
28+
"table",
2729
] as const
2830
const supportedLngs = Object.keys(baseLocales)
2931

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@
4545
"@radix-ui/react-portal": "^1.1.1",
4646
"@radix-ui/react-progress": "^1.1.0",
4747
"@radix-ui/react-radio-group": "^1.2.0",
48+
"@radix-ui/react-select": "^2.1.1",
4849
"@radix-ui/react-slot": "^1.1.0",
4950
"@radix-ui/react-switch": "^1.1.0",
5051
"@radix-ui/react-tabs": "^1.1.0",
5152
"@radix-ui/react-tooltip": "^1.1.2",
5253
"@radix-ui/react-visually-hidden": "^1.1.0",
5354
"@socialgouv/matomo-next": "^1.8.0",
55+
"@tanstack/react-table": "^8.19.3",
5456
"chart.js": "^4.4.2",
5557
"chartjs-plugin-datalabels": "^2.2.0",
5658
"class-variance-authority": "^0.7.0",
@@ -87,6 +89,7 @@
8789
"tailwind-variants": "^0.2.1",
8890
"tailwindcss-animate": "^1.0.7",
8991
"usehooks-ts": "^3.1.0",
92+
"vaul": "^1.0.0",
9093
"yaml-loader": "^0.8.0"
9194
},
9295
"devDependencies": {

src/components/CentralizedExchanges/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import type { ChildOnlyProp, Lang } from "@/lib/types"
55

66
import CardList from "@/components/CardList"
77
import Emoji from "@/components/Emoji"
8-
import Select from "@/components/ui/Select"
8+
import InlineLink from "@/components/ui/Link"
99

1010
import { getLocaleTimestamp } from "@/lib/utils/time"
1111

1212
import { WEBSITE_EMAIL } from "@/lib/constants"
1313

14-
import InlineLink from "../ui/Link"
14+
import Select from "../Select"
1515

1616
import { useCentralizedExchanges } from "@/hooks/useCentralizedExchanges"
1717

src/components/DataTable/index.tsx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { Fragment, useEffect, useRef, useState } from "react"
2+
import {
3+
ColumnDef,
4+
flexRender,
5+
getCoreRowModel,
6+
getExpandedRowModel,
7+
useReactTable,
8+
} from "@tanstack/react-table"
9+
10+
import {
11+
Table,
12+
TableBody,
13+
TableCell,
14+
TableHeader,
15+
TableProps,
16+
TableRow,
17+
} from "@/components/ui/Table"
18+
19+
type DataTableProps<TData, TValue> = TableProps & {
20+
columns: ColumnDef<TData, TValue>[]
21+
data: TData[]
22+
subComponent?: React.FC<TData>
23+
noResultsComponent?: React.FC
24+
}
25+
26+
const DataTable = <TData, TValue>({
27+
columns,
28+
data,
29+
subComponent,
30+
noResultsComponent,
31+
...props
32+
}: DataTableProps<TData, TValue>) => {
33+
const [isVisible, setIsVisible] = useState(true)
34+
const [currentData, setCurrentData] = useState(data)
35+
const previousDataRef = useRef(data)
36+
37+
const table = useReactTable({
38+
data: currentData,
39+
columns,
40+
getRowCanExpand: () => true,
41+
getCoreRowModel: getCoreRowModel(),
42+
getExpandedRowModel: getExpandedRowModel(),
43+
})
44+
45+
useEffect(() => {
46+
if (JSON.stringify(data) !== JSON.stringify(previousDataRef.current)) {
47+
setIsVisible(false)
48+
const timer = setTimeout(() => {
49+
setCurrentData(data)
50+
setIsVisible(true)
51+
previousDataRef.current = data
52+
}, 25) // Adjust this value to match your CSS transition duration
53+
54+
return () => clearTimeout(timer)
55+
}
56+
}, [data])
57+
58+
return (
59+
<Table {...props}>
60+
<TableHeader>
61+
{table.getHeaderGroups().map((headerGroup) => (
62+
<TableRow key={headerGroup.id}>
63+
{headerGroup.headers.map((header) => {
64+
return (
65+
<Fragment key={header.id}>
66+
{header.isPlaceholder
67+
? null
68+
: flexRender(
69+
header.column.columnDef.header,
70+
header.getContext()
71+
)}
72+
</Fragment>
73+
)
74+
})}
75+
</TableRow>
76+
))}
77+
</TableHeader>
78+
<TableBody
79+
className={`duration-25 transition-opacity ${
80+
isVisible ? "opacity-100" : "opacity-0"
81+
}`}
82+
>
83+
{table.getRowModel().rows?.length ? (
84+
table.getRowModel().rows.map((row, idx) => (
85+
<Fragment key={row.id}>
86+
<TableRow
87+
data-state={row.getIsSelected() && "selected"}
88+
className={`${row.getIsExpanded() ? "cursor-pointer border-b-background-highlight bg-background-highlight" : "cursor-pointer"} hover:bg-background-highlight`}
89+
onClick={(e) => {
90+
// Prevent expanding the wallet more info section when clicking on the "Visit website" button
91+
if (!(e.target as Element).matches("a, a svg")) {
92+
row.getToggleExpandedHandler()()
93+
}
94+
}}
95+
>
96+
{row.getVisibleCells().map((cell) => (
97+
<TableCell key={cell.id}>
98+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
99+
</TableCell>
100+
))}
101+
</TableRow>
102+
{row.getIsExpanded() && (
103+
<TableRow className={`bg-background-highlight`}>
104+
<TableCell colSpan={row.getAllCells().length}>
105+
{subComponent && subComponent(row.original, idx)}
106+
</TableCell>
107+
</TableRow>
108+
)}
109+
</Fragment>
110+
))
111+
) : (
112+
<TableRow>
113+
<TableCell colSpan={columns.length} className="h-24 text-center">
114+
{noResultsComponent && noResultsComponent({})}
115+
</TableCell>
116+
</TableRow>
117+
)}
118+
</TableBody>
119+
</Table>
120+
)
121+
}
122+
123+
export default DataTable

src/components/FindWallet/LanguageSupportFilter.tsx

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)