2020-06-17 09:52:03 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Button as WPButton } from 'wordpress-components';
|
2023-01-09 18:21:09 +00:00
|
|
|
import type { Button as WPButtonType } from '@wordpress/components';
|
2020-06-17 09:52:03 +00:00
|
|
|
import classNames from 'classnames';
|
2021-06-16 12:44:40 +00:00
|
|
|
|
2020-06-17 09:52:03 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2023-10-20 11:26:09 +00:00
|
|
|
import Spinner from '../../../../../packages/components/spinner';
|
2020-06-17 09:52:03 +00:00
|
|
|
|
2023-01-09 18:21:09 +00:00
|
|
|
export interface ButtonProps
|
2023-03-13 07:34:12 +00:00
|
|
|
extends Omit< WPButtonType.ButtonProps, 'variant' | 'href' > {
|
2022-02-03 12:29:06 +00:00
|
|
|
/**
|
|
|
|
* Show spinner
|
|
|
|
*
|
|
|
|
* @default false
|
|
|
|
*/
|
2023-01-09 18:21:09 +00:00
|
|
|
showSpinner?: boolean | undefined;
|
2022-02-09 17:32:05 +00:00
|
|
|
/**
|
|
|
|
* Button variant
|
|
|
|
*/
|
|
|
|
variant?: 'text' | 'contained' | 'outlined';
|
2023-03-13 07:34:12 +00:00
|
|
|
/**
|
|
|
|
* The URL the button should link to.
|
|
|
|
*/
|
|
|
|
href?: string | undefined;
|
2023-01-09 18:21:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface AnchorProps extends Omit< ButtonProps, 'href' > {
|
2022-12-14 06:51:16 +00:00
|
|
|
/**
|
|
|
|
* Button href
|
|
|
|
*/
|
|
|
|
href?: string | undefined;
|
2021-04-26 09:49:57 +00:00
|
|
|
}
|
2020-09-20 23:54:08 +00:00
|
|
|
|
2020-06-17 09:52:03 +00:00
|
|
|
/**
|
2020-09-20 23:54:08 +00:00
|
|
|
* Component that visually renders a button but semantically might be `<button>` or `<a>` depending
|
|
|
|
* on the props.
|
2020-06-17 09:52:03 +00:00
|
|
|
*/
|
2021-04-26 09:49:57 +00:00
|
|
|
const Button = ( {
|
|
|
|
className,
|
|
|
|
showSpinner = false,
|
|
|
|
children,
|
2022-02-09 17:32:05 +00:00
|
|
|
variant = 'contained',
|
2021-04-26 09:49:57 +00:00
|
|
|
...props
|
|
|
|
}: ButtonProps ): JSX.Element => {
|
2020-06-17 09:52:03 +00:00
|
|
|
const buttonClassName = classNames(
|
|
|
|
'wc-block-components-button',
|
2022-12-20 15:02:12 +00:00
|
|
|
'wp-element-button',
|
2020-06-17 09:52:03 +00:00
|
|
|
className,
|
2022-02-09 17:32:05 +00:00
|
|
|
variant,
|
2020-06-17 09:52:03 +00:00
|
|
|
{
|
|
|
|
'wc-block-components-button--loading': showSpinner,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<WPButton className={ buttonClassName } { ...props }>
|
2021-06-16 12:44:40 +00:00
|
|
|
{ showSpinner && <Spinner /> }
|
2020-06-17 09:52:03 +00:00
|
|
|
<span className="wc-block-components-button__text">
|
|
|
|
{ children }
|
|
|
|
</span>
|
|
|
|
</WPButton>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Button;
|