@mui/x-date-pickers 8.10.0 → 8.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/AdapterDateFns/AdapterDateFns.js +194 -195
  2. package/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -62
  3. package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -198
  4. package/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +196 -196
  5. package/AdapterDateFnsV2/AdapterDateFnsV2.js +193 -193
  6. package/AdapterDayjs/AdapterDayjs.js +378 -379
  7. package/AdapterLuxon/AdapterLuxon.js +324 -326
  8. package/AdapterMoment/AdapterMoment.js +297 -302
  9. package/AdapterMomentHijri/AdapterMomentHijri.js +78 -78
  10. package/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -80
  11. package/CHANGELOG.md +309 -0
  12. package/PickersTextField/PickersInputBase/PickersInputBase.js +14 -1
  13. package/PickersTextField/PickersTextField.js +3 -2
  14. package/esm/AdapterDateFns/AdapterDateFns.js +194 -194
  15. package/esm/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -62
  16. package/esm/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -197
  17. package/esm/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +196 -196
  18. package/esm/AdapterDateFnsV2/AdapterDateFnsV2.js +193 -193
  19. package/esm/AdapterDayjs/AdapterDayjs.js +378 -379
  20. package/esm/AdapterLuxon/AdapterLuxon.js +324 -325
  21. package/esm/AdapterMoment/AdapterMoment.js +297 -301
  22. package/esm/AdapterMomentHijri/AdapterMomentHijri.js +78 -78
  23. package/esm/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -80
  24. package/esm/PickersTextField/PickersInputBase/PickersInputBase.js +14 -1
  25. package/esm/PickersTextField/PickersTextField.js +3 -2
  26. package/esm/index.js +1 -1
  27. package/esm/internals/hooks/useField/syncSelectionToDOM.js +3 -1
  28. package/esm/internals/models/helpers.d.ts +1 -1
  29. package/esm/models/fields.d.ts +4 -0
  30. package/index.js +1 -1
  31. package/internals/hooks/useField/syncSelectionToDOM.js +3 -1
  32. package/internals/models/helpers.d.ts +1 -1
  33. package/models/fields.d.ts +4 -0
  34. package/package.json +15 -16
@@ -118,8 +118,9 @@ const PickersTextField = exports.PickersTextField = /*#__PURE__*/React.forwardRe
118
118
  isInputInFullWidth: fullWidth ?? false,
119
119
  hasStartAdornment: Boolean(startAdornment ?? InputProps?.startAdornment),
120
120
  hasEndAdornment: Boolean(endAdornment ?? InputProps?.endAdornment),
121
- inputHasLabel: !!label
122
- }), [fieldOwnerState, areAllSectionsEmpty, focused, error, props.size, color, fullWidth, startAdornment, endAdornment, InputProps?.startAdornment, InputProps?.endAdornment, label]);
121
+ inputHasLabel: !!label,
122
+ isLabelShrunk: Boolean(InputLabelProps?.shrink)
123
+ }), [fieldOwnerState, areAllSectionsEmpty, focused, error, props.size, color, fullWidth, startAdornment, endAdornment, InputProps?.startAdornment, InputProps?.endAdornment, label, InputLabelProps?.shrink]);
123
124
  const classes = useUtilityClasses(classesProp, ownerState);
124
125
  const PickersInputComponent = VARIANT_COMPONENT[variant];
125
126
  const inputAdditionalProps = {};
@@ -1,4 +1,3 @@
1
- /* eslint-disable class-methods-use-this */
2
1
  import { addDays } from 'date-fns/addDays';
3
2
  import { addSeconds } from 'date-fns/addSeconds';
4
3
  import { addMinutes } from 'date-fns/addMinutes';
@@ -88,198 +87,199 @@ export class AdapterDateFns extends AdapterDateFnsBase {
88
87
  formats,
89
88
  longFormatters
90
89
  });
