forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New components:
MultiInputDateTimeRangePicker
and `MultiInputTimeRa…
…ngePicker` (mui#6392)
- Loading branch information
1 parent
40b0fc9
commit 277ab07
Showing
47 changed files
with
1,284 additions
and
216 deletions.
There are no files selected for viewing
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
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
10 changes: 8 additions & 2 deletions
10
docs/data/date-pickers/date-range-field/BasicDateRangeField.tsx.preview
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,6 +1,12 @@ | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={4}> | ||
<MultiInputDateRangeField /> | ||
<SingleInputDateRangeField /> | ||
<MultiInputDateRangeField | ||
value={value} | ||
onChange={(newValue) => setValue(newValue)} | ||
/> | ||
<SingleInputDateRangeField | ||
value={value} | ||
onChange={(newValue) => setValue(newValue)} | ||
/> | ||
</Stack> | ||
</LocalizationProvider> |
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
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
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
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
2 changes: 1 addition & 1 deletion
2
packages/x-date-pickers-pro/src/DateRangePicker/date-range-manager.test.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
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
7 changes: 0 additions & 7 deletions
7
...es/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.interfaces.ts
This file was deleted.
Oops, something went wrong.
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
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
147 changes: 147 additions & 0 deletions
147
...ages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.tsx
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 |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import * as React from 'react'; | ||
import Stack, { StackProps } from '@mui/material/Stack'; | ||
import TextField, { TextFieldProps } from '@mui/material/TextField'; | ||
import Typography, { TypographyProps } from '@mui/material/Typography'; | ||
import { styled, useThemeProps } from '@mui/material/styles'; | ||
import { useSlotProps } from '@mui/base/utils'; | ||
import { MultiInputDateTimeRangeFieldProps } from './MultiInputDateTimeRangeField.types'; | ||
import { useMultiInputDateTimeRangeField } from '../internal/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField'; | ||
|
||
const MultiInputDateTimeRangeFieldRoot = styled( | ||
React.forwardRef((props: StackProps, ref: React.Ref<HTMLDivElement>) => ( | ||
<Stack ref={ref} {...props} spacing={2} direction="row" alignItems="center" /> | ||
)), | ||
{ | ||
name: 'MuiMultiInputDateTimeRangeField', | ||
slot: 'Root', | ||
overridesResolver: (props, styles) => styles.root, | ||
}, | ||
)({}); | ||
|
||
const MultiInputDateTimeRangeFieldSeparator = styled( | ||
(props: TypographyProps) => <Typography {...props}>{props.children ?? ' — '}</Typography>, | ||
{ | ||
name: 'MuiMultiInputDateTimeRangeField', | ||
slot: 'Separator', | ||
overridesResolver: (props, styles) => styles.separator, | ||
}, | ||
)({}); | ||
|
||
type MultiInputDateTimeRangeFieldComponent = (<TDate>( | ||
props: MultiInputDateTimeRangeFieldProps<TDate> & React.RefAttributes<HTMLInputElement>, | ||
) => JSX.Element) & { propTypes?: any }; | ||
|
||
export const MultiInputDateTimeRangeField = React.forwardRef(function MultiInputDateTimeRangeField< | ||
TDate, | ||
>(inProps: MultiInputDateTimeRangeFieldProps<TDate>, ref: React.Ref<HTMLInputElement>) { | ||
const themeProps = useThemeProps({ | ||
props: inProps, | ||
name: 'MuiMultiInputDateTimeRangeField', | ||
}); | ||
|
||
const { | ||
components, | ||
componentsProps, | ||
value, | ||
defaultValue, | ||
format, | ||
onChange, | ||
readOnly, | ||
onError, | ||
shouldDisableDate, | ||
minDate, | ||
maxDate, | ||
minTime, | ||
maxTime, | ||
minDateTime, | ||
maxDateTime, | ||
minutesStep, | ||
shouldDisableTime, | ||
disableFuture, | ||
disablePast, | ||
...other | ||
} = themeProps; | ||
|
||
const ownerState = themeProps; | ||
|
||
const Root = components?.Root ?? MultiInputDateTimeRangeFieldRoot; | ||
const rootProps = useSlotProps({ | ||
elementType: Root, | ||
externalSlotProps: componentsProps?.root, | ||
externalForwardedProps: other, | ||
additionalProps: { | ||
ref, | ||
}, | ||
ownerState, | ||
}); | ||
|
||
const Input = components?.Input ?? TextField; | ||
const startInputProps: TextFieldProps = useSlotProps({ | ||
elementType: Input, | ||
externalSlotProps: componentsProps?.input, | ||
ownerState: { ...ownerState, position: 'start' }, | ||
}); | ||
const endInputProps: TextFieldProps = useSlotProps({ | ||
elementType: Input, | ||
externalSlotProps: componentsProps?.input, | ||
ownerState: { ...ownerState, position: 'end' }, | ||
}); | ||
|
||
const Separator = components?.Separator ?? MultiInputDateTimeRangeFieldSeparator; | ||
const separatorProps = useSlotProps({ | ||
elementType: Separator, | ||
externalSlotProps: componentsProps?.separator, | ||
ownerState, | ||
}); | ||
|
||
const { | ||
startDate: { onKeyDown: onStartInputKeyDown, ref: startInputRef, ...startDateProps }, | ||
endDate: { onKeyDown: onEndInputKeyDown, ref: endInputRef, ...endDateProps }, | ||
} = useMultiInputDateTimeRangeField<TDate, TextFieldProps>({ | ||
sharedProps: { | ||
value, | ||
defaultValue, | ||
format, | ||
onChange, | ||
readOnly, | ||
onError, | ||
shouldDisableDate, | ||
minDate, | ||
maxDate, | ||
minTime, | ||
maxTime, | ||
minDateTime, | ||
maxDateTime, | ||
minutesStep, | ||
shouldDisableTime, | ||
disableFuture, | ||
disablePast, | ||
}, | ||
startInputProps, | ||
endInputProps, | ||
startInputRef: startInputProps.inputRef, | ||
endInputRef: endInputProps.inputRef, | ||
}); | ||
|
||
return ( | ||
<Root {...rootProps}> | ||
<Input | ||
{...startDateProps} | ||
inputProps={{ | ||
...startDateProps.inputProps, | ||
ref: startInputRef, | ||
onKeyDown: onStartInputKeyDown, | ||
}} | ||
/> | ||
<Separator {...separatorProps} /> | ||
<Input | ||
{...endDateProps} | ||
inputProps={{ | ||
...endDateProps.inputProps, | ||
ref: endInputRef, | ||
onKeyDown: onEndInputKeyDown, | ||
}} | ||
/> | ||
</Root> | ||
); | ||
}) as MultiInputDateTimeRangeFieldComponent; |
79 changes: 79 additions & 0 deletions
79
...x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as React from 'react'; | ||
import { SlotComponentProps } from '@mui/base/utils'; | ||
import Typography from '@mui/material/Typography'; | ||
import Stack from '@mui/material/Stack'; | ||
import TextField, { TextFieldProps } from '@mui/material/TextField'; | ||
import { | ||
UseDateTimeRangeFieldDefaultizedProps, | ||
UseDateTimeRangeFieldProps, | ||
} from '../internal/models/dateTimeRange'; | ||
|
||
export interface UseMultiInputDateTimeRangeFieldParams<TDate, TChildProps extends {}> { | ||
sharedProps: Omit<TChildProps, keyof UseMultiInputDateTimeRangeFieldProps<TDate>> & | ||
UseMultiInputDateTimeRangeFieldProps<TDate>; | ||
startInputProps: TChildProps; | ||
endInputProps: TChildProps; | ||
startInputRef?: React.Ref<HTMLInputElement>; | ||
endInputRef?: React.Ref<HTMLInputElement>; | ||
} | ||
|
||
export interface UseMultiInputDateTimeRangeFieldProps<TDate> | ||
extends UseDateTimeRangeFieldProps<TDate> {} | ||
|
||
export type UseMultiInputDateTimeRangeFieldComponentProps<TDate, TChildProps extends {}> = Omit< | ||
TChildProps, | ||
keyof UseMultiInputDateTimeRangeFieldProps<TDate> | ||
> & | ||
UseMultiInputDateTimeRangeFieldProps<TDate>; | ||
|
||
export interface MultiInputDateTimeRangeFieldProps<TDate> | ||
extends UseMultiInputDateTimeRangeFieldComponentProps<TDate, TextFieldProps> { | ||
/** | ||
* Overrideable components. | ||
* @default {} | ||
*/ | ||
components?: MultiInputDateTimeRangeFieldSlotsComponent; | ||
/** | ||
* The props used for each component slot. | ||
* @default {} | ||
*/ | ||
componentsProps?: MultiInputDateTimeRangeFieldSlotsComponentsProps<TDate>; | ||
} | ||
|
||
export type MultiInputDateTimeRangeFieldOwnerState<TDate> = | ||
MultiInputDateTimeRangeFieldProps<TDate>; | ||
|
||
export interface MultiInputDateTimeRangeFieldSlotsComponent { | ||
/** | ||
* Element rendered at the root. | ||
* @default MultiInputDateTimeRangeFieldRoot | ||
*/ | ||
Root?: React.ElementType; | ||
/** | ||
* Input rendered for the start or end date. | ||
* @default TextField | ||
*/ | ||
Input?: React.ElementType; | ||
/** | ||
* Element rendered between the two inputs. | ||
* @default MultiInputDateTimeRangeFieldSeparator | ||
*/ | ||
Separator?: React.ElementType; | ||
} | ||
|
||
export interface MultiInputDateTimeRangeFieldSlotsComponentsProps<TDate> { | ||
root?: SlotComponentProps<typeof Stack, {}, MultiInputDateTimeRangeFieldOwnerState<TDate>>; | ||
input?: SlotComponentProps< | ||
typeof TextField, | ||
{}, | ||
MultiInputDateTimeRangeFieldOwnerState<TDate> & { position: 'start' | 'end' } | ||
>; | ||
separator?: SlotComponentProps< | ||
typeof Typography, | ||
{}, | ||
MultiInputDateTimeRangeFieldOwnerState<TDate> | ||
>; | ||
} | ||
|
||
export type UseMultiInputDateTimeRangeFieldDefaultizedProps<TDate> = | ||
UseDateTimeRangeFieldDefaultizedProps<TDate>; |
2 changes: 2 additions & 0 deletions
2
packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/index.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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { MultiInputDateTimeRangeField as Unstable_MultiInputDateTimeRangeField } from './MultiInputDateTimeRangeField'; | ||
export type { UseMultiInputDateTimeRangeFieldProps } from './MultiInputDateTimeRangeField.types'; |
Oops, something went wrong.