@web3auth/modal
Version:
Multi chain wallet aggregator for web3Auth
138 lines (134 loc) • 5.86 kB
JavaScript
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var auth = require('@web3auth/auth');
var utils = require('../../utils.js');
var Button = require('../Button/Button.js');
var Button_type = require('../Button/Button.type.js');
var LoginHint = require('../LoginHint/LoginHint.js');
function getProviderIcon(method, isDark, extension) {
const imageId = method === auth.AUTH_CONNECTION.TWITTER ? `login-X${isDark ? "-light" : "-dark"}` : `login-${method}${isDark ? "-light" : "-dark"}`;
const hoverId = method === auth.AUTH_CONNECTION.APPLE || method === auth.AUTH_CONNECTION.GITHUB || method === auth.AUTH_CONNECTION.TWITTER ? imageId : `login-${method}-active`;
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
children: [jsxRuntime.jsx("img", {
id: "active-login-img",
src: `https://images.web3auth.io/${hoverId}${extension}`,
alt: "active-login-img",
className: "w3a--hidden w3a--size-5 w3a--object-contain group-hover:w3a--block"
}), jsxRuntime.jsx("img", {
id: "login-img",
src: `https://images.web3auth.io/${imageId}${extension}`,
alt: "login-img",
className: "w3a--block w3a--size-5 w3a--object-contain group-hover:w3a--hidden"
})]
});
}
function SocialLoginList(props) {
const {
visibleRow,
otherRow,
isDark,
canShowMore,
handleSocialLoginClick,
handleExpandSocialLogins,
buttonRadius
} = props;
const getGridRowFromVisibleLogin = () => {
if (visibleRow.length === 1) {
return "w3a--grid-cols-1";
} else if (visibleRow.length === 2) {
return "w3a--grid-cols-2";
} else if (visibleRow.length === 3) {
return "w3a--grid-cols-3";
} else {
return "w3a--grid-cols-4";
}
};
if (visibleRow.length !== 0 && (otherRow === null || otherRow === void 0 ? void 0 : otherRow.length) === 0) {
return jsxRuntime.jsx("div", {
className: "w3a--flex w3a--w-full w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-2",
children: jsxRuntime.jsxs("div", {
className: utils.cn("w3a--grid w3a--w-full w3a--gap-x-2", getGridRowFromVisibleLogin()),
children: [visibleRow.filter((_, index) => visibleRow.length === 4 ? index <= 3 : index < 3).map(row => jsxRuntime.jsx(LoginHint, {
content: "Last Login",
isDark: isDark,
hideHint: true,
children: jsxRuntime.jsx(Button, {
type: Button_type.BUTTON_TYPE.SOCIAL,
props: {
showText: false,
method: row.method,
isDark,
isPrimaryBtn: false,
btnStyle: "w3a--flex w3a--items-center !w3a--justify-center w3a--w-full w3a--h-11 w3a--group",
children: jsxRuntime.jsx(jsxRuntime.Fragment, {
children: getProviderIcon(row.method, isDark, ".svg")
}),
onClick: () => handleSocialLoginClick({
connector: row.connector,
loginParams: row.loginParams
}),
buttonRadius
}
}, row.method)
}, row.method)), canShowMore && visibleRow.length > 4 && jsxRuntime.jsx(Button, {
type: Button_type.BUTTON_TYPE.SOCIAL,
props: {
showIcon: false,
onClick: handleExpandSocialLogins,
btnStyle: "w3a--flex w3a--items-center !w3a--justify-center w3a--w-full w3a--h-11",
children: jsxRuntime.jsx("img", {
src: utils.getIcons(isDark ? "dots-dark-horizontal" : "dots-light-horizontal"),
alt: "Logo",
className: "w3a--object-contain"
}),
buttonRadius
}
})]
})
});
}
return jsxRuntime.jsxs("div", {
className: "w3a--flex w3a--w-full w3a--flex-col w3a--items-start w3a--justify-start w3a--gap-y-4",
children: [jsxRuntime.jsx("button", {
type: "button",
className: "w3a--appearance-none",
onClick: () => handleExpandSocialLogins(),
children: jsxRuntime.jsx("img", {
src: utils.getIcons(isDark ? "arrow-left-dark" : "arrow-left-light"),
alt: "Logo",
className: "w3a--object-contain"
})
}), jsxRuntime.jsx("div", {
className: "w3a--social-container w3a--grid w3a--h-[300px] w3a--w-full w3a--auto-rows-min w3a--grid-cols-1 w3a--gap-y-2 w3a--overflow-y-auto w3a--pl-2 w3a--pr-3",
children: otherRow.map(row => jsxRuntime.jsx("div", {
className: "w3a--h-11 w3a--w-full",
children: jsxRuntime.jsx(Button, {
type: Button_type.BUTTON_TYPE.SOCIAL,
props: {
method: row.method,
isDark,
isPrimaryBtn: false,
onClick: () => handleSocialLoginClick({
connector: row.connector,
loginParams: row.loginParams
}),
btnStyle: "w3a--group w3a--relative w3a--overflow-hidden w3a--flex w3a--items-center !w3a--justify-start w3a--w-full w3a--h-11",
buttonRadius,
children: jsxRuntime.jsxs(jsxRuntime.Fragment, {
children: [getProviderIcon(row.method, isDark, ".svg"), jsxRuntime.jsx("p", {
className: "w3a--text-sm w3a--font-normal w3a--text-app-gray-900 dark:w3a--text-app-white",
children: row.name
}), jsxRuntime.jsx("img", {
id: "login-arrow",
className: "w3a--absolute w3a--right-4 w3a--top-1/2 -w3a--translate-x-10 -w3a--translate-y-1/2 w3a--opacity-0 w3a--transition-all w3a--duration-300\n group-hover:w3a--translate-x-0 group-hover:w3a--opacity-100",
src: utils.getIcons(isDark ? "chevron-right-dark" : "chevron-right-light"),
alt: "arrow"
})]
})
}
})
}, row.method))
})]
});
}
module.exports = SocialLoginList;