Skip to content

Commit 11a833e

Browse files
committed
[React] Fix: Improve social button icon arrangement (#4718)
![Screenshot 2024-09-19 at 5 13 13 PM](https://github.com/user-attachments/assets/ae06781e-6b44-4231-9385-0a4ac27be563) ![Screenshot 2024-09-19 at 5 13 07 PM](https://github.com/user-attachments/assets/23b3f073-b6ab-4aae-8be8-a5820763cd65) <!-- start pr-codex --> --- ## PR-Codex overview This PR improves the layout of social icons in the Connect UI by organizing them into columns for better user experience. ### Detailed summary - Added logic to arrange social icons into columns based on the number of login options - Updated the layout of social buttons to display them in columns instead of a row > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent c67d8a9 commit 11a833e

File tree

2 files changed

+86
-48
lines changed

2 files changed

+86
-48
lines changed

.changeset/rude-frogs-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Improve arrangement of social icons in Connect UI

packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx

Lines changed: 81 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ export const ConnectWalletSocialOptions = (
135135
const isEmailEnabled = emailIndex !== -1;
136136
const phoneIndex = authOptions.indexOf("phone");
137137
const isPhoneEnabled = phoneIndex !== -1;
138+
const socialLogins: SocialAuthOption[] = authOptions.filter((o) =>
139+
socialAuthOptions.includes(o as SocialAuthOption),
140+
) as SocialAuthOption[];
141+
142+
const columnCount = useMemo(() => {
143+
switch (socialLogins.length) {
144+
case 7:
145+
return 4;
146+
case 6:
147+
return 4;
148+
default:
149+
return 5;
150+
}
151+
}, [socialLogins.length]);
152+
153+
const socialLoginColumns: SocialAuthOption[][] = useMemo(() => {
154+
return Array.from(
155+
{ length: Math.ceil(socialLogins.length / columnCount) },
156+
(_, i) => socialLogins.slice(i * columnCount, (i + 1) * columnCount),
157+
);
158+
}, [socialLogins, columnCount]);
138159

139160
const [manualInputMode, setManualInputMode] = useState<
140161
"email" | "phone" | "none" | null
@@ -175,10 +196,6 @@ export const ConnectWalletSocialOptions = (
175196
type = "tel";
176197
}
177198

178-
const socialLogins = authOptions.filter((o) =>
179-
socialAuthOptions.includes(o as SocialAuthOption),
180-
);
181-
182199
const hasSocialLogins = socialLogins.length > 0;
183200
const ecosystemInfo = isEcosystemWallet(wallet)
184201
? {
@@ -315,49 +332,46 @@ export const ConnectWalletSocialOptions = (
315332
)}
316333
{/* Social Login */}
317334
{hasSocialLogins && (
318-
<Container
319-
flex="row"
320-
center="x"
321-
gap={socialLogins.length > 4 ? "xs" : "sm"}
322-
style={{
323-
justifyContent: "space-between",
324-
display: "grid",
325-
gridTemplateColumns: `repeat(${socialLogins.length}, 1fr)`,
326-
}}
327-
>
328-
{socialLogins.map((loginMethod) => {
329-
const imgIconSize = (() => {
330-
if (!showOnlyIcons) {
331-
return iconSize.md;
332-
}
333-
if (socialLogins.length > 4) {
334-
return iconSize.md;
335-
}
336-
return iconSize.lg;
337-
})();
338-
339-
return (
340-
<SocialButton
341-
aria-label={`Login with ${loginMethod}`}
342-
data-variant={showOnlyIcons ? "icon" : "full"}
343-
key={loginMethod}
344-
variant={"outline"}
345-
disabled={props.disabled}
346-
onClick={() => {
347-
handleSocialLogin(loginMethod as SocialAuthOption);
348-
}}
349-
>
350-
<Img
351-
src={socialIcons[loginMethod as SocialAuthOption]}
352-
width={imgIconSize}
353-
height={imgIconSize}
354-
client={props.client}
355-
/>
356-
{!showOnlyIcons &&
357-
`${socialLogins.length === 1 ? "Continue with " : ""}${loginMethodsLabel[loginMethod as SocialAuthOption]}`}
358-
</SocialButton>
359-
);
360-
})}
335+
<Container flex="column" gap={socialLogins.length > 4 ? "xs" : "sm"}>
336+
{socialLoginColumns.map((column) => (
337+
<SocialButtonRow key={column[0]}>
338+
{column.map((loginMethod) => {
339+
const imgIconSize = (() => {
340+
if (!showOnlyIcons) {
341+
return iconSize.md;
342+
}
343+
if (socialLogins.length > 4) {
344+
return iconSize.md;
345+
}
346+
return iconSize.lg;
347+
})();
348+
return (
349+
<SocialButton
350+
aria-label={`Login with ${loginMethod}`}
351+
data-variant={showOnlyIcons ? "icon" : "full"}
352+
key={loginMethod}
353+
variant={"outline"}
354+
disabled={props.disabled}
355+
onClick={() => {
356+
handleSocialLogin(loginMethod as SocialAuthOption);
357+
}}
358+
style={{
359+
flexGrow: socialLogins.length < 7 ? 1 : 0,
360+
}}
361+
>
362+
<Img
363+
src={socialIcons[loginMethod as SocialAuthOption]}
364+
width={imgIconSize}
365+
height={imgIconSize}
366+
client={props.client}
367+
/>
368+
{!showOnlyIcons &&
369+
`${socialLogins.length === 1 ? "Continue with " : ""}${loginMethodsLabel[loginMethod as SocialAuthOption]}`}
370+
</SocialButton>
371+
);
372+
})}
373+
</SocialButtonRow>
374+
))}
361375
</Container>
362376
)}
363377

@@ -476,8 +490,27 @@ export const ConnectWalletSocialOptions = (
476490
);
477491
};
478492

493+
const SocialButtonRow = (props: { children: React.ReactNode[] }) => (
494+
<Container
495+
flex="row"
496+
center="x"
497+
gap={props.children.length > 4 ? "xs" : "sm"}
498+
style={{
499+
justifyContent: "center",
500+
display: "flex",
501+
...{
502+
"& > *": {
503+
flexBasis: `${100 / props.children.length}%`,
504+
maxWidth: `${100 / props.children.length}%`,
505+
},
506+
},
507+
}}
508+
>
509+
{props.children}
510+
</Container>
511+
);
512+
479513
const SocialButton = /* @__PURE__ */ styled(Button)({
480-
flexGrow: 1,
481514
"&[data-variant='full']": {
482515
display: "flex",
483516
justifyContent: "flex-start",

0 commit comments

Comments
 (0)