mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 13:12:08 +08:00
23 lines
729 B
TypeScript
23 lines
729 B
TypeScript
import { ReactNode } from 'react';
|
|
|
|
import { SceneObject } from '@grafana/scenes';
|
|
|
|
import { ConditionalRendering } from './ConditionalRendering';
|
|
import { ConditionalRenderingOverlay } from './ConditionalRenderingOverlay';
|
|
|
|
export function useIsConditionallyHidden(scene: SceneObject): [boolean, string | undefined, ReactNode | null] {
|
|
const state = scene.useState();
|
|
|
|
if (!('conditionalRendering' in state) || !(state.conditionalRendering instanceof ConditionalRendering)) {
|
|
return [false, undefined, null];
|
|
}
|
|
|
|
const value = state.conditionalRendering.evaluate() ?? true;
|
|
|
|
return [
|
|
!value,
|
|
value ? undefined : 'dashboard-visible-hidden-element',
|
|
value ? null : <ConditionalRenderingOverlay />,
|
|
];
|
|
}
|