Files
react-test/docs/data/material/components/text-fields/CustomizedInputsStyled.tsx
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

151 lines
3.8 KiB
TypeScript

import { alpha, styled } from '@mui/material/styles';
import InputBase from '@mui/material/InputBase';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import TextField, { TextFieldProps } from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
import { OutlinedInputProps } from '@mui/material/OutlinedInput';
const CssTextField = styled(TextField)({
'& label.Mui-focused': {
color: '#A0AAB4',
},
'& .MuiInput-underline:after': {
borderBottomColor: '#B2BAC2',
},
'& .MuiOutlinedInput-root': {
'& fieldset': {
borderColor: '#E0E3E7',
},
'&:hover fieldset': {
borderColor: '#B2BAC2',
},
'&.Mui-focused fieldset': {
borderColor: '#6F7E8C',
},
},
});
const BootstrapInput = styled(InputBase)(({ theme }) => ({
'label + &': {
marginTop: theme.spacing(3),
},
'& .MuiInputBase-input': {
borderRadius: 4,
position: 'relative',
backgroundColor: '#F3F6F9',
border: '1px solid',
borderColor: '#E0E3E7',
fontSize: 16,
width: 'auto',
padding: '10px 12px',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
// Use the system font instead of the default Roboto font.
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:focus': {
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
borderColor: theme.palette.primary.main,
},
...theme.applyStyles('dark', {
backgroundColor: '#1A2027',
borderColor: '#2D3843',
}),
},
}));
const RedditTextField = styled((props: TextFieldProps) => (
<TextField
slotProps={{
input: { disableUnderline: true } as Partial<OutlinedInputProps>,
}}
{...props}
/>
))(({ theme }) => ({
'& .MuiFilledInput-root': {
overflow: 'hidden',
borderRadius: 4,
border: '1px solid',
backgroundColor: '#F3F6F9',
borderColor: '#E0E3E7',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
'&:hover': {
backgroundColor: 'transparent',
},
'&.Mui-focused': {
backgroundColor: 'transparent',
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 2px`,
borderColor: theme.palette.primary.main,
},
...theme.applyStyles('dark', {
backgroundColor: '#1A2027',
borderColor: '#2D3843',
}),
},
}));
const ValidationTextField = styled(TextField)({
'& input:valid + fieldset': {
borderColor: '#E0E3E7',
borderWidth: 1,
},
'& input:invalid + fieldset': {
borderColor: 'red',
borderWidth: 1,
},
'& input:valid:focus + fieldset': {
borderLeftWidth: 4,
padding: '4px !important', // override inline-style
},
});
export default function CustomizedInputsStyled() {
return (
<Box
component="form"
noValidate
sx={{ display: 'grid', gridTemplateColumns: { sm: '1fr 1fr' }, gap: 2 }}
>
<FormControl variant="standard">
<InputLabel shrink htmlFor="bootstrap-input">
Bootstrap
</InputLabel>
<BootstrapInput defaultValue="react-bootstrap" id="bootstrap-input" />
</FormControl>
<RedditTextField
label="Reddit"
defaultValue="react-reddit"
id="reddit-input"
variant="filled"
style={{ marginTop: 11 }}
/>
<CssTextField label="Custom CSS" id="custom-css-outlined-input" />
<ValidationTextField
label="CSS validation style"
required
variant="outlined"
defaultValue="Success"
id="validation-outlined-input"
/>
</Box>
);
}