UNPKG

@ozen-ui/kit

Version:

React component library

36 lines (35 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ButtonBase = exports.cnButtonBase = void 0; var tslib_1 = require("tslib"); require("./ButtonBase.css"); var react_1 = tslib_1.__importDefault(require("react")); var useThemeProps_1 = require("../../hooks/useThemeProps"); var classname_1 = require("../../utils/classname"); var polymorphicComponentWithRef_1 = require("../../utils/polymorphicComponentWithRef"); var constants_1 = require("./constants"); exports.cnButtonBase = (0, classname_1.cn)('ButtonBase'); exports.ButtonBase = (0, polymorphicComponentWithRef_1.polymorphicComponentWithRef)(function (inProps, ref) { var props = (0, useThemeProps_1.useThemeProps)({ props: inProps, name: 'Button', }); var _a = props.as, Tag = _a === void 0 ? constants_1.BUTTON_BASE_DEFAULT_TAG : _a, loadingProp = props.loading, disabledProp = props.disabled, children = props.children, className = props.className, onClick = props.onClick, unstyled = props.unstyled, other = tslib_1.__rest(props, ["as", "loading", "disabled", "children", "className", "onClick", "unstyled"]); var loading = Boolean(loadingProp); var disabled = Boolean(disabledProp || loadingProp); // TODO: подумать на тем, чтобы не блокировать кнопку в «заблокированном состоянии», // чтобы не терять установленный на неё фокус var onDisabledClick = function (event) { event.preventDefault(); event.stopPropagation(); event.nativeEvent.stopImmediatePropagation(); }; return (react_1.default.createElement(Tag, tslib_1.__assign({ disabled: disabled, onClick: disabled ? onDisabledClick : onClick }, (disabled && { 'aria-disabled': true, }), { type: "button", className: (0, exports.cnButtonBase)({ disabled: disabled, loading: loading, unstyled: unstyled, }, [className]) }, (disabled && { tabIndex: -1 }), other, { ref: ref }), children)); }); exports.ButtonBase.displayName = 'ButtonBase';