Skip to content

Commit 91befea

Browse files
committed
fix: adding dynamic css settings for page layout and card layout
1 parent 9625efd commit 91befea

File tree

7 files changed

+120
-21
lines changed

7 files changed

+120
-21
lines changed

src/common/Logo/index.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,42 @@ const Logo: React.FC<LogoProps> = ({
1313
className,
1414
imageClassName,
1515
}) => {
16-
// Get logo URL from CSS variable (theme system sets this)
17-
const getCSSVariable = (varName: string): string => {
16+
// Get logo URL from Auth0 theme system
17+
const getThemeLogoUrl = (): string => {
1818
return getComputedStyle(document.documentElement)
19-
.getPropertyValue(varName)
19+
.getPropertyValue("--ul-theme-widget-logo-url")
2020
.trim()
21-
.replace(/^"(.*)"$/, "$1"); // Remove quotes
21+
.replace(/^"(.*)"$/, "$1"); // Remove quotes from CSS string
2222
};
2323

24-
const logoFromCSS = getCSSVariable("--ul-theme-widget-logo-url");
25-
const logoSrc = imageUrl || logoFromCSS;
24+
// Get logo position from Auth0 theme system (via Tailwind semantic variable)
25+
const getLogoPosition = (): string => {
26+
return getComputedStyle(document.documentElement)
27+
.getPropertyValue("--ul-theme-widget-logo-position")
28+
.trim();
29+
};
30+
31+
const logoSrc = imageUrl || getThemeLogoUrl();
32+
const logoPosition = getLogoPosition();
33+
34+
// Hide logo completely when position is "none"
35+
if (logoPosition === "none") {
36+
return null;
37+
}
2638

2739
return (
28-
<div className={cn("flex justify-center items-center mb-6", className)}>
40+
<div
41+
className={cn("flex items-center mb-6", className)}
42+
style={{ justifyContent: "var(--justify-widget-logo)" }}
43+
>
2944
<img
3045
src={logoSrc}
3146
alt={altText}
3247
loading="eager"
3348
decoding="async"
3449
fetchPriority="high"
3550
className={cn(
36-
"object-contain max-w-full max-h-full aspect-square",
51+
"object-contain max-w-full aspect-square h-widget-logo",
3752
imageClassName,
3853
)}
3954
/>

src/index.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
--color-input-bg: var(--ul-theme-color-input-background);
2828
--color-page-bg: var(--ul-theme-page-bg-background-color);
2929

30+
/* Background images */
31+
--image-page-bg: var(--ul-theme-page-bg-background-image-url);
32+
3033
/* Border colors */
3134
--color-widget-border: var(--ul-theme-color-widget-border);
3235
--color-input-border: var(--ul-theme-color-input-border);
@@ -38,6 +41,9 @@
3841
--color-info: var(--ul-theme-color-primary-button);
3942
--color-icons: var(--ul-theme-color-icons);
4043

44+
/* Captcha theme */
45+
--captcha-widget-theme: var(--ul-theme-color-captcha-widget-theme);
46+
4147
/* Border radius - using CSS variables */
4248
--radius-button: var(--ul-theme-border-button-border-radius);
4349
--radius-input: var(--ul-theme-border-input-border-radius);
@@ -49,6 +55,15 @@
4955
/* Spacing tokens - semantic spacing for components */
5056
--spacing-widget-padding: 2.5rem; /* 40px - standard widget padding */
5157

58+
/* Widget */
59+
--height-widget-logo: var(--ul-theme-widget-logo-height);
60+
--justify-widget-logo: var(--ul-theme-widget-logo-position);
61+
--text-align-header: var(--ul-theme-widget-header-text-alignment);
62+
--social-buttons-layout: var(--ul-theme-widget-social-buttons-layout);
63+
64+
/* Page Layout */
65+
--justify-page-layout: var(--ul-theme-page-bg-page-layout);
66+
5267
/* Typography */
5368
--text-title: var(--ul-theme-font-title-size);
5469
--text-subtitle: var(--ul-theme-font-subtitle-size);
@@ -126,6 +141,7 @@
126141
/* Page Background */
127142
--ul-theme-page-bg-page-layout: center;
128143
--ul-theme-page-bg-background-color: #bababa;
144+
--ul-theme-page-bg-background-image-url: none;
129145

130146
/* Widget */
131147
--ul-theme-widget-logo-position: center;
@@ -158,6 +174,10 @@
158174
body {
159175
margin: 0;
160176
background-color: var(--ul-theme-page-bg-background-color);
177+
background-image: var(--ul-theme-page-bg-background-image-url);
178+
background-size: cover;
179+
background-position: center;
180+
background-repeat: no-repeat;
161181
color: var(--ul-theme-color-body-text);
162182
min-height: 100vh;
163183
}

src/screens/login-id/components/AlternativeLogins.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import type { SocialConnection } from "@/utils/helpers/socialUtils";
66
import { getIcon } from "@/utils/helpers/iconUtils";
77
import { useLoginIdManager } from "../hooks/useLoginIdManager";
88

9-
// No props needed as it uses hooks internally
10-
const AlternativeLogins: React.FC = () => {
9+
interface AlternativeLoginsProps {
10+
layout?: "top" | "bottom";
11+
}
12+
13+
const AlternativeLogins: React.FC<AlternativeLoginsProps> = ({
14+
layout = "top",
15+
}) => {
1116
const { loginIdInstance, handleSocialLogin, handlePasskeyLogin, texts } =
1217
useLoginIdManager();
1318

@@ -26,7 +31,10 @@ const AlternativeLogins: React.FC = () => {
2631

2732
return (
2833
<>
29-
{showSeparator && <Separator text={separatorText} />}
34+
{/* Separator at top when layout is bottom */}
35+
{showSeparator && layout === "bottom" && (
36+
<Separator text={separatorText} />
37+
)}
3038

3139
<div className="space-y-3 mt-4">
3240
{isPasskeyAvailable && (
@@ -55,6 +63,9 @@ const AlternativeLogins: React.FC = () => {
5563
);
5664
})}
5765
</div>
66+
67+
{/* Separator at bottom when layout is top */}
68+
{showSeparator && layout === "top" && <Separator text={separatorText} />}
5869
</>
5970
);
6071
};

src/screens/login-id/components/Header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const Header: React.FC = () => {
1010

1111
return (
1212
<>
13-
<Logo imageClassName="h-13" altText={logoAltText} />
14-
<h1 className="text-2xl font-normal text-center [color:var(--ul-theme-color-header)] mt-6 mb-4">
13+
<Logo altText={logoAltText} />
14+
<h1 className="text-2xl font-normal [text-align:var(--text-align-header)] [color:var(--ul-theme-color-header)] mt-6 mb-4">
1515
{title}
1616
</h1>
17-
<p className="text-center [color:var(--ul-theme-color-body-text)] text-sm mb-4">
17+
<p className="[text-align:var(--text-align-header)] [color:var(--ul-theme-color-body-text)] text-sm mb-4">
1818
{description}
1919
</p>
2020
</>

src/screens/login-id/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,28 @@ const LoginIdScreen: React.FC = () => {
1616
// Apply theme from SDK instance when screen loads
1717
applyAuth0Theme(loginIdInstance);
1818

19+
// Get social buttons layout from theme
20+
const socialButtonsLayout =
21+
getComputedStyle(document.documentElement)
22+
.getPropertyValue("--social-buttons-layout")
23+
.trim() || "bottom";
24+
25+
// Get page layout from theme
26+
const pageLayout =
27+
getComputedStyle(document.documentElement)
28+
.getPropertyValue("--justify-page-layout")
29+
.trim() || "center";
30+
1931
return (
20-
<div className="min-h-screen flex items-center justify-center px-10 py-20">
32+
<div className={`min-h-screen flex items-center px-20 py-20`} style={{ justifyContent: pageLayout }}>
2133
<Card className="w-full max-w-[400px]">
2234
<Header />
35+
{socialButtonsLayout === "top" && <AlternativeLogins layout="top" />}
2336
<IdentifierForm />
2437
<Footer />
25-
<AlternativeLogins />
38+
{socialButtonsLayout === "bottom" && (
39+
<AlternativeLogins layout="bottom" />
40+
)}
2641
</Card>
2742
</div>
2843
);

src/utils/theme/themeEngine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function extractSettingsOverrides(screenInstance: any): Record<string, string> {
4444
// Essential variable mappings for precedence overrides
4545
const variableMapping = {
4646
"colors.primary": "--ul-theme-color-primary-button",
47-
"colors.pageBackground": "--ul-theme-page-bg-background-color",
47+
"colors.page_background": "--ul-theme-page-bg-background-color",
4848
logoUrl: "--ul-theme-widget-logo-url",
4949
};
5050

@@ -64,7 +64,7 @@ function extractOrganizationOverrides(
6464
// Essential variable mappings for precedence overrides
6565
const variableMapping = {
6666
"colors.primary": "--ul-theme-color-primary-button",
67-
"colors.pageBackground": "--ul-theme-page-bg-background-color",
67+
"colors.page_background": "--ul-theme-page-bg-background-color",
6868
logoUrl: "--ul-theme-widget-logo-url",
6969
};
7070

src/utils/theme/themeFlatteners.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,23 @@ export function flattenPageBackground(
189189
if (pageBackground.background_color)
190190
result["--ul-theme-page-bg-background-color"] =
191191
pageBackground.background_color;
192-
if (pageBackground.page_layout)
192+
if (pageBackground.background_image_url) {
193+
result["--ul-theme-page-bg-background-image-url"] =
194+
pageBackground.background_image_url === null || pageBackground.background_image_url === ""
195+
? "none"
196+
: `url("${pageBackground.background_image_url}")`;
197+
}
198+
if (pageBackground.page_layout) {
193199
result["--ul-theme-page-bg-page-layout"] = pageBackground.page_layout;
200+
201+
// Convert to CSS justify-content values for use with arbitrary properties
202+
const layoutMap: Record<string, string> = {
203+
"center": "center",
204+
"left": "flex-start",
205+
"right": "flex-end"
206+
};
207+
result["--justify-page-layout"] = layoutMap[pageBackground.page_layout] || "center";
208+
}
194209

195210
return result;
196211
}
@@ -201,18 +216,41 @@ export function flattenPageBackground(
201216
export function flattenWidget(widget: any): Record<string, string> {
202217
const result: Record<string, string> = {};
203218

204-
if (widget.logo_position)
219+
// Logo position: convert Auth0 values to Tailwind justify values
220+
if (widget.logo_position) {
205221
result["--ul-theme-widget-logo-position"] = widget.logo_position;
222+
223+
// Convert to Tailwind semantic variable
224+
const positionMap: Record<string, string> = {
225+
center: "center",
226+
left: "flex-start",
227+
right: "flex-end",
228+
none: "none",
229+
};
230+
result["--justify-widget-logo"] =
231+
positionMap[widget.logo_position] || "center";
232+
}
206233
if (widget.logo_url)
207234
result["--ul-theme-widget-logo-url"] = `"${widget.logo_url}"`;
208235

209236
// Logo height needs px units
210237
if (widget.logo_height)
211238
result["--ul-theme-widget-logo-height"] = `${widget.logo_height}px`;
212239

213-
if (widget.header_text_alignment)
240+
// Header text alignment: convert Auth0 values to CSS text-align values
241+
if (widget.header_text_alignment) {
214242
result["--ul-theme-widget-header-text-alignment"] =
215243
widget.header_text_alignment;
244+
245+
// Convert to CSS text-align values for use with arbitrary properties
246+
const alignmentMap: Record<string, string> = {
247+
center: "center",
248+
left: "left",
249+
right: "right",
250+
};
251+
result["--text-align-header"] =
252+
alignmentMap[widget.header_text_alignment] || "center";
253+
}
216254
if (widget.social_buttons_layout)
217255
result["--ul-theme-widget-social-buttons-layout"] =
218256
widget.social_buttons_layout;

0 commit comments

Comments
 (0)