@engie-group/fluid-design-system-react
Version:
Fluid Design System React
29 lines (26 loc) • 1.55 kB
JavaScript
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { Root as Slot } from '../../node_modules/.pnpm/@radix-ui_react-slot@1.2.3_@types_react@19.2.6_react@19.2.0/node_modules/@radix-ui/react-slot/dist/index.js';
import { forwardRef, Children, cloneElement } from 'react';
import { isDefaultComponent } from '../../utils/typeHelpers.js';
import { Utils } from '../../utils/util.js';
import { NJIcon } from '../icon/NJIcon.js';
const rootClass = 'nj-icon-btn';
const NJIconButton = forwardRef((props, forwardedRef) => {
const { icon, scale, variant, customIcon, children, iconRef, asChild, ...htmlProps } = props;
let className = Utils.classNames(rootClass, {
[`nj-icon-btn--${scale}`]: !!scale,
[`nj-icon-btn--${variant}`]: !!variant
});
const iconElement = (jsxs(Fragment, { children: [customIcon && jsx(Slot, { className: "nj-icon-btn__icon", children: customIcon }), !customIcon && icon && jsx(NJIcon, { ref: iconRef, name: icon, className: "nj-icon-btn__icon" })] }));
if (isDefaultComponent(asChild)) {
className = Utils.classNames(className, htmlProps.className);
return (jsx("button", { ref: forwardedRef, type: "button", ...htmlProps, className: className, children: iconElement }));
}
const onlyChild = Children.only(children);
const child = cloneElement(onlyChild, {
children: iconElement
});
return (jsx(Slot, { ref: forwardedRef, className: className, children: child }));
});
NJIconButton.displayName = 'NJIconButton';
export { NJIconButton };