@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 --------------------------------
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { FormControlProps } from '@mui/material/FormControl';
|
|
2
|
+
import { FormControlOwnProps, FormControlProps } from '@mui/material/FormControl';
|
|
3
3
|
import { FormHelperTextProps } from '@mui/material/FormHelperText';
|
|
4
4
|
import { InputLabelProps } from '@mui/material/InputLabel';
|
|
5
5
|
import { TextFieldVariants } from '@mui/material/TextField';
|
|
6
6
|
import { PickersInputPropsUsedByField } from './PickersInputBase/PickersInputBase.types';
|
|
7
|
-
import { PickersInputProps } from './PickersInput';
|
|
8
|
-
import { PickersOutlinedInputProps } from './PickersOutlinedInput';
|
|
9
|
-
import { PickersFilledInputProps } from './PickersFilledInput';
|
|
7
|
+
import type { PickersInputProps } from './PickersInput';
|
|
8
|
+
import type { PickersOutlinedInputProps } from './PickersOutlinedInput';
|
|
9
|
+
import type { PickersFilledInputProps } from './PickersFilledInput';
|
|
10
|
+
import { FieldOwnerState } from '../models';
|
|
10
11
|
interface PickersTextFieldPropsUsedByField {
|
|
11
12
|
onFocus: React.FocusEventHandler<HTMLDivElement>;
|
|
12
13
|
onBlur: React.FocusEventHandler<HTMLDivElement>;
|
|
@@ -64,4 +65,42 @@ export interface PickersFilledTextFieldProps extends PickersBaseTextFieldProps {
|
|
|
64
65
|
InputProps?: Partial<PickersFilledInputProps>;
|
|
65
66
|
}
|
|
66
67
|
export type PickersTextFieldProps<Variant extends TextFieldVariants = TextFieldVariants> = Variant extends 'filled' ? PickersFilledTextFieldProps : Variant extends 'standard' ? PickersStandardTextFieldProps : PickersOutlinedTextFieldProps;
|
|
68
|
+
export interface PickerTextFieldOwnerState extends FieldOwnerState {
|
|
69
|
+
/**
|
|
70
|
+
* `true` if the value of the field is currently empty.
|
|
71
|
+
*/
|
|
72
|
+
isFieldValueEmpty: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* `true` if the field is focused, `false` otherwise.
|
|
75
|
+
*/
|
|
76
|
+
isFieldFocused: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* `true` if the field has an error, `false` otherwise.
|
|
79
|
+
*/
|
|
80
|
+
hasFieldError: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The size of the input.
|
|
83
|
+
*/
|
|
84
|
+
inputSize: Exclude<FormControlOwnProps['size'], undefined>;
|
|
85
|
+
/**
|
|
86
|
+
* The color of the input.
|
|
87
|
+
*/
|
|
88
|
+
inputColor: Exclude<FormControlOwnProps['color'], undefined>;
|
|
89
|
+
/**
|
|
90
|
+
* `true` if the input takes up the full width of its container.
|
|
91
|
+
*/
|
|
92
|
+
isInputInFullWidth: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* `true` if the input has a start adornment, `false` otherwise.
|
|
95
|
+
*/
|
|
96
|
+
hasStartAdornment: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* `true` if the input has an end adornment, `false` otherwise.
|
|
99
|
+
*/
|
|
100
|
+
hasEndAdornment: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* `true` if the input has a label, `false` otherwise.
|
|
103
|
+
*/
|
|
104
|
+
inputHasLabel: boolean;
|
|
105
|
+
}
|
|
67
106
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PickerTextFieldOwnerState } from './PickersTextField.types';
|
|
3
|
+
export declare const PickerTextFieldOwnerStateContext: React.Context<PickerTextFieldOwnerState | null>;
|
|
4
|
+
export declare const usePickerTextFieldOwnerState: () => PickerTextFieldOwnerState;
|
|
@@ -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
|
+
};
|
package/TimeClock/Clock.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ export interface ClockProps extends ReturnType<typeof useMeridiemMode>, FormProp
|
|
|
26
26
|
* The current full date value.
|
|
27
27
|
*/
|
|
28
28
|
value: PickerValidDate | null;
|
|
29
|
+
/**
|
|
30
|
+
* Minimum and maximum value of the clock.
|
|
31
|
+
*/
|
|
32
|
+
viewRange: [number, number];
|
|
29
33
|
className?: string;
|
|
30
34
|
classes?: Partial<ClockClasses>;
|
|
31
35
|
}
|
package/TimeClock/Clock.js
CHANGED
|
@@ -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':
|
package/TimeClock/TimeClock.js
CHANGED
|
@@ -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 = {
|
|
@@ -6,7 +6,7 @@ import { YearCalendarClasses } from './yearCalendarClasses';
|
|
|
6
6
|
import { BaseDateValidationProps, YearValidationProps } from '../internals/models/validation';
|
|
7
7
|
import { PickerOwnerState, PickerValidDate, TimezoneProps } from '../models';
|
|
8
8
|
import { FormProps } from '../internals/models/formProps';
|
|
9
|
-
export interface
|
|
9
|
+
export interface YearButtonOwnerState extends PickerOwnerState {
|
|
10
10
|
isYearSelected: boolean;
|
|
11
11
|
isYearDisabled: boolean;
|
|
12
12
|
}
|
|
@@ -20,7 +20,7 @@ export interface YearCalendarSlots {
|
|
|
20
20
|
export interface YearCalendarSlotProps {
|
|
21
21
|
yearButton?: SlotComponentPropsFromProps<React.HTMLAttributes<HTMLButtonElement> & {
|
|
22
22
|
sx: SxProps;
|
|
23
|
-
}, {},
|
|
23
|
+
}, {}, YearButtonOwnerState>;
|
|
24
24
|
}
|
|
25
25
|
export interface ExportedYearCalendarProps {
|
|
26
26
|
/**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { YearCalendarSlotProps, YearCalendarSlots } from './YearCalendar.types';
|
|
3
|
+
import { YearCalendarClasses } from './yearCalendarClasses';
|
|
4
|
+
export interface YearCalendarButtonProps {
|
|
5
|
+
value: number;
|
|
6
|
+
tabIndex: number;
|
|
7
|
+
selected: boolean;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
autoFocus: boolean;
|
|
10
|
+
classes: Partial<YearCalendarClasses> | undefined;
|
|
11
|
+
slots: YearCalendarSlots | undefined;
|
|
12
|
+
slotProps: YearCalendarSlotProps | undefined;
|
|
13
|
+
'aria-current': React.AriaAttributes['aria-current'];
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
onClick: (event: React.MouseEvent, year: number) => void;
|
|
16
|
+
onKeyDown: (event: React.KeyboardEvent, year: number) => void;
|
|
17
|
+
onFocus: (event: React.FocusEvent, year: number) => void;
|
|
18
|
+
onBlur: (event: React.FocusEvent, year: number) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @ignore - internal component.
|
|
22
|
+
*/
|
|
23
|
+
export declare const YearCalendarButton: React.NamedExoticComponent<YearCalendarButtonProps>;
|