Coder Social home page Coder Social logo

mujahidfa / vue-boring-avatars Goto Github PK

View Code? Open in Web Editor NEW
104.0 2.0 6.0 531 KB

A Vue.js port of Boring Avatars, a JS library that generates custom, SVG-based avatars from any username and color palette.

HTML 0.72% Vue 57.73% TypeScript 38.51% JavaScript 3.04%
boring-avatars vue vuejs vue3 vue-components vuejs-library vuejs-components vuejs3

vue-boring-avatars's Introduction

vue-boring-avatars

hi License: MIT MadeWithVueJs.com shield

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:

pnpm i vue-boring-avatars
# or
yarn add vue-boring-avatars
# or
npm install vue-boring-avatars

CDN:

<!-- ESM version -->
<script type="module">
  import Avatar from "https://unpkg.com/vue-boring-avatars/dist/vue-boring-avatars.js";
</script>

<!-- UMD version -->
<script src="https://unpkg.com/vue-boring-avatars/dist/vue-boring-avatars.umd.cjs"></script>

Props

Props:

  • size: number
    • Default: 40
    • Determines the size of the Avatar.
  • square: boolean
    • Default: false
    • Whether the Avatar is shaped as a square or circle (default).
  • title: boolean
    • Default: false
    • Whether to generate the <title> element or not.
  • name: string
    • Default: "Clara Barton"
    • Name that determines the pattern of the Avatar, and appears in the <title> element if title is true.
  • variant: string
    • Accepts either of the following: "bauhaus", "beam", "marble", "pixel", "ring", "sunset".
    • Default: "marble"
    • Determines the variant of the Avatar.
  • colors: string[]
    • Accepts a string of colors.
    • Default: ["#92A1C6", "#146A7C", "#F0AB3D", "#C271B4", "#C20D90"]
    • Determines the range of colors in the Avatar.
  • id: string
    • ID for the SVG element.

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"
    :title="true"
  />
  <Avatar :size="size" variant="marble" :name="name" />
  <Avatar
    :size="size"
    variant="pixel"
    :name="name"
    :square="true"
    :title="true"
  />
  <Avatar :size="size" variant="ring" :name="name" />
  <Avatar
    :size="size"
    variant="sunset"
    :name="name"
    :square="true"
    :title="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>

Development

pnpm i # install packages
pnpm dev # launch in browser
pnpm test # run tests (download react-boring-avatars, lint, type check, then run tests)
pnpm build # build the dist

Credits

Credits to @hihayk (GitHub) and @josep_martins (GitHub) for creating the original Boring Avatars library at boringdesigners!

vue-boring-avatars's People

Contributors

mujahidfa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-boring-avatars's Issues

Vue2 support

I know you've written this in the repo already, but I'd like to chime in with a great need for Vue 2 support.

Optimize package size

First of all, thank you for this port!

We would consider using the package if the bundle was smaller. Bundlephobia says it is 16KB large, while the underlying React library is around 3KB large.

Is there a way to optimize the output? 16KB for creating customized avatars unfortunately would be a dealbreaker in my case.

Thanks again

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.