brightyui
Version:
Brighty UI library
28 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var cnbuilder_1 = require("cnbuilder");
var Button_module_scss_1 = tslib_1.__importDefault(require("../../../src/styles/Button.module.scss"));
var SmallLoader_1 = tslib_1.__importDefault(require("../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 = (0, react_1.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 ((0, jsx_runtime_1.jsxs)("button", { ref: ref, className: (0, cnbuilder_1.cnb)(Button_module_scss_1.default.button_root, className, Button_module_scss_1.default["button_theme__".concat(theme)], Button_module_scss_1.default["button_".concat(type, "Type")], Button_module_scss_1.default["button_size__".concat(size)], (_b = {},
_b[Button_module_scss_1.default.button_rootDisabled] = disabled || loading,
_b[Button_module_scss_1.default.button_rootFullwidth] = fullwidth,
_b)), onClick: onClick ? handleClick : undefined, type: type === 'submit' ? 'submit' : 'button', children: [loading && (0, jsx_runtime_1.jsx)(SmallLoader_1.default, {}), (0, jsx_runtime_1.jsxs)("div", { style: { opacity: loading ? '0' : '1' }, className: Button_module_scss_1.default.contentWrapper, children: [!!icon && theme === 'textPrimary' && icon, title ? title : children, !!icon && theme === 'textSecondary' && icon] })] }));
};
exports.default = Button;
//# sourceMappingURL=Button.js.map