ReturnToPrevious: create DismissableButton and ReturnToPrevious components (#80878)

This commit is contained in:
Laura Fernández 2024-01-22 15:28:11 +01:00 committed by GitHub
parent d4e831b051
commit a0e7aef840
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 141 additions and 0 deletions

View File

@ -0,0 +1,58 @@
import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { Button, ButtonGroup, useStyles2 } from '@grafana/ui';
import { t } from 'app/core/internationalization';
export interface DismissableButtonProps {
label: string;
onClick: () => void;
onDismiss: () => void;
}
export const DismissableButton = ({ label, onClick, onDismiss }: DismissableButtonProps) => {
const styles = useStyles2(getStyles);
return (
<ButtonGroup className={styles.buttonGroup}>
<Button
icon="angle-left"
size="sm"
variant="primary"
fill="outline"
onClick={onClick}
title={label}
className={styles.mainDismissableButton}
>
{label}
</Button>
<Button
icon="times"
aria-label={t('return-to-previous.dismissable-button', 'Close')}
variant="primary"
fill="outline"
size="sm"
onClick={onDismiss}
/>
</ButtonGroup>
);
};
const getStyles = (theme: GrafanaTheme2) => ({
mainDismissableButton: css({
width: '100%',
['> span']: {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
maxWidth: '270px',
display: 'inline-block',
},
}),
buttonGroup: css({
width: 'fit-content',
backgroundColor: theme.colors.background.secondary,
}),
});
DismissableButton.displayName = 'DismissableButton';

View File

@ -0,0 +1,47 @@
import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { useStyles2 } from '@grafana/ui';
import { t } from 'app/core/internationalization';
import { DismissableButton } from './DismissableButton';
export interface ReturnToPreviousProps {
href: string;
title: string;
}
export const ReturnToPrevious = ({ href, title }: ReturnToPreviousProps) => {
const styles = useStyles2(getStyles);
const handleOnClick = () => {
console.log('Going to...', href);
};
const handleOnDismiss = () => {
console.log('Closing button');
};
return (
<div className={styles.returnToPrevious}>
<DismissableButton
label={t('return-to-previous.button.label', 'Back to {{title}}', { title })}
onClick={handleOnClick}
onDismiss={handleOnDismiss}
/>
</div>
);
};
const getStyles = (theme: GrafanaTheme2) => ({
returnToPrevious: css({
label: 'return-to-previous',
display: 'flex',
justifyContent: 'center',
left: '50%',
transform: 'translateX(-50%)',
zIndex: theme.zIndex.portal,
position: 'fixed',
bottom: theme.spacing.x4,
}),
});
ReturnToPrevious.displayName = 'ReturnToPrevious';

View File

@ -1224,6 +1224,12 @@
"turned-off": "Automatische Aktualisierung aus"
}
},
"return-to-previous": {
"button": {
"label": ""
},
"dismissable-button": ""
},
"search": {
"actions": {
"include-panels": "Panels einschließen",

View File

@ -1224,6 +1224,12 @@
"turned-off": "Auto refresh off"
}
},
"return-to-previous": {
"button": {
"label": "Back to {{title}}"
},
"dismissable-button": "Close"
},
"search": {
"actions": {
"include-panels": "Include panels",

View File

@ -1230,6 +1230,12 @@
"turned-off": "Actualización automática desactivada"
}
},
"return-to-previous": {
"button": {
"label": ""
},
"dismissable-button": ""
},
"search": {
"actions": {
"include-panels": "Incluir paneles",

View File

@ -1230,6 +1230,12 @@
"turned-off": "Actualisation automatique désactivée"
}
},
"return-to-previous": {
"button": {
"label": ""
},
"dismissable-button": ""
},
"search": {
"actions": {
"include-panels": "Inclure des panneaux",

View File

@ -1224,6 +1224,12 @@
"turned-off": "Åūŧő řęƒřęşĥ őƒƒ"
}
},
"return-to-previous": {
"button": {
"label": "ßäčĸ ŧő {{title}}"
},
"dismissable-button": "Cľőşę"
},
"search": {
"actions": {
"include-panels": "Ĩʼnčľūđę päʼnęľş",

View File

@ -1218,6 +1218,12 @@
"turned-off": "自动刷新关闭"
}
},
"return-to-previous": {
"button": {
"label": ""
},
"dismissable-button": ""
},
"search": {
"actions": {
"include-panels": "包括面板",