-
-
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.
[docs] Add example to add a second icon next to the field's opening b…
…utton (#12524)
- Loading branch information
1 parent
ec57ad7
commit 02867d1
Showing
6 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
docs/data/date-pickers/custom-opening-button/AddWarningIconWhenInvalid.js
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,42 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import InputAdornment from '@mui/material/InputAdornment'; | ||
import PriorityHighIcon from '@mui/icons-material/PriorityHigh'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { DatePicker } from '@mui/x-date-pickers/DatePicker'; | ||
|
||
function CustomInputAdornment(props) { | ||
const { hasError, children, sx, ...other } = props; | ||
return ( | ||
<InputAdornment {...other}> | ||
<PriorityHighIcon | ||
color="error" | ||
sx={{ marginLeft: 1, opacity: hasError ? 1 : 0 }} | ||
/> | ||
{children} | ||
</InputAdornment> | ||
); | ||
} | ||
|
||
export default function AddWarningIconWhenInvalid() { | ||
const [error, setError] = React.useState(null); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DatePicker']}> | ||
<DatePicker | ||
label="Picker with error icon" | ||
maxDate={dayjs('2022-04-17')} | ||
defaultValue={dayjs('2022-04-18')} | ||
onError={setError} | ||
slots={{ inputAdornment: CustomInputAdornment }} | ||
slotProps={{ | ||
inputAdornment: { hasError: !!error }, | ||
}} | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
docs/data/date-pickers/custom-opening-button/AddWarningIconWhenInvalid.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,43 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import InputAdornment, { InputAdornmentProps } from '@mui/material/InputAdornment'; | ||
import PriorityHighIcon from '@mui/icons-material/PriorityHigh'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { DatePicker } from '@mui/x-date-pickers/DatePicker'; | ||
import { DateValidationError } from '@mui/x-date-pickers/models'; | ||
|
||
function CustomInputAdornment(props: InputAdornmentProps & { hasError?: boolean }) { | ||
const { hasError, children, sx, ...other } = props; | ||
return ( | ||
<InputAdornment {...other}> | ||
<PriorityHighIcon | ||
color="error" | ||
sx={{ marginLeft: 1, opacity: hasError ? 1 : 0 }} | ||
/> | ||
{children} | ||
</InputAdornment> | ||
); | ||
} | ||
|
||
export default function AddWarningIconWhenInvalid() { | ||
const [error, setError] = React.useState<DateValidationError>(null); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DatePicker']}> | ||
<DatePicker | ||
label="Picker with error icon" | ||
maxDate={dayjs('2022-04-17')} | ||
defaultValue={dayjs('2022-04-18')} | ||
onError={setError} | ||
slots={{ inputAdornment: CustomInputAdornment }} | ||
slotProps={{ | ||
inputAdornment: { hasError: !!error } as any, | ||
}} | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
docs/data/date-pickers/custom-opening-button/AddWarningIconWhenInvalid.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<DatePicker | ||
label="Picker with error icon" | ||
maxDate={dayjs('2022-04-17')} | ||
defaultValue={dayjs('2022-04-18')} | ||
onError={setError} | ||
slots={{ inputAdornment: CustomInputAdornment }} | ||
slotProps={{ | ||
inputAdornment: { hasError: !!error } as any, | ||
}} | ||
/> |
47 changes: 47 additions & 0 deletions
47
docs/data/date-pickers/custom-opening-button/AddWarningIconWhenInvalidRange.js
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,47 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import InputAdornment from '@mui/material/InputAdornment'; | ||
import PriorityHighIcon from '@mui/icons-material/PriorityHigh'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker'; | ||
|
||
function CustomInputAdornment(props) { | ||
const { hasError, children, sx, ...other } = props; | ||
return ( | ||
<InputAdornment {...other}> | ||
<PriorityHighIcon color="error" sx={{ opacity: hasError ? 1 : 0 }} /> | ||
{children} | ||
</InputAdornment> | ||
); | ||
} | ||
|
||
export default function AddWarningIconWhenInvalidRange() { | ||
const [error, setError] = React.useState([null, null]); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DatePicker']}> | ||
<DateRangePicker | ||
label="Picker with error icon" | ||
maxDate={dayjs('2022-04-19')} | ||
defaultValue={[dayjs('2022-04-18'), dayjs('2022-04-21')]} | ||
onError={setError} | ||
slotProps={{ | ||
textField: (ownerState) => ({ | ||
InputProps: { | ||
endAdornment: ( | ||
<CustomInputAdornment | ||
position="end" | ||
hasError={!!error[ownerState.position === 'start' ? 0 : 1]} | ||
/> | ||
), | ||
}, | ||
}), | ||
}} | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
48 changes: 48 additions & 0 deletions
48
docs/data/date-pickers/custom-opening-button/AddWarningIconWhenInvalidRange.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,48 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import InputAdornment, { InputAdornmentProps } from '@mui/material/InputAdornment'; | ||
import PriorityHighIcon from '@mui/icons-material/PriorityHigh'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker'; | ||
import { DateRangeValidationError } from '@mui/x-date-pickers-pro/models'; | ||
|
||
function CustomInputAdornment(props: InputAdornmentProps & { hasError?: boolean }) { | ||
const { hasError, children, sx, ...other } = props; | ||
return ( | ||
<InputAdornment {...other}> | ||
<PriorityHighIcon color="error" sx={{ opacity: hasError ? 1 : 0 }} /> | ||
{children} | ||
</InputAdornment> | ||
); | ||
} | ||
|
||
export default function AddWarningIconWhenInvalidRange() { | ||
const [error, setError] = React.useState<DateRangeValidationError>([null, null]); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DatePicker']}> | ||
<DateRangePicker | ||
label="Picker with error icon" | ||
maxDate={dayjs('2022-04-19')} | ||
defaultValue={[dayjs('2022-04-18'), dayjs('2022-04-21')]} | ||
onError={setError} | ||
slotProps={{ | ||
textField: (ownerState) => ({ | ||
InputProps: { | ||
endAdornment: ( | ||
<CustomInputAdornment | ||
position="end" | ||
hasError={!!error[ownerState.position === 'start' ? 0 : 1]} | ||
/> | ||
), | ||
}, | ||
}), | ||
}} | ||
/> | ||
</DemoContainer> | ||
</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