https://github.com/patrickvaler/st-gravatar-img
Web Component to display Gravatar images
https://github.com/patrickvaler/st-gravatar-img
Last synced: 6 months ago
JSON representation
Web Component to display Gravatar images
- Host: GitHub
- URL: https://github.com/patrickvaler/st-gravatar-img
- Owner: patrickvaler
- License: mit
- Created: 2018-07-18T19:15:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-29T21:55:03.000Z (about 6 years ago)
- Last Synced: 2025-03-18T14:08:55.391Z (over 1 year ago)
- Language: TypeScript
- Size: 7.2 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# st-gravatar-img
[](http://badge.fury.io/js/st-gravatar-img)
[](https://travis-ci.org/patrickvaler/st-gravatar-img)
[](https://david-dm.org/patrickvaler/st-gravatar-img)
[](https://github.com/semantic-release/semantic-release)
[](https://greenkeeper.io/)

A simple web component to display [gravatar] images based on [stencil].
Checkout the [Demo] / [Demo with Editor].
## Install this component
### By cdn
```html
```
### By npm (self hosted)
```bash
npm install st-gravatar-img --save
```
```html
```
## Use this component
```html
```
## Attributes
| Attribute | Type | Default | Description |
| --------- | -------- | ------- | ---------------------------------------------------------- |
| `hash` | _string_ | _none_ | MD5 hash of your email (avoid to expose your email) |
| `email` | _string_ | _none_ | Gravatar account email (**warning** email will be exposed) |
| `size` | _number_ | `120` | Size (px) of the image |
## CSS Variables
[CSS Variables][css-variables] can be used to style the web component:
### Available variables
| Attribute | Default | Description |
| ------------------------------ | ------- | ------------------------------------------------------ |
| `--gravatar-img-border` | _none_ | Defines `border` property of the `img` element |
| `--gravatar-img-border-radius` | _none_ | Defines `border-radiues` property of the `img` element |
| `--gravatar-img-background` | _none_ | Defines `background` property of the `img` element |
### Example usage
```css
:root {
--gravatar-img-border: 10px solid #a52525;
--gravatar-img-border-radius: 100%;
--gravatar-img-background: #a52525;
}
```
## How to create a hash
Images on [Gravatar] can be accessed by a `MD5` hash of your email address.
### How to use `createHash` method
This web component offers the possibility to create a hash based on your email address by the exposed `createHash` method.
```javascript
let gravatarImg = document.querySelector('st-gravatar-img');
// method is available when component is ready
gravatarImg.componentOnReady().then(() => {
// create hash
const hash = gravatarImg.createHash('my@email.ccom');
// now you can apply the hash on the web component
gravatarImg.setAttribute('hash', hash);
});
```
[stencil]: https://stenciljs.com/
[gravatar]: https://gravatar.com/
[css-variables]: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables
[demo]: https://st-gravatar-img-vanilla-js.stackblitz.io/
[demo with editor]: https://stackblitz.com/edit/st-gravatar-img-vanilla-js