2021-12-14 03:40:42 +00:00
|
|
|
import React from 'react';
|
2022-02-01 06:34:46 +00:00
|
|
|
import cx from 'classnames';
|
2021-09-21 13:48:28 +00:00
|
|
|
var tinycolor = require('tinycolor2');
|
2021-04-02 04:16:26 +00:00
|
|
|
|
2021-12-14 03:40:42 +00:00
|
|
|
export const Button = function Button({ height, properties, styles, fireEvent }) {
|
|
|
|
|
const { loadingState, text } = properties;
|
2022-04-05 11:27:22 +00:00
|
|
|
const { backgroundColor, textColor, borderRadius, visibility, disabledState, loaderColor } = styles;
|
2021-04-02 09:24:51 +00:00
|
|
|
|
2021-04-30 06:31:32 +00:00
|
|
|
const computedStyles = {
|
|
|
|
|
backgroundColor,
|
2021-12-14 03:40:42 +00:00
|
|
|
color: textColor,
|
2021-11-16 11:44:09 +00:00
|
|
|
width: '100%',
|
2021-12-14 03:40:42 +00:00
|
|
|
borderRadius: `${borderRadius}px`,
|
2021-05-31 03:57:54 +00:00
|
|
|
height,
|
2021-12-14 03:40:42 +00:00
|
|
|
display: visibility ? '' : 'none',
|
2021-09-21 13:48:28 +00:00
|
|
|
'--tblr-btn-color-darker': tinycolor(backgroundColor).darken(8).toString(),
|
2022-04-05 11:27:22 +00:00
|
|
|
'--loader-color': tinycolor(loaderColor ?? '#fff').toString(),
|
2021-04-30 06:31:32 +00:00
|
|
|
};
|
2021-04-02 09:24:51 +00:00
|
|
|
|
2021-04-30 06:31:32 +00:00
|
|
|
return (
|
2022-04-14 09:11:30 +00:00
|
|
|
<div className="widget-button">
|
|
|
|
|
<button
|
|
|
|
|
disabled={disabledState}
|
|
|
|
|
className={cx('jet-button btn btn-primary p-1 overflow-hidden', {
|
|
|
|
|
'btn-loading': loadingState,
|
|
|
|
|
})}
|
|
|
|
|
style={computedStyles}
|
|
|
|
|
onClick={(event) => {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
fireEvent('onClick');
|
|
|
|
|
}}
|
2022-05-16 10:09:10 +00:00
|
|
|
data-cy="button-widget"
|
2022-04-14 09:11:30 +00:00
|
|
|
>
|
|
|
|
|
{text}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2021-04-30 06:31:32 +00:00
|
|
|
);
|
2021-04-02 04:16:26 +00:00
|
|
|
};
|