2023-07-11 17:11:25 +08:00
|
|
|
import { css, cx } from '@emotion/css';
|
|
|
|
|
import React, { ComponentProps, HTMLAttributes } from 'react';
|
2023-03-02 20:49:38 +08:00
|
|
|
|
2023-11-07 00:15:52 +08:00
|
|
|
import { Icon, IconName, useStyles2, Text, Stack } from '@grafana/ui';
|
2023-03-02 20:49:38 +08:00
|
|
|
|
2023-03-14 22:38:21 +08:00
|
|
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
2023-03-02 20:49:38 +08:00
|
|
|
icon?: IconName;
|
2023-07-20 18:59:42 +08:00
|
|
|
color?: ComponentProps<typeof Text>['color'];
|
2023-03-02 20:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-11 17:11:25 +08:00
|
|
|
const MetaText = ({ children, icon, color = 'secondary', ...rest }: Props) => {
|
2023-03-02 20:49:38 +08:00
|
|
|
const styles = useStyles2(getStyles);
|
|
|
|
|
const interactive = typeof rest.onClick === 'function';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
2023-07-11 17:11:25 +08:00
|
|
|
className={cx({
|
2023-03-02 20:49:38 +08:00
|
|
|
[styles.interactive]: interactive,
|
|
|
|
|
})}
|
2023-07-11 17:11:25 +08:00
|
|
|
// allow passing ARIA and data- attributes
|
2023-03-02 20:49:38 +08:00
|
|
|
{...rest}
|
|
|
|
|
>
|
2023-09-26 16:44:18 +08:00
|
|
|
<Text variant="bodySmall" color={color}>
|
2023-11-07 00:15:52 +08:00
|
|
|
<Stack direction="row" alignItems="center" gap={0.5} wrap={'wrap'}>
|
2023-09-26 16:44:18 +08:00
|
|
|
{icon && <Icon size="sm" name={icon} />}
|
2023-07-11 17:11:25 +08:00
|
|
|
{children}
|
|
|
|
|
</Stack>
|
2023-07-20 18:59:42 +08:00
|
|
|
</Text>
|
2023-03-02 20:49:38 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-11 17:11:25 +08:00
|
|
|
const getStyles = () => ({
|
2023-03-02 20:49:38 +08:00
|
|
|
interactive: css`
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export { MetaText };
|