diff --git a/packages/grafana-ui/src/components/Tabs/Counter.tsx b/packages/grafana-ui/src/components/Tabs/Counter.tsx new file mode 100644 index 00000000000..90edecca440 --- /dev/null +++ b/packages/grafana-ui/src/components/Tabs/Counter.tsx @@ -0,0 +1,30 @@ +import React, { FC, useContext } from 'react'; +import { css } from 'emotion'; +import { stylesFactory, ThemeContext } from '../../themes'; +import { GrafanaTheme, locale } from '@grafana/data'; + +const getStyles = stylesFactory((theme: GrafanaTheme) => { + return { + counter: css` + label: counter; + margin-left: ${theme.spacing.sm}; + border-radius: ${theme.spacing.lg}; + background-color: ${theme.colors.bg2}; + padding: ${theme.spacing.xxs} ${theme.spacing.sm}; + color: ${theme.colors.textWeak}; + font-weight: ${theme.typography.weight.semibold}; + font-size: ${theme.typography.size.sm}; + `, + }; +}); + +export interface CounterProps { + value: number; +} + +export const Counter: FC = ({ value }) => { + const theme = useContext(ThemeContext); + const styles = getStyles(theme); + + return {locale(value, 0).text}; +}; diff --git a/packages/grafana-ui/src/components/Tabs/Tab.tsx b/packages/grafana-ui/src/components/Tabs/Tab.tsx index b4a09ce52e1..cea1676c112 100644 --- a/packages/grafana-ui/src/components/Tabs/Tab.tsx +++ b/packages/grafana-ui/src/components/Tabs/Tab.tsx @@ -4,12 +4,14 @@ import { GrafanaTheme } from '@grafana/data'; import { Icon } from '../Icon/Icon'; import { IconName } from '../../types'; import { stylesFactory, useTheme } from '../../themes'; +import { Counter } from './Counter'; export interface TabProps { label: string; active?: boolean; icon?: IconName; onChangeTab: () => void; + counter?: number; } const getTabStyles = stylesFactory((theme: GrafanaTheme) => { @@ -57,7 +59,7 @@ const getTabStyles = stylesFactory((theme: GrafanaTheme) => { }; }); -export const Tab: FC = ({ label, active, icon, onChangeTab }) => { +export const Tab: FC = ({ label, active, icon, onChangeTab, counter }) => { const theme = useTheme(); const tabsStyles = getTabStyles(theme); @@ -65,6 +67,7 @@ export const Tab: FC = ({ label, active, icon, onChangeTab }) => {
  • {icon && } {label} + {!!counter && }
  • ); }; diff --git a/packages/grafana-ui/src/components/Tabs/Tabs.story.tsx b/packages/grafana-ui/src/components/Tabs/Tabs.story.tsx index 4603fcb7a1a..f7279567f76 100644 --- a/packages/grafana-ui/src/components/Tabs/Tabs.story.tsx +++ b/packages/grafana-ui/src/components/Tabs/Tabs.story.tsx @@ -30,6 +30,7 @@ export const Simple = () => { label={tab.label} active={tab.active} onChangeTab={() => updateState(state.map((tab, idx) => ({ ...tab, active: idx === index })))} + counter={(index + 1) * 1000} /> ); })} diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx index 3db0846c049..87ac1d3f613 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditorTabs.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { config } from 'app/core/config'; import { css } from 'emotion'; -import { TabsBar, Tab, stylesFactory, TabContent, IconName } from '@grafana/ui'; +import { IconName, stylesFactory, Tab, TabContent, TabsBar } from '@grafana/ui'; import { DataTransformerConfig, LoadingState, PanelData } from '@grafana/data'; import { PanelEditorTab, PanelEditorTabId } from './types'; import { DashboardModel } from '../../state';