1.2.0 • Published 6 years ago

@felixbores/react-avatar v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

React Avatar Build Status

A simple component that renders an user avatar using a picture with a fallback system that renders a SVG image based on user's name or initials in case of the configured picture failed to load.

React Avatar Component Preview

Installation

npm install @felixbores/react-avatar --save

You need to install react, prop-types and styled-components libraries by yourself, as they are peer dependencies

Usage

Import Avatar element:

  import Avatar from "@felixbores/react-avatar";

How to use:

  <Avatar size={48} name="John Smith" />
  <Avatar size={90} name="George Jungle" src="http://i.pravatar.cc/90" />
  <Avatar size={120} initials="ST" url="http://i.pravatar.cc/120" border={3} />
  <Avatar size={120} name="BJ" />
  <Avatar size={60} name="Jane Doe" bgColor="#FFF" fgColor="#000" />
  <Avatar size={256} name="Fred Rock" border={2} borderColor="lightgreen" />

Component Props

PropTypeDefaultDescription
classNamestringClass names to be added to the avatar
sizenumber60Size of the avatar
bordernumber0Border size of the avatar
initialsstringThe initials to show as text when avatar is text based
namestringIf initials is not present, the name will be used to generate user initials
bgColorstring#000000The background color when the avatar is text based
fgColorstring#ffffffThe text color when the avatar is text based
borderColorstring#ffffffThe border color of the avatar
roundedboolfalseDisplay the avatar as a circle
urlstringUrl to load image using ajax. The image is converted to base64
srcstringUsed as traditional src image attribute. Will be used only if url was not defined or failed to load
onClickfunctionMouse click event
onContextMenufunctionMouse contextmenu event
onDoubleClickfunctionMouse dblclick event
onMouseDownfunctionMouse mousedown event
onMouseEnterfunctionMouse mouseenter event
onMouseLeavefunctionMouse mouseleave event
onMouseOutfunctionMouse mouseout event
onMouseOverfunctionMouse mouseover event
onMouseUpfunctionMouse mouseup event
randomBgColorarray of colorsDetermine a random background color from the array input based on name or initials props
randomBgColorstringDetermine a random background color from the palette input based on name or initials props. The valid palette options are: social , material, flat, metro and fluent
randomBgColorboolDetermine a random background color from social palette based on name or initials props

In case name and initials were not set, and images from url or src were not set or failed to load, a placeholder image is used.

License

MIT License

1.2.0

6 years ago

1.1.1

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago