@atlaskit/avatar
Version:
An avatar is a visual representation of a user or entity.
54 lines (51 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useEnsureIsInsideAvatar = exports.useAvatarContext = exports.useAvatarContent = exports.EnsureIsInsideAvatarContext = exports.AvatarContext = exports.AvatarContentContext = void 0;
var _react = require("react");
/**
* __Avatar context__
*
* This allows setting the size of all avatars under a context provider.
*
* ```tsx
* <AvatarContext.Provider value={{ size: 'small' }}>
* <Avatar
* // ...props
* />
* </AvatarContext.Provider>
* ```
*/
var AvatarContext = exports.AvatarContext = /*#__PURE__*/(0, _react.createContext)(undefined);
var useAvatarContext = exports.useAvatarContext = function useAvatarContext() {
return (0, _react.useContext)(AvatarContext);
};
var defaultAvatarContentProps = {
as: 'span',
appearance: 'circle',
avatarImage: null,
ref: null,
size: 'medium'
};
/**
* __Avatar content context__
*
* This context provides the props for the AvatarContent component, enabling
* consumers to compose the AvatarContent with the Avatar component.
*/
var AvatarContentContext = exports.AvatarContentContext = /*#__PURE__*/(0, _react.createContext)(defaultAvatarContentProps);
var useAvatarContent = exports.useAvatarContent = function useAvatarContent() {
return (0, _react.useContext)(AvatarContentContext);
};
/**
* Used to ensure Avatar sub-components are used within a Avatar component,
* and provide a useful error message if not.
*/
var EnsureIsInsideAvatarContext = exports.EnsureIsInsideAvatarContext = /*#__PURE__*/(0, _react.createContext)(false);
var useEnsureIsInsideAvatar = exports.useEnsureIsInsideAvatar = function useEnsureIsInsideAvatar() {
var context = (0, _react.useContext)(EnsureIsInsideAvatarContext);
if (!context) {
throw new Error('Avatar sub-components must be used within a Avatar component.');
}
};