@third.chat/vue-boring-avatars
v1.1.3
Published
vue-boring-avatars is a Vue.js port of Boring Avatars, a JS library that generates custom, SVG-based avatars from any username and color palette.
Downloads
7
Maintainers
Readme
vue-boring-avatars
vue-boring-avatars
is a Vue 3 port of Boring Avatars, a JS library that generates custom, SVG-based avatars from any username and color palette.
Features
- Supports Vue 3 (for Vue 2, look at this implementation).
- Built using TypeScript and comes with TS types.
- Similar API with the React version of Boring Avatars.
Installation
NPM:
yarn add vue-boring-avatars
# or
npm install vue-boring-avatars
CDN:
<!-- UMD version -->
<script src="https://unpkg.com/vue-boring-avatars/dist/vue-boring-avatars.umd.js"></script>
<!-- ESM version -->
<script type="module">
import Avatar from 'https://unpkg.com/vue-boring-avatars/dist/vue-boring-avatars.es.js'
</script>
Props
Props:
size
: number- Default:
40
- Default:
square
: boolean- Default:
false
- Default:
name
: string- Default:
"Clara Barton"
- Default:
variant
: string- Accepts either of the following:
"bauhaus", "beam", "marble", "pixel", "ring", "sunset"
. - Default:
"marble"
- Accepts either of the following:
colors
: string[]- Accepts a string of colors.
- Default:
["#92A1C6", "#146A7C", "#F0AB3D", "#C271B4", "#C20D90"]
Usage
Basic usage (with default props):
<template>
<Avatar />
</template>
<script>
import Avatar from "vue-boring-avatars";
export default {
components: {
Avatar,
},
});
</script>
Basic usage with <script setup>
(with default props):
<script setup>
import Avatar from "vue-boring-avatars";
</script>
<template>
<Avatar />
</template>
With props:
<template>
<Avatar
:size="80"
variant="bauhaus"
name="Mujahid Anuar"
:colors="colors"
/>
</template>
<script>
import Avatar from "vue-boring-avatars";
export default {
data() {
return {
colors: ["#92A1C6", "#146A7C", "#F0AB3D", "#C271B4", "#C20D90"]
}
},
components: {
Avatar,
},
});
</script>
With Composition API:
<template>
<input type="text" v-model="name" />
<input type="number" v-model.number="size" />
<Avatar :size="size" variant="bauhaus" :name="name" />
<Avatar :size="size" variant="beam" :name="name" :square="true" />
<Avatar :size="size" variant="marble" :name="name" />
<Avatar :size="size" variant="pixel" :name="name" :square="true" />
<Avatar :size="size" variant="ring" :name="name" />
<Avatar :size="size" variant="sunset" :name="name" :square="true" />
</template>
<script lang="ts">
import { defineComponent, ref } from "vue";
import Avatar from "vue-boring-avatars";
export default defineComponent({
name: "App",
setup() {
const name = ref("Clara Barton");
const size = ref(80);
return {
name,
size,
};
},
components: {
Avatar,
},
});
</script>
Credits
Credits to @hihayk (GitHub) and @josep_martins (GitHub) for creating the original Boring Avatars library at boringdesigners!