@ui5/webcomponents-react-base
Advanced tools
Comparing version 1.29.10 to 1.29.11
import type { StyleDataCSP } from '@ui5/webcomponents-base/dist/ManagedStyles.js'; | ||
export declare function useStylesheet(styles: StyleDataCSP, componentName: string): void; | ||
interface UseStyleSheetOptions { | ||
alwaysInject?: boolean; | ||
} | ||
export declare function useStylesheet(styles: StyleDataCSP, componentName: string, options?: UseStyleSheetOptions): void; | ||
export {}; |
'use client'; | ||
import { createOrUpdateStyle, removeStyle } from '@ui5/webcomponents-base/dist/ManagedStyles.js'; | ||
import { getCurrentRuntimeIndex } from '@ui5/webcomponents-base/dist/Runtimes.js'; | ||
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js'; | ||
import { StyleStore } from '../stores/StyleStore.js'; | ||
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js'; | ||
export function useStylesheet(styles, componentName) { | ||
export function useStylesheet(styles, componentName, options) { | ||
const { staticCssInjected, componentsMap } = useSyncExternalStore(StyleStore.subscribe, StyleStore.getSnapshot, StyleStore.getServerSnapshot); | ||
useIsomorphicLayoutEffect(() => { | ||
const shouldInject = !staticCssInjected; | ||
const scopedComponentName = `${componentName}-${getCurrentRuntimeIndex()}`; | ||
const shouldInject = options?.alwaysInject || !staticCssInjected; | ||
if (shouldInject) { | ||
createOrUpdateStyle(styles, 'data-ui5wcr-component', componentName); | ||
createOrUpdateStyle(styles, 'data-ui5wcr-component', scopedComponentName); | ||
StyleStore.mountComponent(componentName); | ||
@@ -19,3 +21,3 @@ } | ||
if (numberOfMountedComponents <= 0) { | ||
removeStyle('data-ui5wcr-component', componentName); | ||
removeStyle('data-ui5wcr-component', scopedComponentName); | ||
} | ||
@@ -22,0 +24,0 @@ } |
{ | ||
"name": "@ui5/webcomponents-react-base", | ||
"version": "1.29.10", | ||
"version": "1.29.11", | ||
"description": "Base for ui5-webcomponents-react", | ||
@@ -63,3 +63,3 @@ "type": "module", | ||
}, | ||
"gitHead": "81f0d40625c92de86314072d8fe7e62371767279" | ||
"gitHead": "28675d0bfeb93233443663199ad3491f3a652688" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
287277
3645