From 040310d8d6be21b40aa5015ef015bfea992b6011 Mon Sep 17 00:00:00 2001 From: Volodymyr Gerun Date: Thu, 8 Aug 2024 17:39:34 +0300 Subject: [PATCH] style(InfoBadge component): rename, add props and use everywhere --- app/lib/utils.ts | 16 +++++++++ app/page.tsx | 6 ++-- app/settings/page.tsx | 6 ++-- app/ui/categories/categories.tsx | 12 +++---- app/ui/categories/category-item.tsx | 4 +-- app/ui/hoverables.tsx | 4 +-- app/ui/{info-badge.tsx => info-text.tsx} | 11 +++++-- app/ui/logo.tsx | 9 +++--- app/ui/sign-in/sign-in.tsx | 6 ++-- app/ui/transaction-form-edit.tsx | 6 ++-- app/ui/transaction-list.tsx | 41 ++++++++++++++---------- 11 files changed, 76 insertions(+), 45 deletions(-) rename app/ui/{info-badge.tsx => info-text.tsx} (57%) diff --git a/app/lib/utils.ts b/app/lib/utils.ts index 40bfc29..dffc5a3 100644 --- a/app/lib/utils.ts +++ b/app/lib/utils.ts @@ -1,6 +1,8 @@ import toast from 'react-hot-toast' +import config from '@/tailwind.config' import { CalendarDate } from '@internationalized/date' +import { type ClassValue, clsx } from 'clsx' import { format, getDate, @@ -10,11 +12,25 @@ import { isYesterday, } from 'date-fns' import emojiRegex from 'emoji-regex' +import { extendTailwindMerge } from 'tailwind-merge' import { CURRENCY_CODE, DEFAULT_CATEGORY } from '@/config/constants/main' import type { TGetTransactions, THTMLElement, TTransaction } from './types' +export const customTwMerge = extendTailwindMerge({ + extend: { + classGroups: { + 'font-size': Object.keys(config?.theme?.extend?.fontSize!).map( + (key) => `text-${key}`, + ), + }, + }, +}) +export function cn(...args: ClassValue[]) { + return customTwMerge(clsx(args)) +} + export const capitalizeFirstLetter = (str: string): string => { if (!str) return str return str.charAt(0).toUpperCase() + str.slice(1) diff --git a/app/page.tsx b/app/page.tsx index a90fd7d..ae4c580 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -32,7 +32,7 @@ import { pluralize, } from './lib/utils' import BalanceLine from './ui/balance-line' -import InfoBadge from './ui/info-badge' +import InfoText from './ui/info-text' import NoTransactionsPlug from './ui/no-transaction-text' import PaginationList from './ui/pagination/pagination-list' import Search from './ui/search' @@ -143,8 +143,8 @@ export default async function Home({ <>
- - + +
) : ( diff --git a/app/settings/page.tsx b/app/settings/page.tsx index 566b562..c0044ce 100644 --- a/app/settings/page.tsx +++ b/app/settings/page.tsx @@ -11,7 +11,7 @@ import { getTransactionLimit, signOutAccount, } from '../lib/actions' -import InfoBadge from '../ui/info-badge' +import InfoText from '../ui/info-text' import NoTransactionsPlug from '../ui/no-transaction-text' import Currency from '../ui/settings/currency' import DeleteAccount from '../ui/settings/delete-account' @@ -50,8 +50,8 @@ export default async function Page() { > <>
- - + +
diff --git a/app/ui/categories/categories.tsx b/app/ui/categories/categories.tsx index 706c774..cadacf4 100644 --- a/app/ui/categories/categories.tsx +++ b/app/ui/categories/categories.tsx @@ -33,7 +33,7 @@ import { import { capitalizeFirstLetter, deepCompareArrays } from '@/app/lib/utils' import { HoverableElement } from '../hoverables' -import InfoBadge from '../info-badge' +import InfoText from '../info-text' import Category from './category' type TProps = { @@ -232,10 +232,10 @@ function Categories({ userId, userCategories }: TProps) {
- - - - + + + - +
diff --git a/app/ui/hoverables.tsx b/app/ui/hoverables.tsx index 441be6e..d6a1988 100644 --- a/app/ui/hoverables.tsx +++ b/app/ui/hoverables.tsx @@ -5,11 +5,11 @@ import { useHover } from 'react-use' import Link from 'next/link' import { motion } from 'framer-motion' -import { twMerge } from 'tailwind-merge' import { DIV } from '@/config/constants/framer' import type { TNavLink, TSelect } from '../lib/types' +import { cn } from '../lib/utils' type THoverableElement = { element: TSelect['icon'] | string @@ -51,7 +51,7 @@ export const HoverableNavLink = ({ return useHover((hovered: boolean) => ( {withDoubleAsterisk && ' ** '} {!withDoubleAsterisk && withAsterisk && ' * '} diff --git a/app/ui/logo.tsx b/app/ui/logo.tsx index 2197126..315167a 100644 --- a/app/ui/logo.tsx +++ b/app/ui/logo.tsx @@ -1,7 +1,8 @@ 'use client' import { Badge } from '@nextui-org/react' -import { twMerge } from 'tailwind-merge' + +import { cn } from '../lib/utils' type TSize = 'sm' | 'md' | 'lg' @@ -52,7 +53,7 @@ export default function Logo({ >
Ex diff --git a/app/ui/sign-in/sign-in.tsx b/app/ui/sign-in/sign-in.tsx index fd95f5c..b64c7a1 100644 --- a/app/ui/sign-in/sign-in.tsx +++ b/app/ui/sign-in/sign-in.tsx @@ -35,7 +35,7 @@ import { import ClientButton from '../default-button' import { HoverableElement } from '../hoverables' -import InfoBadge from '../info-badge' +import InfoText from '../info-text' import Logo from '../logo' const ACCORDION_ITEM_KEY = 'More' @@ -217,8 +217,8 @@ function SignIn() {
- - + +
) diff --git a/app/ui/transaction-form-edit.tsx b/app/ui/transaction-form-edit.tsx index cf0d3e5..875f877 100644 --- a/app/ui/transaction-form-edit.tsx +++ b/app/ui/transaction-form-edit.tsx @@ -32,7 +32,7 @@ import { getTransactionsWithChangedCategory, } from '../lib/utils' import Loading from '../loading' -import InfoBadge from './info-badge' +import InfoText from './info-text' const AMOUNT_LENGTH = 6 @@ -269,8 +269,8 @@ function TransactionFormEdit({ transaction }: TProps) { {isTransactionWithChangedCategory && (
- - + +
)} diff --git a/app/ui/transaction-list.tsx b/app/ui/transaction-list.tsx index 6eb5272..a30a9bb 100644 --- a/app/ui/transaction-list.tsx +++ b/app/ui/transaction-list.tsx @@ -12,6 +12,7 @@ import type { TTransaction, } from '../lib/types' import { getFormattedCurrency } from '../lib/utils' +import InfoText from './info-text' type TProps = { groupedTransactionsByDate: TGroupedTransactions @@ -26,34 +27,40 @@ function TransactionList({ transactionsWithChangedCategory, currency, }: TProps) { - const totalsWrapper = - 'flex items-center gap-1 text-default-300 md:hover:text-foreground' - return ( <> {Object.keys(groupedTransactionsByDate)?.map((date) => { const { income, expense } = totalsTransactionsByDate[date] + const incomeIcon = + const expenseIcon = + const totalsWrapper = 'flex items-center gap-1' + const totalsCurrency = currency?.code || DEFAULT_CURRENCY_CODE + return (
-

- {date} -

-
+ +
{income > 0 && ( -

- - {getFormattedCurrency(income)}{' '} - {currency?.code || DEFAULT_CURRENCY_CODE} -

+
+ {incomeIcon} + +
)} {expense > 0 && ( -

- - {getFormattedCurrency(expense)}{' '} - {currency?.code || DEFAULT_CURRENCY_CODE} -

+
+ {expenseIcon} + +
)}