外觀
多月顯示
並排顯示超過 2 個月。對於範圍選擇器,預設為 2。
import { useState } from "react";import "react-date-range-picker-styled/rdrp-styles.css";import { DateRangePicker } from "react-date-range-picker-styled";
function MultiMonth() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return <DateRangePicker value={value} onChange={setValue} numberOfMonths={3} />;}自訂語系
使用 createLocale from the headless package to customize month/day names and UI strings.
import { useState } from "react";import { DateRangePicker } from "react-date-range-picker-styled";import { createLocale } from "react-date-range-picker-headless";import "react-date-range-picker-styled/rdrp-styles.css";
const koLocale = createLocale("ko-KR", { confirm: "확인", cancel: "취소", clear: "초기화", today: "오늘", rangePlaceholder: "날짜 범위 선택", rangeSeparator: " ~ ",});
function CustomLocale() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return <DateRangePicker value={value} onChange={setValue} locale={koLocale} />;}標題下拉選單
將按鈕導覽切換為月份和年份的下拉選單。適用於選擇遠離當前月份的日期。
import { useState } from "react";import { DateRangePicker } from "react-date-range-picker-styled";import "react-date-range-picker-styled/rdrp-styles.css";
function CaptionDropdown() { const [value, setValue] = useState<{ start: Date | null; end: Date | null }>({ start: null, end: null, });
return ( <DateRangePicker value={value} onChange={setValue} captionLayout="dropdown" fromYear={2020} toYear={2030} /> );}