-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc89d3c
commit 01934b9
Showing
16 changed files
with
331 additions
and
362 deletions.
There are no files selected for viewing
45 changes: 21 additions & 24 deletions
45
packages/x-date-pickers-pro/src/SingleInputDateRangeField/useSingleInputDateRangeField.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,37 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { useField, useDefaultizedDateField } from '@mui/x-date-pickers/internals'; | ||
import { useField, useFieldInternalPropsWithDefaults } from '@mui/x-date-pickers/internals'; | ||
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks'; | ||
import { UseSingleInputDateRangeFieldProps } from './SingleInputDateRangeField.types'; | ||
import { rangeValueManager, getRangeFieldValueManager } from '../internals/utils/valueManagers'; | ||
import { validateDateRange } from '../validation'; | ||
import { getDateRangeValueManager } from '../valueManagers'; | ||
|
||
export const useSingleInputDateRangeField = < | ||
TEnableAccessibleFieldDOMStructure extends boolean, | ||
TAllProps extends UseSingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>, | ||
>( | ||
inProps: TAllProps, | ||
props: TAllProps, | ||
) => { | ||
const props = useDefaultizedDateField< | ||
UseSingleInputDateRangeFieldProps<TEnableAccessibleFieldDOMStructure>, | ||
TAllProps | ||
>(inProps); | ||
const valueManager = React.useMemo( | ||
() => | ||
getDateRangeValueManager({ | ||
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure, | ||
dateSeparator: props.dateSeparator, | ||
}), | ||
[props.enableAccessibleFieldDOMStructure, props.dateSeparator], | ||
); | ||
|
||
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date'); | ||
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({ | ||
valueManager, | ||
internalProps, | ||
}); | ||
|
||
const fieldValueManager = React.useMemo( | ||
() => getRangeFieldValueManager({ dateSeparator: internalProps.dateSeparator }), | ||
[internalProps.dateSeparator], | ||
); | ||
|
||
return useField< | ||
true, | ||
TEnableAccessibleFieldDOMStructure, | ||
typeof forwardedProps, | ||
typeof internalProps | ||
>({ | ||
return useField({ | ||
forwardedProps, | ||
internalProps, | ||
valueManager: rangeValueManager, | ||
fieldValueManager, | ||
validator: validateDateRange, | ||
valueType: 'date', | ||
internalProps: internalPropsWithDefaults, | ||
valueManager: valueManager.legacyValueManager, | ||
fieldValueManager: valueManager.fieldValueManager, | ||
validator: valueManager.validator, | ||
valueType: valueManager.valueType, | ||
}); | ||
}; |
47 changes: 22 additions & 25 deletions
47
.../x-date-pickers-pro/src/SingleInputDateTimeRangeField/useSingleInputDateTimeRangeField.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,37 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { useField, useDefaultizedDateTimeField } from '@mui/x-date-pickers/internals'; | ||
import { useField, useFieldInternalPropsWithDefaults } from '@mui/x-date-pickers/internals'; | ||
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks'; | ||
import { UseSingleInputDateTimeRangeFieldProps } from './SingleInputDateTimeRangeField.types'; | ||
import { rangeValueManager, getRangeFieldValueManager } from '../internals/utils/valueManagers'; | ||
import { validateDateTimeRange } from '../validation'; | ||
import { getDateTimeRangeValueManager } from '../valueManagers'; | ||
|
||
export const useSingleInputDateTimeRangeField = < | ||
TEnableAccessibleFieldDOMStructure extends boolean, | ||
TAllProps extends UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, | ||
>( | ||
inProps: TAllProps, | ||
props: TAllProps, | ||
) => { | ||
const props = useDefaultizedDateTimeField< | ||
UseSingleInputDateTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, | ||
TAllProps | ||
>(inProps); | ||
|
||
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date-time'); | ||
|
||
const fieldValueManager = React.useMemo( | ||
() => getRangeFieldValueManager({ dateSeparator: internalProps.dateSeparator }), | ||
[internalProps.dateSeparator], | ||
const valueManager = React.useMemo( | ||
() => | ||
getDateTimeRangeValueManager({ | ||
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure, | ||
dateSeparator: props.dateSeparator, | ||
}), | ||
[props.enableAccessibleFieldDOMStructure, props.dateSeparator], | ||
); | ||
|
||
return useField< | ||
true, | ||
TEnableAccessibleFieldDOMStructure, | ||
typeof forwardedProps, | ||
typeof internalProps | ||
>({ | ||
forwardedProps, | ||
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date'); | ||
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({ | ||
valueManager, | ||
internalProps, | ||
valueManager: rangeValueManager, | ||
fieldValueManager, | ||
validator: validateDateTimeRange, | ||
valueType: 'date-time', | ||
}); | ||
|
||
return useField({ | ||
forwardedProps, | ||
internalProps: internalPropsWithDefaults, | ||
valueManager: valueManager.legacyValueManager, | ||
fieldValueManager: valueManager.fieldValueManager, | ||
validator: valueManager.validator, | ||
valueType: valueManager.valueType, | ||
}); | ||
}; |
47 changes: 22 additions & 25 deletions
47
packages/x-date-pickers-pro/src/SingleInputTimeRangeField/useSingleInputTimeRangeField.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,37 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { useField, useDefaultizedTimeField } from '@mui/x-date-pickers/internals'; | ||
import { useField, useFieldInternalPropsWithDefaults } from '@mui/x-date-pickers/internals'; | ||
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks'; | ||
import { UseSingleInputTimeRangeFieldProps } from './SingleInputTimeRangeField.types'; | ||
import { rangeValueManager, getRangeFieldValueManager } from '../internals/utils/valueManagers'; | ||
import { validateTimeRange } from '../validation'; | ||
import { getTimeRangeValueManager } from '../valueManagers'; | ||
|
||
export const useSingleInputTimeRangeField = < | ||
TEnableAccessibleFieldDOMStructure extends boolean, | ||
TAllProps extends UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, | ||
>( | ||
inProps: TAllProps, | ||
props: TAllProps, | ||
) => { | ||
const props = useDefaultizedTimeField< | ||
UseSingleInputTimeRangeFieldProps<TEnableAccessibleFieldDOMStructure>, | ||
TAllProps | ||
>(inProps); | ||
|
||
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'time'); | ||
|
||
const fieldValueManager = React.useMemo( | ||
() => getRangeFieldValueManager({ dateSeparator: internalProps.dateSeparator }), | ||
[internalProps.dateSeparator], | ||
const valueManager = React.useMemo( | ||
() => | ||
getTimeRangeValueManager({ | ||
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure, | ||
dateSeparator: props.dateSeparator, | ||
}), | ||
[props.enableAccessibleFieldDOMStructure, props.dateSeparator], | ||
); | ||
|
||
return useField< | ||
true, | ||
TEnableAccessibleFieldDOMStructure, | ||
typeof forwardedProps, | ||
typeof internalProps | ||
>({ | ||
forwardedProps, | ||
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date'); | ||
const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({ | ||
valueManager, | ||
internalProps, | ||
valueManager: rangeValueManager, | ||
fieldValueManager, | ||
validator: validateTimeRange, | ||
valueType: 'time', | ||
}); | ||
|
||
return useField({ | ||
forwardedProps, | ||
internalProps: internalPropsWithDefaults, | ||
valueManager: valueManager.legacyValueManager, | ||
fieldValueManager: valueManager.fieldValueManager, | ||
validator: valueManager.validator, | ||
valueType: valueManager.valueType, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.