@atlaskit/avatar
Version:
An avatar is a visual representation of a user or entity.
123 lines (121 loc) • 7.3 kB
JavaScript
/* avatar-content.tsx generated by @compiled/babel-plugin v0.39.1 */
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AvatarContent = void 0;
require("./avatar-content.compiled.css");
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _contentContext = require("./internal/content-context");
var _ensureIsInsideAvatarContext = require("./internal/ensure-is-inside-avatar-context");
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 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)
*/
var AvatarContent = exports.AvatarContent = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
var children = _ref.children;
(0, _ensureIsInsideAvatarContext.useEnsureIsInsideAvatar)();
var _useContext = (0, _react.useContext)(_contentContext.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, (0, _extends2.default)({
style: (0, _defineProperty2.default)((0, _defineProperty2.default)({}, 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: (0, _runtime.ax)([unboundStyles.root, (0, _platformFeatureFlags.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 && (0, _platformFeatureFlags.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: (0, _defineProperty2.default)((0, _defineProperty2.default)({}, bgColorCssVar, borderColor), boxShadowCssVar, "0 0 0 2px ".concat(borderColor)),
"data-testid": testId ? "".concat(testId, "-hexagon-focus-container") : 'hexagon-focus-container',
className: (0, _runtime.ax)([unboundStyles.hexagonFocusContainer, !(0, _platformFeatureFlags.fg)('platform_dst_hexagon_avatar_unified_size') && marginAdjustmentMap[size], (0, _platformFeatureFlags.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: (0, _runtime.ax)([unboundStyles.hexagonBorderContainer, (0, _platformFeatureFlags.fg)('avatar-custom-border') && unboundStyles.hexagonBorderContainerCustomBorder, (0, _platformFeatureFlags.fg)('platform_dst_hexagon_avatar_unified_size') && unboundStyles.hexagonBorderContainerMarginFg])
}, renderedContent));
});