Gathering detailed insights and metrics for @gravatar-com/hovercards
Gathering detailed insights and metrics for @gravatar-com/hovercards
Gathering detailed insights and metrics for @gravatar-com/hovercards
Gathering detailed insights and metrics for @gravatar-com/hovercards
npm install @gravatar-com/hovercards
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Release @gravatar-com/hovercards 0.14.0
Updated on Jun 30, 2025
Release @gravatar-com/hovercards 0.13.0
Updated on Apr 30, 2025
Release @gravatar-com/hovercards 0.12.0
Updated on Apr 23, 2025
Release @gravatar-com/hovercards 0.11.0
Updated on Apr 21, 2025
Release @gravatar-com/quick-editor 0.8.0
Updated on Mar 24, 2025
Release @gravatar-com/hovercards 0.10.8
Updated on Mar 17, 2025
TypeScript (77.11%)
JavaScript (11.82%)
SCSS (7.33%)
HTML (3.53%)
Shell (0.22%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
193 Stars
231 Commits
68 Forks
14 Watchers
2 Branches
140 Contributors
Updated on Jul 12, 2025
Latest Version
0.14.0
Package Id
@gravatar-com/hovercards@0.14.0
Unpacked Size
865.21 kB
Size
210.62 kB
File Count
38
NPM Version
10.8.2
Node Version
20.19.2
Published on
Jun 30, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
30
Gravatar Hovercards is an easy-to-use library that brings Gravatar profiles to your website. It converts static Gravatar images, or any element with the data-gravatar-hash
attribute into interactive hovercards.
This Gravatar Hovercards library supports both Vanilla JavaScript (including TypeScript) and React. Install it via Yarn, NPM, or directly include it via UNPKG CDN.
Add the package to your project:
1npm install @gravatar-com/hovercards
or
1yarn add @gravatar-com/hovercards
For React, also add react
and react-dom
(v16.8.0
or above):
1npm install add react react-dom @gravatar-com/hovercards
For Vanilla JavaScript, import the library as shown below:
1<!-- Import the hovercard styles --> 2<link rel="stylesheet" href="https://unpkg.com/@gravatar-com/hovercards@x.x.x/dist/style.css"> 3 4<!-- Import the hovercards library --> 5<script src="https://unpkg.com/@gravatar-com/hovercards@x.x.x" defer></script> 6 7<script> 8 // The library is accessible as a global variable 9 console.log( Gravatar ); 10</script>
For React, import the library as shown below:
1<link rel="stylesheet" href="https://unpkg.com/@gravatar-com/hovercards@x.x.x/dist/style.css"> 2 3<!-- Ensure React and ReactDOM are imported before the library --> 4<script src="https://unpkg.com/react@x.x.x" defer></script> 5<script src="https://unpkg.com/react-dom@x.x.x" defer></script> 6<!-- Import the React hovercards library --> 7<script src="https://unpkg.com/@gravatar-com/hovercards@x.x.x/dist/index.react.umd.js" defer></script> 8 9<script> 10 console.log( Gravatar ); 11</script>
Replace
x.x.x
with the latest version number. Please refer to UNPKG's documentation for more information.
You can add hovercards to your page by either using existing Gravatar images, or by adding a data attribute to any element.
Ensure your page includes Gravatar images. The URLs of these images should contain hashed email addresses. For more information, refer to the gravatar images implementation guide.
For example:
1<div id="container"> 2 <img id="avatar-1" src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image"> 3 <img id="avatar-2" src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image"> 4 5 <!-- Image URL with specified parameters --> 6 <img id="avatar-3" src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>?s=250&d=retro&r=pg" alt="Gravatar Image"> 7</div>
These can be turned into hovercards:
1import { Hovercards } from '@gravatar-com/hovercards'; 2// Import the hovercard styles 3import '@gravatar-com/hovercards/dist/style.css'; 4 5document.addEventListener( 'DOMContentLoaded', () => { 6 // Start the hovercards feature with your preferred settings 7 const hovercards = new Hovercards( { /* Options */ } ); 8 9 // Make hovercards work on a specific Gravatar image 10 hovercards.attach( document.getElementById( 'avatar-1' ) ); 11 12 // Alternatively, make hovercards work on all Gravatar images within a specific container 13 hovercards.attach( document.getElementById( 'container' ) ); 14 15 // If you want hovercards on all Gravatar images across the entire page, use `document.body` as the target 16 hovercards.attach( document.body ); 17 18 // You can exclude certain Gravatar images from hovercards by using `ignoreSelector` 19 hovercards.attach( document.body, { ignoreSelector: '.ignore img[src*="gravatar.com/avatar/"]' } ); 20} );
data-gravatar-hash
AttributeAlternatively, use the data-gravatar-hash
attribute to specify the Gravatar hash for any element. This will automatically be converted into an interactive hovercard.
Note: The data attributes takes priority over the image URL.
For example:
1<div id="container"> 2 <div id="ref-1" data-gravatar-hash="<HASHED_EMAIL_ADDRESS>">@Meow</div> 3 <div id="ref-2" data-gravatar-hash="<HASHED_EMAIL_ADDRESS>">@Woof</div> 4 5 <!-- A hash with specified parameters --> 6 <div id="ref-3" data-gravatar-hash="<HASHED_EMAIL_ADDRESS>?s=250&d=retro&r=pg">@Haha</div> 7</div>
To convert these elements into interactive hovercards:
1import { Hovercards } from '@gravatar-com/hovercards'; 2import '@gravatar-com/hovercards/dist/styles.css'; 3 4document.addEventListener( 'DOMContentLoaded', () => { 5 // Start the hovercards feature with your preferred settings 6 const hovercards = new Hovercards( { /* Options */ } ); 7 8 // Attach hovercards on a specific image 9 hovercards.attach( document.getElementById( 'ref-1' ) ); 10 11 // Attach to all images within a container 12 hovercards.attach( document.getElementById( 'container' ) ); 13 14 // Attach to all images on the page 15 hovercards.attach( document.body ); 16} );
You can pass an object of options to the Hovercards
constructor to customize the behavior of your hovercards. The following options are available:
placement: string = 'right-start'
The placement of the hovercard relative to the target element. Possible values are top
, bottom
, left
, right
, top-start
, top-end
, bottom-start
, bottom-end
, left-start
, left-end
, right-start
, and right-end
.
autoFlip: boolean = true
Determines whether the hovercard's placement should automatically flip when there is not enough display space.
autoShift: boolean = true
Determines whether the hovercard's placement should automatically shift when there is not enough display space.
hideOnTargetClick: boolean = false
Hides the hovercard when its trigger element is clicked.
offset: number = 10
The offset of the hovercard relative to the target element, in pixels.
delayToShow: number = 500
The delay in milliseconds before the hovercard is shown.
delayToHide: number = 300
The delay in milliseconds before the hovercard is hidden.
i18n: Record< string, string >
Translated text strings to use instead of the default English.
additionalClass: string = ''
Additional class names to be added to the outermost element of the hovercard. This is useful for customizing the styling of the hovercard.
myHash: string = ''
It enables personalized hovercard features for the current user. It allows displaying customized options like "Edit your profile" when the user's "about me" field is empty on their Gravatar editing page.
onQueryHovercardRef: ( ref: HTMLElement ) => HTMLElement
This callback function is triggered when the library queries a hovercard ref (or a Gravatar image), allowing you to customize the ref element. The function receives the ref element as an argument and should return the modified version of the element.
onFetchProfileStart: ( hash: string ) => void
This callback function is triggered when the library starts fetching a Gravatar profile. It takes the Gravatar hash as a parameter. Note that this function is executed only once per Gravatar hash due to the caching mechanism.
onFetchProfileSuccess: ( hash: string, profileData: ProfileData ) => void
This callback function is triggered when the library successfully fetches a Gravatar profile. It takes the Gravatar hash and the profile data as parameters. Note that this function is executed only once per Gravatar hash due to the caching mechanism.
The profileData
parameter is an object that contains the following properties:
1interface ProfileData { 2 hash: string; 3 avatarUrl: string; 4 profileUrl: string; 5 displayName: string; 6 location?: string; 7 description?: string; 8 jobTitle?: string; 9 company?: string; 10 headerImage?: string; 11 backgroundColor?: string; 12 verifiedAccounts?: Record< 'label' | 'icon' | 'url' | 'type', string >[]; 13 contactInfo?: ContactInfo; 14 payments?: Payments; 15}
onFetchProfileFailure: ( hash: string, error: FetchProfileError ) => void
This callback function is triggered when the library fails to fetch a Gravatar profile. It takes the Gravatar hash and the error as parameters. Note this function is executed only once per Gravatar hash due to the caching mechanism.
The error
parameter is an object that contains the following properties:
1interface FetchProfileError { 2 code: number; 3 message: string; 4}
onHovercardShown: ( hash: string, hovercard: HTMLDivElement ) => void
This callback function is triggered when the hovercard is shown. It takes the Gravatar hash and the hovercard element as parameters.
onHovercardHidden: ( hash: string, hovercard: HTMLDivElement ) => void
This callback function is triggered when the hovercard is hidden. It takes the Gravatar hash and the hovercard element as parameters.
onCanShowHovercard: ( hash: string ) => bool
This callback function is triggered just before a hovercard is shown, giving you control over the card at runtime. It takes the Gravatar hash and returns a boolean value. If the value returned is false
then the card won't be shown.
The Hovercards
class provides the following methods:
(static) createHovercard( profileData: ProfileData, options?: { additionalClass?: string; myHash?: string, i18n?: Record< string, string > } ): HTMLDivElement
This method generates a hovercard element using the provided profile data. It accepts the profileData
parameter, which represents the data needed to populate the hovercard, and an optional options object that can include properties such as additionalClass
, myHash
and i18n
. It's useful when you want to display static hovercards on your website.
1import { Hovercards } from '@gravatar-com/hovercards'; 2 3const hovercard = Hovercards.createHovercard( { 4 hash: '...', 5 avatarUrl: '...', 6 profileUrl: '...', 7 displayName: '...', 8 description: '...', 9 location: '...', 10 jobTitle: '...', 11 company: '...', 12 verifiedAccounts = [ { 13 label: '...', 14 icon: '...', 15 url: '...', 16 type: '...', 17 } ], 18} ); 19 20document.getElementById( 'container' ).appendChild( hovercard );
(static) createHovercardSkeleton( options?: { additionalClass?: string } ): HTMLDivElement
This method generates a skeleton hovercard element. It accepts an optional options object that can include the additionalClass
property. It's useful when you want to display a loading state while fetching the Gravatar profile.
1import { Hovercards } from '@gravatar-com/hovercards';
2
3const hovercardSkeleton = Hovercards.createHovercardSkeleton();
4
5document.getElementById( 'container' ).appendChild( hovercardSkeleton );
(static) createHovercardError( avatarUrl: string, message: string, options?: { additionalClass?: string; avatarAlt?: string; additionalMessage?: string } ): HTMLDivElement
This method generates an error hovercard element. It accepts the avatarUrl
parameter, which represents the URL of the avatar image, the message
parameter, which represents the error message, and an optional options object that can include properties such as additionalClass
, avatarAlt
(default: 'Avatar'
), among others. It's useful when you want to display an error message when fetching the Gravatar profile fails.
1import { Hovercards } from '@gravatar-com/hovercards';
2
3const hovercardError = Hovercards.createHovercardError( 'https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>', 'Error message' );
4
5document.getElementById( 'container' ).appendChild( hovercardError );
attach( target: HTMLElement, options?: { dataAttributeName?: string; ignoreSelector?: string } ): void
This method attaches the hovercards to the specified target element, thereby enabling the hovercard functionality. It accepts the target
parameter, which represents the target element to which the hovercards will be attached, and an optional options object that can include properties such as dataAttributeName
and ignoreSelector
.
dataAttributeName
(default: 'gravatar-hash'
) - The name of the data-*
attribute that contains the Gravatar hash. This option is useful when you want to use a custom attribute name instead of data-gravatar-hash
. If you want to disable the data-*
attribute feature, you can set this option to an empty string.ignoreSelector
(default: ''
) - A query selector that specifies elements to be excluded from displaying hovercards. This option is useful when you want to prevent certain elements from triggering hovercards.Note: Each
attach()
call automatically detaches hovercards from their current target before attaching them to the new target.
detach(): void
This method detaches the hovercards from their current target element, thereby disabling the hovercard functionality.
This library offers a React component and a hook, their operation is similar to the Vanilla JavaScript version.
Here is a basic example:
1// Import the React component 2import { Hovercards } from '@gravatar-com/hovercards/react'; 3// Import the hovercard styles 4import '@gravatar-com/hovercards/dist/style.css'; 5 6function App() { 7 // ... 8 9 return ( 10 <Hovercards> 11 { /* Work with Gravatar images */ } 12 <img src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image" /> 13 <img src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image" /> 14 15 { /* Work with elements having `data-gravatar-hash` attribute */ } 16 <div data-gravatar-hash="<HASHED_EMAIL_ADDRESS>">@Meow</div> 17 <div data-gravatar-hash="<HASHED_EMAIL_ADDRESS>">@Woof</div> 18 </Hovercards> 19 ); 20}
Note: The component will create a
div
container element to wrap all the children. You can customize the container element by using theclassName
orstyle
props.
To attach hovercards to the whole page or a specific element, use the attach
prop:
1import { Hovercards } from '@gravatar-com/hovercards/react'; 2import '@gravatar-com/hovercards/dist/style.css'; 3 4function App() { 5 // ... 6 7 return ( 8 <> 9 <div> 10 <img src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image" /> 11 <img src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image" /> 12 <img src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image" /> 13 </div> 14 { /* Attach hovercards to the entire page */ } 15 <Hovercards attach={ document.body } /> 16 </> 17 ); 18}
The Hovercards
component accepts the following props:
attach?: HTMLElement
This prop specifies the target element to which the hovercards will be attached. It's useful when you want to attach hovercards to an entire page.
dataAttributeName?: string = 'gravatar-hash'
This prop specifies the name of the data-*
attribute that contains the Gravatar hash. It's useful when you want to use a custom attribute name instead of data-gravatar-hash
. If you want to disable the data-*
attribute feature, you can set this prop to an empty string.
ignoreSelector?: string = ''
This prop specifies a query selector that specifies elements to be excluded from displaying hovercards. It's useful when you want to prevent certain elements from triggering hovercards.
className?: string
This prop allows you to specify class names to be added to the container element, which is created by the component to wrap all the children.
style?: React.CSSProperties
This prop allows you to specify styles to be added to the container element, which is created by the component to wrap all the children.
For the remaining props, please refer to the Options section.
Here are some basic examples of how to use the React hook:
1import { useEffect, useRef } from 'react'; 2// Import the React hook 3import { useHovercards } from '@gravatar-com/hovercards/react'; 4// Import the hovercard styles 5import '@gravatar-com/hovercards/dist/style.css'; 6 7function App() { 8 const { attach } = useHovercards( { /* Options */ } ); 9 const containerRef = useRef(); 10 11 useEffect( () => { 12 if ( containerRef.current ) { 13 attach( containerRef.current ); 14 } 15 }, [ attach ] ); 16 17 return ( 18 <div ref={ containerRef }> 19 { /* Work with Gravatar images */ } 20 <img src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image" /> 21 <img src="https://www.gravatar.com/avatar/<HASHED_EMAIL_ADDRESS>" alt="Gravatar Image" /> 22 23 { /* Work with elements having `data-gravatar-hash` attribute */ } 24 <div data-gravatar-hash="<HASHED_EMAIL_ADDRESS>">@Meow</div> 25 <div data-gravatar-hash="<HASHED_EMAIL_ADDRESS>">@Woof</div> 26 </div> 27 ); 28}
Note: When the component is unmounted, the hook will automatically detach the hovercards from the target element.
You can also use the hook to create a custom component:
1import sha256 from 'js-sha256'; 2import { useEffect, useRef } from 'react'; 3import { useHovercards } from '@gravatar-com/hovercards/react'; 4import '@gravatar-com/hovercards/dist/style.css'; 5 6// A custom Avatar component for convenience 7function Avatar( { email } ) { 8 const { attach } = useHovercards(); 9 const imgRef = useRef(); 10 11 useEffect( () => { 12 if ( imgRef.current ) { 13 attach( imgRef.current ); 14 } 15 }, [ attach ] ); 16 17 return ( 18 <img ref={ imgRef } src={ `https://www.gravatar.com/avatar/${ sha256( email ) }` } alt="Gravatar Image" /> 19 ); 20}
The hook accepts the same options and methods as the Hovercards
class. Please refer to the API section for further details.
This library is written in TypeScript and comes with type definitions. You can check the following files for the available types:
A few items of text are used when displaying a hovercard. The library contains English by default, but you can supply your own translations through the use of the i18n
option.
The following phrases are used:
Edit your profile →
View profile →
Contact
Send money
Sorry, we are unable to load this Gravatar profile.
Gravatar not found.
Too Many Requests.
Internal Server Error.
Is this you?
Claim your free profile.
Email
Home Phone
Work Phone
Cell Phone
Contact Form
Calendar
The i18n
option is an object that maps from the English text to the language of your choice (even another English phrase, if you wish to change the text).
1{ 2 'Edit your profile →': 'Modifier votre profil →' 3}
We welcome contributions to this project. Please follow the guidelines outlined in the CONTRIBUTING.md file.
Gravatar Hovercards is licensed under GNU General Public License v2 (or later).
No vulnerabilities found.
No security vulnerabilities found.