UNPKG

@atlaskit/navigation-system

Version:

The latest navigation system for Atlassian apps.

40 lines (37 loc) • 1.63 kB
import React from 'react'; import { fg } from '@atlaskit/platform-feature-flags/fg'; function isIconRenderProp(func) { return !func.displayName && // most function components and class components have a displayName, negate them !func.render && // forwardRef doesn't require a display name, however it does include a render function, negate them typeof func === 'function' // at the very least we need to be a function ; } /** * __Icon renderer__ * * Used to support render props with icons. * * This is copied from @atlaskit/button to render IconButtons. Some IconButton's DOM element * will be re-created during SSR -> SPA hydration without using this, which delays TTVC. As * IconRenderer is already used in @atlaskit/button to mitigate this issue, add it here to * mitigate the same issue for IconButtons in navigation-system, especially for ThemedIconButton. * */ var IconRenderer = function IconRenderer(_ref) { // React Compiler opt-out: RC-incompatible (memoization breaks runtime behaviour). 'use no memo'; var Icon = _ref.icon; var isRenderProp = isIconRenderProp(Icon); var iconProps = { label: '', color: 'currentColor', size: fg('platform_dst_button_chevron_sizing') ? function (iconName) { return iconName.startsWith('Chevron') ? 'small' : 'medium'; } : undefined }; // @ts-expect-error -- The render-prop guard returns IconProp (a component type), which is not a ReactNode. return /*#__PURE__*/React.createElement(React.Fragment, null, isRenderProp ? Icon(iconProps) : /*#__PURE__*/React.createElement(Icon, iconProps)); }; export default IconRenderer;