@atlaskit/icon
Version:
An icon is a symbol representing a command, device, directory, or common action.
140 lines (137 loc) • 6.57 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Icon = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("react");
var _react2 = require("@emotion/react");
var _styles = require("./styles");
var _utils = require("./utils");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
* @jsxRuntime classic
* @jsx jsx
*/ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
/**
* We are hiding these props from consumers as they're used to
* hack around icon sizing specifically for icon-file-type.
*/
var iconStyles = (0, _react2.css)({
display: 'inline-block',
flexShrink: 0,
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
lineHeight: 1,
// eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
'> svg': _objectSpread(_objectSpread({}, _styles.commonSVGStyles), {}, {
maxWidth: '100%',
maxHeight: '100%',
color: 'var(--icon-primary-color)',
fill: 'var(--icon-secondary-color)',
verticalAlign: 'bottom'
})
});
/**
* For windows high contrast mode
*/
var baseHcmStyles = (0, _react2.css)({
'@media screen and (forced-colors: active)': {
// eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
'> svg': {
filter: 'grayscale(1)',
'--icon-primary-color': 'CanvasText',
// foreground
'--icon-secondary-color': 'Canvas' // background
}
}
});
var primaryEqualsSecondaryHcmStyles = (0, _react2.css)({
'@media screen and (forced-colors: active)': {
// eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
'> svg': {
// if the primaryColor is the same as the secondaryColor we
// set the --icon-primary-color to Canvas
// this is usually to convey state i.e. Checkbox checked -> not checked
'--icon-primary-color': 'Canvas' // foreground
}
}
});
var secondaryTransparentHcmStyles = (0, _react2.css)({
'@media screen and (forced-colors: active)': {
// eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
'> svg': {
'--icon-secondary-color': 'transparent' // background
}
}
});
/**
* __Icon__
*
* An icon is used as a visual representation of common actions and commands to provide context.
*
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/icon)
* - [Code](https://atlaskit.atlassian.com/packages/design-system/icon/docs/custom-icons)
*/
var Icon = exports.Icon = /*#__PURE__*/(0, _react.memo)(function Icon(props) {
var _ref = props,
Glyph = _ref.glyph,
dangerouslySetGlyph = _ref.dangerouslySetGlyph,
_ref$primaryColor = _ref.primaryColor,
primaryColor = _ref$primaryColor === void 0 ? 'currentColor' : _ref$primaryColor,
secondaryColor = _ref.secondaryColor,
size = _ref.size,
testId = _ref.testId,
label = _ref.label,
width = _ref.width,
height = _ref.height,
UNSAFE_margin = _ref.UNSAFE_margin;
var glyphProps = dangerouslySetGlyph ? {
dangerouslySetInnerHTML: {
__html: dangerouslySetGlyph
}
} : {
children: Glyph ? (0, _react2.jsx)(Glyph, {
role: "presentation"
}) : null
};
var dimensions = (0, _styles.getIconSize)({
width: width,
height: height,
size: size
});
return (0, _react2.jsx)("span", (0, _extends2.default)({
"data-testid": testId,
"data-vc": "icon-".concat(testId),
role: label ? 'img' : undefined,
"aria-label": label ? label : undefined,
"aria-hidden": label ? undefined : true
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
,
style: {
'--icon-primary-color': primaryColor,
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
'--icon-secondary-color': secondaryColor || (0, _utils.getBackground)(),
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
margin: UNSAFE_margin
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
}
}, glyphProps, {
css: [iconStyles, baseHcmStyles, primaryColor === secondaryColor && primaryEqualsSecondaryHcmStyles, secondaryColor === 'transparent' && secondaryTransparentHcmStyles,
// NB: This can be resolved if this component, composes base SVG / and/or skeleton
// We could then simplify how common styles are dealt with simply by encapsulating them
// at their appropriate level and/or having a singular approach to css variables in the package
dimensions &&
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
(0, _react2.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
width: dimensions.width,
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
height: dimensions.height,
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
'> svg': dimensions
})]
}));
});
var _default = exports.default = Icon;