What is rc-time-picker?
The rc-time-picker package is a React component for selecting time. It provides a simple and customizable time picker component that can be easily integrated into React applications.
What are rc-time-picker's main functionalities?
Basic Time Picker
This feature allows you to add a basic time picker to your React application. The component is imported and used directly in the JSX.
import React from 'react';
import TimePicker from 'rc-time-picker';
import 'rc-time-picker/assets/index.css';
const App = () => (
<TimePicker />
);
export default App;
Time Picker with Default Value
This feature allows you to set a default time value for the time picker. The default value is set using the moment.js library.
import React from 'react';
import TimePicker from 'rc-time-picker';
import moment from 'moment';
import 'rc-time-picker/assets/index.css';
const App = () => (
<TimePicker defaultValue={moment('12:08', 'HH:mm')} />
);
export default App;
Time Picker with 12-Hour Format
This feature allows you to configure the time picker to use a 12-hour format instead of the default 24-hour format.
import React from 'react';
import TimePicker from 'rc-time-picker';
import 'rc-time-picker/assets/index.css';
const App = () => (
<TimePicker use12Hours />
);
export default App;
Time Picker with Disabled Hours
This feature allows you to disable specific hours in the time picker. In this example, the hours from 0 to 6 are disabled.
import React from 'react';
import TimePicker from 'rc-time-picker';
import 'rc-time-picker/assets/index.css';
const App = () => (
<TimePicker disabledHours={() => [0, 1, 2, 3, 4, 5, 6]} />
);
export default App;
Other packages similar to rc-time-picker
react-time-picker
The react-time-picker package is another React component for selecting time. It offers a similar set of features to rc-time-picker but with a different API and styling options. It is known for its ease of use and integration with React applications.
react-datepicker
The react-datepicker package is a comprehensive date and time picker component for React. It provides a wide range of features including date selection, time selection, and date-time range selection. It is more feature-rich compared to rc-time-picker but also more complex to integrate.
react-datetime
The react-datetime package is a versatile date and time picker component for React. It combines both date and time selection in a single component and offers extensive customization options. It is a good alternative to rc-time-picker for applications that require both date and time selection.
TimePicker
React TimePicker
example
http://react-component.github.io/time-picker/
install
npm install rc-time-picker
Usage
import TimePicker from 'rc-time-picker';
import ReactDOM from 'react-dom';
ReactDOM.render(<TimePicker />, container);
API
TimePicker
Name | Type | Default | Description |
---|
prefixCls | String | 'rc-time-picker' | prefixCls of this component |
clearText | String | 'clear' | clear tooltip of icon |
disabled | Boolean | false | whether picker is disabled |
allowEmpty | Boolean | true | allow clearing text |
open | Boolean | false | current open state of picker. controlled prop |
defaultValue | moment | null | default initial value |
defaultOpenValue | moment | moment() | default open panel value, used to set utcOffset,locale if value/defaultValue absent |
value | moment | null | current value |
placeholder | String | '' | time input's placeholder |
className | String | '' | time picker className |
popupClassName | String | '' | time panel className |
showHour | Boolean | true | whether show hour |
showMinute | Boolean | true | whether show minute |
showSecond | Boolean | true | whether show second |
format | String | - | moment format |
disabledHours | Function | - | disabled hour options |
disabledMinutes | Function | - | disabled minute options |
disabledSeconds | Function | - | disabled second options |
use12Hours | Boolean | false | 12 hours display mode |
hideDisabledOptions | Boolean | false | whether hide disabled options |
onChange | Function | null | called when select a different value |
addon | Function | - | called from timepicker panel to render some addon to its bottom, like an OK button. Receives panel instance as parameter, to be able to close it like panel.close() . |
placement | String | bottomLeft | one of ['left','right','top','bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'] |
transitionName | String | '' | |
name | String | - | sets the name of the generated input |
onOpen | Function({ open }) | | when TimePicker panel is opened |
onClose | Function({ open }) | | when TimePicker panel is opened |
Test Case
npm test
npm run chrome-test
Coverage
npm run coverage
open coverage/ dir
License
rc-time-picker is released under the MIT license.