Skip to content

Commit a7c219b

Browse files
Merge pull request #2330 from Web3Auth/fix/enabling-description-for--mainOption
fix: updated socialLogin lsit to support description
2 parents e489243 + f1993cd commit a7c219b

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

packages/modal/src/ui/components/Button/ButtonSocial/ButtonSocial.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function SocialLoginButton(props: ButtonSocialProps) {
2727
})}
2828
>
2929
{showIcon && getProviderIcon(method, isDark, isPrimaryBtn)}
30-
{showText && <p className="w3a--text-sm w3a--font-normal w3a--text-app-gray-900 dark:w3a--text-app-white">{text}</p>}
3130
{children}
31+
{showText && <p className="w3a--text-sm w3a--font-normal w3a--text-app-gray-900 dark:w3a--text-app-white">{text}</p>}
3232
</button>
3333
);
3434
}

packages/modal/src/ui/components/Login/Login.tsx

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function Login(props: LoginProps) {
7777
const [canShowMore, setCanShowMore] = useState(false);
7878
const [visibleRow, setVisibleRow] = useState<rowType[]>([]);
7979
const [otherRow, setOtherRow] = useState<rowType[]>([]);
80+
const [mainOptionsRow, setMainOptionsRow] = useState<rowType[]>([]);
8081
const [isPasswordLessCtaClicked, setIsPasswordLessCtaClicked] = useState(false);
8182
const [showOtpFlow, setShowOtpFlow] = useState(false);
8283
const [authConnection, setAuthConnection] = useState<AUTH_CONNECTION_TYPE | undefined>(undefined);
@@ -100,6 +101,7 @@ function Login(props: LoginProps) {
100101

101102
const visibleRows: rowType[] = [];
102103
const otherRows: rowType[] = [];
104+
const mainOptionsRows: rowType[] = [];
103105

104106
const loginMethodsOrder = (socialLoginsConfig.loginMethodsOrder || []).reduce(
105107
(acc, method, index) => {
@@ -140,51 +142,43 @@ function Login(props: LoginProps) {
140142
const order = index + 1;
141143

142144
const isPrimaryBtn = socialLoginsConfig?.uiConfig?.primaryButton === "socialLogin" && order === 1;
145+
const isMainOption = connectorConfig.mainOption;
143146

144147
const loginOptionLength = loginOptions.length;
145148
const moreThanFour = loginOptionLength >= 4;
146149

147150
const lengthCheck = moreThanFour ? order > 0 && order <= loginOptionLength : order > 0 && order < 4;
148151

149-
if (lengthCheck) {
150-
visibleRows.push({
151-
method,
152-
isDark,
153-
isPrimaryBtn,
154-
name,
155-
connector: socialLoginsConfig.connector,
156-
loginParams: {
157-
authConnection: connectorConfig.authConnection || (method as AUTH_CONNECTION_TYPE),
158-
authConnectionId: connectorConfig.authConnectionId,
159-
groupedAuthConnectionId: connectorConfig.groupedAuthConnectionId,
160-
extraLoginOptions: connectorConfig.extraLoginOptions,
161-
name,
162-
login_hint: "",
163-
},
164-
order,
165-
});
166-
}
167-
168-
otherRows.push({
152+
const rows = {
153+
description: connectorConfig.description || "",
169154
method,
170155
isDark,
171156
isPrimaryBtn,
172157
name: name === "Twitter" ? "X" : name,
173158
connector: socialLoginsConfig.connector,
174159
loginParams: {
175-
authConnection: method as AUTH_CONNECTION_TYPE,
160+
authConnection: connectorConfig.authConnection || (method as AUTH_CONNECTION_TYPE),
176161
authConnectionId: connectorConfig.authConnectionId,
177162
groupedAuthConnectionId: connectorConfig.groupedAuthConnectionId,
178163
extraLoginOptions: connectorConfig.extraLoginOptions,
179164
name,
180165
login_hint: "",
181166
},
182167
order,
183-
});
168+
};
169+
170+
if (isMainOption) {
171+
mainOptionsRows.push(rows);
172+
} else if (lengthCheck) {
173+
visibleRows.push(rows);
174+
}
175+
176+
otherRows.push(rows);
184177
});
185178

186179
setVisibleRow(visibleRows);
187180
setOtherRow(otherRows);
181+
setMainOptionsRow(mainOptionsRows);
188182
setCanShowMore(maxOptions.length > 4); // Update the state based on the condition
189183
}, [socialLoginsConfig, isDark, buttonRadius]);
190184

@@ -432,6 +426,7 @@ function Login(props: LoginProps) {
432426
isDark={isDark}
433427
visibleRow={visibleRow}
434428
canShowMore={canShowMore}
429+
mainOptionsRow={mainOptionsRow}
435430
handleSocialLoginClick={handleSocialLoginClick}
436431
socialLoginsConfig={socialLoginsConfig}
437432
handleExpandSocialLogins={handleSocialLoginExpand}

packages/modal/src/ui/components/SocialLoginList/SocialLoginList.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function getProviderIcon(method: string, isDark: boolean, extension: string) {
2828
}
2929

3030
function SocialLoginList(props: SocialLoginListProps) {
31-
const { visibleRow, otherRow, isDark, canShowMore, handleSocialLoginClick, handleExpandSocialLogins, buttonRadius } = props;
31+
const { visibleRow, otherRow, mainOptionsRow, isDark, canShowMore, handleSocialLoginClick, handleExpandSocialLogins, buttonRadius } = props;
3232

3333
const getGridRowFromVisibleLogin = () => {
3434
if (visibleRow.length === 1) {
@@ -45,6 +45,25 @@ function SocialLoginList(props: SocialLoginListProps) {
4545
if (visibleRow.length !== 0 && otherRow?.length === 0) {
4646
return (
4747
<div className="w3a--flex w3a--w-full w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-2">
48+
<div className="w3a--grid w3a--w-full w3a--gap-y-2">
49+
{mainOptionsRow.map((row) => (
50+
<Button
51+
type={BUTTON_TYPE.SOCIAL}
52+
key={row.method}
53+
props={{
54+
showText: true,
55+
text: row.description,
56+
method: row.method,
57+
isDark,
58+
isPrimaryBtn: false,
59+
btnStyle: "w3a--flex w3a--items-center !w3a--justify-center w3a--w-full w3a--h-11 w3a--group",
60+
children: <>{getProviderIcon(row.method, isDark, ".svg")}</>,
61+
onClick: () => handleSocialLoginClick({ connector: row.connector, loginParams: row.loginParams }),
62+
buttonRadius,
63+
}}
64+
/>
65+
))}
66+
</div>
4867
<div className={cn("w3a--grid w3a--w-full w3a--gap-x-2", getGridRowFromVisibleLogin())}>
4968
{visibleRow
5069
.filter((_, index) => (visibleRow.length === 4 ? index <= 3 : index < 3))

packages/modal/src/ui/components/SocialLoginList/SocialLoginList.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface SocialLoginListProps {
44
isDark: boolean;
55
visibleRow: rowType[];
66
canShowMore: boolean;
7+
mainOptionsRow: rowType[];
78
socialLoginsConfig: SocialLoginsConfig;
89
otherRow?: rowType[];
910
handleSocialLoginClick: (params: SocialLoginEventType) => void;

packages/modal/src/ui/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export type browser = "chrome" | "firefox" | "edge" | "safari" | "brave";
166166
export type mobileOs = "ios" | "android";
167167

168168
export type rowType = {
169+
description: string;
169170
method: string;
170171
isDark: boolean;
171172
isPrimaryBtn: boolean;
@@ -180,6 +181,7 @@ export type rowType = {
180181
extraLoginOptions?: ExtraLoginOptions;
181182
};
182183
order: number;
184+
mainOption?: boolean;
183185
};
184186

185187
export type PasswordlessHandlerParams = {

0 commit comments

Comments
 (0)