// These polyfills are only necessary for the sake of IE11 being able to render the syntax highlighter import 'core-js/features/symbol' import 'core-js/features/promise' import 'core-js/features/object/assign' import 'core-js/features/array/includes' import 'core-js/features/array/find' import 'core-js/features/array/find-index' import React, { Component, useState } from 'react' import './App.css' import { TimeInputPolyfill, TimeInputPolyfillProps, } from './core/TimeInputPolyfill' import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' import { dark } from 'react-syntax-highlighter/dist/esm/styles/prism' import { version } from '../package.json' import { getIDsAndLabels, staticValues } from '@time-input-polyfill/tests' import { EventName, AltEventName, IDsAndLabels } from './App-tests-shared-stuff' interface ExampleBlockProps extends Omit { label: string codeString?: string } const ExampleBlock = ({ label, codeString, ...restProps }: ExampleBlockProps) => { const [value, setValue] = useState('20:30') const [forcePolyfill, setForcePolyfill] = useState(true) const { IDs } = getIDsAndLabels({ primaryTestsLabel: label }) return (
e.preventDefault()}>

{label}

{label} returned value: "{value}"

{Boolean(codeString) && ( {codeString.replace(/^\n/, '')} )}
) } class ClassBasedComponentExample extends Component { state = { value: staticValues.defaultValue.cpuValue, eventsValue: staticValues.defaultValue.cpuValue, eventsReturnValue: staticValues.defaultValue.inputValue, eventMainName: 'none', eventAltName: 'none', forcePolyfill: true, } exampleId = 'class-based-component-example' render() { const { value, forcePolyfill } = this.state const { eventsInputID, eventsAltNameID, eventsMainNameID, eventsValueID, primaryValueID, primaryInputID, buttonIDs, } = IDsAndLabels.classBased.IDs const { eventTestsLabel, primaryTestsLabel } = IDsAndLabels.classBased.labels return (
e.preventDefault()} >

Class based component example

The time input polyfill has been optimized to work best with React Hooks but you can still use it in a class based component.

this.setState({ value: newValue })} forcePolyfill={forcePolyfill} id={primaryInputID} />

class based returned value: "{value}"

{` /* TimeInput.js */ import React, { Component } from 'react' // Import the component into your project import TimeInputPolyfill from '@time-input-polyfill/react' export class TimeInput extends Component { render() { const { value, setValue, label } = this.props return ( ) } } /////////////////////////////////////////////////// /* ExampleForm.js */ import React, { Component } from 'react' // import your local time input component into your form component import { TimeInput } from './TimeInput' export class ExampleForm extends Component { state = { inputValue: '20:30' } render() { return ( this.setState({inputValue: newValue})} /> ) } } `.replace(/^\n/, '')}
{process.env.NODE_ENV === 'development' && ( <>

{eventTestsLabel}


{ this.setState({ eventsValue: newValue }) }} forcePolyfill onChange={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventAltName: 'change', }) }} onFocus={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventMainName: 'focus', }) }} onBlur={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventMainName: 'blur', }) }} onMouseDown={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventMainName: 'mouseDown', }) }} onMouseUp={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventMainName: 'mouseUp', }) }} onClick={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventAltName: 'click', }) }} onKeyDown={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventMainName: 'keyDown', }) }} onKeyUp={(e) => { this.setState({ eventsReturnValue: e.currentTarget.value, eventMainName: 'keyUp', }) }} />

{this.state.eventsReturnValue}

{this.state.eventMainName}

{this.state.eventAltName}

)} ) } } function App() { // let [addedLater, setAddedLater] = useState(false) // setTimeout(() => setAddedLater(true), 2000) const [testValue, setTestValue] = useState( staticValues.defaultValue.inputValue, ) const [eventMainName, setEventName] = useState('none') const [eventAltName, setAltEventName] = useState('none') const { eventTestsLabel } = IDsAndLabels.functionBased.labels const { eventsValueID, eventsAltNameID, eventsMainNameID } = IDsAndLabels.functionBased.IDs return (

React Time Input Polyfill

v{version}

Code examples are simplified guides, not exact code replicas.

npm install @time-input-polyfill/react

Visit me on GitHub

{ return ( ) } /////////////////////////////////////////////////// /* ExampleForm.js */ import React, { useState } from 'react' // import your local time input component into your form component import { TimeInput } from './TimeInput' export const ExampleForm = ()=> { // Use state to keep track of the value const [inputValue, setInputValue] = useState('20:30') // default to 8:30 PM // Make use of useEffect to react to inputValue changes useEffect(() => { console.log({ inputValue }) }, [ inputValue ]) return (
) } `} /> {process.env.NODE_ENV === 'development' && ( <> { setTestValue(e.currentTarget.value) setAltEventName('change') }} onFocus={(e) => { setTestValue(e.currentTarget.value) setEventName('focus') }} onBlur={(e) => { setTestValue(e.currentTarget.value) setEventName('blur') }} onMouseDown={(e) => { setTestValue(e.currentTarget.value) setEventName('mouseDown') }} onMouseUp={(e) => { setTestValue(e.currentTarget.value) setEventName('mouseUp') }} onClick={(e) => { setTestValue(e.currentTarget.value) setAltEventName('click') }} onKeyDown={(e) => { setTestValue(e.currentTarget.value) setEventName('keyDown') }} onKeyUp={(e) => { setTestValue(e.currentTarget.value) setEventName('keyUp') }} />

{testValue}

{eventMainName}

{eventAltName}

)}
) } export default App