Skip to content

Commit

Permalink
[docs] Add conditional range picker props example (#10227)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy authored Sep 13, 2023
1 parent b04bef5 commit 7469b90
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
import { LocalizationProvider } from '@mui/x-date-pickers-pro';
import { AdapterDayjs } from '@mui/x-date-pickers-pro/AdapterDayjs';
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker';

export default function MultiInputFieldTextFieldProps() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DateRangePicker']}>
<DateRangePicker
slotProps={{
textField: ({ position }) => ({
color: position === 'start' ? 'success' : 'warning',
focused: true,
}),
}}
defaultValue={[dayjs('2022-04-17'), null]}
/>
</DemoContainer>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
import { LocalizationProvider } from '@mui/x-date-pickers-pro';
import { AdapterDayjs } from '@mui/x-date-pickers-pro/AdapterDayjs';
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker';

export default function MultiInputFieldTextFieldProps() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DateRangePicker']}>
<DateRangePicker
slotProps={{
textField: ({ position }) => ({
color: position === 'start' ? 'success' : 'warning',
focused: true,
}),
}}
defaultValue={[dayjs('2022-04-17'), null]}
/>
</DemoContainer>
</LocalizationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<DateRangePicker
slotProps={{
textField: ({ position }) => ({
color: position === 'start' ? 'success' : 'warning',
focused: true,
}),
}}
defaultValue={[dayjs('2022-04-17'), null]}
/>
6 changes: 6 additions & 0 deletions docs/data/date-pickers/custom-field/custom-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ You can use the `fieldSeparator` slot to pass custom props to the `Typography` r

{{"demo": "MultiInputFieldSeparatorSlotProps.js"}}

### Customize the `start` and `end` fields differently [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')

You can pass conditional props to the `textField` slot to customize the input styling based on the `position`.

{{"demo": "MultiInputFieldTextFieldProps.js"}}

### Use single input fields on range pickers [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')

You can pass the single input fields to the range picker to use it for keyboard editing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ You can pass the `SingleInputDateRangeField` component to the Date Range Picker
{{"demo": "SingleInputDateRangePicker.js"}}

:::info
For more information, check out the [Custom field](/x/react-date-pickers/custom-field/#use-single-input-fields-on-range-pickers) page.
You can find more information in a [dedicated documentation page section](/x/react-date-pickers/custom-field/#use-single-input-fields-on-range-pickers).
:::

### Add shortcuts
Expand All @@ -97,6 +97,10 @@ To simplify range selection, you can add [shortcuts](/x/react-date-pickers/short

{{"demo": "BasicRangeShortcuts.js", "bg": "inline", "defaultCodeOpen": false}}

### Customize the field

You can find the documentation in the [Custom field page](/x/react-date-pickers/custom-field/).

## Validation

You can find the documentation in the [Validation page](/x/react-date-pickers/validation/).
Expand Down

0 comments on commit 7469b90

Please sign in to comment.