@atlaskit/icon
Version:
An icon is a symbol representing a command, device, directory, or common action.
68 lines (65 loc) • 3.62 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.IconFacade = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _icon = require("./icon");
var _excluded = ["dangerouslySetGlyph", "size"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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.
*/
var IconFacade = exports.IconFacade = /*#__PURE__*/(0, _react.memo)(function IconFacade(_ref) {
var dangerouslySetGlyph = _ref.dangerouslySetGlyph,
size = _ref.size,
props = (0, _objectWithoutProperties2.default)(_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
(0, _platformFeatureFlags.fg)('platform-visual-refresh-icons-legacy-facade');
if (useNewIcon && NewIcon && (iconSize === 'small' || iconSize === 'medium')) {
if (props.iconType === 'utility') {
var Icon = NewIcon;
return /*#__PURE__*/_react.default.createElement(Icon, (0, _extends2.default)({}, props, {
spacing: (0, _platformFeatureFlags.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.default.createElement(_Icon, (0, _extends2.default)({}, props, {
size: iconSize,
spacing: sizeSpacingMap['core'][iconSize],
color: props.primaryColor || 'currentColor',
type: props.iconType
}));
}
}
return /*#__PURE__*/_react.default.createElement(_icon.Icon, (0, _extends2.default)({
dangerouslySetGlyph: dangerouslySetGlyph,
size: size
}, props));
});
;