@engie-group/fluid-design-system-react
Version:
Fluid Design System React
28 lines (25 loc) • 1.4 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 React__default from 'react';
import { isDefaultComponent } from '../../utils/typeHelpers.js';
import { Utils } from '../../utils/util.js';
import { NJIcon } from '../icon/NJIcon.js';
const NJFab = React__default.forwardRef(({ scale, noRotate, variant, icon, label, children, asChild, ...htmlProps }, forwardedRef) => {
let fabClass = Utils.classNames('nj-fab', {
['nj-fab--light']: variant === 'light',
[`nj-fab--sm`]: scale === 'sm',
['no-rotate']: noRotate
});
const content = (jsxs(Fragment, { children: [jsx(NJIcon, { name: icon }), jsx("span", { className: "nj-sr-only", children: label })] }));
if (isDefaultComponent(asChild)) {
fabClass = Utils.classNames(fabClass, htmlProps.className);
return (jsx("button", { ref: forwardedRef, type: "button", ...htmlProps, className: fabClass, children: content }));
}
const onlyChild = React__default.Children.only(children);
const child = React__default.cloneElement(onlyChild, {
children: onlyChild.props.children ?? content
});
return jsx(Slot, { className: fabClass, children: child });
});
NJFab.displayName = 'NJFab';
export { NJFab };