Tabs: add suffix prop for the tab name (#43869)

* Tabs: add suffix prop for the tab name

* Replace FC with JSX.Element
This commit is contained in:
Agnès Toulet
2022-01-12 15:37:16 +01:00
committed by GitHub
parent 105bf8fd94
commit 5eaaadd59d
4 changed files with 9 additions and 1 deletions

View File

@@ -95,6 +95,9 @@ export class GrafanaBootConfig implements GrafanaConfig {
recordedQueries = {
enabled: false,
};
featureHighlights = {
enabled: false,
};
constructor(options: GrafanaBootConfig) {
const mode = options.bootData.user.lightTheme ? 'light' : 'dark';

View File

@@ -8,6 +8,7 @@ interface ModalTab {
value: string;
label: string;
icon?: IconName;
labelSuffix?: () => JSX.Element;
}
interface Props {
@@ -28,6 +29,7 @@ export const ModalTabsHeader: React.FC<Props> = ({ icon, title, tabs, activeTab,
key={`${t.value}-${index}`}
label={t.label}
icon={t.icon}
suffix={t.labelSuffix}
active={t.value === activeTab}
onChangeTab={() => onChangeTab(t)}
/>

View File

@@ -18,10 +18,11 @@ export interface TabProps extends HTMLProps<HTMLAnchorElement> {
onChangeTab?: (event?: React.MouseEvent<HTMLAnchorElement>) => void;
/** A number rendered next to the text. Usually used to display the number of items in a tab's view. */
counter?: number | null;
suffix?: () => JSX.Element;
}
export const Tab = React.forwardRef<HTMLAnchorElement, TabProps>(
({ label, active, icon, onChangeTab, counter, className, href, ...otherProps }, ref) => {
({ label, active, icon, onChangeTab, counter, suffix, className, href, ...otherProps }, ref) => {
const theme = useTheme2();
const tabsStyles = getTabStyles(theme);
const content = () => (
@@ -29,6 +30,7 @@ export const Tab = React.forwardRef<HTMLAnchorElement, TabProps>(
{icon && <Icon name={icon} />}
{label}
{typeof counter === 'number' && <Counter value={counter} />}
{suffix && suffix()}
</>
);

View File

@@ -10,5 +10,6 @@ export interface ShareModalTabProps {
export interface ShareModalTabModel {
label: string;
value: string;
labelSuffix?: () => JSX.Element;
component: React.ComponentType<ShareModalTabProps>;
}