VueAvatar
Avatar component for VueJS 2
- Use username to create letter avatar (up to 3 chars)
- If an image src is provided, will try to use it as avatar
- Images are lazy loaded. If it is not loaded successfully, it will not be used (letter avatar as fallback)
Installation
npm install --save @lossendae/vue-avatar
Usage
ES6
CommonJS
Make available globally
Usage
Props
Name | Type | Required | Default | Description |
---|---|---|---|---|
username | String | true |
- | String used for the letter avatar (up to three characters) |
size | Number | false |
50 |
Size in pixels of the avatar |
src | String | false |
- | Optional image source path to use for the avatar |
colors | Array | false |
DEFAULT_COLORS[] (see below) |
Pool of colors used for avatar background image (expect array of hsl values) |
borderRadius | Number | false |
50 |
Value of the border radius for the avatar |
customStyles | Object | false |
{} |
Custom style object to merge with the default style |
delay | Number | false |
0 |
* See below |
delay
prop
Specify the delay in milliseconds to wait before attempting to load the image src.
This allows to show the letter avatar for the given time and then eventually load the image.
Vue-avatar uses vuejs built-in transitions to let you switch smoothly between the letters and the image.
By default, the transition will not do anything, but with a little bit of css you can for example flip the avatar to the image once loaded :
The above transition was made using animate.css
Default colors
In you want to override those colors, use the colors props by passing an array of hsl colors
See below the values used for the above example: