1.0.0 • Published 4 years ago

react-simple-time-input v1.0.0

Weekly downloads
28
License
-
Repository
-
Last release
4 years ago

react-simple-time-input

A simple time input that accepts times in flexible format. It has support for both 12- and 24-hour format.

View live demo

demo

Installation

npm install react-simple-time-input --save

Usage

import React, { useState } from 'react'
import SimpleTimeInput from 'react-simple-time-input'

function MyComponent () {
  const [time, setTime] = useState('14:00')

  const valueChanged = newValue => {
    setTime(newValue)
    alert(`Time changed to ${newValue}`)
  }

  return (
    <SimpleTimeInput
      value={time}
      clockMode={12}
      onValueChange={valueChanged} // called on blur
    />
  )
}

Prop types

PropRequiredTypeDescription
valueYesStringThe current value, always in 24-hour format (e.g. 14:00)
clockModeYes12 or 24 (Number)The clock input and display mode (12- or 24-hour format)
asNoelementTypeType of component to be rendered, e.g. as={TextField}. If not passed, an HTML input will be used by default.
onValueChangeNoFunctionFunction to be called on blur event. It passes the interpreted time as argument.
invalidClassNameNoStringclassName appended to element when user is typing a time in invalid format. If not passed, the class name invalid-time will be used by default.

Any additional prop passed is forwarded to the input component.

When onChange is used, the event is forwarded and an object is passed as the second argument with a valid flag and time with the time interpreted.

1.0.0

4 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago