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

[docs][base] Move styles to the bottom of demos code for InputUnstyled #36724

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
158 changes: 79 additions & 79 deletions docs/data/base/components/input/InputAdornments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Input
slots={{
root: StyledInputRoot,
input: StyledInputElement,
...slots,
}}
{...other}
ref={ref}
/>
);
});

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 (
<Box sx={{ display: 'flex', '& > * + *': { ml: 1 } }}>
<CustomInput
id="outlined-start-adornment"
startAdornment={<InputAdornment>kg</InputAdornment>}
/>
<CustomInput
id="outlined-adornment-password"
type={values.showPassword ? 'text' : 'password'}
value={values.password}
onChange={handleChange('password')}
endAdornment={
<InputAdornment>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</Box>
);
}

const blue = {
100: '#DAECFF',
200: '#80BFFF',
Expand Down Expand Up @@ -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 (
<Input
slots={{
root: StyledInputRoot,
input: StyledInputElement,
...slots,
}}
{...other}
ref={ref}
/>
);
});

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 (
<Box sx={{ display: 'flex', '& > * + *': { ml: 1 } }}>
<CustomInput
id="outlined-start-adornment"
startAdornment={<InputAdornment>kg</InputAdornment>}
/>
<CustomInput
id="outlined-adornment-password"
type={values.showPassword ? 'text' : 'password'}
value={values.password}
onChange={handleChange('password')}
endAdornment={
<InputAdornment>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</Box>
);
}
156 changes: 78 additions & 78 deletions docs/data/base/components/input/InputAdornments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement>,
) {
const { slots, ...other } = props;
return (
<Input
slots={{
root: StyledInputRoot,
input: StyledInputElement,
...slots,
}}
{...other}
ref={ref}
/>
);
});

interface State {
amount: string;
password: string;
weight: string;
weightRange: string;
showPassword: boolean;
}

export default function InputAdornments() {
const [values, setValues] = React.useState<State>({
amount: '',
password: '',
weight: '',
weightRange: '',
showPassword: false,
});

const handleChange =
(prop: keyof State) => (event: React.ChangeEvent<HTMLInputElement>) => {
setValues({ ...values, [prop]: event.target.value });
};

const handleClickShowPassword = () => {
setValues({
...values,
showPassword: !values.showPassword,
});
};

const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
};

return (
<Box sx={{ display: 'flex', '& > * + *': { ml: 1 } }}>
<CustomInput
id="outlined-start-adornment"
startAdornment={<InputAdornment>kg</InputAdornment>}
/>
<CustomInput
id="outlined-adornment-password"
type={values.showPassword ? 'text' : 'password'}
value={values.password}
onChange={handleChange('password')}
endAdornment={
<InputAdornment>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</Box>
);
}

const blue = {
100: '#DAECFF',
200: '#80BFFF',
Expand Down Expand Up @@ -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<HTMLDivElement>,
) {
const { slots, ...other } = props;
return (
<Input
slots={{
root: StyledInputRoot,
input: StyledInputElement,
...slots,
}}
{...other}
ref={ref}
/>
);
});

interface State {
amount: string;
password: string;
weight: string;
weightRange: string;
showPassword: boolean;
}

export default function InputAdornments() {
const [values, setValues] = React.useState<State>({
amount: '',
password: '',
weight: '',
weightRange: '',
showPassword: false,
});

const handleChange =
(prop: keyof State) => (event: React.ChangeEvent<HTMLInputElement>) => {
setValues({ ...values, [prop]: event.target.value });
};

const handleClickShowPassword = () => {
setValues({
...values,
showPassword: !values.showPassword,
});
};

const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
};

return (
<Box sx={{ display: 'flex', '& > * + *': { ml: 1 } }}>
<CustomInput
id="outlined-start-adornment"
startAdornment={<InputAdornment>kg</InputAdornment>}
/>
<CustomInput
id="outlined-adornment-password"
type={values.showPassword ? 'text' : 'password'}
value={values.password}
onChange={handleChange('password')}
endAdornment={
<InputAdornment>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</Box>
);
}
32 changes: 16 additions & 16 deletions docs/data/base/components/input/InputMultiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Input
slots={{ input: StyledInputElement, textarea: StyledTextareaElement }}
{...props}
ref={ref}
/>
);
});

export default function InputMultiline() {
return (
<CustomInput aria-label="Demo input" multiline placeholder="Type something…" />
);
}

const blue = {
100: '#DAECFF',
200: '#80BFFF',
Expand Down Expand Up @@ -85,19 +101,3 @@ const StyledTextareaElement = styled('textarea', {
}
`,
);

const CustomInput = React.forwardRef(function CustomInput(props, ref) {
return (
<Input
slots={{ input: StyledInputElement, textarea: StyledTextareaElement }}
{...props}
ref={ref}
/>
);
});

export default function UnstyledInputBasic() {
return (
<CustomInput aria-label="Demo input" multiline placeholder="Type something…" />
);
}
Loading