Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

thaidatepicker-react

buildingwatsize1.2kMIT2.1.2TypeScript support: included

Thaidatepicker-react is a component for ReactJS that likes other DatePicker, but all we need is Buddhist Year (25XX - aka Thai Year) come with the right render day (example: Sat, 29 Feb 2020 must be equal to Sat, 29 Feb 2563) so I wish this component will

react, datepicker, buddhist, thai, leap, year, date

readme

thaidatepicker-react

NPM NPM CodeQL Downloads


🎉 RELEASE v2 🎉

Thank you to everyone who used my little side project. I appreciate all you guys. Hope to keep it active.


📘 About

The thaidatepicker-react is a component for ReactJS that likes other DatePicker library but all we need is Buddhist Year (25XX – aka Thai Year) come with the right render day on "Leap" year (example: Sat, 29 Feb 2020 must be equal to Sat, 29 Feb 2563) so I wish this component will be a useful thing to you :D. Happy Coding.

⚙ Install

npm install thaidatepicker-react
# or just `yarn add thaidatepicker-react`

📌 Example Usage

import React, { useState } from "react";
import { ThaiDatePicker } from "thaidatepicker-react";

const App = () => {
  const [selectedDate, setSelectedDate] = useState("2024-02-29");
  const [selectedThaiDate, setSelectedThaiDate] = useState("2567-02-29");

  const handleDatePickerChange = (christDate, buddhistDate) => {
    console.log(christDate);
    console.log(buddhistDate);
    setSelectedDate(christDate);
    setSelectedThaiDate(buddhistDate);
  };

  return (
    <>
      <ThaiDatePicker
        value={selectedDate}
        onChange={handleDatePickerChange}
      />
      <div>christDate: {selectedDate}</div>
      <div>thaiDate: {selectedThaiDate}</div>
    </>
  );
};

export default App;

📋 Properties

Property Description Type Default Version
children the children element inside like {children} by default you don't need to defined as props. React.ReactNode | null null
id #id for container element string "thdpk-container"
value A christ date value with fixed dayjs format (YYYY-MM-DD) string ""
onChange Handle function with maximum 2 parameters, christDate and thaiDate (christDate: string, thaiDate: string) => void (_christDate: string, _thaiDate: string) => null
disabled Disabled property for input boolean false
readOnly ReadOnly property for input boolean false
clearable Clear the value (please note clearable will work smoothly with onChange props) boolean true
placeholder Placeholder property for input string ""
header An object for setting up header component. To change button icon use prevButtonIcon and nextButtonIcon. To change className of button and select use prevButtonClassName, nextButtonClassName, monthSelectClassName, and yearSelectClassName Object { prevButtonIcon?: React.ReactNode; nextButtonIcon?: React.ReactNode; prevButtonClassName?: string; nextButtonClassName?: string; monthSelectClassName?: string; yearSelectClassName?: string; } | null } {}
yearBoundary A config boundary ±Year (e.g. yearBoundary = 2; it means currentYear ± 2.) number 99
inputProps An override input properties. (any & { displayFormat?: string; }) | null null
reactDatePickerProps An override react-datepicker properties. See more (https://reactdatepicker.com/ or https://github.com/Hacker0x01/react-datepicker/blob/master/docs/datepicker.md) React.ComponentProps<typeof DatePicker> {}
minDate A config minimum selectable date. To use, you can provide the string like 2023-01-31. (Note: It's will depend on yearBoundary too.) Date | string undefined
maxDate A config maximum selectable date. To use, you can provide the string like 2023-12-31. (Note: It's will depend on yearBoundary too.) Date | string undefined
highlightDates A highlight selected date. To use, you can provide an array of Date like [new Date()] (Date | HighlightDate)[] GetHighlightByDate()
customInput A config for using custom input element. To use, you can provide a name of element like Input React.ComponentType<any> | null null
noIntegratedStyle A config for define to exclude integrated css Note: if you using 2 components, which the first one contain noIntegratedStyle props but the second is not. It will import css and then it apply to them all boolean false v2.0.0

🎩 Some Useful Tricks

  1. To style dates outside the selected month, use the .react-datepicker__day--outside-month CSS class.

    .react-datepicker__day--outside-month {
      color: #aaa;
    }

    However, be aware that the appearance may resemble the 'disabled' attribute, which could affect the user experience

📝 Need More Example?

I made a couple difference stack demos. Try looking at the examples of "vite" or "next" projects on ./example.

Changelog

Please see more CHANGELOG.md

License

MIT © buildingwatsize

⚒ Thanks a lot

changelog

Changelog

🎉 Release - v2 🎉

v2.1.2 - 2025-02-13

Edited

  • Edited peerDependencies to support react 18 and later

v2.1.1 - 2025-02-13

Updated

  • Patched for peerDependencies back-compatibility with react^18.3.1

v2.1.0 - 2025-02-11

Updated

  • Supported React 19
  • Updated dependencies
  • Migrated React 19 forwardRef
  • Migrated deprecated React.MutableRefObject to React.RefObject

Edited

  • Edited customInput props type to React.ElementType to support more various kinds component
  • Edited more patched css
  • Refactor className, style with cn utils

v2.0.2 - 2024-11-19

Updated

  • Fixed known vulnerabilities
  • Updated dependencies
  • Fixed bugs on css in example project

v2.0.1 - 2024-09-20

Updated

  • Fixed known vulnerabilities
  • Updated dependencies

v2.0.0 - 2024-09-09

Added

  • TypeScript is now supported.
  • Added new props noIntegratedStyle which can be define to exclude integrated css

Updated

  • Updated dependencies

🎉 Release - v1 🎉

v1.3.6 - 2024-08-15

Updated

  • Updated dependencies

v1.3.5 - 2024-06-21

Edited

  • Updated security alerts from Dependabot

v1.3.4 - 2024-06-21

Edited

v1.3.3 - 2024-05-10

Added

  • More example for Typescript project

Edited

  • Fixed bugs for explicit define types on package.json
  • Code preparing for Typescript migration (defaultProps will be removed)

Updated

  • dependencies

v1.3.2 - 2024-05-02

Updated

  • dependencies

v1.3.1 - 2024-04-19

Edited

  • Refactor code to explicit props declaration and also minimize the export
  • Refactor code to support webpack 5
  • Updated example for selectable with input formatting

v1.3.0 - 2024-04-18

Added

  • Support dayjs/locale/th as default
  • Support dayjs/plugin/buddhistEra as default

Updated

  • dependencies
  • example/with-vite-andt-tailwind's deps, source code, and also bumps the vite major version

v1.2.1 - 2024-02-20

Edited

  • Fixed bugs on dist output when publish to npmjs

v1.2.0 - 2024-02-14

Edited

  • 🌹 Happy Valentine Day
  • updated dependencies (Alert! bump major version. So if something not working as expected, don't hesitate for opening the issues/PR.)
  • updated demo example/with-vite-antd-tailwind

v1.1.0 - 2023-09-27

Edited

  • updated dependencies

v1.0.5 - 2023-06-12

Edited

  • Fixed package linking

v1.0.4 - 2023-06-09

Edited

  • bump dependencies

v1.0.3 - 2023-04-11

Added

  • Vercel Analytics for demo project

Edited

  • bump dependencies
  • fixed z-index over the properties table in example

v1.0.2 - 2023-01-26

Added

  • some devDependencies like mockdate for ease to develop
  • supporting es import and be standalone without css
  • example for this new release

Edited

  • code structure as component separated
  • package.json scripts
  • replace enzyme testing with react testing library

Updated

Removed

  • eslint for reducing project complexity (using vscode extension instead)
  • antd, @ant-design/icons for reduce package size (customization available)

[v1.0.0...v1.0.1] - 2023-01-25

I have to skipping for the old versions which was unpublished once on first created.


Legacy Version - v0.x.x

v0.2.2 - 2022-06-16

  • [Fixed] When the value of props.value changes, the state will no longer be updated.
  • [Updated] Dependencies

v0.2.1 - 2022-04-29

  • [Removed] some dependency which not used anymore
  • [Edited] Example page for update latest version

v0.2.0 - 2022-04-29

  • [Updated] Dependencies (Note: Upgrade major version of `React@18.1.0andreact-datepicker`)
  • [Added] inputProps property for customizable of input
  • [Added] inputProps description on README.md and also a missing one reactDatePickerProps
  • [Edited] ESLint and prettier
  • [Edited] missing remove unused code

v0.1.5 - 2021-04-02

  • [Updated] Dependencies
  • [Fixed] bug on "Form Submit" after click prev/next month button

v0.1.4 - 2021-01-19

  • [Merged] PR#2
  • [Added] CodeQL Analysis
  • [Added] Supported props disabled and readOnly
  • [Added] Supported year boundaries with yearBoundary props. The default is 99 btw It depends on minDate and maxDate
  • [Added] Clearable button will hide on disabled or readOnly props is true. The default is true
  • [Added] Supported more props of react-datepicker by using reactDatePickerProps props
  • [Fixed] some buggy on yarn

v0.1.3 - 2021-01-12

  • [Merged] PR#1
  • [Added] more features, displayFormat, inputStyle, and clearable

v0.1.2 - 2021-01-11

  • [Fixed] Known vulnerabilities
  • [Added] Link for demo
  • [Added] display date format for input
  • [Added] clearable props to let user clear their selected date
  • [Added] inputStyle to control input box styling

v0.1.1 - 2020-05-11

  • Initialized Project

v0.1.0 - 2020-05-11

  • Initialized Project