1- import { CircularProgress , createStyles , makeStyles , Theme , Typography } from '@material-ui/core'
1+ import { CircularProgress , createStyles , makeStyles , Theme , Typography , useTheme } from '@material-ui/core'
22import { ODataFieldParameter } from '@sensenet/client-core'
33import { GenericContent } from '@sensenet/default-content-types'
44import { CurrentContentContext , useLogger , useRepository } from '@sensenet/hooks-react'
55import React , { useContext , useEffect , useMemo , useRef , useState } from 'react'
66import { useLocation } from 'react-router-dom'
7- import { AUIApplicationBridgeLocation , createBridgeLocation } from './auiapplication-bridge'
7+ import {
8+ AUIApplicationBridgeLocation ,
9+ AUIApplicationBridgeTheme ,
10+ createBridgeLocation ,
11+ createBridgeTheme ,
12+ } from './auiapplication-bridge'
813
914export const AUI_APPLICATION_CONTENT_TYPE = 'AUIApplication'
1015
@@ -67,6 +72,7 @@ const createApplicationDocument = (
6772 adminUiUrl : string ,
6873 content : AUIApplicationContent | undefined ,
6974 location : AUIApplicationBridgeLocation ,
75+ theme : AUIApplicationBridgeTheme ,
7076) => {
7177 const baseUrl = getApplicationBaseUrl ( repositoryUrl , content ?. Path ?? '' )
7278 const bootstrap = `<base href="${ escapeAttribute ( baseUrl ) } ">
@@ -145,6 +151,7 @@ const createApplicationDocument = (
145151 Type : content ?. Type ,
146152 } ) } ,
147153 location: ${ makeSafeScriptJson ( location ) } ,
154+ theme: ${ makeSafeScriptJson ( theme ) } ,
148155 fetch: (input, init = {}) => {
149156 const requestId = \`\${Date.now()}-\${Math.random().toString(36).slice(2)}\`;
150157
@@ -222,6 +229,7 @@ const useStyles = makeStyles((theme: Theme) =>
222229
223230export const AUIApplicationView : React . FC = ( ) => {
224231 const classes = useStyles ( )
232+ const theme = useTheme < Theme > ( )
225233 const frameRef = useRef < HTMLIFrameElement > ( null )
226234 const repository = useRepository ( )
227235 const logger = useLogger ( 'AUIApplicationView' )
@@ -335,6 +343,7 @@ export const AUIApplicationView: React.FC = () => {
335343 ( ) => createBridgeLocation ( adminUiUrl , routerLocation ) ,
336344 [ adminUiUrl , routerLocation . hash , routerLocation . pathname , routerLocation . search ] ,
337345 )
346+ const bridgeTheme = useMemo ( ( ) => createBridgeTheme ( theme . palette . type ) , [ theme . palette . type ] )
338347 const srcDoc = useMemo (
339348 ( ) =>
340349 createApplicationDocument (
@@ -343,8 +352,9 @@ export const AUIApplicationView: React.FC = () => {
343352 adminUiUrl ,
344353 content ,
345354 bridgeLocation ,
355+ bridgeTheme ,
346356 ) ,
347- [ adminUiUrl , applicationHtml , bridgeLocation , content , repository . configuration . repositoryUrl ] ,
357+ [ adminUiUrl , applicationHtml , bridgeLocation , bridgeTheme , content , repository . configuration . repositoryUrl ] ,
348358 )
349359
350360 if ( isLoading ) {
0 commit comments