0.3.1 • Published 9 months ago

vue-avatar-3 v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

vue-avatar-3

CI npm

A useful avatar component for Vue 2&3, with support for letter avatars. Inspired by react-avatar.

Live demo: https://stackblitz.com/edit/vue-avatar-3.

Installation

npm install vue-avatar-3

yarn

yarn add vue-avatar-3

pnpm

pnpm add vue-avatar-3

Usage

<script setup>
import { ref } from 'vue'
import Avatar from 'vue-avatar-3'

const src = ref('https://fakeimg.pl/300/')
const name = ref('Foo Bar')
</script>

<template>
  <Avatar :src="src" :name="name" />
</template>

The priority of displaying avatars is as follows:

  1. If src is set, then src will have the highest priority.
  2. If src is not set or the load fails, then the name will be used to generate a letter avatar (you can use fallback to control this behavior).

Options

NameTypeDefaultDescription
srcstringThe image source.
altstringThe image alt.
srcSetstringThe image srcSet.
sizesstringThe image sizes.
imgPropsobjectThe image attributes that will be applied to the image. This option will override above options.
namestringSpecify a name to generate a letter avatar. This option will only take effect if the image is not loaded successfully and the fallback option is true.
bgColorstringSpecify a background color for the letter avatar (must be a 6-value hex color, this is to automatically determine the text color).
sizestring / number40pxThe size of the avatar. You can use a number or a string with a unit.
variantcircular / rounded / squarecircularThe variant of the avatar.
roundstring / number8pxThe radius of the avatar. Take effect when variant is rounded. You can use a number or a string with a unit.
fallbackbooleantrueWhether to show the letter avatar when the image is not loaded successfully.

Credits

This project is inspired by the following projects:

License

Released under the MIT License.

0.3.0

9 months ago

0.3.1

9 months ago

0.2.3

1 year ago

0.2.4

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago