@mui/x-date-pickers 8.0.0-alpha.4 → 8.0.0-alpha.6
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 +182 -0
- package/DatePicker/DatePickerToolbar.d.ts +1 -2
- package/DatePicker/DatePickerToolbar.js +6 -17
- package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/DateTimePicker/DateTimePickerTabs.d.ts +2 -5
- package/DateTimePicker/DateTimePickerTabs.js +6 -13
- package/DateTimePicker/DateTimePickerToolbar.d.ts +8 -4
- package/DateTimePicker/DateTimePickerToolbar.js +13 -24
- package/DateTimePicker/shared.d.ts +2 -2
- package/DesktopDatePicker/DesktopDatePicker.types.d.ts +2 -3
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +2 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +1 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -11
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/MobileDatePicker/MobileDatePicker.types.d.ts +2 -3
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +4 -4
- package/MobileTimePicker/MobileTimePicker.types.d.ts +4 -4
- 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/PickersActionBar/PickersActionBar.d.ts +0 -4
- package/PickersActionBar/PickersActionBar.js +12 -13
- package/PickersLayout/PickersLayout.d.ts +2 -2
- package/PickersLayout/PickersLayout.js +1 -11
- package/PickersLayout/PickersLayout.types.d.ts +12 -14
- package/PickersLayout/usePickerLayout.d.ts +2 -2
- package/PickersLayout/usePickerLayout.js +3 -18
- 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/StaticDatePicker/StaticDatePicker.types.d.ts +2 -3
- package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +2 -2
- package/StaticTimePicker/StaticTimePicker.types.d.ts +2 -2
- package/TimeClock/Clock.d.ts +4 -0
- package/TimeClock/Clock.js +9 -6
- package/TimeClock/TimeClock.js +21 -4
- package/TimePicker/TimePicker.types.d.ts +2 -2
- package/TimePicker/TimePickerToolbar.d.ts +2 -2
- package/TimePicker/TimePickerToolbar.js +6 -20
- 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/hooks/index.d.ts +1 -0
- package/hooks/index.js +2 -1
- package/hooks/usePickerActionsContext.d.ts +5 -0
- package/hooks/usePickerActionsContext.js +16 -0
- package/hooks/usePickerContext.d.ts +3 -1
- package/hooks/usePickerContext.js +0 -1
- package/index.js +1 -1
- package/internals/components/PickerProvider.d.ts +11 -6
- package/internals/components/PickerProvider.js +12 -6
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +3 -3
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.types.d.ts +1 -1
- package/internals/components/PickersModalDialog.d.ts +1 -3
- package/internals/components/PickersModalDialog.js +9 -3
- package/internals/components/PickersPopper.d.ts +1 -3
- package/internals/components/PickersPopper.js +11 -6
- package/internals/components/PickersToolbar.d.ts +3 -3
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -9
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +5 -5
- package/internals/hooks/useFieldOwnerState.d.ts +1 -0
- package/internals/hooks/useFieldOwnerState.js +6 -2
- package/internals/hooks/useMobilePicker/useMobilePicker.js +8 -7
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +5 -5
- package/internals/hooks/usePicker/usePicker.js +1 -3
- package/internals/hooks/usePicker/usePicker.types.d.ts +2 -2
- package/internals/hooks/usePicker/usePickerProvider.js +5 -4
- package/internals/hooks/usePicker/usePickerValue.js +46 -64
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +38 -17
- package/internals/hooks/usePicker/usePickerViews.d.ts +15 -4
- package/internals/hooks/usePicker/usePickerViews.js +9 -7
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +4 -4
- package/internals/index.d.ts +4 -4
- package/internals/index.js +1 -1
- package/internals/models/props/tabs.d.ts +0 -13
- package/internals/models/props/toolbar.d.ts +1 -16
- package/models/fields.d.ts +11 -1
- package/modern/DatePicker/DatePickerToolbar.js +6 -17
- package/modern/DateTimePicker/DateTimePickerTabs.js +6 -13
- package/modern/DateTimePicker/DateTimePickerToolbar.js +13 -24
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -11
- 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/PickersActionBar/PickersActionBar.js +12 -13
- package/modern/PickersLayout/PickersLayout.js +1 -11
- package/modern/PickersLayout/usePickerLayout.js +3 -18
- 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/TimePicker/TimePickerToolbar.js +6 -20
- 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/hooks/index.js +2 -1
- package/modern/hooks/usePickerActionsContext.js +16 -0
- package/modern/hooks/usePickerContext.js +0 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerProvider.js +12 -6
- package/modern/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +3 -3
- package/modern/internals/components/PickersModalDialog.js +9 -3
- package/modern/internals/components/PickersPopper.js +11 -6
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -9
- package/modern/internals/hooks/useFieldOwnerState.js +6 -2
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +8 -7
- package/modern/internals/hooks/usePicker/usePicker.js +1 -3
- package/modern/internals/hooks/usePicker/usePickerProvider.js +5 -4
- package/modern/internals/hooks/usePicker/usePickerValue.js +46 -64
- package/modern/internals/hooks/usePicker/usePickerViews.js +9 -7
- package/modern/internals/index.js +1 -1
- package/node/DatePicker/DatePickerToolbar.js +6 -17
- package/node/DateTimePicker/DateTimePickerTabs.js +6 -13
- package/node/DateTimePicker/DateTimePickerToolbar.js +14 -25
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -11
- 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/PickersActionBar/PickersActionBar.js +12 -13
- package/node/PickersLayout/PickersLayout.js +1 -11
- package/node/PickersLayout/usePickerLayout.js +3 -18
- 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/TimePicker/TimePickerToolbar.js +6 -20
- 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/hooks/index.js +8 -1
- package/node/hooks/usePickerActionsContext.js +22 -0
- package/node/index.js +1 -1
- package/node/internals/components/PickerProvider.js +13 -7
- package/node/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +3 -3
- package/node/internals/components/PickersModalDialog.js +9 -3
- package/node/internals/components/PickersPopper.js +11 -6
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -9
- package/node/internals/hooks/useFieldOwnerState.js +6 -2
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +8 -7
- package/node/internals/hooks/usePicker/usePicker.js +1 -3
- package/node/internals/hooks/usePicker/usePickerProvider.js +5 -4
- package/node/internals/hooks/usePicker/usePickerValue.js +46 -64
- package/node/internals/hooks/usePicker/usePickerViews.js +9 -7
- package/node/internals/index.js +2 -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 +4 -7
- 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
|
@@ -14,6 +14,7 @@ import { getPickersPopperUtilityClass } from "./pickersPopperClasses.js";
|
|
|
14
14
|
import { getActiveElement } from "../utils/utils.js";
|
|
15
15
|
import { useDefaultReduceAnimations } from "../hooks/useDefaultReduceAnimations.js";
|
|
16
16
|
import { usePickerPrivateContext } from "../hooks/usePickerPrivateContext.js";
|
|
17
|
+
import { usePickerContext } from "../../hooks/index.js";
|
|
17
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
19
|
const useUtilityClasses = classes => {
|
|
19
20
|
const slots = {
|
|
@@ -210,8 +211,6 @@ export function PickersPopper(inProps) {
|
|
|
210
211
|
containerRef = null,
|
|
211
212
|
shouldRestoreFocus,
|
|
212
213
|
onBlur,
|
|
213
|
-
onDismiss,
|
|
214
|
-
open,
|
|
215
214
|
role,
|
|
216
215
|
placement = 'bottom',
|
|
217
216
|
slots,
|
|
@@ -219,17 +218,23 @@ export function PickersPopper(inProps) {
|
|
|
219
218
|
reduceAnimations: inReduceAnimations,
|
|
220
219
|
classes: classesProp
|
|
221
220
|
} = props;
|
|
221
|
+
const {
|
|
222
|
+
open
|
|
223
|
+
} = usePickerContext();
|
|
224
|
+
const {
|
|
225
|
+
dismissViews
|
|
226
|
+
} = usePickerPrivateContext();
|
|
222
227
|
React.useEffect(() => {
|
|
223
228
|
function handleKeyDown(nativeEvent) {
|
|
224
229
|
if (open && nativeEvent.key === 'Escape') {
|
|
225
|
-
|
|
230
|
+
dismissViews();
|
|
226
231
|
}
|
|
227
232
|
}
|
|
228
233
|
document.addEventListener('keydown', handleKeyDown);
|
|
229
234
|
return () => {
|
|
230
235
|
document.removeEventListener('keydown', handleKeyDown);
|
|
231
236
|
};
|
|
232
|
-
}, [
|
|
237
|
+
}, [dismissViews, open]);
|
|
233
238
|
const lastFocusedElementRef = React.useRef(null);
|
|
234
239
|
React.useEffect(() => {
|
|
235
240
|
if (role === 'tooltip' || shouldRestoreFocus && !shouldRestoreFocus()) {
|
|
@@ -247,7 +252,7 @@ export function PickersPopper(inProps) {
|
|
|
247
252
|
});
|
|
248
253
|
}
|
|
249
254
|
}, [open, role, shouldRestoreFocus]);
|
|
250
|
-
const [clickAwayRef, onPaperClick, onPaperTouchStart] = useClickAwayListener(open, onBlur ??
|
|
255
|
+
const [clickAwayRef, onPaperClick, onPaperTouchStart] = useClickAwayListener(open, onBlur ?? dismissViews);
|
|
251
256
|
const paperRef = React.useRef(null);
|
|
252
257
|
const handleRef = useForkRef(paperRef, containerRef);
|
|
253
258
|
const handlePaperRef = useForkRef(handleRef, clickAwayRef);
|
|
@@ -264,7 +269,7 @@ export function PickersPopper(inProps) {
|
|
|
264
269
|
if (event.key === 'Escape') {
|
|
265
270
|
// stop the propagation to avoid closing parent modal
|
|
266
271
|
event.stopPropagation();
|
|
267
|
-
|
|
272
|
+
dismissViews();
|
|
268
273
|
}
|
|
269
274
|
};
|
|
270
275
|
const Transition = slots?.desktopTransition ?? reduceAnimations ? Fade : Grow;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { BaseToolbarProps } from '../models/props/toolbar';
|
|
3
3
|
import { PickersToolbarClasses } from './pickersToolbarClasses';
|
|
4
|
-
import {
|
|
5
|
-
export interface PickersToolbarProps<TValue extends PickerValidValue
|
|
4
|
+
import { PickerValidValue } from '../models';
|
|
5
|
+
export interface PickersToolbarProps<TValue extends PickerValidValue> extends Pick<BaseToolbarProps<TValue>, 'isLandscape' | 'hidden' | 'titleId'> {
|
|
6
6
|
className?: string;
|
|
7
7
|
landscapeDirection?: 'row' | 'column';
|
|
8
8
|
toolbarTitle: React.ReactNode;
|
|
9
9
|
classes?: Partial<PickersToolbarClasses>;
|
|
10
10
|
}
|
|
11
|
-
type PickersToolbarComponent = (<TValue extends PickerValidValue
|
|
11
|
+
type PickersToolbarComponent = (<TValue extends PickerValidValue>(props: React.PropsWithChildren<PickersToolbarProps<TValue>> & React.RefAttributes<HTMLDivElement>) => React.JSX.Element) & {
|
|
12
12
|
propTypes?: any;
|
|
13
13
|
};
|
|
14
14
|
export declare const PickersToolbar: PickersToolbarComponent;
|
|
@@ -52,8 +52,6 @@ export const useDesktopPicker = _ref => {
|
|
|
52
52
|
const labelId = useId();
|
|
53
53
|
const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
|
|
54
54
|
const {
|
|
55
|
-
open,
|
|
56
|
-
actions,
|
|
57
55
|
hasUIView,
|
|
58
56
|
layoutProps,
|
|
59
57
|
providerProps,
|
|
@@ -85,7 +83,11 @@ export const useDesktopPicker = _ref => {
|
|
|
85
83
|
externalSlotProps: innerSlotProps?.openPickerButton,
|
|
86
84
|
additionalProps: {
|
|
87
85
|
disabled: disabled || readOnly,
|
|
88
|
-
|
|
86
|
+
// This direct access to `providerProps` will go away in https://github.com/mui/mui-x/pull/15671
|
|
87
|
+
onClick: event => {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
providerProps.contextValue.setOpen(prevOpen => !prevOpen);
|
|
90
|
+
},
|
|
89
91
|
'aria-label': getOpenDialogAriaText(pickerFieldProps.value),
|
|
90
92
|
edge: inputAdornmentProps.position
|
|
91
93
|
},
|
|
@@ -121,7 +123,7 @@ export const useDesktopPicker = _ref => {
|
|
|
121
123
|
sx,
|
|
122
124
|
label,
|
|
123
125
|
name,
|
|
124
|
-
focused: open ? true : undefined
|
|
126
|
+
focused: providerProps.contextValue.open ? true : undefined
|
|
125
127
|
}, isToolbarHidden && {
|
|
126
128
|
id: labelId
|
|
127
129
|
}, !!inputRef && {
|
|
@@ -170,12 +172,10 @@ export const useDesktopPicker = _ref => {
|
|
|
170
172
|
slots: slotsForField,
|
|
171
173
|
slotProps: slotProps,
|
|
172
174
|
unstableFieldRef: handleFieldRef
|
|
173
|
-
})), /*#__PURE__*/_jsx(PickersPopper,
|
|
175
|
+
})), /*#__PURE__*/_jsx(PickersPopper, {
|
|
174
176
|
role: "dialog",
|
|
175
177
|
placement: "bottom-start",
|
|
176
|
-
anchorEl: containerRef.current
|
|
177
|
-
}, actions, {
|
|
178
|
-
open: open,
|
|
178
|
+
anchorEl: containerRef.current,
|
|
179
179
|
slots: slots,
|
|
180
180
|
slotProps: slotProps,
|
|
181
181
|
shouldRestoreFocus: shouldRestoreFocus,
|
|
@@ -185,7 +185,7 @@ export const useDesktopPicker = _ref => {
|
|
|
185
185
|
slotProps: slotProps,
|
|
186
186
|
children: renderCurrentView()
|
|
187
187
|
}))
|
|
188
|
-
})
|
|
188
|
+
})]
|
|
189
189
|
}));
|
|
190
190
|
return {
|
|
191
191
|
renderPicker
|
|
@@ -14,7 +14,7 @@ import { DateOrTimeViewWithMeridiem, PickerValue } from '../../models';
|
|
|
14
14
|
import { UseClearableFieldSlots, UseClearableFieldSlotProps } from '../../../hooks/useClearableField';
|
|
15
15
|
import { PickersTextFieldProps } from '../../../PickersTextField';
|
|
16
16
|
import { UsePickerProviderNonStaticProps } from '../usePicker/usePickerProvider';
|
|
17
|
-
export interface UseDesktopPickerSlots
|
|
17
|
+
export interface UseDesktopPickerSlots extends Pick<PickersPopperSlots, 'desktopPaper' | 'desktopTransition' | 'desktopTrapFocus' | 'popper'>, ExportedPickersLayoutSlots<PickerValue>, UseClearableFieldSlots {
|
|
18
18
|
/**
|
|
19
19
|
* Component used to enter the date with the keyboard.
|
|
20
20
|
*/
|
|
@@ -39,9 +39,9 @@ export interface UseDesktopPickerSlots<TView extends DateOrTimeViewWithMeridiem>
|
|
|
39
39
|
*/
|
|
40
40
|
openPickerIcon: React.ElementType;
|
|
41
41
|
}
|
|
42
|
-
export interface UseDesktopPickerSlotProps<
|
|
42
|
+
export interface UseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<PickerValue>, 'toolbar'> {
|
|
43
43
|
}
|
|
44
|
-
export interface ExportedUseDesktopPickerSlotProps<
|
|
44
|
+
export interface ExportedUseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends PickersPopperSlotProps, ExportedPickersLayoutSlotProps<PickerValue>, UseClearableFieldSlotProps {
|
|
45
45
|
field?: SlotComponentPropsFromProps<PickerFieldSlotProps<PickerValue, TEnableAccessibleFieldDOMStructure>, {}, PickerOwnerState>;
|
|
46
46
|
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState>;
|
|
47
47
|
inputAdornment?: SlotComponentPropsFromProps<InputAdornmentProps, {}, PickerOwnerState>;
|
|
@@ -60,12 +60,12 @@ export interface UseDesktopPickerProps<TView extends DateOrTimeViewWithMeridiem,
|
|
|
60
60
|
* Overridable component slots.
|
|
61
61
|
* @default {}
|
|
62
62
|
*/
|
|
63
|
-
slots: UseDesktopPickerSlots
|
|
63
|
+
slots: UseDesktopPickerSlots;
|
|
64
64
|
/**
|
|
65
65
|
* The props used for each component slot.
|
|
66
66
|
* @default {}
|
|
67
67
|
*/
|
|
68
|
-
slotProps?: UseDesktopPickerSlotProps<
|
|
68
|
+
slotProps?: UseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure>;
|
|
69
69
|
}
|
|
70
70
|
export interface UseDesktopPickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseDesktopPickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParams<PickerValue, TView, TExternalProps, {}>, 'valueManager' | 'valueType' | 'validator' | 'rendererInterceptor'> {
|
|
71
71
|
props: TExternalProps;
|
|
@@ -2,5 +2,6 @@ import { FieldOwnerState } from '../../models';
|
|
|
2
2
|
import { FormProps } from '../models';
|
|
3
3
|
export declare function useFieldOwnerState(parameters: UseFieldOwnerStateParameters): FieldOwnerState;
|
|
4
4
|
interface UseFieldOwnerStateParameters extends FormProps {
|
|
5
|
+
required?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export {};
|
|
@@ -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
|
}
|
|
@@ -46,8 +46,6 @@ export const useMobilePicker = _ref => {
|
|
|
46
46
|
const labelId = useId();
|
|
47
47
|
const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
|
|
48
48
|
const {
|
|
49
|
-
open,
|
|
50
|
-
actions,
|
|
51
49
|
layoutProps,
|
|
52
50
|
providerProps,
|
|
53
51
|
renderCurrentView,
|
|
@@ -86,8 +84,12 @@ export const useMobilePicker = _ref => {
|
|
|
86
84
|
}, isToolbarHidden && {
|
|
87
85
|
id: labelId
|
|
88
86
|
}, !(disabled || readOnly) && {
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
// These direct access to `providerProps` will go away in https://github.com/mui/mui-x/pull/15671
|
|
88
|
+
onClick: event => {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
providerProps.contextValue.setOpen(true);
|
|
91
|
+
},
|
|
92
|
+
onKeyDown: onSpaceOrEnter(() => providerProps.contextValue.setOpen(true))
|
|
91
93
|
}, !!inputRef && {
|
|
92
94
|
inputRef
|
|
93
95
|
}),
|
|
@@ -124,8 +126,7 @@ export const useMobilePicker = _ref => {
|
|
|
124
126
|
slots: slotsForField,
|
|
125
127
|
slotProps: slotProps,
|
|
126
128
|
unstableFieldRef: handleFieldRef
|
|
127
|
-
})), /*#__PURE__*/_jsx(PickersModalDialog,
|
|
128
|
-
open: open,
|
|
129
|
+
})), /*#__PURE__*/_jsx(PickersModalDialog, {
|
|
129
130
|
slots: slots,
|
|
130
131
|
slotProps: slotProps,
|
|
131
132
|
children: /*#__PURE__*/_jsx(Layout, _extends({}, layoutProps, slotProps?.layout, {
|
|
@@ -133,7 +134,7 @@ export const useMobilePicker = _ref => {
|
|
|
133
134
|
slotProps: slotProps,
|
|
134
135
|
children: renderCurrentView()
|
|
135
136
|
}))
|
|
136
|
-
})
|
|
137
|
+
})]
|
|
137
138
|
}));
|
|
138
139
|
return {
|
|
139
140
|
renderPicker
|
|
@@ -11,7 +11,7 @@ import { UsePickerViewsProps } from '../usePicker/usePickerViews';
|
|
|
11
11
|
import { DateOrTimeViewWithMeridiem, PickerValue } from '../../models';
|
|
12
12
|
import { PickersTextFieldProps } from '../../../PickersTextField';
|
|
13
13
|
import { UsePickerProviderNonStaticProps } from '../usePicker/usePickerProvider';
|
|
14
|
-
export interface UseMobilePickerSlots
|
|
14
|
+
export interface UseMobilePickerSlots extends PickersModalDialogSlots, ExportedPickersLayoutSlots<PickerValue> {
|
|
15
15
|
/**
|
|
16
16
|
* Component used to enter the date with the keyboard.
|
|
17
17
|
*/
|
|
@@ -22,11 +22,11 @@ export interface UseMobilePickerSlots<TView extends DateOrTimeViewWithMeridiem>
|
|
|
22
22
|
*/
|
|
23
23
|
textField?: React.ElementType;
|
|
24
24
|
}
|
|
25
|
-
export interface ExportedUseMobilePickerSlotProps<
|
|
25
|
+
export interface ExportedUseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends PickersModalDialogSlotProps, ExportedPickersLayoutSlotProps<PickerValue> {
|
|
26
26
|
field?: SlotComponentPropsFromProps<PickerFieldSlotProps<PickerValue, TEnableAccessibleFieldDOMStructure>, {}, PickerOwnerState>;
|
|
27
27
|
textField?: SlotComponentPropsFromProps<PickersTextFieldProps | TextFieldProps, {}, FieldOwnerState>;
|
|
28
28
|
}
|
|
29
|
-
export interface UseMobilePickerSlotProps<
|
|
29
|
+
export interface UseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<PickerValue>, 'toolbar'> {
|
|
30
30
|
}
|
|
31
31
|
export interface MobileOnlyPickerProps extends BaseNonStaticPickerProps, BaseNonRangeNonStaticPickerProps, UsePickerValueNonStaticProps, UsePickerProviderNonStaticProps {
|
|
32
32
|
}
|
|
@@ -35,12 +35,12 @@ export interface UseMobilePickerProps<TView extends DateOrTimeViewWithMeridiem,
|
|
|
35
35
|
* Overridable component slots.
|
|
36
36
|
* @default {}
|
|
37
37
|
*/
|
|
38
|
-
slots: UseMobilePickerSlots
|
|
38
|
+
slots: UseMobilePickerSlots;
|
|
39
39
|
/**
|
|
40
40
|
* The props used for each component slot.
|
|
41
41
|
* @default {}
|
|
42
42
|
*/
|
|
43
|
-
slotProps?: UseMobilePickerSlotProps<
|
|
43
|
+
slotProps?: UseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure>;
|
|
44
44
|
}
|
|
45
45
|
export interface UseMobilePickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseMobilePickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParams<PickerValue, TView, TExternalProps, {}>, 'valueManager' | 'valueType' | 'validator'> {
|
|
46
46
|
props: TExternalProps;
|
|
@@ -45,15 +45,13 @@ export const usePicker = ({
|
|
|
45
45
|
});
|
|
46
46
|
return {
|
|
47
47
|
// Picker value
|
|
48
|
-
open: pickerValueResponse.open,
|
|
49
|
-
actions: pickerValueResponse.actions,
|
|
50
48
|
fieldProps: pickerValueResponse.fieldProps,
|
|
51
49
|
// Picker views
|
|
52
50
|
renderCurrentView: pickerViewsResponse.renderCurrentView,
|
|
53
51
|
hasUIView: pickerViewsResponse.provider.hasUIView,
|
|
54
52
|
shouldRestoreFocus: pickerViewsResponse.shouldRestoreFocus,
|
|
55
53
|
// Picker layout
|
|
56
|
-
layoutProps: _extends({},
|
|
54
|
+
layoutProps: _extends({}, pickerValueResponse.layoutProps),
|
|
57
55
|
// Picker provider
|
|
58
56
|
providerProps,
|
|
59
57
|
// Picker owner state
|
|
@@ -13,9 +13,9 @@ export interface UsePickerProps<TValue extends PickerValidValue, TView extends D
|
|
|
13
13
|
export interface UsePickerParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any, any>, TAdditionalProps extends {}> extends Pick<UsePickerValueParams<TValue, TExternalProps>, 'valueManager' | 'valueType' | 'variant' | 'validator'>, Pick<UsePickerViewParams<TValue, TView, TExternalProps, TAdditionalProps>, 'additionalViewProps' | 'autoFocusView' | 'rendererInterceptor' | 'fieldRef'>, Pick<UsePickerProviderParameters<TValue, TView>, 'localeText'> {
|
|
14
14
|
props: TExternalProps;
|
|
15
15
|
}
|
|
16
|
-
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<UsePickerValueResponse<TValue, TError>, '
|
|
16
|
+
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<UsePickerValueResponse<TValue, TError>, 'fieldProps'>, Pick<UsePickerViewsResponse<TView>, 'shouldRestoreFocus' | 'renderCurrentView'> {
|
|
17
17
|
ownerState: PickerOwnerState;
|
|
18
18
|
providerProps: UsePickerProviderReturnValue;
|
|
19
|
-
layoutProps: UsePickerValueResponse<TValue, TError>['layoutProps']
|
|
19
|
+
layoutProps: UsePickerValueResponse<TValue, TError>['layoutProps'];
|
|
20
20
|
hasUIView: boolean;
|
|
21
21
|
}
|
|
@@ -53,18 +53,19 @@ export function usePickerProvider(parameters) {
|
|
|
53
53
|
pickerOrientation: orientation,
|
|
54
54
|
pickerVariant: variant
|
|
55
55
|
}), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
|
|
56
|
-
const contextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.contextValue, {
|
|
56
|
+
const contextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, {
|
|
57
57
|
disabled: props.disabled ?? false,
|
|
58
58
|
readOnly: props.readOnly ?? false,
|
|
59
59
|
variant,
|
|
60
60
|
orientation
|
|
61
|
-
}), [paramsFromUsePickerValue.contextValue, variant, orientation, props.disabled, props.readOnly]);
|
|
62
|
-
const privateContextValue = React.useMemo(() => ({
|
|
61
|
+
}), [paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, variant, orientation, props.disabled, props.readOnly]);
|
|
62
|
+
const privateContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.privateContextValue, {
|
|
63
63
|
ownerState
|
|
64
|
-
}), [ownerState]);
|
|
64
|
+
}), [paramsFromUsePickerValue, ownerState]);
|
|
65
65
|
return {
|
|
66
66
|
localeText,
|
|
67
67
|
contextValue,
|
|
68
|
+
actionsContextValue: paramsFromUsePickerValue.actionsContextValue,
|
|
68
69
|
privateContextValue
|
|
69
70
|
};
|
|
70
71
|
}
|
|
@@ -251,49 +251,6 @@ export const usePickerValue = ({
|
|
|
251
251
|
hasBeenModifiedSinceMount: true
|
|
252
252
|
}));
|
|
253
253
|
}
|
|
254
|
-
const handleClear = useEventCallback(() => {
|
|
255
|
-
updateDate({
|
|
256
|
-
value: valueManager.emptyValue,
|
|
257
|
-
name: 'setValueFromAction',
|
|
258
|
-
pickerAction: 'clear'
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
const handleAccept = useEventCallback(() => {
|
|
262
|
-
updateDate({
|
|
263
|
-
value: dateState.lastPublishedValue,
|
|
264
|
-
name: 'setValueFromAction',
|
|
265
|
-
pickerAction: 'accept'
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
const handleDismiss = useEventCallback(() => {
|
|
269
|
-
updateDate({
|
|
270
|
-
value: dateState.lastPublishedValue,
|
|
271
|
-
name: 'setValueFromAction',
|
|
272
|
-
pickerAction: 'dismiss'
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
const handleCancel = useEventCallback(() => {
|
|
276
|
-
updateDate({
|
|
277
|
-
value: dateState.lastCommittedValue,
|
|
278
|
-
name: 'setValueFromAction',
|
|
279
|
-
pickerAction: 'cancel'
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
const handleSetToday = useEventCallback(() => {
|
|
283
|
-
updateDate({
|
|
284
|
-
value: valueManager.getTodayValue(utils, timezone, valueType),
|
|
285
|
-
name: 'setValueFromAction',
|
|
286
|
-
pickerAction: 'today'
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
const handleOpen = useEventCallback(event => {
|
|
290
|
-
event.preventDefault();
|
|
291
|
-
setOpen(true);
|
|
292
|
-
});
|
|
293
|
-
const handleClose = useEventCallback(event => {
|
|
294
|
-
event?.preventDefault();
|
|
295
|
-
setOpen(false);
|
|
296
|
-
});
|
|
297
254
|
const handleChange = useEventCallback((newValue, selectionState = 'partial') => updateDate({
|
|
298
255
|
name: 'setValueFromView',
|
|
299
256
|
value: newValue,
|
|
@@ -310,15 +267,6 @@ export const usePickerValue = ({
|
|
|
310
267
|
value: newValue,
|
|
311
268
|
context
|
|
312
269
|
}));
|
|
313
|
-
const actions = {
|
|
314
|
-
onClear: handleClear,
|
|
315
|
-
onAccept: handleAccept,
|
|
316
|
-
onDismiss: handleDismiss,
|
|
317
|
-
onCancel: handleCancel,
|
|
318
|
-
onSetToday: handleSetToday,
|
|
319
|
-
onOpen: handleOpen,
|
|
320
|
-
onClose: handleClose
|
|
321
|
-
};
|
|
322
270
|
const fieldResponse = {
|
|
323
271
|
value: dateState.draft,
|
|
324
272
|
onChange: handleChangeFromField
|
|
@@ -327,8 +275,8 @@ export const usePickerValue = ({
|
|
|
327
275
|
const viewResponse = {
|
|
328
276
|
value: valueWithoutError,
|
|
329
277
|
onChange: handleChange,
|
|
330
|
-
|
|
331
|
-
|
|
278
|
+
open,
|
|
279
|
+
setOpen
|
|
332
280
|
};
|
|
333
281
|
const isValid = testedValue => {
|
|
334
282
|
const error = validator({
|
|
@@ -339,28 +287,62 @@ export const usePickerValue = ({
|
|
|
339
287
|
});
|
|
340
288
|
return !valueManager.hasError(error);
|
|
341
289
|
};
|
|
342
|
-
const layoutResponse =
|
|
290
|
+
const layoutResponse = {
|
|
343
291
|
value: valueWithoutError,
|
|
344
292
|
onChange: handleChange,
|
|
345
293
|
onSelectShortcut: handleSelectShortcut,
|
|
346
294
|
isValid
|
|
295
|
+
};
|
|
296
|
+
const clearValue = useEventCallback(() => updateDate({
|
|
297
|
+
value: valueManager.emptyValue,
|
|
298
|
+
name: 'setValueFromAction',
|
|
299
|
+
pickerAction: 'clear'
|
|
300
|
+
}));
|
|
301
|
+
const setValueToToday = useEventCallback(() => updateDate({
|
|
302
|
+
value: valueManager.getTodayValue(utils, timezone, valueType),
|
|
303
|
+
name: 'setValueFromAction',
|
|
304
|
+
pickerAction: 'today'
|
|
305
|
+
}));
|
|
306
|
+
const acceptValueChanges = useEventCallback(() => updateDate({
|
|
307
|
+
value: dateState.lastPublishedValue,
|
|
308
|
+
name: 'setValueFromAction',
|
|
309
|
+
pickerAction: 'accept'
|
|
310
|
+
}));
|
|
311
|
+
const cancelValueChanges = useEventCallback(() => updateDate({
|
|
312
|
+
value: dateState.lastCommittedValue,
|
|
313
|
+
name: 'setValueFromAction',
|
|
314
|
+
pickerAction: 'cancel'
|
|
315
|
+
}));
|
|
316
|
+
const dismissViews = useEventCallback(() => {
|
|
317
|
+
updateDate({
|
|
318
|
+
value: dateState.lastPublishedValue,
|
|
319
|
+
name: 'setValueFromAction',
|
|
320
|
+
pickerAction: 'dismiss'
|
|
321
|
+
});
|
|
347
322
|
});
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
323
|
+
const actionsContextValue = React.useMemo(() => ({
|
|
324
|
+
setOpen,
|
|
325
|
+
clearValue,
|
|
326
|
+
setValueToToday,
|
|
327
|
+
acceptValueChanges,
|
|
328
|
+
cancelValueChanges
|
|
329
|
+
}), [setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
330
|
+
const contextValue = React.useMemo(() => _extends({}, actionsContextValue, {
|
|
331
|
+
open
|
|
332
|
+
}), [actionsContextValue, open]);
|
|
333
|
+
const privateContextValue = React.useMemo(() => ({
|
|
334
|
+
dismissViews
|
|
335
|
+
}), [dismissViews]);
|
|
354
336
|
const providerParams = {
|
|
355
337
|
value: valueWithoutError,
|
|
356
|
-
contextValue
|
|
338
|
+
contextValue,
|
|
339
|
+
actionsContextValue,
|
|
340
|
+
privateContextValue
|
|
357
341
|
};
|
|
358
342
|
return {
|
|
359
|
-
open,
|
|
360
343
|
fieldProps: fieldResponse,
|
|
361
344
|
viewProps: viewResponse,
|
|
362
345
|
layoutProps: layoutResponse,
|
|
363
|
-
actions,
|
|
364
346
|
provider: providerParams
|
|
365
347
|
};
|
|
366
348
|
};
|
|
@@ -237,15 +237,6 @@ export interface UsePickerValueParams<TValue extends PickerValidValue, TExternal
|
|
|
237
237
|
variant: PickerVariant;
|
|
238
238
|
validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
|
|
239
239
|
}
|
|
240
|
-
export interface UsePickerValueActions {
|
|
241
|
-
onAccept: () => void;
|
|
242
|
-
onClear: () => void;
|
|
243
|
-
onDismiss: () => void;
|
|
244
|
-
onCancel: () => void;
|
|
245
|
-
onSetToday: () => void;
|
|
246
|
-
onOpen: (event: React.UIEvent) => void;
|
|
247
|
-
onClose: (event?: React.UIEvent) => void;
|
|
248
|
-
}
|
|
249
240
|
export type UsePickerValueFieldResponse<TValue extends PickerValidValue, TError> = Required<Pick<UseFieldInternalProps<TValue, any, TError>, 'value' | 'onChange'>>;
|
|
250
241
|
/**
|
|
251
242
|
* Props passed to `usePickerViews`.
|
|
@@ -254,12 +245,12 @@ export interface UsePickerValueViewsResponse<TValue extends PickerValidValue> {
|
|
|
254
245
|
value: TValue;
|
|
255
246
|
onChange: (value: TValue, selectionState?: PickerSelectionState) => void;
|
|
256
247
|
open: boolean;
|
|
257
|
-
|
|
248
|
+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
258
249
|
}
|
|
259
250
|
/**
|
|
260
251
|
* Props passed to `usePickerLayoutProps`.
|
|
261
252
|
*/
|
|
262
|
-
export interface UsePickerValueLayoutResponse<TValue extends PickerValidValue>
|
|
253
|
+
export interface UsePickerValueLayoutResponse<TValue extends PickerValidValue> {
|
|
263
254
|
value: TValue;
|
|
264
255
|
onChange: (newValue: TValue) => void;
|
|
265
256
|
onSelectShortcut: (newValue: TValue, changeImportance: PickerShortcutChangeImportance, shortcut: PickersShortcutsItemContext) => void;
|
|
@@ -271,18 +262,24 @@ export interface UsePickerValueLayoutResponse<TValue extends PickerValidValue> e
|
|
|
271
262
|
export interface UsePickerValueProviderParams<TValue extends PickerValidValue> {
|
|
272
263
|
value: TValue;
|
|
273
264
|
contextValue: UsePickerValueContextValue;
|
|
265
|
+
actionsContextValue: UsePickerValueActionsContextValue;
|
|
266
|
+
privateContextValue: UsePickerValuePrivateContextValue;
|
|
274
267
|
}
|
|
275
268
|
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
276
|
-
open: boolean;
|
|
277
|
-
actions: UsePickerValueActions;
|
|
278
269
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
279
270
|
fieldProps: UsePickerValueFieldResponse<TValue, TError>;
|
|
280
271
|
layoutProps: UsePickerValueLayoutResponse<TValue>;
|
|
281
272
|
provider: UsePickerValueProviderParams<TValue>;
|
|
282
273
|
}
|
|
283
|
-
export interface UsePickerValueContextValue {
|
|
274
|
+
export interface UsePickerValueContextValue extends UsePickerValueActionsContextValue {
|
|
275
|
+
/**
|
|
276
|
+
* `true` if the picker is open, `false` otherwise.
|
|
277
|
+
*/
|
|
278
|
+
open: boolean;
|
|
279
|
+
}
|
|
280
|
+
export interface UsePickerValueActionsContextValue {
|
|
284
281
|
/**
|
|
285
|
-
*
|
|
282
|
+
* Set the current open state of the Picker.
|
|
286
283
|
* ```ts
|
|
287
284
|
* setOpen(true); // Opens the picker.
|
|
288
285
|
* setOpen(false); // Closes the picker.
|
|
@@ -293,7 +290,31 @@ export interface UsePickerValueContextValue {
|
|
|
293
290
|
*/
|
|
294
291
|
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
295
292
|
/**
|
|
296
|
-
*
|
|
293
|
+
* Set the current value of the picker to be empty.
|
|
294
|
+
* The value will be `null` on single pickers and `[null, null]` on range pickers.
|
|
297
295
|
*/
|
|
298
|
-
|
|
296
|
+
clearValue: () => void;
|
|
297
|
+
/**
|
|
298
|
+
* Set the current value of the picker to be the current date.
|
|
299
|
+
* The value will be `today` on single pickers and `[today, today]` on range pickers.
|
|
300
|
+
* With `today` being the current date, with its time set to `00:00:00` on Date Pickers and its time set to the current time on Time and Date Pickers.
|
|
301
|
+
*/
|
|
302
|
+
setValueToToday: () => void;
|
|
303
|
+
/**
|
|
304
|
+
* Accept the current value of the picker.
|
|
305
|
+
* Will call `onAccept` if defined.
|
|
306
|
+
* If the picker is re-opened, this value will be the one used to initialize the views.
|
|
307
|
+
*/
|
|
308
|
+
acceptValueChanges: () => void;
|
|
309
|
+
/**
|
|
310
|
+
* Cancel the changes made to the current value of the picker.
|
|
311
|
+
* The value will be reset to the last accepted value.
|
|
312
|
+
*/
|
|
313
|
+
cancelValueChanges: () => void;
|
|
314
|
+
}
|
|
315
|
+
export interface UsePickerValuePrivateContextValue {
|
|
316
|
+
/**
|
|
317
|
+
* Closes the picker and accepts the current value if it is not equal to the last accepted value.
|
|
318
|
+
*/
|
|
319
|
+
dismissViews: () => void;
|
|
299
320
|
}
|
|
@@ -7,7 +7,7 @@ import { DateOrTimeViewWithMeridiem, PickerRangeValue, PickerValidValue, PickerV
|
|
|
7
7
|
import { FieldRef, PickerValidDate, TimezoneProps } from '../../../models';
|
|
8
8
|
interface PickerViewsRendererBaseExternalProps<TView extends DateOrTimeViewWithMeridiem> extends Omit<UsePickerViewsProps<any, TView, any, any>, 'openTo' | 'viewRenderers'> {
|
|
9
9
|
}
|
|
10
|
-
export type PickerViewsRendererProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = Omit<TExternalProps, 'className' | 'sx'> & TAdditionalProps & UsePickerValueViewsResponse<TValue> & {
|
|
10
|
+
export type PickerViewsRendererProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = Omit<TExternalProps, 'className' | 'sx'> & TAdditionalProps & Pick<UsePickerValueViewsResponse<TValue>, 'value' | 'onChange'> & {
|
|
11
11
|
view: TView;
|
|
12
12
|
views: readonly TView[];
|
|
13
13
|
focusedView: TView | null;
|
|
@@ -65,17 +65,28 @@ export interface UsePickerViewParams<TValue extends PickerValidValue, TView exte
|
|
|
65
65
|
export interface UsePickerViewsResponse<TView extends DateOrTimeViewWithMeridiem> {
|
|
66
66
|
renderCurrentView: () => React.ReactNode;
|
|
67
67
|
shouldRestoreFocus: () => boolean;
|
|
68
|
-
layoutProps: UsePickerViewsLayoutResponse<TView>;
|
|
69
68
|
provider: UsePickerViewsProviderParams<TView>;
|
|
70
69
|
}
|
|
71
|
-
export interface
|
|
70
|
+
export interface UsePickerViewsContextValue<TView extends DateOrTimeViewWithMeridiem> {
|
|
71
|
+
/**
|
|
72
|
+
* Available views.
|
|
73
|
+
*/
|
|
74
|
+
views: readonly TView[];
|
|
75
|
+
/**
|
|
76
|
+
* View currently rendered.
|
|
77
|
+
*/
|
|
72
78
|
view: TView | null;
|
|
79
|
+
/**
|
|
80
|
+
* Callback called when the view to render changes
|
|
81
|
+
* @template TView
|
|
82
|
+
* @param {TView} view The view to render
|
|
83
|
+
*/
|
|
73
84
|
onViewChange: (view: TView) => void;
|
|
74
|
-
views: readonly TView[];
|
|
75
85
|
}
|
|
76
86
|
export interface UsePickerViewsProviderParams<TView extends DateOrTimeViewWithMeridiem> {
|
|
77
87
|
hasUIView: boolean;
|
|
78
88
|
views: readonly TView[];
|
|
89
|
+
contextValue: UsePickerViewsContextValue<TView>;
|
|
79
90
|
}
|
|
80
91
|
/**
|
|
81
92
|
* Manage the views of all the pickers:
|