mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 18:02:33 +00:00
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { StyleRegistry, createStyleRegistry } from 'styled-jsx';
|
|
import { ServerStyleSheet, StyleSheetManager } from 'styled-components';
|
|
|
|
type ChildProps = { children: React.ReactNode };
|
|
|
|
export function useStyledComponentsRegistry() {
|
|
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());
|
|
|
|
const styledComponentsFlushEffect = () => {
|
|
const styles = styledComponentsStyleSheet.getStyleElement();
|
|
styledComponentsStyleSheet.instance.clearTag();
|
|
return <>{styles}</>;
|
|
};
|
|
|
|
function StyledComponentsRegistry({ children }: ChildProps) {
|
|
return (
|
|
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
|
|
{children as React.ReactChild}
|
|
</StyleSheetManager>
|
|
);
|
|
}
|
|
|
|
return [StyledComponentsRegistry, styledComponentsFlushEffect] as const;
|
|
}
|
|
|
|
export function useStyledJsxRegistry() {
|
|
const [jsxStyleRegistry] = useState(() => createStyleRegistry());
|
|
|
|
function styledJsxFlushEffect() {
|
|
const styles = jsxStyleRegistry.styles();
|
|
jsxStyleRegistry.flush();
|
|
return <>{styles}</>;
|
|
}
|
|
|
|
function StyledJsxRegistry({ children }: ChildProps) {
|
|
return (
|
|
<StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry>
|
|
);
|
|
}
|
|
|
|
return [StyledJsxRegistry, styledJsxFlushEffect] as const;
|
|
}
|