Skip to content

Commit a2423ca

Browse files
authored
feat: Add modalSize prop on ConnectEmbed (#2686)
1 parent e5e3347 commit a2423ca

File tree

3 files changed

+68
-28
lines changed

3 files changed

+68
-28
lines changed

.changeset/sharp-gorillas-melt.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+
Add `modalSize` prop on `ConnectEmbed` to allow `"wide"` modal size.

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import {
22
SetModalConfigCtx,
33
WalletUIStatesProvider,
44
} from "../../../providers/wallet-ui-states-provider.js";
5-
import { modalMaxWidthCompact, defaultTheme } from "../constants.js";
5+
import {
6+
modalMaxWidthCompact,
7+
defaultTheme,
8+
modalMaxWidthWide,
9+
wideModalMaxHeight,
10+
} from "../constants.js";
611
import { useSetupScreen } from "./screen.js";
712
import { type ComponentProps, useContext, useEffect, useState } from "react";
813
import { radius, type Theme } from "../../design-system/index.js";
@@ -300,6 +305,15 @@ export type ConnectEmbedProps = {
300305
* You can disable this button by setting `showAllWallets` prop to `false`
301306
*/
302307
showAllWallets?: boolean;
308+
309+
/**
310+
* ConnectEmbed supports two modal size variants: `compact` and `wide`.
311+
*
312+
* By default it is set to `compact`, you can set it to `wide` if you want to show a wider modal.
313+
*
314+
* Note that if the screen width can not fit the wide modal, the `compact` version will be shown regardless of this `modalSize` options provided
315+
*/
316+
modalSize?: "compact" | "wide";
303317
};
304318

305319
/**
@@ -338,9 +352,13 @@ export function ConnectEmbed(props: ConnectEmbedProps) {
338352

339353
const contextTheme = useCustomTheme();
340354

355+
const modalSize = !canFitWideModal()
356+
? "compact"
357+
: props.modalSize || ("compact" as const);
358+
341359
const walletUIStatesProps = {
342360
theme: props.theme || contextTheme || defaultTheme,
343-
modalSize: "compact" as const,
361+
modalSize: modalSize,
344362
title: undefined,
345363
termsOfServiceUrl: props.termsOfServiceUrl,
346364
privacyPolicyUrl: props.privacyPolicyUrl,
@@ -368,7 +386,9 @@ export function ConnectEmbed(props: ConnectEmbedProps) {
368386
return (
369387
<>
370388
{autoConnectComp}
371-
<LoadingScreen />;
389+
<EmbedContainer modalSize={modalSize}>
390+
<LoadingScreen />
391+
</EmbedContainer>
372392
</>
373393
);
374394
}
@@ -419,6 +439,10 @@ const ConnectEmbedContent = (
419439

420440
let content = null;
421441

442+
const modalSize = !canFitWideModal()
443+
? "compact"
444+
: props.modalSize || ("compact" as const);
445+
422446
// show spinner on page load and during auto connecting a wallet
423447
if (isAutoConnecting) {
424448
content = <LoadingScreen />;
@@ -439,14 +463,15 @@ const ConnectEmbedContent = (
439463

440464
return (
441465
<EmbedContainer
466+
modalSize={modalSize}
442467
className={props.className}
443-
style={{
444-
height: "auto",
445-
maxWidth: modalMaxWidthCompact,
446-
...props.style,
447-
}}
468+
style={props.style}
448469
>
449-
<DynamicHeight> {content} </DynamicHeight>
470+
{modalSize === "wide" ? (
471+
content
472+
) : (
473+
<DynamicHeight> {content} </DynamicHeight>
474+
)}
450475
</EmbedContainer>
451476
);
452477
};
@@ -489,22 +514,29 @@ export function SyncedWalletUIStates(
489514
return <WalletUIStatesProvider {...props} />;
490515
}
491516

492-
const EmbedContainer = /* @__PURE__ */ StyledDiv(() => {
493-
const theme = useCustomTheme();
494-
return {
495-
color: theme.colors.primaryText,
496-
background: theme.colors.modalBg,
497-
width: "100%",
498-
boxSizing: "border-box",
499-
position: "relative",
500-
lineHeight: "normal",
501-
borderRadius: radius.xl,
502-
border: `1px solid ${theme.colors.borderColor}`,
503-
overflow: "hidden",
504-
fontFamily: theme.fontFamily,
505-
"& *::selection": {
506-
backgroundColor: theme.colors.primaryText,
507-
color: theme.colors.modalBg,
508-
},
509-
};
510-
});
517+
const EmbedContainer = /* @__PURE__ */ StyledDiv(
518+
(props: { modalSize: "compact" | "wide" }) => {
519+
const { modalSize } = props;
520+
const theme = useCustomTheme();
521+
return {
522+
color: theme.colors.primaryText,
523+
background: theme.colors.modalBg,
524+
height: modalSize === "compact" ? "auto" : wideModalMaxHeight,
525+
width: modalSize === "compact" ? modalMaxWidthCompact : modalMaxWidthWide,
526+
boxSizing: "border-box",
527+
position: "relative",
528+
lineHeight: "normal",
529+
borderRadius: radius.xl,
530+
border: `1px solid ${theme.colors.borderColor}`,
531+
overflow: "hidden",
532+
fontFamily: theme.fontFamily,
533+
"& *::selection": {
534+
backgroundColor: theme.colors.primaryText,
535+
color: theme.colors.modalBg,
536+
},
537+
"& *": {
538+
boxSizing: "border-box",
539+
},
540+
};
541+
},
542+
);

packages/thirdweb/src/react/web/ui/components/Modal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ const DialogContent = /* @__PURE__ */ StyledDiv(() => {
187187
outline: "none",
188188
overflow: "hidden",
189189
fontFamily: theme.fontFamily,
190+
"& *": {
191+
boxSizing: "border-box",
192+
},
190193
[media.mobile]: {
191194
top: "auto",
192195
bottom: 0,

0 commit comments

Comments
 (0)