diff --git a/authui/src/inline-preview.ts b/authui/src/inline-preview.ts index a3828d1d5b..324f8d96d1 100644 --- a/authui/src/inline-preview.ts +++ b/authui/src/inline-preview.ts @@ -3,6 +3,7 @@ import { PreviewableResourceController } from "./previewable-resource"; import { injectCSSAttrs } from "./cssattrs"; interface PreviewCustomisationMessage { + theme: string; cssVars: Record; images: Record; translations: Record; @@ -15,6 +16,7 @@ function parsePreviewCustomisationMessage( return null; } return { + theme: message.theme ?? "", cssVars: message.cssVars ?? {}, images: message.images ?? {}, translations: message.translations ?? {}, @@ -89,6 +91,11 @@ export class InlinePreviewController extends Controller { outlet?.setValue(value); } + el.classList.remove("dark"); + if (customisationMessage.theme === "dark") { + el.classList.add("dark"); + } + injectCSSAttrs(document.documentElement); }; } diff --git a/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx b/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx index 397fee5bb5..009b608b1d 100644 --- a/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx +++ b/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx @@ -807,6 +807,8 @@ const Preview: React.VFC = function Preview(props) { const authUIIframeRef = useRef(null); + const [isIframeLoading, setIsIframeLoading] = useState(true); + useEffect(() => { const message = mapDesignFormStateToPreviewCustomisationMessage( designForm.state @@ -844,20 +846,23 @@ const Preview: React.VFC = function Preview(props) { const src = useMemo(() => { const url = new URL(effectiveAppConfig.http?.public_origin ?? ""); url.pathname = selectedPreviewPage; - url.searchParams.append("x_color_scheme", designForm.state.selectedTheme); url.searchParams.append("ui_locales", designForm.state.selectedLanguage); return url.toString(); }, [ effectiveAppConfig.http?.public_origin, designForm.state.selectedLanguage, - designForm.state.selectedTheme, selectedPreviewPage, ]); + useEffect(() => { + setIsIframeLoading(true); + }, [src]); + const onLoadIframe = useCallback(() => { const message = mapDesignFormStateToPreviewCustomisationMessage( designForm.state ); + setIsIframeLoading(false); authUIIframeRef.current?.contentWindow?.postMessage(message, "*"); }, [designForm.state]); @@ -892,6 +897,7 @@ const Preview: React.VFC = function Preview(props) { /> ) : null} + {isIframeLoading ? : null}