UNPKG

@atlaskit/button

Version:

A button triggers an event or action. They let users know what will happen next.

34 lines (31 loc) 1.14 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. * */ const IconRenderer = ({ icon: Icon }) => { // React Compiler opt-out: RC-incompatible (memoization breaks runtime behaviour). 'use no memo'; const isRenderProp = isIconRenderProp(Icon); let iconProps = { label: '', color: 'currentColor', size: fg('platform_dst_button_chevron_sizing') ? iconName => iconName.startsWith('Chevron') ? 'small' : 'medium' : undefined }; // @ts-ignore - TS2322 TypeScript 5.9.2 upgrade return /*#__PURE__*/React.createElement(React.Fragment, null, isRenderProp ? Icon(iconProps) : /*#__PURE__*/React.createElement(Icon, iconProps)); }; export default IconRenderer;