npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

svelte-relative-time-card

v0.0.1

Published

A hover card that displays relative time relative to local time with timezone information.

Downloads

5

Readme

Svelte Relative Time Card

A hover card component that displays relative time relative to local time with timezone information. Built for Svelte 5.

Installation

npm install svelte-relative-time-card
# or
pnpm add svelte-relative-time-card
# or
yarn add svelte-relative-time-card

Usage

Import the component and its styles:

<script lang="ts">
	import { RelativeTimeCard } from 'svelte-relative-time-card';
</script>

<RelativeTimeCard date={new Date()} />

API

Props

| Prop | Type | Default | Description | | ---------------- | ---------------------------------------- | ----------- | -------------------------------------------------------------------- | | date | Date \| string \| number | Required | The date to display. Can be a Date object, ISO string, or timestamp. | | timezones | string[] | ["UTC"] | List of timezones to display in the hover card. | | updateInterval | number | 1000 | Interval in milliseconds to update the relative time display. | | variant | "default" \| "muted" \| "ghost" | "default" | The visual style of the trigger element. | | side | "top" \| "right" \| "bottom" \| "left" | "top" | The preferred side of the trigger to render against when open. | | align | "start" \| "center" \| "end" | "center" | The preferred alignment against the trigger. | | sideOffset | number | 4 | The distance in pixels from the trigger. | | alignOffset | number | 0 | An offset in pixels from the "start" or "end" alignment options. | | openDelay | number | 500 | The delay in milliseconds before the hover card opens. | | closeDelay | number | 300 | The delay in milliseconds before the hover card closes. | | trigger | (props: { dateObj: Date }) => Snippet | - | Custom trigger element render function. |

Variants

The component supports three visual variants for the trigger element:

  • default: Standard appearance with 70% opacity, increasing to 90% on hover
  • muted: Subtle appearance with 50% opacity, increasing to 70% on hover
  • ghost: Text-only appearance with underline on hover

Examples

Basic Usage

<RelativeTimeCard date={new Date()} />

Multiple Timezones

<RelativeTimeCard
	date={new Date()}
	timezones={['America/New_York', 'Europe/London', 'Asia/Tokyo']}
/>

Custom Trigger

<RelativeTimeCard date={new Date()}>
	{#snippet trigger({ dateObj })}
		<button class="custom-trigger">
			<Clock class="icon" size={16} />
			View time details
		</button>
	{/snippet}
</RelativeTimeCard>

Different Positions

<RelativeTimeCard date={new Date()} side="top" align="start">
	{#snippet trigger({ dateObj })}
		Top Start
	{/snippet}
</RelativeTimeCard>

<RelativeTimeCard date={new Date()} side="right" align="center">
	{#snippet trigger({ dateObj })}
		Right Center
	{/snippet}
</RelativeTimeCard>

<RelativeTimeCard date={new Date()} side="bottom" align="end">
	{#snippet trigger({ dateObj })}
		Bottom End
	{/snippet}
</RelativeTimeCard>

Accessibility

The component is fully keyboard accessible:

  • Focusable via Tab key
  • Shows preview on focus
  • Hides preview on blur
  • Supports custom trigger elements

Styling

The component uses CSS variables for theming. You can customize the appearance by setting these variables in your CSS:

:root {
	--background: hsl(0 0% 100%);
	--foreground: hsl(240 10% 3.9%);
	--muted: hsl(240 4.8% 95.9%);
	--muted-foreground: hsl(240 3.8% 46.1%);
	--popover: hsl(0 0% 100%);
	--popover-foreground: hsl(240 10% 3.9%);
	--border: hsl(240 5.9% 90%);
	--ring: hsl(240 5% 64.9%);
	--radius: 0.5rem;
}

Credits

License

MIT