https://github.com/vishnuramana/analogclock
🕰 A customizable analog clock built using React
https://github.com/vishnuramana/analogclock
analog analog-clock clock custom customizable hacktoberfest learning-by-doing react reactjs styled-components
Last synced: about 1 year ago
JSON representation
🕰 A customizable analog clock built using React
- Host: GitHub
- URL: https://github.com/vishnuramana/analogclock
- Owner: vishnuramana
- License: mit
- Created: 2018-12-26T11:03:36.000Z (over 7 years ago)
- Default Branch: dev
- Last Pushed: 2021-10-24T16:48:46.000Z (almost 5 years ago)
- Last Synced: 2025-04-21T20:07:15.646Z (over 1 year ago)
- Topics: analog, analog-clock, clock, custom, customizable, hacktoberfest, learning-by-doing, react, reactjs, styled-components
- Language: JavaScript
- Homepage: http://vishnuramana.github.io/analogclock
- Size: 1.93 MB
- Stars: 22
- Watchers: 3
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Analog Clock using React
[](https://circleci.com/gh/vishnuramana/analogclock/tree/dev) [](https://coveralls.io/github/vishnuramana/analogclock?branch=dev) [](https://www.npmjs.com/package/analog-clock-react)  [](https://github.com/vishnuramana/analogclock/blob/dev/LICENSE)
This is a customizable analog clock completely built using React. It is customizable by passing an options JSON Object to the component which allows you to modify the clock colors. It also allows you to use multiple timezones.

## Demo
You can customize/view a live demo of the clock [here](http://vishnuramana.github.io/analogclock).
## Installation
Install the package using
npm install --save analog-clock-react
## Usage
Import the `AnalogClock` component into your React Component like this
import AnalogClock from 'analog-clock-react';
Then use the `AnalogClock` Component like this
let options = {
width: "300px",
border: true,
borderColor: "#2e2e2e",
baseColor: "#17a2b8",
centerColor: "#459cff",
centerBorderColor: "#ffffff",
handColors: {
second: "#d81c7a",
minute: "#ffffff",
hour: "#ffffff"
}
};
.....
You can customize the clock using the different properties in the `options` JSON Object.
Please visit the [demo](http://vishnuramana.github.io/analogclock) page to get a live preview of the clock.
## Features
- ### Custom Time / Timezone Support
*AnalogClock* now supports using your own custom time/timezone. To enable custom time usage, set `useCustomTime` to `true` and set your own `hours`, `minutes` and `seconds` in the `options` JSON Object like below:
let options = {
useCustomTime: true, // set this to true
width: "300px",
border: true,
borderColor: "#2e2e2e",
baseColor: "#17a2b8",
centerColor: "#459cff",
centerBorderColor: "#ffffff",
handColors: {
second: "#d81c7a",
minute: "#ffffff",
hour: "#ffffff"
},
"seconds": 1, // set your
"minutes": 10, // own
"hours": 22 // time here.
};
Once you do that, `AnalogClock` will expect you to give it the `hours`, `minutes` and `seconds` value.
*Note: You will have to use a setInterval in the component where you use `` to update the `options` object with the time that you pass. An example is given below:*
updateClock = () => {
let ausTime = new Date().toLocaleString("en-US", { timeZone: "Australia/Brisbane" });
let date = new Date(ausTime);
this.setState({
'options': {
...this.state.options,
seconds: date.getSeconds(),
minutes: date.getMinutes(),
hours: date.getHours()
}
})
}
....
this.interval = setInterval(this.updateClock, 1000);
## Change Log
- **v1.3.0**
- Added finer movement of hour hand
- **v1.2.2**
- Fixed clock hand centering issues
- Removed unwanted code
## Contribution
If you wish to contribute to this project, please use the `dev` branch to add your changes and test. Make sure all the tests are passed and optimal code coverage is present. Once you are done with your changes, please raise a PR.
## Issues/Feature Requests
For any issues/feature-requests, you can create an issue in Github or email me at [me@vishnu.codes](mailto:me@vishnu.codes)
## License
MIT License