1- import boot from '@ui5/webcomponents-base/dist/boot' ;
21import { getCompactSize } from '@ui5/webcomponents-base/dist/config/CompactSize' ;
32import { getTheme } from '@ui5/webcomponents-base/dist/config/Theme' ;
43import { createGenerateClassName } from '@ui5/webcomponents-react-base/lib/createGenerateClassName' ;
5- import { Device } from '@ui5/webcomponents-react-base/lib/Device' ;
64import * as sap_fiori_3 from '@ui5/webcomponents-react-base/lib/sap_fiori_3' ;
75import { ContentDensity } from '@ui5/webcomponents-react/lib/ContentDensity' ;
86import { MessageToast } from '@ui5/webcomponents-react/lib/MessageToast' ;
9- import { Themes } from '@ui5/webcomponents-react/lib/Themes' ;
10- import { _ as fiori3Theme } from '@ui5/webcomponents/dist/assets/themes/sap_fiori_3/parameters-bundle.css.json' ;
117import { Jss } from 'jss' ;
12- import React , { FC , Fragment , ReactNode , useEffect , useMemo } from 'react' ;
8+ import React , { FC , Fragment , ReactNode , useMemo } from 'react' ;
139import { JssProvider , ThemeProvider as ReactJssThemeProvider } from 'react-jss' ;
1410
1511export interface ThemeProviderProps {
@@ -20,71 +16,26 @@ export interface ThemeProviderProps {
2016 withToastContainer ?: boolean ;
2117 children : ReactNode ;
2218 /*
23- * Allows you to inject a custom JSS instance, e.g. if you need another insertionPoint or differnent plugins.
19+ * Allows you to inject a custom JSS instance, e.g. if you need another insertionPoint or different plugins.
2420 * If not provided, the default instance from `react-jss` will be used.
2521 */
2622 jss ?: Jss ;
27- /*
28- * The Theme Provider injects the fiori_3 theme variables into the document head.
29- * If this prop is set to true, this step is skipped.
30- */
31- noInjectThemeProperties ?: boolean ;
3223}
3324
3425const generateClassName = createGenerateClassName ( ) ;
3526
3627const ThemeProvider : FC < ThemeProviderProps > = ( props ) => {
37- const { withToastContainer, children, jss, noInjectThemeProperties } = props ;
28+ const { withToastContainer, children, jss } = props ;
3829 const theme = getTheme ( ) ;
39-
40- useEffect ( ( ) => {
41- if ( ! noInjectThemeProperties ) {
42- boot ( ) . then ( ( ) => {
43- // only inject parameters for sap_fiori_3 and if they haven't been injected before
44- let styleElement = document . head . querySelector ( 'style[data-ui5-webcomponents-react-theme-properties]' ) ;
45- if ( theme === Themes . sap_fiori_3 ) {
46- if ( ! styleElement ) {
47- styleElement = document . createElement ( 'style' ) ;
48- // @ts -ignore
49- styleElement . type = 'text/css' ;
50- styleElement . setAttribute ( 'data-ui5-webcomponents-react-theme-properties' , '' ) ;
51- document . head . appendChild ( styleElement ) ;
52- }
53-
54- if ( ! styleElement . textContent ) {
55- styleElement . textContent = fiori3Theme ;
56- }
57-
58- const CSSVarsPonyfill = window [ 'CSSVarsPonyfill' ] ;
59- if ( Device . browser . msie && CSSVarsPonyfill ) {
60- setTimeout ( ( ) => {
61- CSSVarsPonyfill . resetCssVars ( ) ;
62- CSSVarsPonyfill . cssVars ( ) ;
63- } , 0 ) ;
64- }
65- } else {
66- if ( styleElement ) {
67- styleElement . textContent = '' ;
68- }
69- }
70- } ) ;
71- }
72- } , [ theme , noInjectThemeProperties ] ) ;
73-
7430 const isCompactSize = getCompactSize ( ) ;
7531
76- const parameters = useMemo ( ( ) => {
77- if ( theme === Themes . sap_fiori_3 ) return sap_fiori_3 ;
78- return null ;
79- } , [ theme ] ) ;
80-
8132 const themeContext = useMemo ( ( ) => {
8233 return {
8334 theme,
8435 contentDensity : isCompactSize ? ContentDensity . Compact : ContentDensity . Cozy ,
85- parameters
36+ parameters : sap_fiori_3
8637 } ;
87- } , [ theme , isCompactSize , parameters ] ) ;
38+ } , [ theme , isCompactSize ] ) ;
8839
8940 return (
9041 < JssProvider generateId = { generateClassName } jss = { jss } >
@@ -100,8 +51,7 @@ const ThemeProvider: FC<ThemeProviderProps> = (props) => {
10051
10152ThemeProvider . displayName = 'ThemeProvider' ;
10253ThemeProvider . defaultProps = {
103- withToastContainer : false ,
104- noInjectThemeProperties : false
54+ withToastContainer : false
10555} ;
10656
10757export { ThemeProvider } ;
0 commit comments