Skip to content

Commit

Permalink
Redesign Error Inputs (#506)
Browse files Browse the repository at this point in the history
Design error state of form fields
  • Loading branch information
Matushl authored Dec 14, 2024
1 parent bfa065a commit 0ce47df
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/components/FormItems/FormAutocomplete/FormAutocomplete.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Autocomplete, TextField, TextFieldProps} from '@mui/material'
import {Autocomplete, TextField, TextFieldProps, Typography} from '@mui/material'
import {Controller, ControllerProps, FieldPath, FieldValues} from 'react-hook-form'

import {SelectOption} from '../FormSelect/FormSelect'
Expand Down Expand Up @@ -44,7 +44,14 @@ export const FormAutocomplete = <
label={label}
variant="outlined"
fullWidth
helperText={error?.message}
error={!!error}
helperText={
error && (
<Typography variant="body2" fontWeight={800}>
{error.message}
</Typography>
)
}
focused={false}
/>
)}
Expand Down
10 changes: 8 additions & 2 deletions src/components/FormItems/FormCheckbox/FormCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Checkbox, CheckboxProps, FormControl, FormControlLabel, FormHelperText} from '@mui/material'
import {Checkbox, CheckboxProps, FormControl, FormControlLabel, FormHelperText, Typography} from '@mui/material'
import {Controller, ControllerProps, FieldPath, FieldValues} from 'react-hook-form'

import {formItemStyle} from '../styles'
Expand Down Expand Up @@ -27,7 +27,13 @@ export const FormCheckbox = <
label={label}
disabled={disabled}
/>
<FormHelperText>{error?.message}</FormHelperText>
{error && (
<FormHelperText>
<Typography variant="body2" fontWeight={800}>
{error.message}
</Typography>
</FormHelperText>
)}
</FormControl>
)}
/>
Expand Down
11 changes: 9 additions & 2 deletions src/components/FormItems/FormInput/FormInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TextField, TextFieldProps} from '@mui/material'
import {TextField, TextFieldProps, Typography} from '@mui/material'
import {Controller, ControllerProps, FieldPath, FieldValues} from 'react-hook-form'

import {formItemStyle} from '../styles'
Expand Down Expand Up @@ -29,7 +29,14 @@ export const FormInput = <
type={type}
variant="outlined"
fullWidth
helperText={error?.message}
error={!!error}
helperText={
error && (
<Typography variant="body2" fontWeight={800}>
{error.message}
</Typography>
)
}
focused={false}
sx={formItemStyle}
{...props}
Expand Down
11 changes: 9 additions & 2 deletions src/components/FormItems/FormSelect/FormSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MenuItem, TextField, TextFieldProps} from '@mui/material'
import {MenuItem, TextField, TextFieldProps, Typography} from '@mui/material'
import {Controller, ControllerProps, FieldPath, FieldValues} from 'react-hook-form'

import {formItemStyle} from '../styles'
Expand Down Expand Up @@ -33,7 +33,14 @@ export const FormSelect = <
variant="outlined"
label={label}
fullWidth
helperText={error?.message}
error={!!error}
helperText={
error && (
<Typography variant="body2" fontWeight={800}>
{error.message}
</Typography>
)
}
focused={false}
sx={formItemStyle}
>
Expand Down
37 changes: 32 additions & 5 deletions src/components/FormItems/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
export const formItemStyle = {
'.MuiFormHelperText-contained': {color: 'black !important', fontWeight: 'bold', textTransform: 'uppercase'},
'.MuiInputLabel-root.MuiInputLabel-shrink': {color: 'black', fontWeight: 'bold'},
'.MuiInputLabel-root.MuiInputLabel-shrink.Mui-disabled': {color: 'rgba(0, 0, 0, 0.38)'},
'.MuiOutlinedInput-root': {borderRadius: 0},
'.MuiOutlinedInput-notchedOutline': {borderWidth: '5px', borderColor: 'black', fontWeight: 'bold'},
'.MuiFormHelperText-contained': {
color: 'black !important',
textTransform: 'uppercase',
},
'.MuiInputLabel-root.Mui-error': {
color: 'white',
},
'.MuiInputLabel-root.MuiInputLabel-shrink': {
color: 'black',
fontWeight: 'bold',
background: 'white',
padding: '0 10px 0 5px',
marginLeft: '-1px',
},
'.MuiInputLabel-root.MuiInputLabel-shrink.Mui-disabled': {
color: 'rgba(0, 0, 0, 0.38)',
},
'.MuiOutlinedInput-root': {
borderRadius: 0,
},
'.MuiOutlinedInput-root.Mui-error': {
color: 'white',
background: 'black',
},
'.MuiOutlinedInput-root.Mui-error .MuiOutlinedInput-notchedOutline': {
borderColor: 'black',
},
'.MuiOutlinedInput-notchedOutline': {
borderWidth: '5px',
borderColor: 'black',
fontWeight: 'bold',
},
}
2 changes: 1 addition & 1 deletion src/components/RegisterForm/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const RegisterForm: FC = () => {
<SchoolSubForm control={control} watch={watch} setValue={setValue} gap={2} />
<FormInput control={control} name="phone" label="telefón v tvare +421 ..." rules={phoneRule} />
<FormInput control={control} name="parent_phone" label="telefón na rodiča" rules={phoneRule} />
<Typography variant="body2" fontWeight={800}>
<Typography variant="body2" fontWeight={800} mx={2} sx={{textTransform: 'uppercase'}}>
* takto označené polia sú povinné
</Typography>
<Typography variant="body2">
Expand Down

0 comments on commit 0ce47df

Please sign in to comment.