Coder Social home page Coder Social logo

g1eny0ung / vue-avatar-3 Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 148 KB

A practical avatar component for Vue 2&3, with support for letter avatars.

Home Page: https://stackblitz.com/edit/vue-avatar-3

License: MIT License

Shell 0.67% Vue 24.70% TypeScript 74.63%

vue-avatar-3's Introduction

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

Name Type Default Description
src string The image source.
alt string The image alt.
srcSet string The image srcSet.
sizes string The image sizes.
imgProps object The image attributes that will be applied to the image. This option will override above options.
name string Specify 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.
bgColor string Specify a background color for the letter avatar (must be a 6-value hex color, this is to automatically determine the text color).
size string / number 40px The size of the avatar. You can use a number or a string with a unit.
variant circular / rounded / square circular The variant of the avatar.
round string / number 8px The radius of the avatar. Take effect when variant is rounded. You can use a number or a string with a unit.
fallback boolean true Whether 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.

vue-avatar-3's People

Contributors

g1eny0ung avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.