@mui/x-date-pickers 8.0.0-alpha.4 → 8.0.0-alpha.5
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.
- package/CHANGELOG.md +103 -0
- package/MonthCalendar/MonthCalendar.d.ts +1 -1
- package/MonthCalendar/MonthCalendar.js +31 -11
- package/MonthCalendar/MonthCalendar.types.d.ts +2 -2
- package/MonthCalendar/MonthCalendarButton.d.ts +24 -0
- package/MonthCalendar/{PickersMonth.js → MonthCalendarButton.js} +20 -61
- package/MonthCalendar/index.d.ts +0 -3
- package/MonthCalendar/index.js +1 -2
- package/MonthCalendar/monthCalendarClasses.d.ts +7 -1
- package/MonthCalendar/monthCalendarClasses.js +1 -1
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +3 -0
- package/PickersSectionList/PickersSectionList.js +21 -16
- package/PickersSectionList/PickersSectionList.types.d.ts +13 -6
- package/PickersTextField/PickersFilledInput/PickersFilledInput.d.ts +7 -0
- package/PickersTextField/PickersFilledInput/PickersFilledInput.js +34 -28
- package/PickersTextField/PickersFilledInput/pickersFilledInputClasses.d.ts +1 -1
- package/PickersTextField/PickersInput/PickersInput.js +20 -14
- package/PickersTextField/PickersInput/pickersInputClasses.d.ts +3 -2
- package/PickersTextField/PickersInput/pickersInputClasses.js +1 -1
- package/PickersTextField/PickersInputBase/PickersInputBase.d.ts +3 -6
- package/PickersTextField/PickersInputBase/PickersInputBase.js +36 -37
- package/PickersTextField/PickersInputBase/PickersInputBase.types.d.ts +1 -0
- package/PickersTextField/PickersOutlinedInput/Outline.d.ts +0 -1
- package/PickersTextField/PickersOutlinedInput/Outline.js +13 -10
- package/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +8 -14
- package/PickersTextField/PickersTextField.js +75 -62
- package/PickersTextField/PickersTextField.types.d.ts +43 -4
- package/PickersTextField/usePickerTextFieldOwnerState.d.ts +4 -0
- package/PickersTextField/usePickerTextFieldOwnerState.js +11 -0
- package/TimeClock/Clock.d.ts +4 -0
- package/TimeClock/Clock.js +9 -6
- package/TimeClock/TimeClock.js +21 -4
- package/YearCalendar/YearCalendar.js +46 -13
- package/YearCalendar/YearCalendar.types.d.ts +2 -2
- package/YearCalendar/YearCalendarButton.d.ts +23 -0
- package/YearCalendar/{PickersYear.js → YearCalendarButton.js} +20 -59
- package/YearCalendar/index.d.ts +0 -3
- package/YearCalendar/index.js +1 -2
- package/YearCalendar/yearCalendarClasses.d.ts +7 -1
- package/YearCalendar/yearCalendarClasses.js +1 -1
- package/index.js +1 -1
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +3 -3
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.types.d.ts +1 -1
- package/internals/hooks/useFieldOwnerState.d.ts +1 -0
- package/internals/hooks/useFieldOwnerState.js +6 -2
- package/models/fields.d.ts +11 -1
- package/modern/MonthCalendar/MonthCalendar.js +31 -11
- package/modern/MonthCalendar/{PickersMonth.js → MonthCalendarButton.js} +20 -61
- package/modern/MonthCalendar/index.js +1 -2
- package/modern/MonthCalendar/monthCalendarClasses.js +1 -1
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +3 -0
- package/modern/PickersSectionList/PickersSectionList.js +21 -16
- package/modern/PickersTextField/PickersFilledInput/PickersFilledInput.js +34 -28
- package/modern/PickersTextField/PickersInput/PickersInput.js +20 -14
- package/modern/PickersTextField/PickersInput/pickersInputClasses.js +1 -1
- package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +36 -37
- package/modern/PickersTextField/PickersOutlinedInput/Outline.js +13 -10
- package/modern/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +8 -14
- package/modern/PickersTextField/PickersTextField.js +75 -62
- package/modern/PickersTextField/usePickerTextFieldOwnerState.js +11 -0
- package/modern/TimeClock/Clock.js +9 -6
- package/modern/TimeClock/TimeClock.js +21 -4
- package/modern/YearCalendar/YearCalendar.js +46 -13
- package/modern/YearCalendar/{PickersYear.js → YearCalendarButton.js} +20 -59
- package/modern/YearCalendar/index.js +1 -2
- package/modern/YearCalendar/yearCalendarClasses.js +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +3 -3
- package/modern/internals/hooks/useFieldOwnerState.js +6 -2
- package/node/MonthCalendar/MonthCalendar.js +31 -11
- package/node/MonthCalendar/{PickersMonth.js → MonthCalendarButton.js} +20 -61
- package/node/MonthCalendar/index.js +1 -8
- package/node/MonthCalendar/monthCalendarClasses.js +1 -1
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +3 -0
- package/node/PickersSectionList/PickersSectionList.js +21 -16
- package/node/PickersTextField/PickersFilledInput/PickersFilledInput.js +34 -28
- package/node/PickersTextField/PickersInput/PickersInput.js +20 -14
- package/node/PickersTextField/PickersInput/pickersInputClasses.js +1 -1
- package/node/PickersTextField/PickersInputBase/PickersInputBase.js +36 -37
- package/node/PickersTextField/PickersOutlinedInput/Outline.js +13 -10
- package/node/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +8 -14
- package/node/PickersTextField/PickersTextField.js +75 -62
- package/node/PickersTextField/usePickerTextFieldOwnerState.js +18 -0
- package/node/TimeClock/Clock.js +9 -6
- package/node/TimeClock/TimeClock.js +21 -4
- package/node/YearCalendar/YearCalendar.js +45 -12
- package/node/YearCalendar/{PickersYear.js → YearCalendarButton.js} +20 -59
- package/node/YearCalendar/index.js +1 -8
- package/node/YearCalendar/yearCalendarClasses.js +1 -1
- package/node/index.js +1 -1
- package/node/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +3 -3
- package/node/internals/hooks/useFieldOwnerState.js +6 -2
- package/package.json +3 -3
- package/themeAugmentation/components.d.ts +0 -8
- package/themeAugmentation/overrides.d.ts +2 -4
- package/themeAugmentation/props.d.ts +2 -4
- package/MonthCalendar/PickersMonth.d.ts +0 -28
- package/MonthCalendar/pickersMonthClasses.d.ts +0 -13
- package/MonthCalendar/pickersMonthClasses.js +0 -5
- package/YearCalendar/PickersYear.d.ts +0 -27
- package/YearCalendar/pickersYearClasses.d.ts +0 -13
- package/YearCalendar/pickersYearClasses.js +0 -5
- package/modern/MonthCalendar/pickersMonthClasses.js +0 -5
- package/modern/YearCalendar/pickersYearClasses.js +0 -5
- package/node/MonthCalendar/pickersMonthClasses.js +0 -12
- package/node/YearCalendar/pickersYearClasses.js +0 -12
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["onFocus", "onBlur", "className", "color", "disabled", "error", "variant", "required", "InputProps", "inputProps", "inputRef", "sectionListRef", "elements", "areAllSectionsEmpty", "onClick", "onKeyDown", "onKeyUp", "onPaste", "onInput", "endAdornment", "startAdornment", "tabIndex", "contentEditable", "focused", "value", "onChange", "fullWidth", "id", "name", "helperText", "FormHelperTextProps", "label", "InputLabelProps"];
|
|
5
|
+
const _excluded = ["onFocus", "onBlur", "className", "classes", "color", "disabled", "error", "variant", "required", "InputProps", "inputProps", "inputRef", "sectionListRef", "elements", "areAllSectionsEmpty", "onClick", "onKeyDown", "onKeyUp", "onPaste", "onInput", "endAdornment", "startAdornment", "tabIndex", "contentEditable", "focused", "value", "onChange", "fullWidth", "id", "name", "helperText", "FormHelperTextProps", "label", "InputLabelProps"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import clsx from 'clsx';
|
|
@@ -18,6 +18,8 @@ import { getPickersTextFieldUtilityClass } from "./pickersTextFieldClasses.js";
|
|
|
18
18
|
import { PickersOutlinedInput } from "./PickersOutlinedInput/index.js";
|
|
19
19
|
import { PickersFilledInput } from "./PickersFilledInput/index.js";
|
|
20
20
|
import { PickersInput } from "./PickersInput/index.js";
|
|
21
|
+
import { useFieldOwnerState } from "../internals/hooks/useFieldOwnerState.js";
|
|
22
|
+
import { PickerTextFieldOwnerStateContext } from "./usePickerTextFieldOwnerState.js";
|
|
21
23
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
24
|
const VARIANT_COMPONENT = {
|
|
23
25
|
standard: PickersInput,
|
|
@@ -29,15 +31,14 @@ const PickersTextFieldRoot = styled(FormControl, {
|
|
|
29
31
|
slot: 'Root',
|
|
30
32
|
overridesResolver: (props, styles) => styles.root
|
|
31
33
|
})({});
|
|
32
|
-
const useUtilityClasses = ownerState => {
|
|
34
|
+
const useUtilityClasses = (classes, ownerState) => {
|
|
33
35
|
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
required
|
|
36
|
+
isFieldFocused,
|
|
37
|
+
isFieldDisabled,
|
|
38
|
+
isFieldRequired
|
|
38
39
|
} = ownerState;
|
|
39
40
|
const slots = {
|
|
40
|
-
root: ['root',
|
|
41
|
+
root: ['root', isFieldFocused && !isFieldDisabled && 'focused', isFieldDisabled && 'disabled', isFieldRequired && 'required']
|
|
41
42
|
};
|
|
42
43
|
return composeClasses(slots, getPickersTextFieldUtilityClass, classes);
|
|
43
44
|
};
|
|
@@ -51,6 +52,7 @@ const PickersTextField = /*#__PURE__*/React.forwardRef(function PickersTextField
|
|
|
51
52
|
onFocus,
|
|
52
53
|
onBlur,
|
|
53
54
|
className,
|
|
55
|
+
classes: classesProp,
|
|
54
56
|
color = 'primary',
|
|
55
57
|
disabled = false,
|
|
56
58
|
error = false,
|
|
@@ -91,64 +93,75 @@ const PickersTextField = /*#__PURE__*/React.forwardRef(function PickersTextField
|
|
|
91
93
|
const id = useId(idProp);
|
|
92
94
|
const helperTextId = helperText && id ? `${id}-helper-text` : undefined;
|
|
93
95
|
const inputLabelId = label && id ? `${id}-label` : undefined;
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
focused,
|
|
99
|
-
required,
|
|
100
|
-
variant
|
|
96
|
+
const fieldOwnerState = useFieldOwnerState({
|
|
97
|
+
disabled: props.disabled,
|
|
98
|
+
required: props.required,
|
|
99
|
+
readOnly: InputProps?.readOnly
|
|
101
100
|
});
|
|
102
|
-
const
|
|
101
|
+
const ownerState = React.useMemo(() => _extends({}, fieldOwnerState, {
|
|
102
|
+
isFieldValueEmpty: areAllSectionsEmpty,
|
|
103
|
+
isFieldFocused: focused ?? false,
|
|
104
|
+
hasFieldError: error ?? false,
|
|
105
|
+
inputSize: props.size ?? 'medium',
|
|
106
|
+
inputColor: color ?? 'primary',
|
|
107
|
+
isInputInFullWidth: fullWidth ?? false,
|
|
108
|
+
hasStartAdornment: Boolean(startAdornment ?? InputProps?.startAdornment),
|
|
109
|
+
hasEndAdornment: Boolean(endAdornment ?? InputProps?.endAdornment),
|
|
110
|
+
inputHasLabel: !!label
|
|
111
|
+
}), [fieldOwnerState, areAllSectionsEmpty, focused, error, props.size, color, fullWidth, startAdornment, endAdornment, InputProps?.startAdornment, InputProps?.endAdornment, label]);
|
|
112
|
+
const classes = useUtilityClasses(classesProp, ownerState);
|
|
103
113
|
const PickersInputComponent = VARIANT_COMPONENT[variant];
|
|
104
|
-
return /*#__PURE__*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
ownerState: ownerState
|
|
115
|
-
}, other, {
|
|
116
|
-
children: [/*#__PURE__*/_jsx(InputLabel, _extends({
|
|
117
|
-
htmlFor: id,
|
|
118
|
-
id: inputLabelId
|
|
119
|
-
}, InputLabelProps, {
|
|
120
|
-
children: label
|
|
121
|
-
})), /*#__PURE__*/_jsx(PickersInputComponent, _extends({
|
|
122
|
-
elements: elements,
|
|
123
|
-
areAllSectionsEmpty: areAllSectionsEmpty,
|
|
124
|
-
onClick: onClick,
|
|
125
|
-
onKeyDown: onKeyDown,
|
|
126
|
-
onKeyUp: onKeyUp,
|
|
127
|
-
onInput: onInput,
|
|
128
|
-
onPaste: onPaste,
|
|
129
|
-
onFocus: onFocus,
|
|
130
|
-
onBlur: onBlur,
|
|
131
|
-
endAdornment: endAdornment,
|
|
132
|
-
startAdornment: startAdornment,
|
|
133
|
-
tabIndex: tabIndex,
|
|
134
|
-
contentEditable: contentEditable,
|
|
135
|
-
value: value,
|
|
136
|
-
onChange: onChange,
|
|
137
|
-
id: id,
|
|
114
|
+
return /*#__PURE__*/_jsx(PickerTextFieldOwnerStateContext.Provider, {
|
|
115
|
+
value: ownerState,
|
|
116
|
+
children: /*#__PURE__*/_jsxs(PickersTextFieldRoot, _extends({
|
|
117
|
+
className: clsx(classes.root, className),
|
|
118
|
+
ref: handleRootRef,
|
|
119
|
+
focused: focused,
|
|
120
|
+
disabled: disabled,
|
|
121
|
+
variant: variant,
|
|
122
|
+
error: error,
|
|
123
|
+
color: color,
|
|
138
124
|
fullWidth: fullWidth,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
125
|
+
required: required,
|
|
126
|
+
ownerState: ownerState
|
|
127
|
+
}, other, {
|
|
128
|
+
children: [/*#__PURE__*/_jsx(InputLabel, _extends({
|
|
129
|
+
htmlFor: id,
|
|
130
|
+
id: inputLabelId
|
|
131
|
+
}, InputLabelProps, {
|
|
132
|
+
children: label
|
|
133
|
+
})), /*#__PURE__*/_jsx(PickersInputComponent, _extends({
|
|
134
|
+
elements: elements,
|
|
135
|
+
areAllSectionsEmpty: areAllSectionsEmpty,
|
|
136
|
+
onClick: onClick,
|
|
137
|
+
onKeyDown: onKeyDown,
|
|
138
|
+
onKeyUp: onKeyUp,
|
|
139
|
+
onInput: onInput,
|
|
140
|
+
onPaste: onPaste,
|
|
141
|
+
onFocus: onFocus,
|
|
142
|
+
onBlur: onBlur,
|
|
143
|
+
endAdornment: endAdornment,
|
|
144
|
+
startAdornment: startAdornment,
|
|
145
|
+
tabIndex: tabIndex,
|
|
146
|
+
contentEditable: contentEditable,
|
|
147
|
+
value: value,
|
|
148
|
+
onChange: onChange,
|
|
149
|
+
id: id,
|
|
150
|
+
fullWidth: fullWidth,
|
|
151
|
+
inputProps: inputProps,
|
|
152
|
+
inputRef: inputRef,
|
|
153
|
+
sectionListRef: sectionListRef,
|
|
154
|
+
label: label,
|
|
155
|
+
name: name,
|
|
156
|
+
role: "group",
|
|
157
|
+
"aria-labelledby": inputLabelId
|
|
158
|
+
}, InputProps)), helperText && /*#__PURE__*/_jsx(FormHelperText, _extends({
|
|
159
|
+
id: helperTextId
|
|
160
|
+
}, FormHelperTextProps, {
|
|
161
|
+
children: helperText
|
|
162
|
+
}))]
|
|
163
|
+
}))
|
|
164
|
+
});
|
|
152
165
|
});
|
|
153
166
|
process.env.NODE_ENV !== "production" ? PickersTextField.propTypes = {
|
|
154
167
|
// ----------------------------- Warning --------------------------------
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export const PickerTextFieldOwnerStateContext = /*#__PURE__*/React.createContext(null);
|
|
5
|
+
export const usePickerTextFieldOwnerState = () => {
|
|
6
|
+
const value = React.useContext(PickerTextFieldOwnerStateContext);
|
|
7
|
+
if (value == null) {
|
|
8
|
+
throw new Error(['MUI X: The `usePickerTextFieldOwnerState` can only be called in components that are used inside a PickerTextField component'].join('\n'));
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
@@ -177,6 +177,7 @@ export function Clock(inProps) {
|
|
|
177
177
|
selectedId,
|
|
178
178
|
type,
|
|
179
179
|
viewValue,
|
|
180
|
+
viewRange: [minViewValue, maxViewValue],
|
|
180
181
|
disabled = false,
|
|
181
182
|
readOnly,
|
|
182
183
|
className,
|
|
@@ -251,6 +252,8 @@ export function Clock(inProps) {
|
|
|
251
252
|
listboxRef.current.focus();
|
|
252
253
|
}
|
|
253
254
|
}, [autoFocus]);
|
|
255
|
+
const clampValue = newValue => Math.max(minViewValue, Math.min(maxViewValue, newValue));
|
|
256
|
+
const circleValue = newValue => (newValue + (maxViewValue + 1)) % (maxViewValue + 1);
|
|
254
257
|
const handleKeyDown = event => {
|
|
255
258
|
// TODO: Why this early exit?
|
|
256
259
|
if (isMoving.current) {
|
|
@@ -259,27 +262,27 @@ export function Clock(inProps) {
|
|
|
259
262
|
switch (event.key) {
|
|
260
263
|
case 'Home':
|
|
261
264
|
// reset both hours and minutes
|
|
262
|
-
handleValueChange(
|
|
265
|
+
handleValueChange(minViewValue, 'partial');
|
|
263
266
|
event.preventDefault();
|
|
264
267
|
break;
|
|
265
268
|
case 'End':
|
|
266
|
-
handleValueChange(
|
|
269
|
+
handleValueChange(maxViewValue, 'partial');
|
|
267
270
|
event.preventDefault();
|
|
268
271
|
break;
|
|
269
272
|
case 'ArrowUp':
|
|
270
|
-
handleValueChange(viewValue + keyboardControlStep, 'partial');
|
|
273
|
+
handleValueChange(circleValue(viewValue + keyboardControlStep), 'partial');
|
|
271
274
|
event.preventDefault();
|
|
272
275
|
break;
|
|
273
276
|
case 'ArrowDown':
|
|
274
|
-
handleValueChange(viewValue - keyboardControlStep, 'partial');
|
|
277
|
+
handleValueChange(circleValue(viewValue - keyboardControlStep), 'partial');
|
|
275
278
|
event.preventDefault();
|
|
276
279
|
break;
|
|
277
280
|
case 'PageUp':
|
|
278
|
-
handleValueChange(viewValue + 5, 'partial');
|
|
281
|
+
handleValueChange(clampValue(viewValue + 5), 'partial');
|
|
279
282
|
event.preventDefault();
|
|
280
283
|
break;
|
|
281
284
|
case 'PageDown':
|
|
282
|
-
handleValueChange(viewValue - 5, 'partial');
|
|
285
|
+
handleValueChange(clampValue(viewValue - 5), 'partial');
|
|
283
286
|
event.preventDefault();
|
|
284
287
|
break;
|
|
285
288
|
case 'Enter':
|
|
@@ -186,6 +186,9 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
186
186
|
{
|
|
187
187
|
const valueWithMeridiem = convertValueToMeridiem(rawValue, meridiemMode, ampm);
|
|
188
188
|
const dateWithNewHours = utils.setHours(valueOrReferenceDate, valueWithMeridiem);
|
|
189
|
+
if (utils.getHours(dateWithNewHours) !== valueWithMeridiem) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
189
192
|
const start = utils.setSeconds(utils.setMinutes(dateWithNewHours, 0), 0);
|
|
190
193
|
const end = utils.setSeconds(utils.setMinutes(dateWithNewHours, 59), 59);
|
|
191
194
|
return !containsValidTime({
|
|
@@ -225,9 +228,20 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
225
228
|
const valueWithMeridiem = convertValueToMeridiem(hourValue, meridiemMode, ampm);
|
|
226
229
|
setValueAndGoToNextView(utils.setHours(valueOrReferenceDate, valueWithMeridiem), isFinish, 'hours');
|
|
227
230
|
};
|
|
231
|
+
const viewValue = utils.getHours(valueOrReferenceDate);
|
|
232
|
+
let viewRange;
|
|
233
|
+
if (ampm) {
|
|
234
|
+
if (viewValue > 12) {
|
|
235
|
+
viewRange = [12, 23];
|
|
236
|
+
} else {
|
|
237
|
+
viewRange = [0, 11];
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
viewRange = [0, 23];
|
|
241
|
+
}
|
|
228
242
|
return {
|
|
229
243
|
onChange: handleHoursChange,
|
|
230
|
-
viewValue
|
|
244
|
+
viewValue,
|
|
231
245
|
children: getHourNumbers({
|
|
232
246
|
value,
|
|
233
247
|
utils,
|
|
@@ -236,7 +250,8 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
236
250
|
getClockNumberText: translations.hoursClockNumberText,
|
|
237
251
|
isDisabled: hourValue => disabled || isTimeDisabled(hourValue, 'hours'),
|
|
238
252
|
selectedId
|
|
239
|
-
})
|
|
253
|
+
}),
|
|
254
|
+
viewRange
|
|
240
255
|
};
|
|
241
256
|
}
|
|
242
257
|
case 'minutes':
|
|
@@ -255,7 +270,8 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
255
270
|
getClockNumberText: translations.minutesClockNumberText,
|
|
256
271
|
isDisabled: minuteValue => disabled || isTimeDisabled(minuteValue, 'minutes'),
|
|
257
272
|
selectedId
|
|
258
|
-
})
|
|
273
|
+
}),
|
|
274
|
+
viewRange: [0, 59]
|
|
259
275
|
};
|
|
260
276
|
}
|
|
261
277
|
case 'seconds':
|
|
@@ -274,7 +290,8 @@ export const TimeClock = /*#__PURE__*/React.forwardRef(function TimeClock(inProp
|
|
|
274
290
|
getClockNumberText: translations.secondsClockNumberText,
|
|
275
291
|
isDisabled: secondValue => disabled || isTimeDisabled(secondValue, 'seconds'),
|
|
276
292
|
selectedId
|
|
277
|
-
})
|
|
293
|
+
}),
|
|
294
|
+
viewRange: [0, 59]
|
|
278
295
|
};
|
|
279
296
|
}
|
|
280
297
|
default:
|
|
@@ -7,9 +7,10 @@ import * as React from 'react';
|
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
import { useRtl } from '@mui/system/RtlProvider';
|
|
10
|
+
import { shouldForwardProp } from '@mui/system/createStyled';
|
|
10
11
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
11
12
|
import { unstable_useForkRef as useForkRef, unstable_composeClasses as composeClasses, unstable_useControlled as useControlled, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
12
|
-
import {
|
|
13
|
+
import { YearCalendarButton } from "./YearCalendarButton.js";
|
|
13
14
|
import { useUtils, useNow, useDefaultDates } from "../internals/hooks/useUtils.js";
|
|
14
15
|
import { getYearCalendarUtilityClass } from "./yearCalendarClasses.js";
|
|
15
16
|
import { applyDefaultDate } from "../internals/utils/date-utils.js";
|
|
@@ -18,7 +19,7 @@ import { SECTION_TYPE_GRANULARITY } from "../internals/utils/getDefaultReference
|
|
|
18
19
|
import { useControlledValueWithTimezone } from "../internals/hooks/useValueWithTimezone.js";
|
|
19
20
|
import { DIALOG_WIDTH, MAX_CALENDAR_HEIGHT } from "../internals/constants/dimensions.js";
|
|
20
21
|
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
|
|
21
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
23
|
const useUtilityClasses = classes => {
|
|
23
24
|
const slots = {
|
|
24
25
|
root: ['root']
|
|
@@ -37,6 +38,7 @@ function useYearCalendarDefaultizedProps(props, name) {
|
|
|
37
38
|
disableFuture: false
|
|
38
39
|
}, themeProps, {
|
|
39
40
|
yearsPerRow: themeProps.yearsPerRow ?? 3,
|
|
41
|
+
yearsOrder: themeProps.yearsOrder ?? 'asc',
|
|
40
42
|
minDate: applyDefaultDate(utils, themeProps.minDate, defaultDates.minDate),
|
|
41
43
|
maxDate: applyDefaultDate(utils, themeProps.maxDate, defaultDates.maxDate)
|
|
42
44
|
});
|
|
@@ -44,19 +46,43 @@ function useYearCalendarDefaultizedProps(props, name) {
|
|
|
44
46
|
const YearCalendarRoot = styled('div', {
|
|
45
47
|
name: 'MuiYearCalendar',
|
|
46
48
|
slot: 'Root',
|
|
47
|
-
|
|
49
|
+
shouldForwardProp: prop => shouldForwardProp(prop) && prop !== 'yearsPerRow'
|
|
48
50
|
})({
|
|
49
51
|
display: 'flex',
|
|
50
|
-
flexDirection: 'row',
|
|
51
52
|
flexWrap: 'wrap',
|
|
53
|
+
justifyContent: 'space-evenly',
|
|
54
|
+
rowGap: 12,
|
|
55
|
+
padding: '6px 0',
|
|
52
56
|
overflowY: 'auto',
|
|
53
57
|
height: '100%',
|
|
54
|
-
padding: '0 4px',
|
|
55
58
|
width: DIALOG_WIDTH,
|
|
56
59
|
maxHeight: MAX_CALENDAR_HEIGHT,
|
|
57
60
|
// avoid padding increasing width over defined
|
|
58
61
|
boxSizing: 'border-box',
|
|
59
|
-
position: 'relative'
|
|
62
|
+
position: 'relative',
|
|
63
|
+
variants: [{
|
|
64
|
+
props: {
|
|
65
|
+
yearsPerRow: 3
|
|
66
|
+
},
|
|
67
|
+
style: {
|
|
68
|
+
columnGap: 24
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
props: {
|
|
72
|
+
yearsPerRow: 4
|
|
73
|
+
},
|
|
74
|
+
style: {
|
|
75
|
+
columnGap: 0,
|
|
76
|
+
padding: '0 2px'
|
|
77
|
+
}
|
|
78
|
+
}]
|
|
79
|
+
});
|
|
80
|
+
const YearCalendarButtonFiller = styled('div', {
|
|
81
|
+
name: 'MuiYearCalendar',
|
|
82
|
+
slot: 'ButtonFiller'
|
|
83
|
+
})({
|
|
84
|
+
height: 36,
|
|
85
|
+
width: 72
|
|
60
86
|
});
|
|
61
87
|
/**
|
|
62
88
|
* Demos:
|
|
@@ -87,7 +113,7 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
|
|
|
87
113
|
onYearFocus,
|
|
88
114
|
hasFocus,
|
|
89
115
|
onFocusedViewChange,
|
|
90
|
-
yearsOrder
|
|
116
|
+
yearsOrder,
|
|
91
117
|
yearsPerRow,
|
|
92
118
|
timezone: timezoneProp,
|
|
93
119
|
gridLabelId,
|
|
@@ -239,18 +265,23 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
|
|
|
239
265
|
if (yearsOrder === 'desc') {
|
|
240
266
|
yearRange.reverse();
|
|
241
267
|
}
|
|
242
|
-
|
|
268
|
+
let fillerAmount = yearsPerRow - yearRange.length % yearsPerRow;
|
|
269
|
+
if (fillerAmount === yearsPerRow) {
|
|
270
|
+
fillerAmount = 0;
|
|
271
|
+
}
|
|
272
|
+
return /*#__PURE__*/_jsxs(YearCalendarRoot, _extends({
|
|
243
273
|
ref: handleRef,
|
|
244
274
|
className: clsx(classes.root, className),
|
|
245
275
|
ownerState: ownerState,
|
|
246
276
|
role: "radiogroup",
|
|
247
|
-
"aria-labelledby": gridLabelId
|
|
277
|
+
"aria-labelledby": gridLabelId,
|
|
278
|
+
yearsPerRow: yearsPerRow
|
|
248
279
|
}, other, {
|
|
249
|
-
children: yearRange.map(year => {
|
|
280
|
+
children: [yearRange.map(year => {
|
|
250
281
|
const yearNumber = utils.getYear(year);
|
|
251
282
|
const isSelected = yearNumber === selectedYear;
|
|
252
283
|
const isDisabled = disabled || isYearDisabled(year);
|
|
253
|
-
return /*#__PURE__*/_jsx(
|
|
284
|
+
return /*#__PURE__*/_jsx(YearCalendarButton, {
|
|
254
285
|
selected: isSelected,
|
|
255
286
|
value: yearNumber,
|
|
256
287
|
onClick: handleYearSelection,
|
|
@@ -261,12 +292,14 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
|
|
|
261
292
|
onFocus: handleYearFocus,
|
|
262
293
|
onBlur: handleYearBlur,
|
|
263
294
|
"aria-current": todayYear === yearNumber ? 'date' : undefined,
|
|
264
|
-
yearsPerRow: yearsPerRow,
|
|
265
295
|
slots: slots,
|
|
266
296
|
slotProps: slotProps,
|
|
297
|
+
classes: classesProp,
|
|
267
298
|
children: utils.format(year, 'year')
|
|
268
299
|
}, utils.format(year, 'year'));
|
|
269
|
-
})
|
|
300
|
+
}), Array.from({
|
|
301
|
+
length: fillerAmount
|
|
302
|
+
}, (_, index) => /*#__PURE__*/_jsx(YearCalendarButtonFiller, {}, index))]
|
|
270
303
|
}));
|
|
271
304
|
});
|
|
272
305
|
process.env.NODE_ENV !== "production" ? YearCalendar.propTypes = {
|
|
@@ -1,47 +1,27 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["autoFocus", "
|
|
3
|
+
const _excluded = ["autoFocus", "classes", "disabled", "selected", "value", "onClick", "onKeyDown", "onFocus", "onBlur", "slots", "slotProps"];
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import
|
|
6
|
-
import { styled, alpha, useThemeProps } from '@mui/material/styles';
|
|
5
|
+
import { styled, alpha } from '@mui/material/styles';
|
|
7
6
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
8
7
|
import composeClasses from '@mui/utils/composeClasses';
|
|
9
8
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
10
|
-
import { getPickersYearUtilityClass, pickersYearClasses } from "./pickersYearClasses.js";
|
|
11
9
|
import { usePickerPrivateContext } from "../internals/hooks/usePickerPrivateContext.js";
|
|
10
|
+
import { getYearCalendarUtilityClass, yearCalendarClasses } from "./yearCalendarClasses.js";
|
|
12
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
12
|
const useUtilityClasses = (classes, ownerState) => {
|
|
14
13
|
const slots = {
|
|
15
|
-
|
|
16
|
-
yearButton: ['yearButton', ownerState.isYearDisabled && 'disabled', ownerState.isYearSelected && 'selected']
|
|
14
|
+
button: ['button', ownerState.isYearDisabled && 'disabled', ownerState.isYearSelected && 'selected']
|
|
17
15
|
};
|
|
18
|
-
return composeClasses(slots,
|
|
16
|
+
return composeClasses(slots, getYearCalendarUtilityClass, classes);
|
|
19
17
|
};
|
|
20
|
-
const
|
|
21
|
-
name: '
|
|
22
|
-
slot: '
|
|
23
|
-
overridesResolver: (_, styles) => [styles.
|
|
24
|
-
}
|
|
25
|
-
display: 'flex',
|
|
26
|
-
alignItems: 'center',
|
|
27
|
-
justifyContent: 'center',
|
|
28
|
-
flexBasis: '33.3%',
|
|
29
|
-
variants: [{
|
|
30
|
-
props: {
|
|
31
|
-
yearsPerRow: 4
|
|
32
|
-
},
|
|
33
|
-
style: {
|
|
34
|
-
flexBasis: '25%'
|
|
35
|
-
}
|
|
36
|
-
}]
|
|
37
|
-
});
|
|
38
|
-
const YearCalendarButton = styled('button', {
|
|
39
|
-
name: 'MuiPickersYear',
|
|
40
|
-
slot: 'YearButton',
|
|
41
|
-
overridesResolver: (_, styles) => [styles.yearButton, {
|
|
42
|
-
[`&.${pickersYearClasses.disabled}`]: styles.disabled
|
|
18
|
+
const DefaultYearButton = styled('button', {
|
|
19
|
+
name: 'MuiYearCalendar',
|
|
20
|
+
slot: 'Button',
|
|
21
|
+
overridesResolver: (_, styles) => [styles.button, {
|
|
22
|
+
[`&.${yearCalendarClasses.disabled}`]: styles.disabled
|
|
43
23
|
}, {
|
|
44
|
-
[`&.${
|
|
24
|
+
[`&.${yearCalendarClasses.selected}`]: styles.selected
|
|
45
25
|
}]
|
|
46
26
|
})(({
|
|
47
27
|
theme
|
|
@@ -51,7 +31,6 @@ const YearCalendarButton = styled('button', {
|
|
|
51
31
|
border: 0,
|
|
52
32
|
outline: 0
|
|
53
33
|
}, theme.typography.subtitle1, {
|
|
54
|
-
margin: '6px 0',
|
|
55
34
|
height: 36,
|
|
56
35
|
width: 72,
|
|
57
36
|
borderRadius: 18,
|
|
@@ -66,10 +45,10 @@ const YearCalendarButton = styled('button', {
|
|
|
66
45
|
cursor: 'auto',
|
|
67
46
|
pointerEvents: 'none'
|
|
68
47
|
},
|
|
69
|
-
[`&.${
|
|
48
|
+
[`&.${yearCalendarClasses.disabled}`]: {
|
|
70
49
|
color: (theme.vars || theme).palette.text.secondary
|
|
71
50
|
},
|
|
72
|
-
[`&.${
|
|
51
|
+
[`&.${yearCalendarClasses.selected}`]: {
|
|
73
52
|
color: (theme.vars || theme).palette.primary.contrastText,
|
|
74
53
|
backgroundColor: (theme.vars || theme).palette.primary.main,
|
|
75
54
|
'&:focus, &:hover': {
|
|
@@ -81,28 +60,17 @@ const YearCalendarButton = styled('button', {
|
|
|
81
60
|
/**
|
|
82
61
|
* @ignore - internal component.
|
|
83
62
|
*/
|
|
84
|
-
export const
|
|
85
|
-
const props = useThemeProps({
|
|
86
|
-
props: inProps,
|
|
87
|
-
name: 'MuiPickersYear'
|
|
88
|
-
});
|
|
63
|
+
export const YearCalendarButton = /*#__PURE__*/React.memo(function YearCalendarButton(props) {
|
|
89
64
|
const {
|
|
90
65
|
autoFocus,
|
|
91
|
-
className,
|
|
92
66
|
classes: classesProp,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
selected = false,
|
|
67
|
+
disabled,
|
|
68
|
+
selected,
|
|
96
69
|
value,
|
|
97
|
-
tabIndex,
|
|
98
70
|
onClick,
|
|
99
71
|
onKeyDown,
|
|
100
72
|
onFocus,
|
|
101
73
|
onBlur,
|
|
102
|
-
'aria-current': ariaCurrent
|
|
103
|
-
// We don't want to forward this prop to the root element
|
|
104
|
-
,
|
|
105
|
-
|
|
106
74
|
slots,
|
|
107
75
|
slotProps
|
|
108
76
|
} = props,
|
|
@@ -124,18 +92,16 @@ export const PickersYear = /*#__PURE__*/React.memo(function PickersYear(inProps)
|
|
|
124
92
|
ref.current?.focus();
|
|
125
93
|
}
|
|
126
94
|
}, [autoFocus]);
|
|
127
|
-
const YearButton = slots?.yearButton ??
|
|
95
|
+
const YearButton = slots?.yearButton ?? DefaultYearButton;
|
|
128
96
|
const yearButtonProps = useSlotProps({
|
|
129
97
|
elementType: YearButton,
|
|
130
98
|
externalSlotProps: slotProps?.yearButton,
|
|
99
|
+
externalForwardedProps: other,
|
|
131
100
|
additionalProps: {
|
|
132
|
-
children,
|
|
133
101
|
disabled,
|
|
134
|
-
tabIndex,
|
|
135
102
|
ref,
|
|
136
103
|
type: 'button',
|
|
137
104
|
role: 'radio',
|
|
138
|
-
'aria-current': ariaCurrent,
|
|
139
105
|
'aria-checked': selected,
|
|
140
106
|
onClick: event => onClick(event, value),
|
|
141
107
|
onKeyDown: event => onKeyDown(event, value),
|
|
@@ -143,12 +109,7 @@ export const PickersYear = /*#__PURE__*/React.memo(function PickersYear(inProps)
|
|
|
143
109
|
onBlur: event => onBlur(event, value)
|
|
144
110
|
},
|
|
145
111
|
ownerState,
|
|
146
|
-
className: classes.
|
|
112
|
+
className: classes.button
|
|
147
113
|
});
|
|
148
|
-
return /*#__PURE__*/_jsx(
|
|
149
|
-
className: clsx(classes.root, className),
|
|
150
|
-
ownerState: ownerState
|
|
151
|
-
}, other, {
|
|
152
|
-
children: /*#__PURE__*/_jsx(YearButton, _extends({}, yearButtonProps))
|
|
153
|
-
}));
|
|
114
|
+
return /*#__PURE__*/_jsx(YearButton, _extends({}, yearButtonProps));
|
|
154
115
|
});
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export { YearCalendar } from "./YearCalendar.js";
|
|
2
|
-
export { yearCalendarClasses, getYearCalendarUtilityClass } from "./yearCalendarClasses.js";
|
|
3
|
-
export { pickersYearClasses } from "./pickersYearClasses.js";
|
|
2
|
+
export { yearCalendarClasses, getYearCalendarUtilityClass } from "./yearCalendarClasses.js";
|
|
@@ -2,4 +2,4 @@ import { unstable_generateUtilityClass as generateUtilityClass, unstable_generat
|
|
|
2
2
|
export function getYearCalendarUtilityClass(slot) {
|
|
3
3
|
return generateUtilityClass('MuiYearCalendar', slot);
|
|
4
4
|
}
|
|
5
|
-
export const yearCalendarClasses = generateUtilityClasses('MuiYearCalendar', ['root']);
|
|
5
|
+
export const yearCalendarClasses = generateUtilityClasses('MuiYearCalendar', ['root', 'button', 'disabled', 'selected']);
|
package/modern/index.js
CHANGED
|
@@ -38,7 +38,7 @@ const PickersArrowSwitcherButton = styled(IconButton, {
|
|
|
38
38
|
})({
|
|
39
39
|
variants: [{
|
|
40
40
|
props: {
|
|
41
|
-
|
|
41
|
+
isButtonHidden: true
|
|
42
42
|
},
|
|
43
43
|
style: {
|
|
44
44
|
visibility: 'hidden'
|
|
@@ -109,7 +109,7 @@ export const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function Picke
|
|
|
109
109
|
onClick: previousProps.goTo
|
|
110
110
|
},
|
|
111
111
|
ownerState: _extends({}, ownerState, {
|
|
112
|
-
|
|
112
|
+
isButtonHidden: previousProps.isHidden ?? false
|
|
113
113
|
}),
|
|
114
114
|
className: clsx(classes.button, classes.previousIconButton)
|
|
115
115
|
});
|
|
@@ -126,7 +126,7 @@ export const PickersArrowSwitcher = /*#__PURE__*/React.forwardRef(function Picke
|
|
|
126
126
|
onClick: nextProps.goTo
|
|
127
127
|
},
|
|
128
128
|
ownerState: _extends({}, ownerState, {
|
|
129
|
-
|
|
129
|
+
isButtonHidden: nextProps.isHidden ?? false
|
|
130
130
|
}),
|
|
131
131
|
className: clsx(classes.button, classes.nextIconButton)
|
|
132
132
|
});
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
3
4
|
import { usePickerPrivateContext } from "./usePickerPrivateContext.js";
|
|
4
5
|
export function useFieldOwnerState(parameters) {
|
|
5
6
|
const {
|
|
6
7
|
ownerState: pickerOwnerState
|
|
7
8
|
} = usePickerPrivateContext();
|
|
9
|
+
const isRtl = useRtl();
|
|
8
10
|
return React.useMemo(() => _extends({}, pickerOwnerState, {
|
|
9
11
|
isFieldDisabled: parameters.disabled ?? false,
|
|
10
|
-
isFieldReadOnly: parameters.readOnly ?? false
|
|
11
|
-
|
|
12
|
+
isFieldReadOnly: parameters.readOnly ?? false,
|
|
13
|
+
isFieldRequired: parameters.required ?? false,
|
|
14
|
+
fieldDirection: isRtl ? 'rtl' : 'ltr'
|
|
15
|
+
}), [pickerOwnerState, parameters.disabled, parameters.readOnly, parameters.required, isRtl]);
|
|
12
16
|
}
|