0.1.6 • Published 2 months ago

@abizzle/react-date-input v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@abizzle/react-date-input

An unstyled, dependency-free replacement for <input type="date" /> for React projects.

This project borrows concepts and code from MUI's Date Field component.

Installation

npm install @abizzle/react-date-input

Usage

Via hook:

import { useDateInput, UseDateInputParams } from "@abizzle/react-date-input":

export type MyDateInputProps = UseDateInputParams;

export function MyDateInput(props: MyDateInputProps) {
  const { inputProps } = useDateInput(props);

  return <input {...inputProps} />
}

Via component:

import { DateInput, DateInputProps } from "@abizzle/react-date-input":

export type MyDateInputProps = DateInputProps;

export function MyDateInput(props: MyDateInputProps) {
  return <DateInput {...props} />
}

The useDateInput hook and DateInput component both accept these optional props:

PropDescription
defaultValueA date string (Ex. "2012-12-21")
inputModeAn inputmode to override the default value of "numeric" used by useDateInput/DateInput
localeA Unicode locale identifier string (Ex. "en-US") used to determine the order of date elements (Ex. "MM/DD/YYYY" vs. "DD/MM/YYYY") as well as the character to use for month, day, and year placeholders. Supported placeholder languages include: English, Spanish, German, Finnish, French, Hungarian, Icelandinc, Italian, Kazakh, Norwegian, Romanian, Russian, and Turkish. Defaults to Navigator.language.
onBlurReact.FocusEventHandler<HTMLInputElement>
onChangeReact.ChangeEventHandler<HTMLInputElement>
onClickReact.MouseEventHandler<HTMLInputElement>
onDateChange(date: string \| null) => void. If not null, date will be a valid date string (Ex. "2012-12-21")
onFocusReact.FocusEventHandler<HTMLInputElement>
onKeyDownReact.KeyboardEventHandler<HTMLInputElement>
onMouseUpReact.MouseEventHandler<HTMLInputElement>
onPasteReact.ClipboardEventHandler<HTMLInputElement>
readOnlyTreat the <input/> as readonly.
refReact.Ref<HTMLInputElement>
valueA date string (Ex. "2012-12-21"). Provide this prop to use "controlled input".

The DateInput component additionally accepts every prop for an <input/> component except max, min, step, and type as they are not supported.

0.1.6

2 months ago

0.1.5

2 months ago

0.1.4

6 months ago

0.1.3

6 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago