world-clock-strip
v0.2.7
Published
Reusable world clock strip extracted from the Dashboard web app.
Maintainers
Readme
World Clock Strip
Reusable world-clock-strip web component extracted from the Dashboard web app. It presents a compact city/time display with optional city landmarks, a moving day-cycle background, editable locations, sharing tools, presets, and a bottom config drawer.
Features
- Shadow DOM custom element:
world-clock-strip - Default cities: Las Vegas, Israel, New Delhi, Macau, Manila, Gold Coast
- City and local time only, with no weather, date, or temperature display
- Compact 55px desktop clock band
- Shareable URL state
- JSON import/export
- Saved presets in local storage
- Optional persistent local config
- Optional read-only mode
- Visual presets:
default,minimal,cinematic,wallboard - Click or keyboard-activate the clock band to cycle
plainandlandmarksbackgrounds - Extensible exported background registry:
clockBackgrounds configchangeevent for host apps
Install
Install from npm:
npm install world-clock-stripIf you want to install directly from GitHub instead:
npm install git+ssh://[email protected]/steve777/World-Clock.gitFor local development in this repo:
npm installRun
npm run devOpen http://127.0.0.1:4173.
Build
npm run buildnpm run build:demonpm run testnpm run test:packageBasic Usage
import { defineWorldClockStrip } from "world-clock-strip";
defineWorldClockStrip();<world-clock-strip></world-clock-strip>Imperative Usage
import { createWorldClockStrip } from "world-clock-strip";
const clock = createWorldClockStrip({
locations: [
{ label: "Las Vegas", timeZone: "America/Los_Angeles" },
{ label: "London", timeZone: "Europe/London" }
],
visualPreset: "cinematic",
backgroundMode: "landmarks",
persistKey: "executive-clock",
enableUrlState: true,
});
document.body.append(clock);Public API
Exports:
defineWorldClockStrip()createWorldClockStrip()normalizeClockLocations()serializeWorldClockConfig()deserializeWorldClockConfig()defaultClockLocationsclockBackgrounds
Types:
ClockLocationClockBackgroundClockBackgroundOptionCommonClockCityVisualPresetWorldClockConfigWorldClockStripOptions
Config Options
WorldClockStripOptions supports:
locationslandmarkAssetBaseUrlvisualPresetbackgroundModereadOnlypersistKeyenableUrlStateshareQueryParamcityCatalog
Sharing
The drawer supports:
Share: copies a URL with encoded clock configJSON: copy current config JSON or import oneSaved presets: save, load, and delete local presets
You can also use the helpers directly:
import {
serializeWorldClockConfig,
deserializeWorldClockConfig,
} from "world-clock-strip";Events
The component dispatches configchange:
clock.addEventListener("configchange", (event) => {
const detail = (event as CustomEvent).detail;
console.log(detail.config, detail.source);
});detail.source is one of:
apidrawerurlstoragepresetattributebackground
Read-Only Mode
Hide the config drawer entirely:
<world-clock-strip read-only></world-clock-strip>Or:
clock.readOnly = true;Docker
docker build -t world-clock-strip .
docker run --rm -p 4173:4173 world-clock-stripNotes
- The drawer stores presets in local storage.
persistKeystores the current config in local storage.- If both persisted state and shared URL state exist, the shared URL wins.
- Weather artwork is no longer rendered or included in the published package.
npm run test:packagevalidates the packed tarball in a clean temporary install.