91
- // TODO: explicit return types can be removed once there is only one date-fns version supported
92
- this.parse = (value, format) => {
93
- if (value === '') {
94
- return null;
95
- }
96
- return dateFnsParse(value, format, new Date(), {
97
- locale: this.locale
98
- });
99
- };
100
- this.isValid = value => {
101
- if (value == null) {
102
- return false;
103
- }
104
- return isValid(value);
105
- };
106
- this.format = (value, formatKey) => {
107
- return this.formatByString(value, this.formats[formatKey]);
108
- };
109
- this.formatByString = (value, formatString) => {
110
- return dateFnsFormat(value, formatString, {
111
- locale: this.locale
112
- });
113
- };
114
- this.isEqual = (value, comparing) => {
115
- if (value === null && comparing === null) {
116
- return true;
117
- }
118
- if (value === null || comparing === null) {
119
- return false;
120
- }
121
- return isEqual(value, comparing);
122
- };
123
- this.isSameYear = (value, comparing) => {
124
- return isSameYear(value, comparing);
125
- };
126
- this.isSameMonth = (value, comparing) => {
127
- return isSameMonth(value, comparing);
128
- };
129
- this.isSameDay = (value, comparing) => {
130
- return isSameDay(value, comparing);
131
- };
132
- this.isSameHour = (value, comparing) => {
133
- return isSameHour(value, comparing);
134
- };
135
- this.isAfter = (value, comparing) => {
136
- return isAfter(value, comparing);
137
- };
138
- this.isAfterYear = (value, comparing) => {
139
- return isAfter(value, endOfYear(comparing));
140
- };
141
- this.isAfterDay = (value, comparing) => {
142
- return isAfter(value, endOfDay(comparing));
143
- };
144
- this.isBefore = (value, comparing) => {
145
- return isBefore(value, comparing);
146
- };
147
- this.isBeforeYear = (value, comparing) => {
148
- return isBefore(value, this.startOfYear(comparing));
149
- };
150
- this.isBeforeDay = (value, comparing) => {
151
- return isBefore(value, this.startOfDay(comparing));
152
- };
153
- this.isWithinRange = (value, [start, end]) => {
154
- return isWithinInterval(value, {
155
- start,
156
- end
157
- });
158
- };
159
- this.startOfYear = value => {
160
- return startOfYear(value);
161
- };
162
- this.startOfMonth = value => {
163
- return startOfMonth(value);
164
- };
165
- this.startOfWeek = value => {
166
- return startOfWeek(value, {
167
- locale: this.locale
168
- });
169
- };
170
- this.startOfDay = value => {
171
- return startOfDay(value);
172
- };
173
- this.endOfYear = value => {
174
- return endOfYear(value);
175
- };
176
- this.endOfMonth = value => {
177
- return endOfMonth(value);
178
- };
179
- this.endOfWeek = value => {
180
- return endOfWeek(value, {
181
- locale: this.locale
182
- });
183
- };
184
- this.endOfDay = value => {
185
- return endOfDay(value);
186
- };
187
- this.addYears = (value, amount) => {
188
- return addYears(value, amount);
189
- };
190
- this.addMonths = (value, amount) => {
191
- return addMonths(value, amount);
192
- };
193
- this.addWeeks = (value, amount) => {
194
- return addWeeks(value, amount);
195
- };
196
- this.addDays = (value, amount) => {
197
- return addDays(value, amount);
198
- };
199
- this.addHours = (value, amount) => {
200
- return addHours(value, amount);
201
- };
202
- this.addMinutes = (value, amount) => {
203
- return addMinutes(value, amount);
204
- };
205
- this.addSeconds = (value, amount) => {
206
- return addSeconds(value, amount);
207
- };
208
- this.getYear = value => {
209
- return getYear(value);
210
- };
211
- this.getMonth = value => {
212
- return getMonth(value);
213
- };
214
- this.getDate = value => {
215
- return getDate(value);
216
- };
217
- this.getHours = value => {
218
- return getHours(value);
219
- };
220
- this.getMinutes = value => {
221
- return getMinutes(value);
222
- };
223
- this.getSeconds = value => {
224
- return getSeconds(value);
225
- };
226
- this.getMilliseconds = value => {
227
- return getMilliseconds(value);
228
- };
229
- this.setYear = (value, year) => {
230
- return setYear(value, year);
231
- };
232
- this.setMonth = (value, month) => {
233
- return setMonth(value, month);
234
- };
235
- this.setDate = (value, date) => {
236
- return setDate(value, date);
237
- };
238
- this.setHours = (value, hours) => {
239
- return setHours(value, hours);
240
- };
241
- this.setMinutes = (value, minutes) => {
242
- return setMinutes(value, minutes);
243
- };
244
- this.setSeconds = (value, seconds) => {
245
- return setSeconds(value, seconds);
246
- };
247
- this.setMilliseconds = (value, milliseconds) => {
248
- return setMilliseconds(value, milliseconds);
249
- };
250
- this.getDaysInMonth = value => {
251
- return getDaysInMonth(value);
252
- };
253
- this.getWeekArray = value => {
254
- const start = this.startOfWeek(this.startOfMonth(value));
255
- const end = this.endOfWeek(this.endOfMonth(value));
256
- let count = 0;
257
- let current = start;
258
- const nestedWeeks = [];
259
- while (this.isBefore(current, end)) {
260
- const weekNumber = Math.floor(count / 7);
261
- nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
262
- nestedWeeks[weekNumber].push(current);
263
- current = this.addDays(current, 1);
264
- count += 1;
265
- }
266
- return nestedWeeks;
267
- };
268
- this.getWeekNumber = value => {
269
- return getWeek(value, {
270
- locale: this.locale
271
- });
272
- };
273
- this.getYearRange = ([start, end]) => {
274
- const startDate = this.startOfYear(start);
275
- const endDate = this.endOfYear(end);
276
- const years = [];
277
- let current = startDate;
278
- while (this.isBefore(current, endDate)) {
279
- years.push(current);
280
- current = this.addYears(current, 1);
281
- }
282
- return years;
283
- };
284
90
  }
