mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 04:34:23 -06:00
A11y: add copy button to API Key modal (#46387)
* add copy button to API Key modal * switch to inline button style * update test snapshot
This commit is contained in:
parent
ec84b7bd23
commit
52c9da1b11
@ -1,7 +1,10 @@
|
||||
import React from 'react';
|
||||
import React, { useCallback } from 'react';
|
||||
import { css } from '@emotion/css';
|
||||
import { Alert, Field, Modal, useStyles2 } from '@grafana/ui';
|
||||
import { Alert, Field, Modal, useStyles2, Input, Icon, ClipboardButton } from '@grafana/ui';
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { notifyApp } from '../../core/actions';
|
||||
import { dispatch } from '../../store/store';
|
||||
import { createSuccessNotification } from '../../core/copy/appNotification';
|
||||
|
||||
export interface Props {
|
||||
onDismiss: () => void;
|
||||
@ -11,12 +14,24 @@ export interface Props {
|
||||
|
||||
export function ApiKeysAddedModal({ onDismiss, apiKey, rootPath }: Props): JSX.Element {
|
||||
const styles = useStyles2(getStyles);
|
||||
const getClipboardText = useCallback(() => apiKey, [apiKey]);
|
||||
const onClipboardCopy = () => {
|
||||
dispatch(notifyApp(createSuccessNotification('Content copied to clipboard')));
|
||||
};
|
||||
return (
|
||||
<Modal title="API Key Created" onDismiss={onDismiss} onClickBackdrop={onDismiss} isOpen>
|
||||
<Field label="Key">
|
||||
<span className={styles.label}>{apiKey}</span>
|
||||
<Input
|
||||
id="Key"
|
||||
value={apiKey}
|
||||
readOnly
|
||||
addonAfter={
|
||||
<ClipboardButton variant="primary" getText={getClipboardText} onClipboardCopy={onClipboardCopy}>
|
||||
<Icon name="copy" /> 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>
|
||||
|
@ -10,11 +10,23 @@ exports[`Render should render component 1`] = `
|
||||
<Field
|
||||
label="Key"
|
||||
>
|
||||
<span
|
||||
className="css-ypoxjz"
|
||||
>
|
||||
api key test
|
||||
</span>
|
||||
<Input
|
||||
addonAfter={
|
||||
<ClipboardButton
|
||||
getText={[Function]}
|
||||
onClipboardCopy={[Function]}
|
||||
variant="primary"
|
||||
>
|
||||
<Icon
|
||||
name="copy"
|
||||
/>
|
||||
Copy
|
||||
</ClipboardButton>
|
||||
}
|
||||
id="Key"
|
||||
readOnly={true}
|
||||
value="api key test"
|
||||
/>
|
||||
</Field>
|
||||
<Alert
|
||||
severity="info"
|
||||
|
Loading…
Reference in New Issue
Block a user