├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENCE ├── README.md ├── bin └── deploy-doc.sh ├── build ├── build.js ├── bundle.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.bundle.conf.js ├── webpack.dev.conf.js ├── webpack.docs.conf.js ├── webpack.min.conf.js └── webpack.test.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── test.env.js ├── docs ├── index.html └── static │ ├── darth-vader.png │ └── js │ ├── app.302bc90c89bc8f7ceb56.js │ ├── app.302bc90c89bc8f7ceb56.js.map │ ├── manifest.e71b1534b4860a25b3be.js │ ├── manifest.e71b1534b4860a25b3be.js.map │ ├── vendor.70ddb044fd355b38f9df.js │ └── vendor.70ddb044fd355b38f9df.js.map ├── documentation ├── _getting-started.pug ├── index.pug ├── main.js └── vue-avatar.min.js ├── index.html ├── lib └── index.js ├── package.json ├── src ├── Avatar.vue └── index.js ├── static └── darth-vader.png ├── test └── unit │ ├── .eslintrc │ ├── .esllintrc │ ├── index.js │ ├── karma.conf.js │ └── specs │ └── Avatar.spec.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "targets": { 5 | "browsers": ["last 2 versions"], 6 | "uglify": true 7 | } 8 | }] 9 | ], 10 | "plugins": ["transform-runtime"], 11 | "comments": false 12 | } 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | src/prism.js 2 | config/*.js 3 | *.pug -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style 4 | extends: 'standard', 5 | // required to lint *.vue files 6 | plugins: [ 7 | 'html' 8 | ], 9 | // add your custom rules here 10 | 'rules': { 11 | // allow paren-less arrow functions 12 | 'arrow-parens': 0, 13 | // allow debugger during development 14 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 15 | } 16 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules/ 3 | dist/ 4 | test/unit/coverage/ 5 | npm-debug.log 6 | package-lock.json 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | npm-debug.log 4 | selenium-debug.log 5 | test/unit/coverage 6 | test/e2e/reports 7 | .babelrc 8 | .editorconfig 9 | .eslintrc.js 10 | .gitignore 11 | .tern-project 12 | .idea 13 | docs/ 14 | documentation/ 15 | gh-pages/ 16 | example/ 17 | static/ 18 | test/ 19 | bin/ 20 | build/ 21 | .eslintignore 22 | index.html 23 | config.js 24 | bower.json 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "8" 5 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2016 kazuya kawaguchi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-avatar 2 | 3 | [](https://travis-ci.org/eliep/vue-avatar) 4 | 5 | An avatar component for vue.js. 6 | 7 | This component display an avatar image and if none is provided fallback to the 8 | user initials. This component is highly inspired from 9 | [react-user-avatar](https://github.com/wbinnssmith/react-user-avatar). 10 | 11 | Rules used to compute user initials: 12 | - divide the username on space and hyphen 13 | - use the first letter of each parts 14 | - never use more than three letters as initials 15 | - if the username is divided in more than three parts and has part 16 | starting with an uppercase, skip parts starting with a lowercase. 17 | 18 | You can find a few examples and the documentation [here](https://eliep.github.io/vue-avatar) 19 | 20 | ## Installation 21 | 22 | `npm install vue-avatar` 23 | 24 | ## Version 25 | 26 | | Vuejs version | vue-avatar version | 27 | | ------------- | ----------------- | 28 | | ^1.0.18 | ^1.3.0 | 29 | | ^2.0.0 | ^2.0.0 | 30 | 31 | 32 | ## Usage 33 | vue-avatar is a UMD module, which can be used as a module in both CommonJS and AMD modular environments. 34 | When in non-modular environment, Avatar will be registered as a global variable.
35 | 36 | ### ES6 37 | ```js 38 | 39 | import Avatar from 'vue-avatar' 40 | 41 | export default { 42 | ... 43 | components: { 44 | Avatar 45 | }, 46 | ... 47 | } 48 | ``` 49 | After that, you can use it in your templates: 50 | 51 | ```html 52 |Name | Required | Default | Type | Description | 89 |
---|---|---|---|---|
username | 92 |N | 93 |- | 94 |String | 95 |The user name that will be used to compute user initial. |
initials | 97 |N | 98 |- | 99 |String | 100 |Force the displayed initials by overriding the computed ones. |
inline | 102 |N | 103 |false | 104 |Boolean | 105 |Uses inline-flex instead of flex |
src | 107 |N | 108 |- | 109 |String | 110 |Path to the avatar image to display. |
:customStyle | 112 |N | 113 |- | 114 |Object | 115 |A custom style object to override the base styles. |
backgroundColor | 117 |N | 118 |- | 119 |String | 120 |The avatar background color to use if no image is provided. If none 121 | is specified, a background color will be picked depending on 122 | the user name length. |
color | 124 |N | 125 |- | 126 |String | 127 |The font color used to render the user initials. If none 128 | is provided, the background color is used to compute 129 | the font color. |
:lighten | 131 |N | 132 |80 | 133 |Number | 134 |A factor by which the background color must be lightened to 135 | produce the font color. Number between [-100,100]. |
:size | 137 |N | 138 |50 | 139 |Number | 140 |The avatar size in pixel. |
:rounded | 142 |N | 143 |true | 144 |Boolean | 145 |True if the avatar must be rounded. |
:parser | 147 |N | 148 |[getInitials()](https://github.com/eliep/vue-avatar/blob/master/src/Avatar.vue#L8-L27) | 149 |Function | 150 |Custom parser to manipulate the string (the parser takes 151 | 2 params: a String and the default parser). It must return a String. |
Name | Arguments | Description | 159 |
---|---|---|
@avatar-initials | 162 |username (the value of the username props), 163 | initials (the value of the computed initials or the initials props if any) | 164 |This event is trigger when the component is ready with component 165 | username and initial. |
An avatar component for vue.js
This component display an avatar image and if none is provided fallback to the user initials. This component is highly inspired fromreact-user-avatar
Rules used to compute user initials:
npm install vue-avatar
Vue.js | vue-avatar |
---|---|
^1.0.18 | ^1.3.0 |
^2.0.0 | ^2..0 |
vue-avatar is a UMD module, which can be used as a module in both CommonJS and AMD modular environments. When in non-modular environment, Avatar will be registered as a global variable.
import Avatar from 'vue-avatar'
31 |
32 | export default {
33 |
34 | components: {
35 | Avatar
36 | },
37 |
38 | }
39 |
After that, you can use it in your templates:
<avatar username="Jane Doe"></avatar>
40 |
which will render to:
var Vue = require('vue')
41 | var Avatar = require('vue-avatar')
42 |
43 | var YourComponent = Vue.extend({
44 | components: {
45 | 'avatar': Avatar
46 | }
47 | })
48 |
<script src="path/to/vue/vue.min.js"></script>
49 | <script src="path/to/vue-avatar/dist/vue-avatar.min.js"></script>
50 |
51 | new Vue({
52 | components: {
53 | 'avatar': Avatar
54 | }
55 | })
56 |
Name | Required | Default | Type | Description |
---|---|---|---|---|
username | Y | - | String | The user name that will be used to compute user initial. |
initials | N | - | String | Force the displayed initials by overriding the computed ones. |
initials | N | false | Boolean | Uses inline-flex instead of flex. |
src | N | - | String | Path to the avatar image to display. |
:customStyle | N | - | Object | A custom style object to override the base styles. |
backgroundColor | N | - | String | The avatar background color to use if no image is provided. If none is specified, a background color will be picked depending on the user name length. |
color | N | - | String | The font color used to render the user initials. If none is provided, the background color is used to compute the font color. |
:lighten | N | 80 | Number | A factor by which the background color must be lightened to produce the font color. Number between [-100,100]. |
:size | N | 50 | Number | The avatar size in pixel. |
:rounded | N | true | Boolean | True for a rounded avatar. |
Name | Arguments | Description |
---|---|---|
@avatar-initials | username (the value of the username props), initials (the value of the computed initials or the initials props if any) | This event is trigger when the component is ready with component username and initial. |
Code | |
---|---|
| |
| |
| |
| |
| |
|
18 default background colors are available and can be seen below. The background color chosen depends on the username length. This way a username will always have the same background color.