Skip to content

Commit 7c05944

Browse files
committed
Code Review: add dateFormat and placeholderText as variables
1 parent 7d63e83 commit 7c05944

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/components/forms/controls/DatePicker/DatePicker.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export const DatePicker = (props: DatePickerProps) => {
3636
const {
3737
unstyled = false,
3838
className,
39+
dateFormat = 'MM/dd/yyyy',
40+
placeholderText = 'MM/DD/YYYY',
3941
...propsRest
4042
} = props;
4143

@@ -48,8 +50,8 @@ export const DatePicker = (props: DatePickerProps) => {
4850
className,
4951
)}>
5052
<ReactDatePicker
51-
dateFormat="MM/dd/yyyy"
52-
placeholderText="MM/DD/YYYY"
53+
dateFormat={dateFormat}
54+
placeholderText={placeholderText}
5355
showIcon
5456
icon={<Icon icon="calendar"/>}
5557
customInput={

src/components/forms/controls/DatePicker/DatePickerRange.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const DatePickerRange = (props: DatePickerRangeProps) => {
3535
const {
3636
unstyled = false,
3737
className,
38+
dateFormat = 'MM/dd/yyyy',
39+
placeholderText = 'MM/DD/YYYY',
3840
...propsRest
3941
} = props;
4042

@@ -47,8 +49,8 @@ export const DatePickerRange = (props: DatePickerRangeProps) => {
4749
<ReactDatePicker
4850
selectsRange
4951
// everything else is the same
50-
dateFormat="MM/dd/yyyy"
51-
placeholderText="MM/DD/YYYY"
52+
dateFormat={dateFormat}
53+
placeholderText={placeholderText}
5254
customInput={<Input />}
5355
{...propsRest}
5456
/>

src/components/forms/controls/DateTimePicker/DateTimePicker.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { TimePicker, type Time } from '../TimePicker/TimePicker.tsx';
1212
import cl from './DateTimePicker.module.scss';
1313

1414

15-
type GenericProps = {
15+
export type DateTimePickerProps = {
1616
/** Whether this component should be unstyled. */
1717
unstyled?: undefined | boolean,
1818

@@ -24,11 +24,22 @@ type GenericProps = {
2424

2525
/** A callback function that is called when either the date or the time picker is changed. */
2626
onChange: ((date: Date | null, event?: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => void),
27+
28+
/** A string for the date format, such as MM/dd/yyyy. */
29+
dateFormat: string,
30+
31+
/** A string for the placeholder text, such as MM/DD/YYYY. */
32+
placeholderText: string,
2733
};
2834

29-
export type DateTimePickerProps = GenericProps;
30-
31-
export const DateTimePicker = ({ unstyled = false, className, date, onChange, ...propsRest }: DateTimePickerProps) => {
35+
export const DateTimePicker = ({
36+
unstyled = false,
37+
className,
38+
date,
39+
onChange,
40+
dateFormat = 'MM/dd/yyyy',
41+
placeholderText = 'MM/DD/YYYY',
42+
}: DateTimePickerProps) => {
3243
// Time from date object.
3344
const time = { hours: date?.getHours() || 0, minutes: date?.getMinutes() || 0 };
3445

@@ -51,6 +62,8 @@ export const DateTimePicker = ({ unstyled = false, className, date, onChange, ..
5162
<DatePicker
5263
selected={date}
5364
onChange={onChange}
65+
dateFormat={dateFormat}
66+
placeholderText={placeholderText}
5467
/>
5568
<TimePicker
5669
time={time}

0 commit comments

Comments
 (0)