React component for a user avatar with fallback to colored initials
A bare-bones user avatar display with support for falling back to using the user's initials on a colored background as the avatar.
npm install -S react-user-avatar
This module uses react-style inline styles to narrow the api, yet allows for reasonable extensibility by exposing a number of DOM classes. Take a look (or simply use)
The fallback avatar's color may be set by passing in the
colorprop, or you can customize the range of colors used by passing in an array of
colors. The component uses a simple calculation to consistently use the same color for the same user's name every time.
If the component determines that the color chosen was visually light, it will apply a
UserAvatar--lightclass to the root element. If the color chosen was dark, it will apply
UserAvatar--dark. Take advantage of these to use the appropriately colored text or border when styling the component.