Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fields] Play with the Base UI DX #14679

Draft
wants to merge 67 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
2b56c37
[fields] Play with the Base UI DX
flaviendelangle Sep 20, 2024
d503fa0
Work
flaviendelangle Sep 20, 2024
4571452
Work
flaviendelangle Sep 20, 2024
f2d7be0
Work
flaviendelangle Sep 20, 2024
a45ba47
Work
flaviendelangle Sep 20, 2024
7107019
Play with TS
flaviendelangle Sep 20, 2024
8376a9b
Work
flaviendelangle Sep 21, 2024
46e1dcc
Work
flaviendelangle Sep 21, 2024
5d70154
Work
flaviendelangle Sep 23, 2024
0049a49
Work
flaviendelangle Sep 23, 2024
d0da335
Work
flaviendelangle Sep 23, 2024
0bab885
Work
flaviendelangle Sep 23, 2024
bcabb4d
Work
flaviendelangle Sep 23, 2024
920e9f1
Work
flaviendelangle Sep 23, 2024
6365384
Fix
flaviendelangle Sep 23, 2024
78dcc0a
Work
flaviendelangle Sep 23, 2024
6c0ac6a
Merge branch 'master' into base-ui-field
flaviendelangle Sep 24, 2024
879187d
Work
flaviendelangle Sep 24, 2024
7575c69
Merge branch 'master' into base-ui-field
flaviendelangle Sep 25, 2024
7fd2f5b
Work
flaviendelangle Sep 25, 2024
3d2fd8d
Merge branch 'master' into base-ui-field
flaviendelangle Sep 27, 2024
7d6ebb1
Work
flaviendelangle Sep 27, 2024
3271712
Work
flaviendelangle Sep 27, 2024
4f01a78
Work
flaviendelangle Sep 27, 2024
caca2fc
Rename controller into value manager
flaviendelangle Sep 30, 2024
732fa64
Work
flaviendelangle Sep 30, 2024
917ffe6
Work
flaviendelangle Oct 1, 2024
5c5d7cc
Work
flaviendelangle Oct 1, 2024
66583e4
Work
flaviendelangle Oct 2, 2024
8c2c9a9
Work
flaviendelangle Oct 2, 2024
cb570f2
Work
flaviendelangle Oct 2, 2024
d010d6e
Work
flaviendelangle Oct 2, 2024
449e345
Work
flaviendelangle Oct 2, 2024
d6601c9
Work
flaviendelangle Oct 2, 2024
3617516
Work
flaviendelangle Oct 2, 2024
4f33bda
Work
flaviendelangle Oct 2, 2024
690534c
WOrk
flaviendelangle Oct 2, 2024
f10a7db
Work
flaviendelangle Oct 2, 2024
6f3ee1c
Work
flaviendelangle Oct 2, 2024
8f2bf9c
Work
flaviendelangle Oct 2, 2024
19f84b2
Fix
flaviendelangle Oct 2, 2024
ece3e7c
Work
flaviendelangle Oct 2, 2024
c10de7a
Work
flaviendelangle Oct 3, 2024
7618ff5
Fix
flaviendelangle Oct 3, 2024
24773d6
Work
flaviendelangle Oct 3, 2024
20a446b
Apply https://github.com/mui/base-ui/pull/700
flaviendelangle Oct 3, 2024
f7ca9e1
Create time and date time value managers
flaviendelangle Oct 3, 2024
f02b939
Work
flaviendelangle Oct 3, 2024
82928f5
Fix
flaviendelangle Oct 3, 2024
dd213a5
Fix
flaviendelangle Oct 3, 2024
70935ca
Work
flaviendelangle Oct 3, 2024
100c514
WOrk
flaviendelangle Oct 3, 2024
451fec1
Migrate multi input range fields to value manager
flaviendelangle Oct 3, 2024
b4c8af1
Work on TS
flaviendelangle Oct 4, 2024
5516b65
Fix
flaviendelangle Oct 4, 2024
849a7c4
Fix
flaviendelangle Oct 4, 2024
e08c95e
Work
flaviendelangle Oct 4, 2024
426dcf0
Work
flaviendelangle Oct 4, 2024
e387b13
Work
flaviendelangle Oct 4, 2024
454e674
Work
flaviendelangle Oct 4, 2024
9e41610
Merge
flaviendelangle Oct 4, 2024
130a287
Fix
flaviendelangle Oct 4, 2024
7c0373b
Work
flaviendelangle Oct 4, 2024
c51a6b5
Work
flaviendelangle Oct 9, 2024
579ce24
Work
flaviendelangle Oct 9, 2024
d2f62a5
Merge branch 'master' into base-ui-field
flaviendelangle Oct 14, 2024
eaee053
Merge
flaviendelangle Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ module.exports = {
rules: {
...baseline.rules,
...(ENABLE_REACT_COMPILER_PLUGIN ? { 'react-compiler/react-compiler': 'error' } : {}),
'@typescript-eslint/no-redeclare': 'off',
// TODO move to @mui/monorepo, codebase is moving away from default exports https://github.com/mui/material-ui/issues/21862
'import/prefer-default-export': 'off',
'import/no-restricted-paths': [
Expand Down
9 changes: 1 addition & 8 deletions docs/data/date-pickers/custom-field/BrowserV6Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { useClearableField } from '@mui/x-date-pickers/hooks';
import {
BaseSingleInputFieldProps,
DateValidationError,
FieldSection,
} from '@mui/x-date-pickers/models';

interface BrowserFieldProps
Expand Down Expand Up @@ -82,13 +81,7 @@ const BrowserField = React.forwardRef(

interface BrowserDateFieldProps
extends UseDateFieldProps<Dayjs, false>,
BaseSingleInputFieldProps<
Dayjs | null,
Dayjs,
FieldSection,
false,
DateValidationError
> {}
BaseSingleInputFieldProps<Dayjs, false, false, DateValidationError> {}

const BrowserDateField = React.forwardRef(
(props: BrowserDateFieldProps, ref: React.Ref<HTMLDivElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import {
import { unstable_useMultiInputDateRangeField as useMultiInputDateRangeField } from '@mui/x-date-pickers-pro/MultiInputDateRangeField';
import {
BaseMultiInputFieldProps,
DateRange,
DateRangeValidationError,
MultiInputFieldSlotTextFieldProps,
RangeFieldSection,
UseDateRangeFieldProps,
} from '@mui/x-date-pickers-pro/models';

Expand Down Expand Up @@ -84,13 +82,7 @@ const BrowserField = React.forwardRef(

interface BrowserMultiInputDateRangeFieldProps
extends UseDateRangeFieldProps<Dayjs, false>,
BaseMultiInputFieldProps<
DateRange<Dayjs>,
Dayjs,
RangeFieldSection,
false,
DateRangeValidationError
> {}
BaseMultiInputFieldProps<Dayjs, false, DateRangeValidationError> {}

type BrowserMultiInputDateRangeFieldComponent = ((
props: BrowserMultiInputDateRangeFieldProps & React.RefAttributes<HTMLDivElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ import {
} from '@mui/x-date-pickers-pro/SingleInputDateRangeField';
import { useClearableField } from '@mui/x-date-pickers/hooks';
import { BaseSingleInputFieldProps } from '@mui/x-date-pickers/models';
import {
DateRangeValidationError,
RangeFieldSection,
DateRange,
FieldType,
} from '@mui/x-date-pickers-pro/models';
import { DateRangeValidationError, FieldType } from '@mui/x-date-pickers-pro/models';

interface BrowserFieldProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
Expand Down Expand Up @@ -89,13 +84,7 @@ const BrowserField = React.forwardRef(

interface BrowserSingleInputDateRangeFieldProps
extends UseSingleInputDateRangeFieldProps<Dayjs, false>,
BaseSingleInputFieldProps<
DateRange<Dayjs>,
Dayjs,
RangeFieldSection,
false,
DateRangeValidationError
> {
BaseSingleInputFieldProps<Dayjs, true, false, DateRangeValidationError> {
onAdornmentClick?: () => void;
}

Expand Down
9 changes: 1 addition & 8 deletions docs/data/date-pickers/custom-field/BrowserV7Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
BaseSingleInputPickersTextFieldProps,
BaseSingleInputFieldProps,
DateValidationError,
FieldSection,
} from '@mui/x-date-pickers/models';
import { Unstable_PickersSectionList as PickersSectionList } from '@mui/x-date-pickers/PickersSectionList';

Expand Down Expand Up @@ -106,13 +105,7 @@ const BrowserTextField = React.forwardRef(

interface BrowserDateFieldProps
extends UseDateFieldProps<Dayjs, true>,
BaseSingleInputFieldProps<
Dayjs | null,
Dayjs,
FieldSection,
true,
DateValidationError
> {}
BaseSingleInputFieldProps<Dayjs, false, true, DateValidationError> {}

const BrowserDateField = React.forwardRef(
(props: BrowserDateFieldProps, ref: React.Ref<HTMLDivElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import {
import { unstable_useMultiInputDateRangeField as useMultiInputDateRangeField } from '@mui/x-date-pickers-pro/MultiInputDateRangeField';
import { Unstable_PickersSectionList as PickersSectionList } from '@mui/x-date-pickers/PickersSectionList';
import {
RangeFieldSection,
BaseMultiInputFieldProps,
BasePickersTextFieldProps,
MultiInputFieldSlotTextFieldProps,
DateRangeValidationError,
DateRange,
UseDateRangeFieldProps,
} from '@mui/x-date-pickers-pro/models';

Expand Down Expand Up @@ -109,13 +107,7 @@ const BrowserTextField = React.forwardRef(

interface BrowserMultiInputDateRangeFieldProps
extends UseDateRangeFieldProps<Dayjs, true>,
BaseMultiInputFieldProps<
DateRange<Dayjs>,
Dayjs,
RangeFieldSection,
true,
DateRangeValidationError
> {}
BaseMultiInputFieldProps<Dayjs, true, DateRangeValidationError> {}

type BrowserMultiInputDateRangeFieldComponent = ((
props: BrowserMultiInputDateRangeFieldProps & React.RefAttributes<HTMLDivElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ import {
import { unstable_useMultiInputDateRangeField as useMultiInputDateRangeField } from '@mui/x-date-pickers-pro/MultiInputDateRangeField';
import {
BaseMultiInputFieldProps,
DateRange,
DateRangeValidationError,
MultiInputFieldSlotTextFieldProps,
RangeFieldSection,
UseDateRangeFieldProps,
} from '@mui/x-date-pickers-pro/models';

Expand Down Expand Up @@ -133,13 +131,7 @@ const MultiInputJoyDateRangeFieldSeparator = styled(

interface JoyMultiInputDateRangeFieldProps
extends UseDateRangeFieldProps<Dayjs, false>,
BaseMultiInputFieldProps<
DateRange<Dayjs>,
Dayjs,
RangeFieldSection,
false,
DateRangeValidationError
> {}
BaseMultiInputFieldProps<Dayjs, false, DateRangeValidationError> {}

type JoyMultiInputDateRangeFieldComponent = ((
props: JoyMultiInputDateRangeFieldProps & React.RefAttributes<HTMLDivElement>,
Expand Down
6 changes: 2 additions & 4 deletions docs/data/date-pickers/custom-field/custom-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,17 @@ On the examples below, you can see that the typing of the props received by a cu
interface JoyDateFieldProps
extends UseDateFieldProps<Dayjs, false>, // The headless field props
BaseSingleInputFieldProps<
Dayjs | null,
Dayjs,
FieldSection,
false,
false, // `true` for `enableAccessibleFieldDOMStructure`
DateValidationError
> {} // The DOM field props

interface JoyDateTimeFieldProps
extends UseDateTimeFieldProps<Dayjs, false>, // The headless field props
BaseSingleInputFieldProps<
Dayjs | null,
Dayjs,
FieldSection,
false,
false, // `true` for `enableAccessibleFieldDOMStructure`
DateTimeValidationError
> {} // The DOM field props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import Typography from '@mui/material/Typography';
import Stack, { StackProps } from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types';
import {
MultiInputFieldRefs,
MultiInputRangeFieldClasses,
RangePosition,
UseDateRangeFieldProps,
} from '../models';
import { MultiInputFieldRefs, MultiInputRangeFieldClasses, RangePosition } from '../models';
import { DateRangeFieldInternalProps } from '../valueManagers';

export type UseMultiInputDateRangeFieldParams<
TDate extends PickerValidDate,
Expand All @@ -25,8 +21,8 @@ export interface UseMultiInputDateRangeFieldProps<
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
> extends Omit<
UseDateRangeFieldProps<TDate, TEnableAccessibleFieldDOMStructure>,
'unstableFieldRef' | 'clearable' | 'onClear'
DateRangeFieldInternalProps<TDate, TEnableAccessibleFieldDOMStructure>,
'unstableFieldRef'
>,
MultiInputFieldRefs {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Typography from '@mui/material/Typography';
import Stack, { StackProps } from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import { UseDateTimeRangeFieldProps } from '../internals/models/dateTimeRange';
import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types';
import { MultiInputFieldRefs, MultiInputRangeFieldClasses, RangePosition } from '../models';
import { DateTimeRangeFieldInternalProps } from '../valueManagers';

export type UseMultiInputDateTimeRangeFieldParams<
TDate extends PickerValidDate,
Expand All @@ -21,8 +21,8 @@ export interface UseMultiInputDateTimeRangeFieldProps<
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
> extends Omit<
UseDateTimeRangeFieldProps<TDate, TEnableAccessibleFieldDOMStructure>,
'unstableFieldRef' | 'clearable' | 'onClear'
DateTimeRangeFieldInternalProps<TDate, TEnableAccessibleFieldDOMStructure>,
'unstableFieldRef'
>,
MultiInputFieldRefs {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Typography from '@mui/material/Typography';
import Stack, { StackProps } from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import { UseTimeRangeFieldProps } from '../internals/models/timeRange';
import { UseMultiInputRangeFieldParams } from '../internals/hooks/useMultiInputRangeField/useMultiInputRangeField.types';
import { MultiInputFieldRefs, MultiInputRangeFieldClasses, RangePosition } from '../models';
import { TimeRangeFieldInternalProps } from '../valueManagers';

export type UseMultiInputTimeRangeFieldParams<
TDate extends PickerValidDate,
Expand All @@ -21,8 +21,8 @@ export interface UseMultiInputTimeRangeFieldProps<
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
> extends Omit<
UseTimeRangeFieldProps<TDate, TEnableAccessibleFieldDOMStructure>,
'unstableFieldRef' | 'clearable' | 'onClear'
TimeRangeFieldInternalProps<TDate, TEnableAccessibleFieldDOMStructure>,
'unstableFieldRef'
>,
MultiInputFieldRefs {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
import * as React from 'react';
import { SlotComponentProps } from '@mui/utils';
import TextField from '@mui/material/TextField';
import { UseFieldInternalProps } from '@mui/x-date-pickers/internals';
import { BuiltInFieldTextFieldProps, PickerValidDate } from '@mui/x-date-pickers/models';
import {
ExportedUseClearableFieldProps,
UseClearableFieldSlots,
UseClearableFieldSlotProps,
ExportedUseClearableFieldProps,
} from '@mui/x-date-pickers/hooks';
import type {
DateRange,
RangeFieldSection,
DateRangeValidationError,
UseDateRangeFieldProps,
} from '../models';
import { DateRangeFieldInternalProps } from '../valueManagers';

export interface UseSingleInputDateRangeFieldProps<
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
> extends UseDateRangeFieldProps<TDate, TEnableAccessibleFieldDOMStructure>,
ExportedUseClearableFieldProps,
Pick<
UseFieldInternalProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
DateRangeValidationError
>,
'unstableFieldRef'
> {}
> extends DateRangeFieldInternalProps<TDate, TEnableAccessibleFieldDOMStructure>,
ExportedUseClearableFieldProps {}

export type SingleInputDateRangeFieldProps<
TDate extends PickerValidDate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
'use client';
import * as React from 'react';
import { useField, useDefaultizedDateField } from '@mui/x-date-pickers/internals';
import { useField } from '@mui/x-date-pickers/internals';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { PickerValidDate } from '@mui/x-date-pickers/models';
import { UseSingleInputDateRangeFieldProps } from './SingleInputDateRangeField.types';
import { rangeValueManager, getRangeFieldValueManager } from '../internals/utils/valueManagers';
import { validateDateRange } from '../validation';
import { RangeFieldSection, DateRange } from '../models';
import { getDateRangeValueManager } from '../valueManagers';

export const useSingleInputDateRangeField = <
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
TAllProps extends UseSingleInputDateRangeFieldProps<TDate, TEnableAccessibleFieldDOMStructure>,
>(
inProps: TAllProps,
props: TAllProps,
) => {
const props = useDefaultizedDateField<
TDate,
UseSingleInputDateRangeFieldProps<TDate, TEnableAccessibleFieldDOMStructure>,
TAllProps
>(inProps);

const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date');

const fieldValueManager = React.useMemo(
() => getRangeFieldValueManager<TDate>({ dateSeparator: internalProps.dateSeparator }),
[internalProps.dateSeparator],
const valueManager = React.useMemo(
() =>
getDateRangeValueManager<TDate, TEnableAccessibleFieldDOMStructure>({
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure,
dateSeparator: props.dateSeparator,
}),
[props.enableAccessibleFieldDOMStructure, props.dateSeparator],
);

return useField<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
typeof forwardedProps,
typeof internalProps
>({
return useField<typeof valueManager, typeof forwardedProps>({
forwardedProps,
internalProps,
valueManager: rangeValueManager,
fieldValueManager,
validator: validateDateRange,
valueType: 'date',
valueManager,
});
};
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import * as React from 'react';
import { SlotComponentProps } from '@mui/utils';
import TextField from '@mui/material/TextField';
import { UseFieldInternalProps } from '@mui/x-date-pickers/internals';
import { BuiltInFieldTextFieldProps, PickerValidDate } from '@mui/x-date-pickers/models';
import {
ExportedUseClearableFieldProps,
UseClearableFieldSlots,
UseClearableFieldSlotProps,
} from '@mui/x-date-pickers/hooks';
import { UseDateTimeRangeFieldProps } from '../internals/models';
import { DateRange, RangeFieldSection, DateTimeRangeValidationError } from '../models';
import { DateTimeRangeFieldInternalProps } from '../valueManagers';

export interface UseSingleInputDateTimeRangeFieldProps<
TDate extends PickerValidDate,
TEnableAccessibleFieldDOMStructure extends boolean,
> extends UseDateTimeRangeFieldProps<TDate, TEnableAccessibleFieldDOMStructure>,
ExportedUseClearableFieldProps,
Pick<
UseFieldInternalProps<
DateRange<TDate>,
TDate,
RangeFieldSection,
TEnableAccessibleFieldDOMStructure,
DateTimeRangeValidationError
>,
'unstableFieldRef'
> {}
> extends DateTimeRangeFieldInternalProps<TDate, TEnableAccessibleFieldDOMStructure>,
ExportedUseClearableFieldProps {}

export type SingleInputDateTimeRangeFieldProps<
TDate extends PickerValidDate,
Expand Down
Loading