Skip to content

Commit

Permalink
Revert unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Nov 4, 2024
1 parent d38a91a commit a0f9d1a
Show file tree
Hide file tree
Showing 32 changed files with 101 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function CustomDayOfWeekFormat() {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateCalendar
value={value}
onChange={setValue}
onChange={(newValue) => setValue(newValue)}
dayOfWeekFormatter={(weekday) => `${weekday.format('dd')}.`}
/>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function CustomDayOfWeekFormat() {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateCalendar
value={value}
onChange={setValue}
onChange={(newValue) => setValue(newValue)}
dayOfWeekFormatter={(weekday) => `${weekday.format('dd')}.`}
/>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<DateCalendar
value={value}
onChange={setValue}
onChange={(newValue) => setValue(newValue)}
dayOfWeekFormatter={(weekday) => `${weekday.format('dd')}.`}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function ControlledComponent() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DatePicker']}>
<DatePicker value={value} onChange={setValue} />
<DatePicker value={value} onChange={(newValue) => setValue(newValue)} />
</DemoContainer>
</LocalizationProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function ControlledComponent() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DatePicker']}>
<DatePicker value={value} onChange={setValue} />
<DatePicker value={value} onChange={(newValue) => setValue(newValue)} />
</DemoContainer>
</LocalizationProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<DatePicker value={value} onChange={setValue} />
<DatePicker value={value} onChange={(newValue) => setValue(newValue)} />
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ButtonDateField(props) {
}
};

const formattedValue = value == null ? parsedFormat : value.format(format);
const valueStr = value == null ? parsedFormat : value.format(format);

return (
<Button
Expand All @@ -52,7 +52,7 @@ function ButtonDateField(props) {
ref={InputProps?.ref}
onClick={handleTogglePicker}
>
{label ? `${label}: ${formattedValue}` : formattedValue}
{label ? `${label}: ${valueStr}` : valueStr}
</Button>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function ButtonDateField(props: DatePickerFieldProps) {
}
};

const formattedValue = value == null ? parsedFormat : value.format(format);
const valueStr = value == null ? parsedFormat : value.format(format);

return (
<Button
Expand All @@ -56,7 +56,7 @@ function ButtonDateField(props: DatePickerFieldProps) {
ref={InputProps?.ref}
onClick={handleTogglePicker}
>
{label ? `${label}: ${formattedValue}` : formattedValue}
{label ? `${label}: ${valueStr}` : valueStr}
</Button>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const ACCEPT_REGEX = /[\d]/gi;
const staticDateWith2DigitTokens = dayjs('2019-11-21T11:30:00.000');
const staticDateWith1DigitTokens = dayjs('2019-01-01T09:00:00.000');

function getInputValueFromDate(date, format) {
if (date == null) {
function getValueStrFromValue(value, format) {
if (value == null) {
return '';
}

return date.isValid() ? date.format(format) : '';
return value.isValid() ? value.format(format) : '';
}

function MaskedField(props) {
Expand All @@ -46,12 +46,12 @@ function MaskedField(props) {

// Control the input text
const [inputValue, setInputValue] = React.useState(() =>
getInputValueFromDate(value, format),
getValueStrFromValue(value, format),
);

React.useEffect(() => {
if (value && value.isValid()) {
const newDisplayDate = getInputValueFromDate(value, format);
const newDisplayDate = getValueStrFromValue(value, format);
setInputValue(newDisplayDate);
}
}, [format, value]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const ACCEPT_REGEX = /[\d]/gi;
const staticDateWith2DigitTokens = dayjs('2019-11-21T11:30:00.000');
const staticDateWith1DigitTokens = dayjs('2019-01-01T09:00:00.000');

function getInputValueFromDate(date: Dayjs | null, format: string) {
if (date == null) {
function getValueStrFromValue(value: Dayjs | null, format: string) {
if (value == null) {
return '';
}

return date.isValid() ? date.format(format) : '';
return value.isValid() ? value.format(format) : '';
}

function MaskedField(props: DatePickerFieldProps) {
Expand All @@ -50,12 +50,12 @@ function MaskedField(props: DatePickerFieldProps) {

// Control the input text
const [inputValue, setInputValue] = React.useState<string>(() =>
getInputValueFromDate(value, format),
getValueStrFromValue(value, format),
);

React.useEffect(() => {
if (value && value.isValid()) {
const newDisplayDate = getInputValueFromDate(value, format);
const newDisplayDate = getValueStrFromValue(value, format);
setInputValue(newDisplayDate);
}
}, [format, value]);
Expand Down
2 changes: 1 addition & 1 deletion docs/data/date-pickers/date-calendar/DateCalendarValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function DateCalendarValue() {
<DateCalendar defaultValue={dayjs('2022-04-17')} />
</DemoItem>
<DemoItem label="Controlled calendar">
<DateCalendar value={value} onChange={setValue} />
<DateCalendar value={value} onChange={(newValue) => setValue(newValue)} />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/date-pickers/date-calendar/DateCalendarValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function DateCalendarValue() {
<DateCalendar defaultValue={dayjs('2022-04-17')} />
</DemoItem>
<DemoItem label="Controlled calendar">
<DateCalendar value={value} onChange={setValue} />
<DateCalendar value={value} onChange={(newValue) => setValue(newValue)} />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<DateCalendar defaultValue={dayjs('2022-04-17')} />
</DemoItem>
<DemoItem label="Controlled calendar">
<DateCalendar value={value} onChange={setValue} />
<DateCalendar value={value} onChange={(newValue) => setValue(newValue)} />
</DemoItem>
6 changes: 5 additions & 1 deletion docs/data/date-pickers/date-field/DateFieldValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export default function DateFieldValue() {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DateField', 'DateField']}>
<DateField label="Uncontrolled field" defaultValue={dayjs('2022-04-17')} />
<DateField label="Controlled field" value={value} onChange={setValue} />
<DateField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoContainer>
</LocalizationProvider>
);
Expand Down
6 changes: 5 additions & 1 deletion docs/data/date-pickers/date-field/DateFieldValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export default function DateFieldValue() {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DateField', 'DateField']}>
<DateField label="Uncontrolled field" defaultValue={dayjs('2022-04-17')} />
<DateField label="Controlled field" value={value} onChange={setValue} />
<DateField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoContainer>
</LocalizationProvider>
);
Expand Down
6 changes: 5 additions & 1 deletion docs/data/date-pickers/date-field/DateFieldValue.tsx.preview
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<DateField label="Uncontrolled field" defaultValue={dayjs('2022-04-17')} />
<DateField label="Controlled field" value={value} onChange={setValue} />
<DateField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export default function DateRangeCalendarValue() {
/>
</DemoItem>
<DemoItem label="Controlled calendar">
<DateRangeCalendar value={value} onChange={setValue} />
<DateRangeCalendar
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoItem>
</DemoContainer>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default function DateRangeCalendarValue() {
/>
</DemoItem>
<DemoItem label="Controlled calendar">
<DateRangeCalendar value={value} onChange={setValue} />
<DateRangeCalendar
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoItem>
</DemoContainer>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
/>
</DemoItem>
<DemoItem label="Controlled calendar">
<DateRangeCalendar value={value} onChange={setValue} />
<DateRangeCalendar
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoItem>
6 changes: 5 additions & 1 deletion docs/data/date-pickers/date-time-field/DateTimeFieldValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export default function DateTimeFieldValue() {
label="Uncontrolled field"
defaultValue={dayjs('2022-04-17T15:30')}
/>
<DateTimeField label="Controlled field" value={value} onChange={setValue} />
<DateTimeField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoContainer>
</LocalizationProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export default function DateTimeFieldValue() {
label="Uncontrolled field"
defaultValue={dayjs('2022-04-17T15:30')}
/>
<DateTimeField label="Controlled field" value={value} onChange={setValue} />
<DateTimeField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoContainer>
</LocalizationProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
label="Uncontrolled field"
defaultValue={dayjs('2022-04-17T15:30')}
/>
<DateTimeField label="Controlled field" value={value} onChange={setValue} />
<DateTimeField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
10 changes: 8 additions & 2 deletions docs/data/date-pickers/digital-clock/DigitalClockValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default function DigitalClockValue() {
<DigitalClock defaultValue={dayjs('2022-04-17T15:30')} />
</DemoItem>
<DemoItem label="Controlled digital clock">
<DigitalClock value={value} onChange={setValue} />
<DigitalClock
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoItem>
</DemoContainer>
<DemoContainer
Expand All @@ -34,7 +37,10 @@ export default function DigitalClockValue() {
<MultiSectionDigitalClock defaultValue={dayjs('2022-04-17T15:30')} />
</DemoItem>
<DemoItem label="Controlled multi section digital clock">
<MultiSectionDigitalClock value={value} onChange={setValue} />
<MultiSectionDigitalClock
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoItem>
</DemoContainer>
</DemoContainer>
Expand Down
10 changes: 8 additions & 2 deletions docs/data/date-pickers/digital-clock/DigitalClockValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default function DigitalClockValue() {
<DigitalClock defaultValue={dayjs('2022-04-17T15:30')} />
</DemoItem>
<DemoItem label="Controlled digital clock">
<DigitalClock value={value} onChange={setValue} />
<DigitalClock
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoItem>
</DemoContainer>
<DemoContainer
Expand All @@ -34,7 +37,10 @@ export default function DigitalClockValue() {
<MultiSectionDigitalClock defaultValue={dayjs('2022-04-17T15:30')} />
</DemoItem>
<DemoItem label="Controlled multi section digital clock">
<MultiSectionDigitalClock value={value} onChange={setValue} />
<MultiSectionDigitalClock
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoItem>
</DemoContainer>
</DemoContainer>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/date-pickers/fields/ClearableBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function ClearableBehavior() {
<DateField
sx={{ width: '300px' }}
value={value}
onChange={setValue}
onChange={(newValue) => setValue(newValue)}
onClear={() => setCleared(true)}
clearable
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/date-pickers/fields/ClearableBehavior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function ClearableBehavior() {
<DateField
sx={{ width: '300px' }}
value={value}
onChange={setValue}
onChange={(newValue) => setValue(newValue)}
onClear={() => setCleared(true)}
clearable
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/date-pickers/time-clock/TimeClockValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function TimeClockValue() {
<TimeClock defaultValue={dayjs('2022-04-17T15:30')} />
</DemoItem>
<DemoItem label="Controlled clock">
<TimeClock value={value} onChange={setValue} />
<TimeClock value={value} onChange={(newValue) => setValue(newValue)} />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/date-pickers/time-clock/TimeClockValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function TimeClockValue() {
<TimeClock defaultValue={dayjs('2022-04-17T15:30')} />
</DemoItem>
<DemoItem label="Controlled clock">
<TimeClock value={value} onChange={setValue} />
<TimeClock value={value} onChange={(newValue) => setValue(newValue)} />
</DemoItem>
</DemoContainer>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<TimeClock defaultValue={dayjs('2022-04-17T15:30')} />
</DemoItem>
<DemoItem label="Controlled clock">
<TimeClock value={value} onChange={setValue} />
<TimeClock value={value} onChange={(newValue) => setValue(newValue)} />
</DemoItem>
6 changes: 5 additions & 1 deletion docs/data/date-pickers/time-field/TimeFieldValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export default function TimeFieldValue() {
label="Uncontrolled field"
defaultValue={dayjs('2022-04-17T15:30')}
/>
<TimeField label="Controlled field" value={value} onChange={setValue} />
<TimeField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoContainer>
</LocalizationProvider>
);
Expand Down
6 changes: 5 additions & 1 deletion docs/data/date-pickers/time-field/TimeFieldValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export default function TimeFieldValue() {
label="Uncontrolled field"
defaultValue={dayjs('2022-04-17T15:30')}
/>
<TimeField label="Controlled field" value={value} onChange={setValue} />
<TimeField
label="Controlled field"
value={value}
onChange={(newValue) => setValue(newValue)}
/>
</DemoContainer>
</LocalizationProvider>
);
Expand Down
Loading

0 comments on commit a0f9d1a

Please sign in to comment.