1.0.3 • Published 4 years ago

react-time-picker-lite v1.0.3

Weekly downloads
55
License
-
Repository
github
Last release
4 years ago

react-time-picker-lite

npm.io

A simple, lightweight React time picker. Requires React 16.8.0 or higher.

  • Supports typed input only (no dropdowns).
  • Rejects input characters that would create an invalid time sting, and resets if input is not a complete, valid time string when unfocussed.
  • Try demo here

Installation

npm install react-time-picker-lite

Basic Example

import React, { useState } from 'react';
import TimePicker from 'react-time-picker-lite';

function App() {
  const [timeMessage, setTimeMessage] = useState(null);
  const [errorMessage, setErrorMessage] = useState(null);
  
  const handleSuccess = (hhmmString) => {
    setTimeMessage(`Time is set to ${hhmmString}.`);
    setErrorMessage(null);
  };

  const handleError = () => {
    setErrorMessage('Please insert a valid time.');
    setTimeMessage(null);
  };

  return (
    <div>
      <TimePicker
        onSuccess={handleSuccess}
        onError={handleError}
      />
      {timeMessage || errorMessage || ''}
    </div>
  );
}

Props

Prop nameDescriptionData TypeDefault Value
placeholderTextThe value to display in the time input before it's facussedString'Set Time'
wrapperWidthThe width of the wrapper containing both the input and the AM/PM buttonsString'120px'
wrapperHeightThe height of the warpper containing both the input and the AM/PM buttonsString'150px'
inputHeightThe height of the inputString'30%' (of the wrapper)
inputWidthThe width of the inputString'100%' (of the wrapper)
inputFontSizeFont size for input textString'20px'
backgroundColorOnBlurColor of input background when blurredString'#000' (black)
textColorOnBlurColor of input text when blurredString'#FFF' (white)
backgroundColorOnfocusColor of input background when focussedString'#FFF' (white)
textColorOnfocusColor of input text when focussedString'#000' (black)
fontFont to be applied to input and AM/PM button textString'inherit'
amPmButtonHeightHeight of AM/PM buttonString'25%' (of the wrapper)
amPmButtonWidthWidth of AM/PM buttonString'25%' (of the wrapper)
amPmButtonFontSizeFont size for the AM/PM button textString'10px'
amPmButtonHighlightedBackgroundColorColor of AM/PM button background when selectedString'#000' (black)
amPmButtonNonHighlightedBackgroundColorColor of AM/PM button background when unselectedString'#FFF' (white)
amPmButtonHighlightedTextColorColor of AM/PM button text when selectedString'#FFF' (white)
amPmButtonNonHighlightedTextColorColor of AM/PM button text when unselectedString'#000' (black)
onErrorFunction that is called when input is reset due to invalid time valueFunction() => null
onSuccessFunction that is called when input is unfocussed with valid time value. Includes 'HH:mm' (in 24-hour format) as argumentFunction() => null
shouldUse24HourModeAllows input to use 24 hour time (hides AM/PM buttons if set to true)Booleanfalse
1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.1-2

4 years ago

1.0.1-1

4 years ago

1.0.1-0

4 years ago

1.0.0

4 years ago

1.0.0-5

4 years ago

1.0.0-4

4 years ago

1.0.0-1

4 years ago

1.0.0-0

4 years ago

0.1.0

4 years ago