1
- import boot from '@ui5/webcomponents-base/dist/boot' ;
2
1
import { getCompactSize } from '@ui5/webcomponents-base/dist/config/CompactSize' ;
3
2
import { getTheme } from '@ui5/webcomponents-base/dist/config/Theme' ;
4
3
import { createGenerateClassName } from '@ui5/webcomponents-react-base/lib/createGenerateClassName' ;
5
- import { Device } from '@ui5/webcomponents-react-base/lib/Device' ;
6
4
import * as sap_fiori_3 from '@ui5/webcomponents-react-base/lib/sap_fiori_3' ;
7
5
import { ContentDensity } from '@ui5/webcomponents-react/lib/ContentDensity' ;
8
6
import { 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' ;
11
7
import { Jss } from 'jss' ;
12
- import React , { FC , Fragment , ReactNode , useEffect , useMemo } from 'react' ;
8
+ import React , { FC , Fragment , ReactNode , useMemo } from 'react' ;
13
9
import { JssProvider , ThemeProvider as ReactJssThemeProvider } from 'react-jss' ;
14
10
15
11
export interface ThemeProviderProps {
@@ -20,71 +16,26 @@ export interface ThemeProviderProps {
20
16
withToastContainer ?: boolean ;
21
17
children : ReactNode ;
22
18
/*
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.
24
20
* If not provided, the default instance from `react-jss` will be used.
25
21
*/
26
22
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 ;
32
23
}
33
24
34
25
const generateClassName = createGenerateClassName ( ) ;
35
26
36
27
const ThemeProvider : FC < ThemeProviderProps > = ( props ) => {
37
- const { withToastContainer, children, jss, noInjectThemeProperties } = props ;
28
+ const { withToastContainer, children, jss } = props ;
38
29
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
-
74
30
const isCompactSize = getCompactSize ( ) ;
75
31
76
- const parameters = useMemo ( ( ) => {
77
- if ( theme === Themes . sap_fiori_3 ) return sap_fiori_3 ;
78
- return null ;
79
- } , [ theme ] ) ;
80
-
81
32
const themeContext = useMemo ( ( ) => {
82
33
return {
83
34
theme,
84
35
contentDensity : isCompactSize ? ContentDensity . Compact : ContentDensity . Cozy ,
85
- parameters
36
+ parameters : sap_fiori_3
86
37
} ;
87
- } , [ theme , isCompactSize , parameters ] ) ;
38
+ } , [ theme , isCompactSize ] ) ;
88
39
89
40
return (
90
41
< JssProvider generateId = { generateClassName } jss = { jss } >
@@ -100,8 +51,7 @@ const ThemeProvider: FC<ThemeProviderProps> = (props) => {
100
51
101
52
ThemeProvider . displayName = 'ThemeProvider' ;
102
53
ThemeProvider . defaultProps = {
103
- withToastContainer : false ,
104
- noInjectThemeProperties : false
54
+ withToastContainer : false
105
55
} ;
106
56
107
57
export { ThemeProvider } ;
0 commit comments