UNPKG

@atlaskit/avatar

Version:

An avatar is a visual representation of a user or entity.

114 lines (113 loc) 5.97 kB
/* avatar-content.tsx generated by @compiled/babel-plugin v0.39.1 */ import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import "./avatar-content.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; import { forwardRef, useContext } from 'react'; import { fg } from '@atlaskit/platform-feature-flags'; import { AvatarContentContext } from './internal/content-context'; import { useEnsureIsInsideAvatar } from './internal/ensure-is-inside-avatar-context'; var boxShadowCssVar = '--avatar-box-shadow'; var bgColorCssVar = '--avatar-bg-color'; var styles = { root: "_19itglyw _12ji1r31 _1qu2glyw _12y31o36 _1reo15vq _18m915vq _v564ieh6 _1e0c1txw _kqswpfqs _4cvr1fhb _1bah1h6o _2lx21bp4 _80om1kw7 _6rthv77o _1pfhv77o _12l2v77o _ahbqv77o _85i5ze3t _1q51ze3t _y4tize3t _bozgze3t _t9ec1aqe _9v7aze3t _qc5o1p41 _z0ai1osq _18postnw _1hfk1j28 _aetrf705 _1peqidpf _11fnglyw _1ejjglyw _mizu194a _1ah3v77o _ra3xnqa1 _128mdkaa _4dave4h9", circle: "_2rko1qll _14mj1qll", square: "_2rkol0p1", positionRelative: "_kqswh2mm", disabled: "_80om13gf _1hfkvuon _1peqs237" }; var unboundStyles = { rootCustomBorder: "_11q7cxp3", root: "_vchh1ntv _bfhkcxp3 _16qs1nhn", hexagonFocusContainer: "_1rjc1wgn _18zr1dm9 _1mou5h37 _bfhk1j28 _mkrz1k6g _1o9o1v1w", hexagonFocusContainerMarginFg: "_195g1ksc", hexagonBorderContainerCustomBorder: "_11q7cxp3", hexagonBorderContainer: "_1rjcf6hp _18zruxly _bfhkcxp3 _mkrz1kw7 _1o9ovuon", hexagonBorderContainerMarginFg: "_1mou18m8 _195gzwb8", hexagon: "_2rkoidpf _mkrz1kw7 _16qsn7od _14mjidpf _1ejjn7od _128midpf _4davidpf", interactive: "_80omtlke _4tpu1g4v _ez1ykb7n _gcm1182g _eeh8kb7n _jlxit94y", interactiveMotion: "_v564155l _1llweo6y" }; var widthHeightMap = { xsmall: "_1bsb7vkz _4t3i7vkz", small: "_1bsb1tcg _4t3i1tcg", medium: "_1bsbzwfg _4t3izwfg", large: "_1bsb1ylp _4t3i1ylp", xlarge: "_1bsb16xz _4t3i16xz", xxlarge: "_1bsb1qr7 _4t3i1qr7" }; var marginAdjustmentMap = { xsmall: "_195gcwjc", small: "_195gcwjc", medium: "_195gs7t4", large: "_195gs7t4", xlarge: "_195g8ocb", xxlarge: "_195g1ukp" }; /** * __Avatar content__ * * Avatar content renders the avatar content. It can be composed with the Avatar component * to create a custom avatar. * * - [Examples](https://atlassian.design/components/avatar/examples) * - [Code](https://atlassian.design/components/avatar/code) * - [Usage](https://atlassian.design/components/avatar/usage) */ export var AvatarContent = /*#__PURE__*/forwardRef(function (_ref, ref) { var children = _ref.children; useEnsureIsInsideAvatar(); var _useContext = useContext(AvatarContentContext), Container = _useContext.as, appearance = _useContext.appearance, avatarImage = _useContext.avatarImage, _useContext$borderCol = _useContext.borderColor, borderColor = _useContext$borderCol === void 0 ? "var(--ds-surface, #FFFFFF)" : _useContext$borderCol, href = _useContext.href, isDisabled = _useContext.isDisabled, label = _useContext.label, onClick = _useContext.onClick, contextRef = _useContext.ref, tabIndex = _useContext.tabIndex, target = _useContext.target, testId = _useContext.testId, size = _useContext.size, stackIndex = _useContext.stackIndex, ariaControls = _useContext['aria-controls'], ariaExpanded = _useContext['aria-expanded'], ariaHasPopup = _useContext['aria-haspopup']; var isInteractive = Boolean(onClick || href || isDisabled || ariaHasPopup); var renderedContent = /*#__PURE__*/React.createElement(Container, _extends({ style: _defineProperty(_defineProperty({}, bgColorCssVar, borderColor), boxShadowCssVar, "0 0 0 2px ".concat(borderColor)), ref: ref || contextRef, "aria-label": isInteractive ? label : undefined, "aria-controls": ariaControls, "aria-expanded": ariaExpanded, "aria-haspopup": ariaHasPopup, onClick: onClick, tabIndex: tabIndex, "data-testid": testId, disabled: isDisabled, type: Container === 'button' ? 'button' : undefined }, href && { href: href, target: target, rel: target === '_blank' ? 'noopener noreferrer' : undefined }, { className: ax([unboundStyles.root, fg('avatar-custom-border') && unboundStyles.rootCustomBorder, styles.root, appearance === 'square' && styles.square, appearance === 'circle' && styles.circle, appearance === 'hexagon' && unboundStyles.hexagon, widthHeightMap[size], stackIndex !== undefined && styles.positionRelative, isInteractive && !isDisabled && unboundStyles.interactive, isInteractive && !isDisabled && fg('platform-dst-motion-uplift') && unboundStyles.interactiveMotion, isDisabled && styles.disabled]) }), children || avatarImage); if (appearance !== 'hexagon') { return renderedContent; } // For a Hexagon Avatar in order to have hexagonal "border" and "outline", we have to // layer multiple elements and use their background colors to create the different layers. return /*#__PURE__*/React.createElement("div", { style: _defineProperty(_defineProperty({}, bgColorCssVar, borderColor), boxShadowCssVar, "0 0 0 2px ".concat(borderColor)), "data-testid": testId ? "".concat(testId, "-hexagon-focus-container") : 'hexagon-focus-container', className: ax([unboundStyles.hexagonFocusContainer, !fg('platform_dst_hexagon_avatar_unified_size') && marginAdjustmentMap[size], fg('platform_dst_hexagon_avatar_unified_size') && unboundStyles.hexagonFocusContainerMarginFg]) }, /*#__PURE__*/React.createElement("div", { "data-testid": testId ? "".concat(testId, "-hexagon-border-container") : 'hexagon-border-container', className: ax([unboundStyles.hexagonBorderContainer, fg('avatar-custom-border') && unboundStyles.hexagonBorderContainerCustomBorder, fg('platform_dst_hexagon_avatar_unified_size') && unboundStyles.hexagonBorderContainerMarginFg]) }, renderedContent)); });