grafana/public/app/features/api-keys/ApiKeysAddedModal.tsx
Ezequiel Victorero 0633840777
GrafanaUI: Add success state to ClipboardButton (#52069)
* User Experience: apply the same pattern feedback for all copy to clipboard buttons

* add copy icon to all ClipboardButton use cases

* Change primary color for copy to clipboard in create token

* Add success button variant

* Remove copy confirmation from TableCellInspectModal because it's in the base component now

* Design tweaks to copy confirmation

 - Only change the icon to tick to avoid the button changing size
 - Change button to success green
 - Only show copy confirmation state for 2 seconds

* revert TabelCellInspectModal text button back

* revert accidental change to ShareLink

Co-authored-by: joshhunt <josh@trtr.co>
2022-07-20 10:33:46 +01:00

56 lines
1.7 KiB
TypeScript

import { css } from '@emotion/css';
import React, { useCallback } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { Alert, Field, Modal, useStyles2, Input, ClipboardButton } from '@grafana/ui';
export interface Props {
onDismiss: () => void;
apiKey: string;
rootPath: string;
}
export function ApiKeysAddedModal({ onDismiss, apiKey, rootPath }: Props): JSX.Element {
const styles = useStyles2(getStyles);
const getClipboardText = useCallback(() => apiKey, [apiKey]);
return (
<Modal title="API Key Created" onDismiss={onDismiss} onClickBackdrop={onDismiss} isOpen>
<Field label="Key">
<Input
id="Key"
value={apiKey}
readOnly
addonAfter={
<ClipboardButton icon="copy" variant="primary" getText={getClipboardText}>
Copy
</ClipboardButton>
}
/>
</Field>
<Alert severity="info" title="You will only be able to view this key here once!">
It is not stored in this form, so be sure to copy it now.
</Alert>
<p className="text-muted">You can authenticate a request using the Authorization HTTP header, example:</p>
<pre className={styles.small}>
curl -H &quot;Authorization: Bearer {apiKey}&quot; {rootPath}/api/dashboards/home
</pre>
</Modal>
);
}
function getStyles(theme: GrafanaTheme2) {
return {
label: css`
padding: ${theme.spacing(1)};
background-color: ${theme.colors.background.secondary};
border-radius: ${theme.shape.borderRadius()};
`,
small: css`
font-size: ${theme.typography.bodySmall.fontSize};
font-weight: ${theme.typography.bodySmall.fontWeight};
`,
};
}