@engie-group/fluid-design-system-react
Version:
Fluid Design System React
44 lines (41 loc) • 2.42 kB
JavaScript
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { Root as Slot, Slottable } 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 linkStyleToCssClasses = {
grayed: 'nj-link--grayed',
contextual: 'nj-link--contextual',
high_contrast: 'nj-link--high-contrast',
inverse: 'nj-link--inverse',
default: ''
};
const linkPositionClasses = {
after: '',
before: 'nj-link-icon--before'
};
const linkSizeClasses = {
sm: 'nj-link--sm',
md: 'nj-link--md'
};
const NJLink = React__default.forwardRef((props, ref) => {
const { children, variant, icon, iconPosition, size, isExternal, externalLabel, asChild, ...htmlProps } = props;
const variantClass = linkStyleToCssClasses[variant || 'default'];
const positionClass = linkPositionClasses[iconPosition || 'after'];
const sizeClass = linkSizeClasses[size || 'md'];
let className = Utils.classNames('nj-link', {
['nj-link-icon']: icon || isExternal,
[positionClass]: icon || isExternal,
[variantClass]: variant && variant !== 'default',
[sizeClass]: size
});
const iconElement = (jsxs(Fragment, { children: [icon && jsx(NJIcon, { name: icon }), !icon && isExternal && jsx(NJIcon, { name: "open_in_new" })] }));
if (isDefaultComponent(asChild)) {
className = Utils.classNames(className, htmlProps.className);
return (jsxs("a", { ref: ref, rel: isExternal ? 'noreferrer' : undefined, target: isExternal ? '_blank' : undefined, ...htmlProps, className: className, children: [iconPosition === 'before' && iconElement, jsx("span", { children: children }), isExternal && externalLabel && jsxs("span", { className: "nj-sr-only", children: ["\u00A0", externalLabel] }), iconPosition !== 'before' && iconElement] }));
}
return (jsxs(Slot, { className: className, children: [iconPosition === 'before' && iconElement, jsx(Slottable, { children: children }), isExternal && externalLabel && jsxs("span", { className: "nj-sr-only", children: ["\u00A0", externalLabel] }), iconPosition !== 'before' && iconElement] }));
});
NJLink.displayName = 'NJLink';
export { NJLink };