Skip to content

Commit f4abd5f

Browse files
authored
Fix-336-responsive-icon-buttons (#337)
* Add icon button variant to Button * Apply in both group and friend pages
1 parent 0bf2d3e commit f4abd5f

File tree

7 files changed

+62
-44
lines changed

7 files changed

+62
-44
lines changed

src/components/Friend/Export.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,7 @@ export const Export: React.FC<ExportCSVProps> = ({
8383
};
8484

8585
return (
86-
<Button
87-
size="sm"
88-
variant="secondary"
89-
className="w-[150px] gap-1 text-sm lg:w-[180px]"
90-
onClick={exportToCSV}
91-
disabled={disabled}
92-
>
86+
<Button size="sm" variant="secondary" responsiveIcon onClick={exportToCSV} disabled={disabled}>
9387
<Download className="h-4 w-4 text-white" size={20} /> Export
9488
</Button>
9589
);

src/components/Friend/Settleup.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type Balance, SplitType, type User } from '@prisma/client';
2-
import { ArrowRightIcon } from 'lucide-react';
2+
import { ArrowRightIcon, HandCoins } from 'lucide-react';
33
import { type User as NextUser } from 'next-auth';
44
import React, { useState } from 'react';
55
import { toast } from 'sonner';
@@ -16,11 +16,19 @@ import { Input } from '../ui/input';
1616
import { EntityAvatar } from '../ui/avatar';
1717

1818
export const SettleUp: React.FC<{
19-
balances: Balance[];
19+
balances?: Balance[];
2020
friend: User;
2121
currentUser: NextUser;
2222
}> = ({ balances, friend, currentUser }) => {
2323
const { t } = useTranslation('friend_details');
24+
if (!balances) {
25+
return (
26+
<Button size="sm" variant="outline" responsiveIcon disabled>
27+
<span className="xs:inline hidden">{t('ui.actions.settle_up')}</span>
28+
</Button>
29+
);
30+
}
31+
2432
const [balanceToSettle, setBalanceToSettle] = useState<Balance | undefined>(
2533
1 < balances.length ? undefined : balances[0],
2634
);
@@ -83,7 +91,7 @@ export const SettleUp: React.FC<{
8391
className="flex w-[150px] items-center gap-2 rounded-md border bg-cyan-500 px-3 text-sm font-normal text-black focus:bg-cyan-600 focus:ring-0 focus-visible:outline-hidden lg:w-[180px]"
8492
disabled={!balances.length}
8593
>
86-
{t('ui.actions.settle_up', { ns: 'common' })}
94+
<HandCoins className="size-4" /> {t('ui.actions.settle_up', { ns: 'common' })}
8795
</Button>
8896
}
8997
disableTrigger={!balances?.length}

src/components/group/AddMembers.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ const AddMembers: React.FC<{
103103

104104
return (
105105
<AppDrawer
106-
trigger={
107-
<div className="flex items-center justify-center gap-2 lg:w-[180px]">{children}</div>
108-
}
106+
trigger={<>{children}</>}
109107
onTriggerClick={handleTriggerClick}
110108
title={t('ui.no_members.add_members_details.title')}
111109
leftAction={t('ui.actions.cancel', { ns: 'common' })}

src/components/ui/button.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,40 @@ export interface ButtonProps
3838
VariantProps<typeof buttonVariants> {
3939
asChild?: boolean;
4040
loading?: boolean;
41+
responsiveIcon?: boolean;
4142
}
4243

4344
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
44-
({ className, variant, size, asChild = false, children, loading, ...props }, ref) => {
45+
(
46+
{
47+
className = '',
48+
variant = 'default',
49+
size,
50+
asChild = false,
51+
responsiveIcon = false,
52+
children,
53+
loading,
54+
...props
55+
},
56+
ref,
57+
) => {
4558
const Comp = asChild ? SlotPrimitive.Slot : 'button';
4659
return (
47-
<Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props}>
60+
<Comp
61+
className={cn(
62+
buttonVariants({
63+
variant,
64+
size,
65+
className:
66+
className +
67+
(responsiveIcon
68+
? 'responsive-icon xs:gap-1 xs:text-sm xs:w-40 w-auto lg:w-[180px]'
69+
: ''),
70+
}),
71+
)}
72+
ref={ref}
73+
{...props}
74+
>
4875
{loading ? <LoadingSpinner /> : children}
4976
</Comp>
5077
);

src/pages/balances/[friendId].tsx

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,10 @@ const FriendPage: NextPageWithUser = ({ user }) => {
112112
</div>
113113
</div>
114114
<div className="mt-6 mb-4 flex justify-center gap-2">
115-
{balances.data ? (
116-
<SettleUp
117-
balances={balances.data}
118-
key={`${friendQuery.data?.id}-${balances.data.length}`}
119-
friend={friendQuery.data}
120-
currentUser={user}
121-
/>
122-
) : (
123-
<Button
124-
size="sm"
125-
variant="outline"
126-
className="w-[150px] gap-1 text-sm lg:w-[180px]"
127-
disabled
128-
>
129-
{t('ui.actions.settle_up')}
130-
</Button>
131-
)}
132-
115+
<SettleUp balances={balances.data} friend={friendQuery.data} currentUser={user} />
133116
<Link href={`/add?friendId=${friendQuery.data.id}`}>
134-
<Button
135-
size="sm"
136-
variant="secondary"
137-
className="w-[150px] gap-1 text-sm lg:w-[180px]"
138-
>
139-
<PlusIcon className="h-4 w-4 text-gray-400" /> {t('ui.actions.add_expense')}
117+
<Button size="sm" variant="secondary" responsiveIcon>
118+
<PlusIcon className="size-4" /> {t('ui.actions.add_expense')}
140119
</Button>
141120
</Link>
142121
<Export

src/pages/groups/[groupId].tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DoorOpen,
99
Info,
1010
Merge,
11+
PlusIcon,
1112
Share,
1213
Trash2,
1314
UserPlus,
@@ -420,11 +421,11 @@ const BalancePage: NextPageWithUser<{
420421
</div>
421422
<div className="mb-4 flex justify-center gap-2 overflow-y-auto border-b pb-4">
422423
<Link href={`/add?groupId=${groupId}`}>
423-
<Button size="sm" className="gap-1 text-sm lg:w-[180px]" disabled={isArchived}>
424-
{t('ui.actions.add_expense', { ns: 'common' })}
424+
<Button size="sm" className="w-40 gap-1 text-sm lg:w-[180px]" disabled={isArchived}>
425+
<PlusIcon className="size-4" /> {t('ui.actions.add_expense', { ns: 'common' })}
425426
</Button>
426427
</Link>
427-
<Button size="sm" className="gap-1 text-sm" variant="secondary" disabled={isArchived}>
428+
<Button size="sm" responsiveIcon variant="secondary" disabled={isArchived}>
428429
{groupDetailQuery.data ? (
429430
<AddMembers
430431
group={groupDetailQuery.data}
@@ -436,14 +437,14 @@ const BalancePage: NextPageWithUser<{
436437
</Button>
437438
<Button
438439
size="sm"
439-
className="gap-1 text-sm lg:w-[180px]"
440+
responsiveIcon
440441
variant="secondary"
441442
onClick={inviteMembers}
442443
disabled={isArchived}
443444
>
444445
{isInviteCopied ? (
445446
<>
446-
<Check className="size-4 text-gray-400" /> {t('ui.copied')}
447+
<Check className="size-4" /> {t('ui.copied')}
447448
</>
448449
) : (
449450
<>

src/styles/globals.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
@custom-variant dark (&:is(.dark *));
44

55
@theme inline {
6+
--breakpoint-xs: 30rem;
7+
68
--color-border: var(--border);
79
--color-input: var(--input);
810
--color-ring: var(--ring);
@@ -78,6 +80,15 @@
7880
}
7981
}
8082

83+
@utility responsive-icon {
84+
@media (width < --theme(--breakpoint-xs)) {
85+
font-size: 0;
86+
svg {
87+
font-size: initial;
88+
}
89+
}
90+
}
91+
8192
/*
8293
The default border color has changed to `currentcolor` in Tailwind CSS v4,
8394
so we've added these compatibility styles to make sure everything still

0 commit comments

Comments
 (0)