@atlaskit/icon
Version:
An icon is a symbol representing a command, device, directory, or common action.
59 lines (57 loc) • 2.53 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["dangerouslySetGlyph", "size"];
import React, { memo } from 'react';
import { fg } from '@atlaskit/platform-feature-flags';
import { Icon as LegacyIcon } from './icon';
var sizeSpacingMap = {
utility: {
small: 'compact',
medium: 'spacious'
},
core: {
small: 'none',
medium: 'spacious'
}
};
/**
* `IconFacade` is a component that conditionally renders either a new or legacy icon based on a feature flag.
*
* @param {IconFacadeProps} props - The props for the IconFacade component. Includes properties for configuring
* the icon such as `size`, `spacing`, `primaryColor`, `iconType`, and potentially others depending on the icon.
* `dangerouslySetGlyph` is a prop specific to the legacy icon component for setting the icon glyph directly.
* @returns A React element representing either the new or legacy icon based on the feature flag and icon size.
*/
export var IconFacade = /*#__PURE__*/memo(function IconFacade(_ref) {
var dangerouslySetGlyph = _ref.dangerouslySetGlyph,
size = _ref.size,
props = _objectWithoutProperties(_ref, _excluded);
var NewIcon = props.newIcon;
// By default, the icon size will be medium for core icons and small for utility icons
var iconSize = size !== null && size !== void 0 ? size : 'medium';
var useNewIcon = !props.isFacadeDisabled &&
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
fg('platform-visual-refresh-icons-legacy-facade');
if (useNewIcon && NewIcon && (iconSize === 'small' || iconSize === 'medium') && !fg('platform-visual-refresh-icons-facade-removal')) {
if (props.iconType === 'utility') {
var Icon = NewIcon;
return /*#__PURE__*/React.createElement(Icon, _extends({}, props, {
spacing: fg('platform-visual-refresh-icons-facade-button-fix') ? sizeSpacingMap['utility'][iconSize] : 'none',
color: props.primaryColor || 'currentColor',
type: props.iconType
}));
} else {
var _Icon = NewIcon;
return /*#__PURE__*/React.createElement(_Icon, _extends({}, props, {
size: iconSize,
spacing: sizeSpacingMap['core'][iconSize],
color: props.primaryColor || 'currentColor',
type: props.iconType
}));
}
}
return /*#__PURE__*/React.createElement(LegacyIcon, _extends({
dangerouslySetGlyph: dangerouslySetGlyph,
size: size
}, props));
});