mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 16:48:12 +08:00
Forms: revamped select (#21092)
This commit is contained in:
@ -18,12 +18,13 @@ type CommonProps = {
|
||||
};
|
||||
|
||||
type ButtonProps = CommonProps & ButtonHTMLAttributes<HTMLButtonElement>;
|
||||
export const Button: React.FunctionComponent<ButtonProps> = props => {
|
||||
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
|
||||
const theme = useContext(ThemeContext);
|
||||
const { size, variant, icon, children, className, styles: stylesProp, ...buttonProps } = props;
|
||||
|
||||
// Default this to 'button', otherwise html defaults to 'submit' which then submits any form it is in.
|
||||
buttonProps.type = buttonProps.type || 'button';
|
||||
|
||||
const styles: ButtonStyles =
|
||||
stylesProp ||
|
||||
getButtonStyles({
|
||||
@ -32,14 +33,14 @@ export const Button: React.FunctionComponent<ButtonProps> = props => {
|
||||
variant: variant || 'primary',
|
||||
});
|
||||
|
||||
const buttonClassName = cx(styles.button, icon && styles.buttonWithIcon, icon && !children && styles.iconButton);
|
||||
return (
|
||||
<button className={cx(styles.button, className)} {...buttonProps}>
|
||||
<ButtonContent iconClassName={styles.icon} className={styles.iconWrap} icon={icon}>
|
||||
{children}
|
||||
</ButtonContent>
|
||||
<button className={buttonClassName} {...buttonProps} ref={ref}>
|
||||
<ButtonContent icon={icon}>{children}</ButtonContent>
|
||||
</button>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
Button.displayName = 'Button';
|
||||
|
||||
type LinkButtonProps = CommonProps &
|
||||
@ -48,7 +49,8 @@ type LinkButtonProps = CommonProps &
|
||||
// disabled.
|
||||
disabled?: boolean;
|
||||
};
|
||||
export const LinkButton: React.FunctionComponent<LinkButtonProps> = props => {
|
||||
|
||||
export const LinkButton = React.forwardRef<HTMLAnchorElement, LinkButtonProps>((props, ref) => {
|
||||
const theme = useContext(ThemeContext);
|
||||
const { size, variant, icon, children, className, styles: stylesProp, ...anchorProps } = props;
|
||||
const styles: ButtonStyles =
|
||||
@ -59,12 +61,11 @@ export const LinkButton: React.FunctionComponent<LinkButtonProps> = props => {
|
||||
variant: variant || 'primary',
|
||||
});
|
||||
|
||||
const buttonClassName = cx(styles.button, icon && styles.buttonWithIcon, icon && !children && styles.iconButton);
|
||||
return (
|
||||
<a className={cx(styles.button, className)} {...anchorProps}>
|
||||
<ButtonContent iconClassName={styles.icon} className={styles.iconWrap} icon={icon}>
|
||||
{children}
|
||||
</ButtonContent>
|
||||
<a className={buttonClassName} {...anchorProps} ref={ref}>
|
||||
<ButtonContent icon={icon}>{children}</ButtonContent>
|
||||
</a>
|
||||
);
|
||||
};
|
||||
});
|
||||
LinkButton.displayName = 'LinkButton';
|
||||
|
Reference in New Issue
Block a user