brightyui
Version:
Brighty UI library
25 lines • 1.75 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useRef } from 'react';
import { cnb } from 'cnbuilder';
import styles from '../../../src/styles/Button.module.scss';
import SmallLoader from '../SmallLoader/SmallLoader';
var Button = function (_a) {
var _b;
var children = _a.children, _c = _a.type, type = _c === void 0 ? 'button' : _c, onClick = _a.onClick, _d = _a.disabled, disabled = _d === void 0 ? false : _d, className = _a.className, title = _a.title, _e = _a.size, size = _e === void 0 ? 'medium' : _e, _f = _a.theme, theme = _f === void 0 ? 'primary' : _f, _g = _a.fullwidth, fullwidth = _g === void 0 ? false : _g, icon = _a.icon, loading = _a.loading;
var ref = useRef(null);
var handleClick = function (e) {
var _a;
if (ref.current) {
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.blur();
}
if (onClick && !disabled) {
onClick(e);
}
};
return (_jsxs("button", { ref: ref, className: cnb(styles.button_root, className, styles["button_theme__".concat(theme)], styles["button_".concat(type, "Type")], styles["button_size__".concat(size)], (_b = {},
_b[styles.button_rootDisabled] = disabled || loading,
_b[styles.button_rootFullwidth] = fullwidth,
_b)), onClick: onClick ? handleClick : undefined, type: type === 'submit' ? 'submit' : 'button', children: [loading && _jsx(SmallLoader, {}), _jsxs("div", { style: { opacity: loading ? '0' : '1' }, className: styles.contentWrapper, children: [!!icon && theme === 'textPrimary' && icon, title ? title : children, !!icon && theme === 'textSecondary' && icon] })] }));
};
export default Button;
//# sourceMappingURL=Button.js.map