mirror of https://github.com/grafana/grafana
NavModel: Enable adding suffix elements to tabs (#44155)
* Trigger extra events * Extend html attributes * Add suffix to tabs * Add upgrade routes * suffix => highlightText * suffix => suffixText * Add size prop * Update prop name * Convert tabSuffix to a componentpull/44469/head
parent
a20894c261
commit
55e1c53e36
@ -1,5 +1,10 @@ |
||||
import { Meta, Props } from '@storybook/addon-docs/blocks'; |
||||
import { Badge } from './Badge'; |
||||
|
||||
<Meta title="MDX|Badge" component={Badge} /> |
||||
|
||||
# Badge |
||||
## Badge |
||||
|
||||
The badge component adds meta information to other content, for example about release status or new elements. You can add any `Icon` component or use the badge without an icon. |
||||
|
||||
<Props of={Badge} /> |
||||
|
||||
@ -0,0 +1,40 @@ |
||||
import React, { HTMLAttributes, useEffect } from 'react'; |
||||
import { css, cx } from '@emotion/css'; |
||||
import { useStyles2 } from '@grafana/ui'; |
||||
import { GrafanaTheme2 } from '@grafana/data'; |
||||
|
||||
export interface Props extends HTMLAttributes<HTMLSpanElement> { |
||||
text?: string; |
||||
/** Function to call when component initializes, e.g. event trackers */ |
||||
onLoad?: (...args: any[]) => void; |
||||
} |
||||
|
||||
export const ProBadge = ({ text = 'PRO', className, onLoad, ...htmlProps }: Props) => { |
||||
const styles = useStyles2(getStyles); |
||||
|
||||
useEffect(() => { |
||||
if (onLoad) { |
||||
onLoad(); |
||||
} |
||||
}, [onLoad]); |
||||
|
||||
return ( |
||||
<span className={cx(styles.badge, className)} {...htmlProps}> |
||||
{text} |
||||
</span> |
||||
); |
||||
}; |
||||
|
||||
const getStyles = (theme: GrafanaTheme2) => { |
||||
return { |
||||
badge: css` |
||||
margin-left: ${theme.spacing(1.25)}; |
||||
border-radius: ${theme.shape.borderRadius(5)}; |
||||
background-color: ${theme.colors.success.main}; |
||||
padding: ${theme.spacing(0.25, 0.75)}; |
||||
color: ${theme.colors.text.maxContrast}; |
||||
font-weight: ${theme.typography.fontWeightMedium}; |
||||
font-size: ${theme.typography.pxToRem(10)}; |
||||
`,
|
||||
}; |
||||
}; |
||||
Loading…
Reference in new issue