Skip to content

Repository files navigation

@ixnode/simple-clock

Releasenpm versionTypeScriptMIT License

A simple, customizable, and responsive clock component for React.

🚀 Features

  • Customizable size and color
  • Supports both digital and analog clocks
  • Displays date, time zone and milliseconds
  • Configurable 12-hour and 24-hour formats
  • Lightweight and built with TypeScript
  • Build on top with storybook

📦 Installation

npm install @ixnode/simple-clock

or

yarn add @ixnode/simple-clock

🔧 Usage

Basic Usage

Basic clock.

importReactfrom'react';import{Clock}from'@ixnode/simple-clock';import'@ixnode/simple-clock/dist/styles.css';constApp=()=>(<Clocksize="large"color="blue"showDate={true}showBorder={true}showTimeZone={true}/>);exportdefaultApp;

More complex usage

Analog clock.

importReactfrom'react';import{Clock}from'@ixnode/simple-clock';import'@ixnode/simple-clock/dist/styles.css';constApp=()=>(<Clockcolor={'default'}size={'small'}isAnalog={true}timeZone={"Europe/Berlin"}locale={"de-DE"}/>);exportdefaultApp;

🔧 Props

PropTypeDefaultDescription
color'default'|'red'|'green'|'blue''default'Sets the color of the clock.
size'small'|'medium'|'large''medium'Sets the size of the clock.
showBorderbooleanfalseWhether to show a border around the clock.
use24HourFormatbooleantrueUse 24-hour format (true) or AM/PM (false).
showTenthsbooleanfalseShow tenth of a second?
isAnalogbooleanfalseShow an analog clock?
showDatebooleanfalseShow date?
showTimeZonebooleanfalseShould a timezone be displayed?
timeZoneType'short'|'long''short'Which type of timezone should be displayed?
localestring'en-US'Which locale should be displayed?
timeZonestring'UTC'Which time zone should be displayed?

Common locales (locale)

timeZone is used with the Intl.DateTimeFormat API:

LocaleDescription
en-USEnglish (United States)
en-GBEnglish (United Kingdom)
de-DEGerman (Germany)
es-ESSpanish (Spain)
fr-FRFrench (France)
it-ITItalian (Italy)
nl-NLDutch (Netherlands)
pl-PLPolish (Poland)
pt-BRPortuguese (Brazil)
ru-RURussian (Russia)
sv-SESwedish (Sweden)
zh-CNChinese (Simplified, China)
zh-TWChinese (Traditional, Taiwan)

Common Time Zone Formats and Examples (timeZone)

timeZone is used with the Intl.DateTimeFormat API:

1. Common Time Zone Strings (IANA-TZ Format)

These strings are based on the IANA Time Zone Database, which defines time zones used worldwide:

Time ZoneDescription
UTCCoordinated Universal Time
America/New_YorkEastern Standard Time (EST)
Europe/BerlinCentral European Time (CET)
Asia/TokyoJapan Standard Time (JST)
Australia/SydneyAustralian Eastern Time (AET)
Africa/CairoEast Africa Time (EAT)
Pacific/AucklandNew Zealand Standard Time (NZST)

2. Short Time Zone Formats (Offset-based)

These formats use the offset from UTC in hours and minutes. Examples:

Time ZoneDescription
GMTGreenwich Mean Time
+02:00Two hours ahead of UTC
-05:00Five hours behind UTC

3. Abbreviated Time Zone Codes

Note: These are not supported by the Intl API and are not standardized. However, many abbreviations are commonly used in practice, such as:

AbbreviationDescription
PSTPacific Standard Time (UTC-8)
CETCentral European Time (UTC+1)
ISTIndian Standard Time (UTC+5:30)

🛠 Development

Building the Project

To build the project locally:

npm run build

Running Storybook

View and develop components in isolation:

npm run storybook

Open: http://localhost:6006/

Storybook

📦 Publishing to npm

Build the project

npm run build

Verify the build

node dist/index.js

Bump the version

Update the version in the package.json, e.g., from 1.0.0 to 1.0.1, to create a new release:

npm version patch

Alternatively:

  • Use npm version minor for new features.
  • Use npm version major for breaking changes.

Publish the package

npm publish --access public

Verify the publication

Check the package on npm: https://www.npmjs.com/package/@ixnode/simple-clock.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Authors

🌟 Contributing

Contributions are welcome! Feel free to submit issues or pull requests to improve this project.

🤝 Acknowledgments

Special thanks to the open-source community for providing amazing tools like React, TypeScript, and Storybook.

About

A simple, updating clock component for React.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages