fix: enhance documentation in SingleDatePicker for props clarity and localization details

This commit is contained in:
Astrian Zheng 2025-02-19 22:12:40 +11:00
parent 44ace7cddb
commit c6d7d49ae4
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -4,12 +4,29 @@ import { useEffect, useState } from 'react'
import { getCalendarDates, getL10Weekday } from '../utils'
interface Props {
/**
* Control the selected
* date programmatically, including situations like provide a default value or control the selected
* date by parent component.
*/
value?: Date | { year: number, month: number, day: number }
/**
* A callback function that will be called when a date is selected inside the panel.
* @param date - The date user selected.
* @returns
*/
onSelect?: (date: {
year: number,
month: number,
day: number
}) => void
/**
* The language code that will be used to localize the panel.
* Accept standard ISO 639-1 language code, such as 'zh-CN', 'en-US', 'ja-JP', etc. Default to the
* language of the users browser. Note that it will not effect to the screen reader, but the screen
* reader will still read the date in the users language.
*/
localization?: string
}
@ -18,16 +35,7 @@ interface Props {
*
* @component
*
* @param {Object} props
* @param {Date | { year: number, month: number, day: number }} props.value - Control the selected
* date programmatically, including situations like provide a default value or control the selected
* date by parent component.
* @param {(date: { year: number, month: number, day: number }) => void} props.onSelect - A callback
* function that will be called when a date is selected inside the panel.
* @param {string} props.localization - The language code that will be used to localize the panel.
* Accept standard ISO 639-1 language code, such as 'zh-CN', 'en-US', 'ja-JP', etc. Default to the
* language of the users browser. Note that it will not effect to the screen reader, but the screen
* reader will still read the date in the users language.
* @param {Props} props
*/
export default ({ value, onSelect, localization }: Props) => {
const [currentMonth, setCurrentMonth] = useState(new Date().getMonth())