UNPKG

@atlaskit/icon

Version:

An icon is a symbol representing a command, device, directory, or common action.

137 lines (133 loc) 6.15 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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) { _defineProperty(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 */ import { memo } from 'react'; // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 import { css, jsx } from '@emotion/react'; import { commonSVGStyles, getIconSize } from './styles'; import { getBackground } from './utils'; /** * We are hiding these props from consumers as they're used to * hack around icon sizing specifically for icon-file-type. */ var iconStyles = 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({}, commonSVGStyles), {}, { maxWidth: '100%', maxHeight: '100%', color: 'var(--icon-primary-color)', fill: 'var(--icon-secondary-color)', verticalAlign: 'bottom' }) }); /** * For windows high contrast mode */ var baseHcmStyles = 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 = 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 = 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) */ export var Icon = /*#__PURE__*/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 ? jsx(Glyph, { role: "presentation" }) : null }; var dimensions = getIconSize({ width: width, height: height, size: size }); return jsx("span", _extends({ "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 || 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 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 })] })); }); export default Icon;