Skip to content

Commit 227116e

Browse files
committed
refactor: categories styles
1 parent 6b1632d commit 227116e

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

app/globals.css

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,48 @@
197197
@apply gap-4 mt-2 md:gap-5 sm:grid-cols-2 lg:grid-cols-1 grid;
198198
}
199199

200+
#categories {
201+
@apply pt-8 mt-5 w-full bg-dark-500 rounded-xl overflow-hidden;
202+
203+
h4 {
204+
@apply text-xl md:text-2xl font-semibold mb-2 pl-5;
205+
}
206+
207+
.category-cell {
208+
@apply pl-5 font-bold;
209+
}
210+
211+
.top-gainers-cell {
212+
@apply flex gap-1 mr-5;
213+
214+
img {
215+
@apply rounded-full py-2;
216+
}
217+
}
218+
219+
.change-header-cell {
220+
@apply font-medium;
221+
}
222+
223+
.change-cell {
224+
@apply flex flex-1 gap-1 items-center pl-2 text-center font-medium;
225+
}
226+
227+
.market-cap-cell {
228+
@apply font-medium;
229+
}
230+
231+
.volume-cell {
232+
@apply font-medium;
233+
}
234+
}
235+
200236
.table-header-cell {
201237
@apply text-purple-100;
202238
}
203239

204240
.table-row-hover {
205-
@apply overflow-hidden border-none hover:!bg-dark-400 rounded-lg;
241+
@apply overflow-hidden border-none hover:bg-dark-400! rounded-lg;
206242
}
207243

208244
.coin-link {

components/DataTable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ export const DataTable = <T,>({
5050
<TableCell
5151
key={columnIndex}
5252
className={cn(
53-
column.cellClassName
54-
// columnIndex === 0 && 'pl-5'
53+
column.cellClassName,
54+
columnIndex === 0 && 'pl-5',
55+
columnIndex === columns.length - 1 && 'pr-5'
5556
)}
5657
>
5758
{column.cell(row, rowIndex)}

components/home/Categories.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
import { TrendingDown, TrendingUp } from 'lucide-react';
2+
import Image from 'next/image';
3+
14
import { DataTable } from '@/components/DataTable';
25
import { getCategories } from '@/lib/coingecko.actions';
36
import { cn, formatPercentage, formatPrice } from '@/lib/utils';
4-
import { TrendingDown, TrendingUp } from 'lucide-react';
5-
import Image from 'next/image';
67

78
export const Categories = async () => {
89
const categories = (await getCategories()) as Category[];
910
const columns = [
1011
{
1112
header: 'Category',
12-
cellClassName: 'pl-5 font-bold',
13+
cellClassName: 'category-cell',
1314
cell: (category: Category) => category.name,
1415
},
1516
{
1617
header: 'Top Gainers',
17-
cellClassName: 'flex gap-1 mr-5',
18+
cellClassName: 'top-gainers-cell',
1819
cell: (category: Category) =>
1920
category.top_3_coins.map((coin: string) => (
2021
<Image
@@ -23,25 +24,21 @@ export const Categories = async () => {
2324
alt='Coin image'
2425
width={28}
2526
height={28}
26-
className='rounded-full py-2'
2727
/>
2828
)),
2929
},
3030
{
3131
header: '24h Change',
32-
cellClassName: 'font-medium',
32+
cellClassName: 'change-header-cell',
3333
cell: (category: Category) => {
3434
const isTrendingUp = category.market_cap_change_24h > 0;
3535

3636
return (
3737
<div
38-
className={cn(
39-
'flex flex-1 gap-1 items-end pl-5 text-base font-medium',
40-
{
41-
'text-green-500': category.market_cap_change_24h > 0,
42-
'text-red-500': category.market_cap_change_24h < 0,
43-
}
44-
)}
38+
className={cn('change-cell', {
39+
'text-green-500': category.market_cap_change_24h > 0,
40+
'text-red-500': category.market_cap_change_24h < 0,
41+
})}
4542
>
4643
<p>{formatPercentage(category.market_cap_change_24h)}</p>
4744
{isTrendingUp ? (
@@ -55,19 +52,19 @@ export const Categories = async () => {
5552
},
5653
{
5754
header: 'Market Cap',
58-
cellClassName: 'font-medium',
55+
cellClassName: 'market-cap-cell',
5956
cell: (category: Category) => formatPrice(category.market_cap),
6057
},
6158
{
6259
header: '24h Volume',
63-
cellClassName: 'font-medium',
60+
cellClassName: 'volume-cell',
6461
cell: (category: Category) => formatPrice(category.volume_24h),
6562
},
6663
];
6764

6865
return (
69-
<div className='custom-scrollbar pt-8 mt-5 w-full bg-dark-500 rounded-xl overflow-hidden'>
70-
<h4 className='section-title pl-5'>Top Categories</h4>
66+
<div id='categories' className='custom-scrollbar'>
67+
<h4>Top Categories</h4>
7168
<DataTable
7269
columns={columns}
7370
data={categories}

0 commit comments

Comments
 (0)