UNPKG

@atlaskit/avatar

Version:

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

48 lines (46 loc) 1.42 kB
import { createContext, useContext } from '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> * ``` */ export var AvatarContext = /*#__PURE__*/createContext(undefined); export var useAvatarContext = function useAvatarContext() { return 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. */ export var AvatarContentContext = /*#__PURE__*/createContext(defaultAvatarContentProps); export var useAvatarContent = function useAvatarContent() { return useContext(AvatarContentContext); }; /** * Used to ensure Avatar sub-components are used within a Avatar component, * and provide a useful error message if not. */ export var EnsureIsInsideAvatarContext = /*#__PURE__*/createContext(false); export var useEnsureIsInsideAvatar = function useEnsureIsInsideAvatar() { var context = useContext(EnsureIsInsideAvatarContext); if (!context) { throw new Error('Avatar sub-components must be used within a Avatar component.'); } };