diff --git a/docs/data/base/components/input/InputAdornments.js b/docs/data/base/components/input/InputAdornments.js index 694f34ba264a14..71e3963941b019 100644 --- a/docs/data/base/components/input/InputAdornments.js +++ b/docs/data/base/components/input/InputAdornments.js @@ -7,6 +7,85 @@ import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput(props, ref) { + const { slots, ...other } = props; + return ( + + ); +}); + +CustomInput.propTypes = { + /** + * The components used for each slot inside the InputBase. + * Either a string to use a HTML element or a component. + * @default {} + */ + slots: PropTypes.shape({ + input: PropTypes.elementType, + root: PropTypes.elementType, + textarea: PropTypes.elementType, + }), +}; + +export default function InputAdornments() { + const [values, setValues] = React.useState({ + amount: '', + password: '', + weight: '', + weightRange: '', + showPassword: false, + }); + + const handleChange = (prop) => (event) => { + setValues({ ...values, [prop]: event.target.value }); + }; + + const handleClickShowPassword = () => { + setValues({ + ...values, + showPassword: !values.showPassword, + }); + }; + + const handleMouseDownPassword = (event) => { + event.preventDefault(); + }; + + return ( + * + *': { ml: 1 } }}> + kg} + /> + + + {values.showPassword ? : } + + + } + /> + + ); +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -92,82 +171,3 @@ const InputAdornment = styled('div')` align-items: center; justify-content: center; `; - -const CustomInput = React.forwardRef(function CustomInput(props, ref) { - const { slots, ...other } = props; - return ( - - ); -}); - -CustomInput.propTypes = { - /** - * The components used for each slot inside the InputBase. - * Either a string to use a HTML element or a component. - * @default {} - */ - slots: PropTypes.shape({ - input: PropTypes.elementType, - root: PropTypes.elementType, - textarea: PropTypes.elementType, - }), -}; - -export default function InputAdornments() { - const [values, setValues] = React.useState({ - amount: '', - password: '', - weight: '', - weightRange: '', - showPassword: false, - }); - - const handleChange = (prop) => (event) => { - setValues({ ...values, [prop]: event.target.value }); - }; - - const handleClickShowPassword = () => { - setValues({ - ...values, - showPassword: !values.showPassword, - }); - }; - - const handleMouseDownPassword = (event) => { - event.preventDefault(); - }; - - return ( - * + *': { ml: 1 } }}> - kg} - /> - - - {values.showPassword ? : } - - - } - /> - - ); -} diff --git a/docs/data/base/components/input/InputAdornments.tsx b/docs/data/base/components/input/InputAdornments.tsx index 481c15387445f3..808931cc4476d6 100644 --- a/docs/data/base/components/input/InputAdornments.tsx +++ b/docs/data/base/components/input/InputAdornments.tsx @@ -6,6 +6,84 @@ import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput( + props: InputProps, + ref: React.ForwardedRef, +) { + const { slots, ...other } = props; + return ( + + ); +}); + +interface State { + amount: string; + password: string; + weight: string; + weightRange: string; + showPassword: boolean; +} + +export default function InputAdornments() { + const [values, setValues] = React.useState({ + amount: '', + password: '', + weight: '', + weightRange: '', + showPassword: false, + }); + + const handleChange = + (prop: keyof State) => (event: React.ChangeEvent) => { + setValues({ ...values, [prop]: event.target.value }); + }; + + const handleClickShowPassword = () => { + setValues({ + ...values, + showPassword: !values.showPassword, + }); + }; + + const handleMouseDownPassword = (event: React.MouseEvent) => { + event.preventDefault(); + }; + + return ( + * + *': { ml: 1 } }}> + kg} + /> + + + {values.showPassword ? : } + + + } + /> + + ); +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -91,81 +169,3 @@ const InputAdornment = styled('div')` align-items: center; justify-content: center; `; - -const CustomInput = React.forwardRef(function CustomInput( - props: InputProps, - ref: React.ForwardedRef, -) { - const { slots, ...other } = props; - return ( - - ); -}); - -interface State { - amount: string; - password: string; - weight: string; - weightRange: string; - showPassword: boolean; -} - -export default function InputAdornments() { - const [values, setValues] = React.useState({ - amount: '', - password: '', - weight: '', - weightRange: '', - showPassword: false, - }); - - const handleChange = - (prop: keyof State) => (event: React.ChangeEvent) => { - setValues({ ...values, [prop]: event.target.value }); - }; - - const handleClickShowPassword = () => { - setValues({ - ...values, - showPassword: !values.showPassword, - }); - }; - - const handleMouseDownPassword = (event: React.MouseEvent) => { - event.preventDefault(); - }; - - return ( - * + *': { ml: 1 } }}> - kg} - /> - - - {values.showPassword ? : } - - - } - /> - - ); -} diff --git a/docs/data/base/components/input/InputMultiline.js b/docs/data/base/components/input/InputMultiline.js index d0ddeed1ed1f05..12af43e924dfe3 100644 --- a/docs/data/base/components/input/InputMultiline.js +++ b/docs/data/base/components/input/InputMultiline.js @@ -2,6 +2,22 @@ import * as React from 'react'; import Input from '@mui/base/Input'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput(props, ref) { + return ( + + ); +}); + +export default function InputMultiline() { + return ( + + ); +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -85,19 +101,3 @@ const StyledTextareaElement = styled('textarea', { } `, ); - -const CustomInput = React.forwardRef(function CustomInput(props, ref) { - return ( - - ); -}); - -export default function UnstyledInputBasic() { - return ( - - ); -} diff --git a/docs/data/base/components/input/InputMultiline.tsx b/docs/data/base/components/input/InputMultiline.tsx index bfd960e0514ac1..d3a8e784bb388e 100644 --- a/docs/data/base/components/input/InputMultiline.tsx +++ b/docs/data/base/components/input/InputMultiline.tsx @@ -2,6 +2,25 @@ import * as React from 'react'; import Input, { InputProps } from '@mui/base/Input'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput( + props: InputProps, + ref: React.ForwardedRef, +) { + return ( + + ); +}); + +export default function InputMultiline() { + return ( + + ); +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -85,22 +104,3 @@ const StyledTextareaElement = styled('textarea', { } `, ); - -const CustomInput = React.forwardRef(function CustomInput( - props: InputProps, - ref: React.ForwardedRef, -) { - return ( - - ); -}); - -export default function UnstyledInputBasic() { - return ( - - ); -} diff --git a/docs/data/base/components/input/InputMultilineAutosize.js b/docs/data/base/components/input/InputMultilineAutosize.js index 6f52efe5e6d270..475b1ee89d7c98 100644 --- a/docs/data/base/components/input/InputMultilineAutosize.js +++ b/docs/data/base/components/input/InputMultilineAutosize.js @@ -3,6 +3,22 @@ import Input from '@mui/base/Input'; import TextareaAutosize from '@mui/base/TextareaAutosize'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput(props, ref) { + return ( + + ); +}); + +export default function InputMultilineAutosize() { + return ( + + ); +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -83,19 +99,3 @@ const StyledTextareaElement = styled(TextareaAutosize)( } `, ); - -const CustomInput = React.forwardRef(function CustomInput(props, ref) { - return ( - - ); -}); - -export default function UnstyledInputBasic() { - return ( - - ); -} diff --git a/docs/data/base/components/input/InputMultilineAutosize.tsx b/docs/data/base/components/input/InputMultilineAutosize.tsx index f23e5e8f505f4a..a5639eaabf1996 100644 --- a/docs/data/base/components/input/InputMultilineAutosize.tsx +++ b/docs/data/base/components/input/InputMultilineAutosize.tsx @@ -3,6 +3,25 @@ import Input, { InputProps } from '@mui/base/Input'; import TextareaAutosize from '@mui/base/TextareaAutosize'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput( + props: InputProps, + ref: React.ForwardedRef, +) { + return ( + + ); +}); + +export default function InputMultilineAutosize() { + return ( + + ); +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -83,22 +102,3 @@ const StyledTextareaElement = styled(TextareaAutosize)( } `, ); - -const CustomInput = React.forwardRef(function CustomInput( - props: InputProps, - ref: React.ForwardedRef, -) { - return ( - - ); -}); - -export default function UnstyledInputBasic() { - return ( - - ); -} diff --git a/docs/data/base/components/input/UnstyledInputBasic.js b/docs/data/base/components/input/UnstyledInputBasic.js index 40e5e3b44560a7..bdcfaa32765aa2 100644 --- a/docs/data/base/components/input/UnstyledInputBasic.js +++ b/docs/data/base/components/input/UnstyledInputBasic.js @@ -2,6 +2,14 @@ import * as React from 'react'; import Input from '@mui/base/Input'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput(props, ref) { + return ; +}); + +export default function UnstyledInputBasic() { + return ; +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -52,11 +60,3 @@ const StyledInputElement = styled('input')( } `, ); - -const CustomInput = React.forwardRef(function CustomInput(props, ref) { - return ; -}); - -export default function UnstyledInputBasic() { - return ; -} diff --git a/docs/data/base/components/input/UnstyledInputBasic.tsx b/docs/data/base/components/input/UnstyledInputBasic.tsx index 375e4cc049d325..6855b5801e13ac 100644 --- a/docs/data/base/components/input/UnstyledInputBasic.tsx +++ b/docs/data/base/components/input/UnstyledInputBasic.tsx @@ -2,6 +2,17 @@ import * as React from 'react'; import Input, { InputProps } from '@mui/base/Input'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput( + props: InputProps, + ref: React.ForwardedRef, +) { + return ; +}); + +export default function UnstyledInputBasic() { + return ; +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -52,14 +63,3 @@ const StyledInputElement = styled('input')( } `, ); - -const CustomInput = React.forwardRef(function CustomInput( - props: InputProps, - ref: React.ForwardedRef, -) { - return ; -}); - -export default function UnstyledInputBasic() { - return ; -} diff --git a/docs/data/base/components/input/UnstyledInputIntroduction.js b/docs/data/base/components/input/UnstyledInputIntroduction.js index 72cb1d0add4eb2..a4ac1068eb6c67 100644 --- a/docs/data/base/components/input/UnstyledInputIntroduction.js +++ b/docs/data/base/components/input/UnstyledInputIntroduction.js @@ -2,6 +2,14 @@ import * as React from 'react'; import Input from '@mui/base/Input'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput(props, ref) { + return ; +}); + +export default function UnstyledInputIntroduction() { + return ; +} + const blue = { 100: '#DAECFF', 200: '#b6daff', @@ -52,11 +60,3 @@ const StyledInputElement = styled('input')( } `, ); - -const CustomInput = React.forwardRef(function CustomInput(props, ref) { - return ; -}); - -export default function UnstyledInputIntroduction() { - return ; -} diff --git a/docs/data/base/components/input/UnstyledInputIntroduction.tsx b/docs/data/base/components/input/UnstyledInputIntroduction.tsx index a69ce7d4a30120..5faf387f0a3d09 100644 --- a/docs/data/base/components/input/UnstyledInputIntroduction.tsx +++ b/docs/data/base/components/input/UnstyledInputIntroduction.tsx @@ -2,6 +2,17 @@ import * as React from 'react'; import Input from '@mui/base/Input'; import { styled } from '@mui/system'; +const CustomInput = React.forwardRef(function CustomInput( + props: React.InputHTMLAttributes, + ref: React.ForwardedRef, +) { + return ; +}); + +export default function UnstyledInputIntroduction() { + return ; +} + const blue = { 100: '#DAECFF', 200: '#b6daff', @@ -52,14 +63,3 @@ const StyledInputElement = styled('input')( } `, ); - -const CustomInput = React.forwardRef(function CustomInput( - props: React.InputHTMLAttributes, - ref: React.ForwardedRef, -) { - return ; -}); - -export default function UnstyledInputIntroduction() { - return ; -} diff --git a/docs/data/base/components/input/UseInput.js b/docs/data/base/components/input/UseInput.js index 692fcd899be9c9..1fbc559f906243 100644 --- a/docs/data/base/components/input/UseInput.js +++ b/docs/data/base/components/input/UseInput.js @@ -3,6 +3,25 @@ import useInput from '@mui/base/useInput'; import { styled } from '@mui/system'; import { unstable_useForkRef as useForkRef } from '@mui/utils'; +const CustomInput = React.forwardRef(function CustomInput(props, ref) { + const { getRootProps, getInputProps } = useInput(props); + + const inputProps = getInputProps(); + + // Make sure that both the forwarded ref and the ref returned from the getInputProps are applied on the input element + inputProps.ref = useForkRef(inputProps.ref, ref); + + return ( +
+ +
+ ); +}); + +export default function UseInput() { + return ; +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -53,22 +72,3 @@ const StyledInputElement = styled('input')( } `, ); - -const CustomInput = React.forwardRef(function CustomInput(props, ref) { - const { getRootProps, getInputProps } = useInput(props); - - const inputProps = getInputProps(); - - // Make sure that both the forwarded ref and the ref returned from the getInputProps are applied on the input element - inputProps.ref = useForkRef(inputProps.ref, ref); - - return ( -
- -
- ); -}); - -export default function UseInput() { - return ; -} diff --git a/docs/data/base/components/input/UseInput.tsx b/docs/data/base/components/input/UseInput.tsx index f65a8bf9898950..7159ce62bf5789 100644 --- a/docs/data/base/components/input/UseInput.tsx +++ b/docs/data/base/components/input/UseInput.tsx @@ -3,6 +3,28 @@ import useInput from '@mui/base/useInput'; import { styled } from '@mui/system'; import { unstable_useForkRef as useForkRef } from '@mui/utils'; +const CustomInput = React.forwardRef(function CustomInput( + props: React.InputHTMLAttributes, + ref: React.ForwardedRef, +) { + const { getRootProps, getInputProps } = useInput(props); + + const inputProps = getInputProps(); + + // Make sure that both the forwarded ref and the ref returned from the getInputProps are applied on the input element + inputProps.ref = useForkRef(inputProps.ref, ref); + + return ( +
+ +
+ ); +}); + +export default function UseInput() { + return ; +} + const blue = { 100: '#DAECFF', 200: '#80BFFF', @@ -53,25 +75,3 @@ const StyledInputElement = styled('input')( } `, ); - -const CustomInput = React.forwardRef(function CustomInput( - props: React.InputHTMLAttributes, - ref: React.ForwardedRef, -) { - const { getRootProps, getInputProps } = useInput(props); - - const inputProps = getInputProps(); - - // Make sure that both the forwarded ref and the ref returned from the getInputProps are applied on the input element - inputProps.ref = useForkRef(inputProps.ref, ref); - - return ( -
- -
- ); -}); - -export default function UseInput() { - return ; -}