Skip to content

Commit 693e2b3

Browse files
authored
Merge pull request #19 from NoahMLoomis/add-date-format-prop
Added displayFormat prop to change the text display of the selected dates
2 parents 412b5b8 + 763d846 commit 693e2b3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- ✅ Shortcuts
2424
- ✅ TypeScript support
2525
- ✅ Localization(i18n)
26+
- ✅ Date formatting
2627
- ⬜ Disable specific dates
2728
- ⬜ Custom shortcuts
2829

src/components/Datepicker.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interface Props {
4646
disabled?: boolean;
4747
inputClassName?: string | null;
4848
containerClassName?: string | null;
49+
displayFormat?: string;
4950
readonly?: boolean;
5051
}
5152

@@ -65,6 +66,7 @@ const Datepicker: React.FC<Props> = ({
6566
disabled = false,
6667
inputClassName = null,
6768
containerClassName = null,
69+
displayFormat = "YYYY-MM-DD",
6870
readonly = false
6971
}) => {
7072
// Ref
@@ -216,7 +218,9 @@ const Datepicker: React.FC<Props> = ({
216218
end: formatDate(endDate)
217219
});
218220
setInputText(
219-
`${formatDate(startDate)}${asSingle ? "" : ` ~ ${formatDate(endDate)}`}`
221+
`${formatDate(startDate, displayFormat)}${
222+
asSingle ? "" : ` ~ ${formatDate(endDate, displayFormat)}`
223+
}`
220224
);
221225
}
222226
}
@@ -227,7 +231,7 @@ const Datepicker: React.FC<Props> = ({
227231
end: null
228232
});
229233
}
230-
}, [asSingle, value]);
234+
}, [asSingle, value, displayFormat]);
231235

232236
// Variable
233237
const colorPrimary = useMemo(() => {

0 commit comments

Comments
 (0)