@i-novus/ui-core
Version:
Базовые UI компоненты
30 lines (29 loc) • 1.52 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef, useMemo } from 'react';
import classNames from 'classnames';
import { useConfigProvider } from '../core';
import { Icon } from '../data-display/Icon';
import { Spin } from '../feedback/Spin';
export const Button = forwardRef((props, ref) => {
const { className, prefix, variant = 'primary', icon, iconPosition = 'left', loading = false, visible = true, children, label, ...restProps } = props;
const { getPrefix } = useConfigProvider();
const prefixCls = getPrefix(prefix);
const buttonIcon = useMemo(() => {
if (loading) {
return _jsx(Spin, { delay: 0, className: `${prefixCls}-btn__spin`, iconClassName: `${prefixCls}-btn__icon` });
}
if (icon) {
return _jsx(Icon, { icon: icon, className: `${prefixCls}-btn__icon` });
}
return null;
}, [icon, loading, prefixCls]);
if (!visible) {
return null;
}
const buttonComponent = (_jsxs("button", { ref: ref, type: "button", className: classNames(`${prefixCls}-btn`, `${prefixCls}-btn-${variant}`, iconPosition === 'right' && `${prefixCls}-btn_icon_right`, className), ...restProps, children: [buttonIcon, children] }));
if (label) {
return (_jsxs("div", { className: `${prefixCls}-btn__content-wrapper`, children: [_jsx("span", { className: `${prefixCls}-btn__label`, children: label }), buttonComponent] }));
}
return buttonComponent;
});
Button.displayName = 'Button';