react-duration-picker
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

React duration picker for mobile, inspired by Android number pickers. A live demo is available here. Supports keyboard and mouse events in addition to touch. A type declaration file is also included.

Installation

npm install react-duration-picker

Then in your React component:

import DurationPicker from 'react-duration-picker'

API

Prop Type Default Description
onChange ({hours: number, minutes: number, seconds: number}) => void () => {} Callback executed by DurationPicker whenever the duration displayed on the picker is updated
initialDuration {hours: number, minutes: number, seconds: number} {hours: 0, minutes: 0, seconds: 0} Duration to display on first render
maxHours number 10 Max number of hours that can be selected
noHours boolean false If true, omits 'hours' column from picker

Example

const onChange = duration => {
  const { hours, minutes, seconds } = duration;
  setState({ hours, minutes, seconds });
};
 
return (
  <Modal open={isOpen}>
    <DurationPicker
      onChange={onChange}
      initialDuration={{ hours: 1, minutes: 2, seconds: 3 }}
      maxHours={5}
    />
    <button onClick={closeModal} />
  </Modal>
);

The example directory contains the code for the demo.

Contributing

Contributions and feedback are welcome. Submit bugs or suggestions as an issue on Github.

Package Sidebar

Install

npm i react-duration-picker

Weekly Downloads

329

Version

1.1.1

License

MIT

Unpacked Size

91 kB

Total Files

22

Last publish

Collaborators

  • flurmbo