mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Do not use pointer cursor on icon by default * Allow items alignment in the HorizontalGroup layout * Add util for rendering components based on their type (element or function) * Components for rendering query and transformation rows in a unified way * Apply new UI fo query and transformation rows * Add some tests * Minor fix for scroll area Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
23 lines
693 B
TypeScript
23 lines
693 B
TypeScript
import React from 'react';
|
|
|
|
/**
|
|
* Given react node or function returns element accordingly
|
|
*
|
|
* @param itemToRender
|
|
* @param props props to be passed to the function if item provided as such
|
|
*/
|
|
export function renderOrCallToRender<TProps = any>(
|
|
itemToRender: ((props?: TProps) => React.ReactNode) | React.ReactNode,
|
|
props?: TProps
|
|
): React.ReactNode {
|
|
if (React.isValidElement(itemToRender) || typeof itemToRender === 'string' || typeof itemToRender === 'number') {
|
|
return itemToRender;
|
|
}
|
|
|
|
if (typeof itemToRender === 'function') {
|
|
return itemToRender(props);
|
|
}
|
|
|
|
throw new Error(`${itemToRender} is not a React element nor a function that returns React element`);
|
|
}
|