Skip to content

Commit f9db86d

Browse files
authored
Merge pull request #1176 from ARYANSHAH1567/aryanshah/add_custom_textfield
Add new component to fix the dynamic allocation for label space
2 parents f90645a + 7b6074e commit f9db86d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { TextField } from '../../base/TextField';
2+
import { styled } from '@mui/material/styles';
3+
import type { TextFieldProps } from '../../base/TextField';
4+
5+
export const StyledTextField = styled(TextField)(({ theme }) => ({
6+
'& .MuiOutlinedInput-root': {
7+
backgroundColor: theme.palette.background.paper,
8+
'& fieldset': {
9+
borderColor: 'theme.palette.background.brand.default',
10+
borderWidth: 1,
11+
},
12+
'&:hover fieldset': {
13+
borderColor: 'theme.palette.background.brand.default',
14+
borderWidth: 2,
15+
},
16+
'&.Mui-focused fieldset': {
17+
borderColor: 'theme.palette.background.brand.default',
18+
borderWidth: 2,
19+
borderLeftWidth: 4,
20+
padding: '4px',
21+
},
22+
},
23+
'& .MuiInputLabel-root': {
24+
color: theme.palette.text.secondary,
25+
'&.Mui-focused': {
26+
color: 'theme.palette.background.brand.default',
27+
},
28+
},
29+
'& .MuiInputLabel-asterisk': {
30+
display: 'none',
31+
},
32+
'& .MuiInputBase-input': {
33+
color: theme.palette.common.black,
34+
},
35+
}));
36+
37+
interface CustomTextFieldProps extends Omit<TextFieldProps, 'variant' | 'size'> {
38+
minWidth?: number;
39+
variant?: 'outlined' | 'filled' | 'standard';
40+
size?: 'small' | 'medium';
41+
}
42+
43+
export const CustomTextField = ({
44+
minWidth = 150,
45+
variant = 'outlined',
46+
size = 'small',
47+
...props
48+
}: CustomTextFieldProps): JSX.Element => {
49+
return (
50+
<StyledTextField
51+
variant={variant}
52+
size={size}
53+
sx={{ minWidth }}
54+
{...props}
55+
/>
56+
);
57+
};

src/custom/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export {
6868
export { SetupPreReq } from './SetupPrerequisite';
6969
export { StyledChapter } from './StyledChapter';
7070
export { StyledSearchBar } from './StyledSearchBar';
71+
export { CustomTextField } from './StyledTextField';
7172
export { Terminal } from './Terminal';
7273
export { TOC } from './TOCChapter';
7374
export { TOCLearning } from './TOCLearning';

0 commit comments

Comments
 (0)