91
+
92
+ // TODO: explicit return types can be removed once there is only one date-fns version supported
93
+ parse = (value, format) => {
94
+ if (value === '') {
95
+ return null;
96
+ }
97
+ return dateFnsParse(value, format, new Date(), {
98
+ locale: this.locale
99
+ });
100
+ };
101
+ isValid = value => {
102
+ if (value == null) {
103
+ return false;
104
+ }
105
+ return isValid(value);
106
+ };
107
+ format = (value, formatKey) => {
108
+ return this.formatByString(value, this.formats[formatKey]);
109
+ };
110
+ formatByString = (value, formatString) => {
111
+ return dateFnsFormat(value, formatString, {
112
+ locale: this.locale
113
+ });
114
+ };
115
+ isEqual = (value, comparing) => {
116
+ if (value === null && comparing === null) {
117
+ return true;
118
+ }
119
+ if (value === null || comparing === null) {
120
+ return false;
121
+ }
122
+ return isEqual(value, comparing);
123
+ };
124
+ isSameYear = (value, comparing) => {
125
+ return isSameYear(value, comparing);
126
+ };
127
+ isSameMonth = (value, comparing) => {
128
+ return isSameMonth(value, comparing);
129
+ };
130
+ isSameDay = (value, comparing) => {
131
+ return isSameDay(value, comparing);
132
+ };
133
+ isSameHour = (value, comparing) => {
134
+ return isSameHour(value, comparing);
135
+ };
136
+ isAfter = (value, comparing) => {
137
+ return isAfter(value, comparing);
138
+ };
139
+ isAfterYear = (value, comparing) => {
140
+ return isAfter(value, endOfYear(comparing));
141
+ };
142
+ isAfterDay = (value, comparing) => {
143
+ return isAfter(value, endOfDay(comparing));
144
+ };
145
+ isBefore = (value, comparing) => {
146
+ return isBefore(value, comparing);
147
+ };
148
+ isBeforeYear = (value, comparing) => {
149
+ return isBefore(value, this.startOfYear(comparing));
150
+ };
151
+ isBeforeDay = (value, comparing) => {
152
+ return isBefore(value, this.startOfDay(comparing));
153
+ };
154
+ isWithinRange = (value, [start, end]) => {
155
+ return isWithinInterval(value, {
156
+ start,
157
+ end
158
+ });
159
+ };
160
+ startOfYear = value => {
161
+ return startOfYear(value);
162
+ };
163
+ startOfMonth = value => {
164
+ return startOfMonth(value);
165
+ };
166
+ startOfWeek = value => {
167
+ return startOfWeek(value, {
168
+ locale: this.locale
169
+ });
170
+ };
171
+ startOfDay = value => {
172
+ return startOfDay(value);
173
+ };
174
+ endOfYear = value => {
175
+ return endOfYear(value);
176
+ };
177
+ endOfMonth = value => {
178
+ return endOfMonth(value);
179
+ };
180
+ endOfWeek = value => {
181
+ return endOfWeek(value, {
182
+ locale: this.locale
183
+ });
184
+ };
185
+ endOfDay = value => {
186
+ return endOfDay(value);
187
+ };
188
+ addYears = (value, amount) => {
189
+ return addYears(value, amount);
190
+ };
191
+ addMonths = (value, amount) => {
192
+ return addMonths(value, amount);
193
+ };
194
+ addWeeks = (value, amount) => {
195
+ return addWeeks(value, amount);
196
+ };
197
+ addDays = (value, amount) => {
198
+ return addDays(value, amount);
199
+ };
200
+ addHours = (value, amount) => {
201
+ return addHours(value, amount);
202
+ };
203
+ addMinutes = (value, amount) => {
204
+ return addMinutes(value, amount);
205
+ };
206
+ addSeconds = (value, amount) => {
207
+ return addSeconds(value, amount);
208
+ };
209
+ getYear = value => {
210
+ return getYear(value);
211
+ };
212
+ getMonth = value => {
213
+ return getMonth(value);
214
+ };
215
+ getDate = value => {
216
+ return getDate(value);
217
+ };
218
+ getHours = value => {
219
+ return getHours(value);
220
+ };
221
+ getMinutes = value => {
222
+ return getMinutes(value);
223
+ };
224
+ getSeconds = value => {
225
+ return getSeconds(value);
226
+ };
227
+ getMilliseconds = value => {
228
+ return getMilliseconds(value);
229
+ };
230
+ setYear = (value, year) => {
231
+ return setYear(value, year);
232
+ };
233
+ setMonth = (value, month) => {
234
+ return setMonth(value, month);
235
+ };
236
+ setDate = (value, date) => {
237
+ return setDate(value, date);
238
+ };
239
+ setHours = (value, hours) => {
240
+ return setHours(value, hours);
241
+ };
242
+ setMinutes = (value, minutes) => {
243
+ return setMinutes(value, minutes);
244
+ };
245
+ setSeconds = (value, seconds) => {
246
+ return setSeconds(value, seconds);
247
+ };
248
+ setMilliseconds = (value, milliseconds) => {
249
+ return setMilliseconds(value, milliseconds);
250
+ };
251
+ getDaysInMonth = value => {
252
+ return getDaysInMonth(value);
253
+ };
254
+ getWeekArray = value => {
255
+ const start = this.startOfWeek(this.startOfMonth(value));
256
+ const end = this.endOfWeek(this.endOfMonth(value));
257
+ let count = 0;
258
+ let current = start;
259
+ const nestedWeeks = [];
260
+ while (this.isBefore(current, end)) {
261
+ const weekNumber = Math.floor(count / 7);
262
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
263
+ nestedWeeks[weekNumber].push(current);
264
+ current = this.addDays(current, 1);
265
+ count += 1;
266
+ }
267
+ return nestedWeeks;
268
+ };
269
+ getWeekNumber = value => {
270
+ return getWeek(value, {
271
+ locale: this.locale
272
+ });
273
+ };
274
+ getYearRange = ([start, end]) => {
275
+ const startDate = this.startOfYear(start);
276
+ const endDate = this.endOfYear(end);
277
+ const years = [];
278
+ let current = startDate;
279
+ while (this.isBefore(current, endDate)) {
280
+ years.push(current);
281
+ current = this.addYears(current, 1);
282
+ }
283
+ return years;
284
+ };
285
285
  }
