Skip to content

Commit a2da611

Browse files
committed
refactor: trendingcoins styles
1 parent fc28bc4 commit a2da611

File tree

3 files changed

+67
-31
lines changed

3 files changed

+67
-31
lines changed

app/globals.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,50 @@
233233
}
234234
}
235235

236+
#trending-coins {
237+
@apply w-full flex flex-col justify-center h-full py-4 bg-dark-500 rounded-xl;
238+
239+
h4 {
240+
@apply text-xl md:text-2xl font-semibold mb-2 px-5;
241+
}
242+
243+
.trending-coins-table {
244+
@apply bg-dark-500 overflow-hidden;
245+
246+
.body-row {
247+
@apply overflow-hidden border-none hover:bg-dark-400! rounded-lg;
248+
}
249+
250+
.name-cell {
251+
@apply font-bold;
252+
253+
a {
254+
@apply pl-1 md:pl-2 py-1 md:py-2 xl:py-1 flex items-center gap-2 md:gap-3;
255+
256+
img {
257+
@apply rounded-full size-8 md:size-9;
258+
}
259+
260+
p {
261+
@apply text-sm md:text-base;
262+
}
263+
}
264+
}
265+
266+
.change-cell {
267+
@apply font-medium py-4 pr-3 md:pr-5;
268+
}
269+
270+
.price-cell {
271+
@apply font-bold pr-5 text-sm max-w-full truncate;
272+
}
273+
274+
.price-change {
275+
@apply flex gap-1 items-center text-sm font-medium;
276+
}
277+
}
278+
}
279+
236280
.table-header-cell {
237281
@apply text-purple-100;
238282
}

components/DataTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const DataTable = <T,>({
1919
bodyRowClassName,
2020
}: DataTableProps<T>) => {
2121
return (
22-
<Table className={tableClassName}>
22+
<Table className={cn('custom-scrollbar', tableClassName)}>
2323
<TableHeader className={headerClassName}>
2424
<TableRow className={cn('hover:bg-transparent!', headerRowClassName)}>
2525
{columns.map((column, columnIndex) => (

components/home/TrendingCoins.tsx

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
1+
import Image from 'next/image';
2+
import Link from 'next/link';
3+
import { TrendingDown, TrendingUp } from 'lucide-react';
4+
15
import { DataTable } from '@/components/DataTable';
26
import { getTrendingCoins } from '@/lib/coingecko.actions';
37
import { cn, formatPercentage, formatPrice } from '@/lib/utils';
4-
import { TrendingDown, TrendingUp } from 'lucide-react';
5-
import Image from 'next/image';
6-
import Link from 'next/link';
78

89
export const TrendingCoins = async () => {
910
const trendingCoins = (await getTrendingCoins()) as TrendingCoin[];
11+
1012
const columns = [
1113
{
1214
header: 'Name',
13-
cellClassName: 'font-bold',
15+
cellClassName: 'name-cell',
1416
cell: (coin: TrendingCoin) => {
1517
const item = coin.item;
1618

1719
return (
18-
<Link href={`/coins/${item.id}`} className='coin-link'>
19-
<Image
20-
src={item.large}
21-
alt={item.name}
22-
width={36}
23-
height={36}
24-
className='coin-image'
25-
/>
26-
<div>
27-
<p className='text-sm md:text-base'>{item.name}</p>
28-
</div>
20+
<Link href={`/coins/${item.id}`}>
21+
<Image src={item.large} alt={item.name} width={36} height={36} />
22+
<p>{item.name}</p>
2923
</Link>
3024
);
3125
},
3226
},
3327
{
3428
header: '24h Change',
35-
cellClassName: 'table-cell-change',
29+
cellClassName: 'change-cell',
3630
cell: (coin: TrendingCoin) => {
3731
const item = coin.item;
3832
const isTrendingUp = item.data.price_change_percentage_24h.usd > 0;
3933

4034
return (
4135
<div
4236
className={cn(
43-
'price-change-indicator',
37+
'price-change',
4438
isTrendingUp ? 'text-green-500' : 'text-red-500'
4539
)}
4640
>
@@ -56,26 +50,24 @@ export const TrendingCoins = async () => {
5650
},
5751
{
5852
header: 'Price',
59-
cellClassName: 'table-cell-price',
53+
cellClassName: 'price-cell',
6054
cell: (coin: TrendingCoin) => {
6155
return formatPrice(coin.item.data.price);
6256
},
6357
},
6458
];
6559

6660
return (
67-
<div className='top-movers-container'>
68-
<h4 className='section-title px-5'>Trending Coins</h4>
69-
<div className='table-scrollbar-container custom-scrollbar'>
70-
<DataTable
71-
columns={columns}
72-
data={trendingCoins.slice(0, 6)}
73-
rowKey={(_, index) => index}
74-
headerClassName='table-header-cell'
75-
headerRowClassName='hover:bg-transparent'
76-
bodyRowClassName='table-row-hover'
77-
/>
78-
</div>
61+
<div id='trending-coins'>
62+
<h4>Trending Coins</h4>
63+
64+
<DataTable
65+
tableClassName='trending-coins-table'
66+
columns={columns}
67+
data={trendingCoins.slice(0, 6)}
68+
rowKey={(_, index) => index}
69+
bodyRowClassName='body-row'
70+
/>
7971
</div>
8072
);
8173
};

0 commit comments

Comments
 (0)