|
| 1 | +# React-Clock |
| 2 | + |
| 3 | +A component to display clock for your React application. |
| 4 | + |
| 5 | +## tl;dr |
| 6 | +* Install by executing `npm install react-clock` or `yarn add react-clock`. |
| 7 | +* Import by adding `import Clock from 'react-clock'`. |
| 8 | +* Use by adding `<Clock />`. |
| 9 | + |
| 10 | +## Demo |
| 11 | + |
| 12 | +Minimal demo page is included in sample directory. |
| 13 | + |
| 14 | +[Online demo](http://projekty.wojtekmaj.pl/react-clock/) is also available! |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Add React-Clock to your project by executing `npm install react-clock` or `yarn add react-clock`. |
| 19 | + |
| 20 | +### Usage |
| 21 | + |
| 22 | +Here's an example of basic usage: |
| 23 | + |
| 24 | +```js |
| 25 | +import React, { Component } from 'react'; |
| 26 | +import Clock from 'react-clock'; |
| 27 | + |
| 28 | +class MyApp extends Component { |
| 29 | + state = { |
| 30 | + date: new Date(), |
| 31 | + } |
| 32 | + |
| 33 | + componentDidMount() { |
| 34 | + setInterval( |
| 35 | + () => this.setState({ date: new Date() }), |
| 36 | + 1000 |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + render() { |
| 41 | + return ( |
| 42 | + <div> |
| 43 | + <p>Current time:</p> |
| 44 | + <Clock |
| 45 | + value={this.state.date} |
| 46 | + /> |
| 47 | + </div> |
| 48 | + ); |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +### Custom styling |
| 54 | + |
| 55 | +If you don't want to use default React-Clock styling to build upon it, you can import React-Clock by using `import Clock from 'react-clock/build/entry.nostyle';` instead. |
| 56 | + |
| 57 | +## User guide |
| 58 | + |
| 59 | +### Clock |
| 60 | + |
| 61 | +Displays a complete clock. |
| 62 | + |
| 63 | +#### Props |
| 64 | + |
| 65 | +|Prop name|Description|Example values| |
| 66 | +|----|----|----| |
| 67 | +|className|Defines class name(s) that will be added along with "react-clock" to the main React-Clock `<time>` element.|<ul><li>String: `"class1 class2"`</li><li>Array of strings: `["class1", "class2 class3"]`</li></ul>| |
| 68 | +|hourHandLength|Defines the length of an hour hand, in %. Defaults to `50`.|`80`| |
| 69 | +|hourHandOppositeLength|Defines the length of the part of an hour hand on the opposite side the hand is pointing to, in %.|???| |
| 70 | +|hourHandWidth|Defines the width of an hour hand, in pixels. Defaults to `4`.|`3`| |
| 71 | +|hourMarksLength|Defines the length of hour marks, in %. Defaults to `10`.|`8`| |
| 72 | +|hourMarksWidth|Defines the width of hour marks, in pixels. Defaults to `3`.|`2`| |
| 73 | +|minuteHandLength|Defines the length of a minute hand, in %. Defaults to `70`.|`80`| |
| 74 | +|minuteHandOppositeLength|Defines the length of the part of a minute hand on the opposite side the hand is pointing to, in %. Defaults to `0`.|`20`| |
| 75 | +|minuteHandWidth|Defines the width of a minute hand, in pixels. Defaults to `2`.|`3`| |
| 76 | +|minuteMarksLength|Defines the length of minute marks, in %. Defaults to `6`.|`8`| |
| 77 | +|minuteMarksWidth|Defines the width of a minute hand, in pixels. Defaults to `1`.|`2`| |
| 78 | +|renderHourMarks|Defines whether hour marks shall be rendered. Defaults to `true`.|`false`| |
| 79 | +|renderMinuteHand|Defines whether minute hand shall be rendered. Defaults to `true`.|`false`| |
| 80 | +|renderMinuteMarks|Defines whether minute marks shall be rendered. Defaults to `true`.|`false`| |
| 81 | +|renderSecondHand|Defines whether second hand shall be rendered. Defaults to `true`.|`false`| |
| 82 | +|secondHandLength|Defines the length of a second hand, in %. Defaults to `90`.|`80`| |
| 83 | +|secondHandOppositeLength|Defines the length of the part of a second hand on the opposite side the hand is pointing to, in %. Defaults to `0`.|`20`| |
| 84 | +|secondHandWidth|Defines the width of a second hand, in pixels. Defaults to `1`.|`2`| |
| 85 | +|size|Defines the size of the clock, in pixels. Defaults to `150`.|`250`| |
| 86 | +|value|Defines the value of the clock. Must be provided.|Date: `new Date()`| |
| 87 | + |
| 88 | +## License |
| 89 | + |
| 90 | +The MIT License. |
| 91 | + |
| 92 | +## Author |
| 93 | + |
| 94 | +<table> |
| 95 | + <tr> |
| 96 | + <td> |
| 97 | + <img src="https://github.com/wojtekmaj.png?s=100" width="100"> |
| 98 | + </td> |
| 99 | + <td> |
| 100 | + Wojciech Maj<br /> |
| 101 | + |
| 102 | + <a href="http://wojtekmaj.pl">http://wojtekmaj.pl</a> |
| 103 | + </td> |
| 104 | + </tr> |
| 105 | +</table> |
0 commit comments