1.0.4 • Published 2 months ago

@hoseinh/react-analog-clock v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

React Analog Clock Component

NPM Downloads NPM License

npm.io

React Analog Clock is a customizable React component that displays an analog clock with various options for customization.

Check out the online demo For Examples.

Installation

You can install the @hoseinh/react-analog-clock package via npm:

npm install @hoseinh/react-analog-clock

Usage

All props for the AnalogClock component are completely optional, empowering users to tailor the clock's appearance and behavior to their specific preferences. The package offers a selection of five distinct clock faces through the "numbersType" prop (refer to the props table), while also providing the flexibility to define a completely custom clock face using the "customBg" prop.

import React from 'react';
import { AnalogClock } from '@hoseinh/react-analog-clock';

const MyClock = () => {
  return (
    <AnalogClock
      showMinuteHand={true}
      showSecondHand={true}
      showBorder={true}
      showHandBase={true}
      smooth={false}
      whiteNumbers={false}
      square={false}
      numbersType="numbersAndLines"
      borderColor="#000000"
      handBaseColor="#000000"
      handColor={{ hour: "#000000", minute: "#000000", second: "#e74c3c" }}
      handLength={{ hour: "65px", minute: "90px", second: "90px" }}
      handThickness={{ hour: "2px", minute: "2px", second: "2px" }}
      size="200px"
      backgroundColor="#ffffff"
    />
  );
};

export default MyClock;

You can show a static time and disable the clock's auto update by passing a "staticDate" Date object:

.
.
.
    <AnalogClock
      staticDate={new Date(2024, 0, 1, 12, 15, 0)}
    />
.
.
.

Props

PropDescriptionOptionsDefault Value
showMinuteHandWhether to show the minute handtrue, falsetrue
showSecondHandWhether to show the second handtrue, falsetrue
showBorderWhether to show the clock bordertrue, falsetrue
showHandBaseWhether to show the hand basetrue, falsetrue
smoothWhether to smoothly transition the hand movementtrue, falsefalse
whiteNumbersWhether to display white numbers on the clock facetrue, falsefalse
squareWhether the clock should be squaretrue, falsefalse
numbersTypeType of numbers to display on the clock face"numbers", "dots", "numbersAndLines", "lines", "roman""numbersAndLines"
borderColorColor of the clock borderAny valid CSS color value#000000
backgroundColorBackground color of the clockAny valid CSS color value#ffffff
handColorObject containing colors for each hand (hour, minute, second)-{ hour: "#000000", minute: "#000000", second: "#e74c3c" }
handLengthObject containing lengths for each hand (hour, minute, second)-{ hour: "65px", minute: "90px", second: "90px" }
handThicknessObject containing thickness for each hand (hour, minute, second)-{ hour: "2px", minute: "2px", second: "2px" }
handBaseColorColor of the hand baseAny valid CSS color value#000000
sizeSize of the clockAny valid CSS size value200px
staticDateStatic date to display on the clock which will disable clock's auto-updateDate object-
customBgCustom background image for the clock which will replace the default backgroundsURL to image file-

License

This project is licensed under the MIT License.

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

0.5.0

2 months ago

0.7.0

2 months ago

0.6.0

2 months ago

0.4.0

2 months ago

0.2.0

2 months ago

0.1.0

2 months ago