styled-components/macro#StyleSheetManager TypeScript Examples
The following examples show how to use
styled-components/macro#StyleSheetManager.
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: ChartIFrameContainer.tsx From datart with Apache License 2.0 | 4 votes |
ChartIFrameContainer: FC<{
dataset: any;
chart: IChart;
config: ChartConfig;
containerId?: string;
width?: any;
height?: any;
isShown?: boolean;
drillOption?: IChartDrillOption;
widgetSpecialConfig?: any;
scale?: [number, number];
}> = memo(props => {
const iframeContainerId = `chart-iframe-root-${props.containerId}`;
const config = setRuntimeDateLevelFieldsInChartConfig(props.config);
const transformToSafeCSSProps = (width, height) => {
let newStyle = { width, height };
if (isNaN(newStyle?.width) || isEmpty(newStyle?.width)) {
newStyle.width = 0;
}
if (isNaN(newStyle?.height) || isEmpty(newStyle?.height)) {
newStyle.height = 0;
}
return newStyle;
};
const render = () => {
if (!props?.chart?.useIFrame) {
return (
<div
id={`chart-root-${props.containerId}`}
key={props.containerId}
style={{ width: '100%', height: '100%', position: 'relative' }}
>
<div
style={{
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
}}
>
<ChartIFrameLifecycleAdapter
dataset={props.dataset}
chart={props.chart}
config={config}
style={transformToSafeCSSProps(props?.width, props?.height)}
widgetSpecialConfig={props.widgetSpecialConfig}
isShown={props.isShown}
drillOption={props?.drillOption}
/>
</div>
</div>
);
}
return (
<Frame
id={iframeContainerId}
key={props.containerId}
frameBorder={0}
style={{ width: '100%', height: '100%' }}
head={
<>
<style>
{`
body {
height: 100%;
overflow: hidden;
background-color: transparent !important;
margin: 0;
}
`}
</style>
</>
}
>
<FrameContextConsumer>
{frameContext => (
<StyleSheetManager target={frameContext.document?.head}>
<div
onContextMenu={event => {
event.stopPropagation();
event.preventDefault();
var iframe = document.getElementById(iframeContainerId);
if (iframe) {
const [scaleX = 1, scaleY = 1] = props.scale || [];
var boundingClientRect = iframe.getBoundingClientRect();
var evt = new CustomEvent('contextmenu', {
bubbles: true,
cancelable: false,
}) as any;
evt.clientX =
event.clientX * scaleX + boundingClientRect.left;
evt.pageX =
event.clientX * scaleX + boundingClientRect.left;
evt.clientY =
event.clientY * scaleY + boundingClientRect.top;
evt.pageY = event.clientY * scaleY + boundingClientRect.top;
iframe.dispatchEvent(evt);
}
}}
>
<ChartIFrameLifecycleAdapter
dataset={props.dataset}
chart={props.chart}
config={config}
style={transformToSafeCSSProps(props?.width, props?.height)}
widgetSpecialConfig={props.widgetSpecialConfig}
isShown={props.isShown}
drillOption={props.drillOption}
/>
</div>
</StyleSheetManager>
)}
</FrameContextConsumer>
</Frame>
);
};
return (
<ChartI18NContext.Provider value={{ i18NConfigs: props?.config?.i18ns }}>
{render()}
</ChartI18NContext.Provider>
);
})