mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
grafana/ui: Add default type="button" to <Button> (#48183)
This commit is contained in:
parent
2f1d404949
commit
6e530d45bc
@ -23,12 +23,26 @@ type CommonProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
fullWidth?: boolean;
|
fullWidth?: boolean;
|
||||||
|
type?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ButtonProps = CommonProps & ButtonHTMLAttributes<HTMLButtonElement>;
|
export type ButtonProps = CommonProps & ButtonHTMLAttributes<HTMLButtonElement>;
|
||||||
|
|
||||||
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
({ variant = 'primary', size = 'md', fill = 'solid', icon, fullWidth, children, className, ...otherProps }, ref) => {
|
(
|
||||||
|
{
|
||||||
|
variant = 'primary',
|
||||||
|
size = 'md',
|
||||||
|
fill = 'solid',
|
||||||
|
icon,
|
||||||
|
fullWidth,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
type = 'button',
|
||||||
|
...otherProps
|
||||||
|
},
|
||||||
|
ref
|
||||||
|
) => {
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
const styles = getButtonStyles({
|
const styles = getButtonStyles({
|
||||||
theme,
|
theme,
|
||||||
@ -45,7 +59,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button className={cx(styles.button, className)} {...otherProps} ref={ref}>
|
<button className={cx(styles.button, className)} type={type} {...otherProps} ref={ref}>
|
||||||
{icon && <Icon name={icon} size={size} className={styles.icon} />}
|
{icon && <Icon name={icon} size={size} className={styles.icon} />}
|
||||||
{children && <span className={styles.content}>{children}</span>}
|
{children && <span className={styles.content}>{children}</span>}
|
||||||
</button>
|
</button>
|
||||||
|
@ -59,7 +59,7 @@ export const ForgottenPassword: FC = () => {
|
|||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<HorizontalGroup>
|
<HorizontalGroup>
|
||||||
<Button>Send reset email</Button>
|
<Button type="submit">Send reset email</Button>
|
||||||
<LinkButton fill="text" href={loginHref}>
|
<LinkButton fill="text" href={loginHref}>
|
||||||
Back to login
|
Back to login
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
|
@ -49,7 +49,12 @@ export const LoginForm: FC<Props> = ({ children, onSubmit, isLoggingIn, password
|
|||||||
{...register('password', { required: 'Password is required' })}
|
{...register('password', { required: 'Password is required' })}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Button aria-label={selectors.pages.Login.submit} className={submitButton} disabled={isLoggingIn}>
|
<Button
|
||||||
|
type="submit"
|
||||||
|
aria-label={selectors.pages.Login.submit}
|
||||||
|
className={submitButton}
|
||||||
|
disabled={isLoggingIn}
|
||||||
|
>
|
||||||
{isLoggingIn ? 'Logging in...' : 'Log in'}
|
{isLoggingIn ? 'Logging in...' : 'Log in'}
|
||||||
</Button>
|
</Button>
|
||||||
{children}
|
{children}
|
||||||
|
@ -207,7 +207,11 @@ export class SharedPreferences extends PureComponent<Props, State> {
|
|||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
<div className="gf-form-button-row">
|
<div className="gf-form-button-row">
|
||||||
<Button variant="primary" data-testid={selectors.components.UserProfile.preferencesSaveButton}>
|
<Button
|
||||||
|
type="submit"
|
||||||
|
variant="primary"
|
||||||
|
data-testid={selectors.components.UserProfile.preferencesSaveButton}
|
||||||
|
>
|
||||||
<Trans id="common.save">Save</Trans>
|
<Trans id="common.save">Save</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -61,7 +61,7 @@ export const VerifyEmail: FC = () => {
|
|||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<HorizontalGroup>
|
<HorizontalGroup>
|
||||||
<Button>Send verification email</Button>
|
<Button type="submit">Send verification email</Button>
|
||||||
<LinkButton fill="text" href={getConfig().appSubUrl + '/login'}>
|
<LinkButton fill="text" href={getConfig().appSubUrl + '/login'}>
|
||||||
Back to login
|
Back to login
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
|
@ -85,7 +85,9 @@ export default function AdminEditOrgPage({ match }: Props) {
|
|||||||
<Field label="Name" invalid={!!errors.orgName} error="Name is required" disabled={!canWriteOrg}>
|
<Field label="Name" invalid={!!errors.orgName} error="Name is required" disabled={!canWriteOrg}>
|
||||||
<Input {...register('orgName', { required: true })} id="org-name-input" />
|
<Input {...register('orgName', { required: true })} id="org-name-input" />
|
||||||
</Field>
|
</Field>
|
||||||
<Button disabled={!canWriteOrg}>Update</Button>
|
<Button type="submit" disabled={!canWriteOrg}>
|
||||||
|
Update
|
||||||
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -39,7 +39,9 @@ export const CrawlerStartButton = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Modal.ButtonRow>
|
<Modal.ButtonRow>
|
||||||
<Button onClick={doStart}>Start</Button>
|
<Button type="submit" onClick={doStart}>
|
||||||
|
Start
|
||||||
|
</Button>
|
||||||
<Button variant="secondary" onClick={onDismiss}>
|
<Button variant="secondary" onClick={onDismiss}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -82,7 +82,9 @@ export const AddAlertManagerModal: FC<Props> = ({ alertmanagers, onChangeAlertma
|
|||||||
)}
|
)}
|
||||||
</FieldArray>
|
</FieldArray>
|
||||||
<div>
|
<div>
|
||||||
<Button onSubmit={() => onSubmit}>Add Alertmanagers</Button>
|
<Button type="submit" onSubmit={() => onSubmit}>
|
||||||
|
Add Alertmanagers
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -33,7 +33,9 @@ export const ReceiversSection: FC<Props> = ({
|
|||||||
</div>
|
</div>
|
||||||
{showButton && (
|
{showButton && (
|
||||||
<Link to={addButtonTo}>
|
<Link to={addButtonTo}>
|
||||||
<Button icon="plus">{addButtonLabel}</Button>
|
<Button type="button" icon="plus">
|
||||||
|
{addButtonLabel}
|
||||||
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -152,7 +152,11 @@ export const TemplateForm: FC<Props> = ({ existing, alertManagerSourceName, conf
|
|||||||
Saving...
|
Saving...
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{!loading && <Button variant="primary">Save template</Button>}
|
{!loading && (
|
||||||
|
<Button type="submit" variant="primary">
|
||||||
|
Save template
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<LinkButton
|
<LinkButton
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
href={makeAMLink('alerting/notifications', alertManagerSourceName)}
|
href={makeAMLink('alerting/notifications', alertManagerSourceName)}
|
||||||
|
@ -99,7 +99,9 @@ export const ApiKeysForm: FC<Props> = ({ show, onClose, onKeyAdded, disabled })
|
|||||||
</InlineField>
|
</InlineField>
|
||||||
</div>
|
</div>
|
||||||
<div className="gf-form">
|
<div className="gf-form">
|
||||||
<Button disabled={disabled}>Add</Button>
|
<Button type="submit" disabled={disabled}>
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -27,7 +27,11 @@ class ButtonDisplay extends PureComponent<CanvasElementProps<ButtonConfig, Butto
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return <Button onClick={onClick}>{data?.text}</Button>;
|
return (
|
||||||
|
<Button type="submit" onClick={onClick}>
|
||||||
|
{data?.text}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,9 @@ const onClose = () => locationService.partial({ editview: null });
|
|||||||
const MakeEditable = (props: { onMakeEditable: () => any }) => (
|
const MakeEditable = (props: { onMakeEditable: () => any }) => (
|
||||||
<div>
|
<div>
|
||||||
<div className="dashboard-settings__header">Dashboard not editable</div>
|
<div className="dashboard-settings__header">Dashboard not editable</div>
|
||||||
<Button onClick={props.onMakeEditable}>Make editable</Button>
|
<Button type="submit" onClick={props.onMakeEditable}>
|
||||||
|
Make editable
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -54,7 +54,9 @@ export const JsonEditorSettings: React.FC<Props> = ({ dashboard }) => {
|
|||||||
</div>
|
</div>
|
||||||
{dashboard.meta.canSave && (
|
{dashboard.meta.canSave && (
|
||||||
<HorizontalGroup>
|
<HorizontalGroup>
|
||||||
<Button onClick={onClick}>Save changes</Button>
|
<Button type="submit" onClick={onClick}>
|
||||||
|
Save changes
|
||||||
|
</Button>
|
||||||
</HorizontalGroup>
|
</HorizontalGroup>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -67,7 +67,9 @@ export const SaveProvisionedDashboardForm: React.FC<SaveDashboardFormProps> = ({
|
|||||||
<ClipboardButton getText={() => dashboardJSON} onClipboardCopy={onCopyToClipboardSuccess}>
|
<ClipboardButton getText={() => dashboardJSON} onClipboardCopy={onCopyToClipboardSuccess}>
|
||||||
Copy JSON to clipboard
|
Copy JSON to clipboard
|
||||||
</ClipboardButton>
|
</ClipboardButton>
|
||||||
<Button onClick={saveToFile}>Save JSON to file</Button>
|
<Button type="submit" onClick={saveToFile}>
|
||||||
|
Save JSON to file
|
||||||
|
</Button>
|
||||||
</HorizontalGroup>
|
</HorizontalGroup>
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
|
@ -69,7 +69,7 @@ export const ChangePasswordForm: FC<Props> = ({ user, onChangePassword, isSaving
|
|||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<HorizontalGroup>
|
<HorizontalGroup>
|
||||||
<Button variant="primary" disabled={isSaving}>
|
<Button variant="primary" disabled={isSaving} type="submit">
|
||||||
Change Password
|
Change Password
|
||||||
</Button>
|
</Button>
|
||||||
<LinkButton variant="secondary" href={`${config.appSubUrl}/profile`} fill="outline">
|
<LinkButton variant="secondary" href={`${config.appSubUrl}/profile`} fill="outline">
|
||||||
|
@ -74,6 +74,7 @@ export const UserProfileEditForm: FC<Props> = ({ user, isSavingUser, updateProfi
|
|||||||
variant="primary"
|
variant="primary"
|
||||||
disabled={isSavingUser}
|
disabled={isSavingUser}
|
||||||
data-testid={selectors.components.UserProfile.profileSaveButton}
|
data-testid={selectors.components.UserProfile.profileSaveButton}
|
||||||
|
type="submit"
|
||||||
>
|
>
|
||||||
<Trans id="common.save">Save</Trans>
|
<Trans id="common.save">Save</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
Reference in New Issue
Block a user