@material-ui/styles#jssPreset TypeScript Examples
The following examples show how to use
@material-ui/styles#jssPreset.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: component.tsx From backstage with Apache License 2.0 | 5 votes |
TechDocsShadowDom = ({
element,
onAppend,
children,
}: TechDocsShadowDomProps) => {
const [jss, setJss] = useState(
create({
...jssPreset(),
insertionPoint: undefined,
}),
);
useShadowDomStylesEvents(element);
const loading = useShadowDomStylesLoading(element);
const ref = useCallback(
(shadowHost: HTMLDivElement) => {
if (!element || !shadowHost) return;
setJss(
create({
...jssPreset(),
insertionPoint: element.querySelector('head') || undefined,
}),
);
let shadowRoot = shadowHost.shadowRoot;
if (!shadowRoot) {
shadowRoot = shadowHost.attachShadow({ mode: 'open' });
}
shadowRoot.replaceChildren(element);
if (typeof onAppend === 'function') {
onAppend(shadowRoot);
}
},
[element, onAppend],
);
return (
<>
{loading && <Progress />}
{/* The sheetsManager={new Map()} is needed in order to deduplicate the injection of CSS in the page. */}
<StylesProvider jss={jss} sheetsManager={new Map()}>
<div ref={ref} data-testid="techdocs-native-shadowroot" />
{children}
</StylesProvider>
</>
);
}