@atlaskit/button
Version:
A button triggers an event or action. They let users know what will happen next.
31 lines (29 loc) • 1.03 kB
JavaScript
import React from 'react';
import { fg } from '@atlaskit/platform-feature-flags';
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
}) => {
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;