@@ -1,6 +1,4 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- /* eslint-disable class-methods-use-this */
3
-
4
2
  const formatTokenMap = {
5
3
  // Year
6
4
  y: {
@@ -216,67 +214,14 @@ const defaultFormats = {
216
214
  * SOFTWARE.
217
215
  */
218
216
  export class AdapterDateFnsBase {
217
+ isMUIAdapter = true;
218
+ isTimezoneCompatible = false;
219
+ formatTokenMap = (() => formatTokenMap)();
220
+ escapedCharacters = {
221
+ start: "'",
222
+ end: "'"
223
+ };
219
224
  constructor(props) {
220
- this.isMUIAdapter = true;
221
- this.isTimezoneCompatible = false;
222
- this.lib = void 0;
223
- this.locale = void 0;
224
- this.formats = void 0;
225
- this.formatTokenMap = formatTokenMap;
226
- this.escapedCharacters = {
227
- start: "'",
228
- end: "'"
229
- };
230
- this.longFormatters = void 0;
231
- this.date = value => {
232
- if (typeof value === 'undefined') {
233
- return new Date();
234
- }
235
- if (value === null) {
236
- return null;
237
- }
238
- return new Date(value);
239
- };
240
- this.getInvalidDate = () => new Date('Invalid Date');
241
- this.getTimezone = () => {
242
- return 'default';
243
- };
244
- this.setTimezone = value => {
245
- return value;
246
- };
247
- this.toJsDate = value => {
248
- return value;
249
- };
250
- this.getCurrentLocaleCode = () => {
251
- // `code` is undefined only in `date-fns` types, but all locales have it
252
- return this.locale.code;
253
- };
254
- // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
255
- // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
256
- this.is12HourCycleInCurrentLocale = () => {
257
- return /a/.test(this.locale.formatLong.time({
258
- width: 'short'
259
- }));
260
- };
261
- this.expandFormat = format => {
262
- const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
263
-
264
- // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
265
- return format.match(longFormatRegexp).map(token => {
266
- const firstCharacter = token[0];
267
- if (firstCharacter === 'p' || firstCharacter === 'P') {
268
- const longFormatter = this.longFormatters[firstCharacter];
269
- return longFormatter(token, this.locale.formatLong);
270
- }
271
- return token;
272
- }).join('');
273
- };
274
- this.formatNumber = numberToFormat => {
275
- return numberToFormat;
276
- };
277
- this.getDayOfWeek = value => {
278
- return value.getDay() + 1;
279
- };
280
225
  const {
281
226
  locale,
282
227
  formats,
@@ -288,4 +233,54 @@ export class AdapterDateFnsBase {
288
233
  this.longFormatters = longFormatters;
289
234
  this.lib = lib || 'date-fns';
290
235
  }
236
+ date = value => {
237
+ if (typeof value === 'undefined') {
238
+ return new Date();
239
+ }
240
+ if (value === null) {
241
+ return null;
242
+ }
243
+ return new Date(value);
244
+ };
245
+ getInvalidDate = () => new Date('Invalid Date');
246
+ getTimezone = () => {
247
+ return 'default';
248
+ };
249
+ setTimezone = value => {
250
+ return value;
251
+ };
252
+ toJsDate = value => {
253
+ return value;
254
+ };
255
+ getCurrentLocaleCode = () => {
256
+ // `code` is undefined only in `date-fns` types, but all locales have it
257
+ return this.locale.code;
258
+ };
259
+
260
+ // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
261
+ // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
262
+ is12HourCycleInCurrentLocale = () => {
263
+ return /a/.test(this.locale.formatLong.time({
264
+ width: 'short'
265
+ }));
266
+ };
267
+ expandFormat = format => {
268
+ const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
269
+
270
+ // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
271
+ return format.match(longFormatRegexp).map(token => {
272
+ const firstCharacter = token[0];
273
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
274
+ const longFormatter = this.longFormatters[firstCharacter];
275
+ return longFormatter(token, this.locale.formatLong);
276
+ }
277
+ return token;
278
+ }).join('');
279
+ };
280
+ formatNumber = numberToFormat => {
281
+ return numberToFormat;
282
+ };
283
+ getDayOfWeek = value => {
284
+ return value.getDay() + 1;
285
+ };
291
286
  }