Skip to content
Open
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
17 changes: 16 additions & 1 deletion src/components/fields/SQFormDropdown/SQFormDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type SQFormDropdownProps = BaseFieldProps & {
children: SQFormOption[];
/** Whether to display empty option - - in options */
displayEmpty?: boolean;
/** Used to display informational Text under the input field same like warning text */
informationalText?: string;
/** Disabled property to disable the input if true */
isDisabled?: boolean;
/** Whether or not to show the helper text */
Expand Down Expand Up @@ -62,6 +64,7 @@ function SQFormDropdown({
onChange,
size = 'auto',
muiFieldProps = {},
informationalText = '',
}: SQFormDropdownProps): React.ReactElement {
const {
formikField: {field},
Expand All @@ -71,6 +74,7 @@ function SQFormDropdown({
name,
onBlur,
onChange,
informationalText,
});
const labelID = label.toLowerCase();

Expand Down Expand Up @@ -162,7 +166,18 @@ function SQFormDropdown({
})}
</Select>
{!isDisabled && displayHelperText && (
<FormHelperText>{HelperTextComponent}</FormHelperText>
<FormHelperText
sx={{
'&.MuiFormHelperText-root': {
color: 'var(--color-slate)',
},
'&.Mui-focused': {
color: 'var(--color-textInfoBlue)',
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does the text field need the orange color added to error and dropdown does not?

}}
>
{HelperTextComponent}
</FormHelperText>
)}
</FormControl>
</Grid>
Expand Down
21 changes: 20 additions & 1 deletion src/components/fields/SQFormTextField/SQFormTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type SQFormTextFieldProps = BaseFieldProps & {
isDisabled?: boolean;
/** Whether or not to show the helper text */
displayHelperText?: boolean;
/** Used to display informational Text under the input field same like warning text */
informationalText?: string;
/** Custom onBlur event callback */
onBlur?: TextFieldProps['onBlur'];
/** Custom onChange event callback */
Expand Down Expand Up @@ -45,6 +47,7 @@ function SQFormTextField({
startAdornment,
endAdornment,
type = 'text',
informationalText = '',
InputProps,
inputProps = {},
maxCharacters,
Expand All @@ -62,6 +65,7 @@ function SQFormTextField({
name,
onBlur,
onChange,
informationalText,
});

const [valueLength, setValueLength] = React.useState(() => {
Expand Down Expand Up @@ -113,7 +117,22 @@ function SQFormTextField({
maxLength: maxCharacters,
...inputProps,
}}
FormHelperTextProps={{error: isFieldError}}
FormHelperTextProps={{
error: isFieldError,
sx: {
'&.MuiFormHelperText-root': {
color: 'var(--color-slate)',
},
'&.Mui-focused': {
color: !isFieldRequired
? 'var(--color-textInfoBlue)'
: 'var(--color-slate)',
},
'&.Mui-error': {
color: 'var(--color-spanishOrange)',
},
},
}}
name={name}
type={type}
label={labelText}
Expand Down
26 changes: 25 additions & 1 deletion src/hooks/useForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Typography} from '@mui/material';
import {
NewReleases as WarningIcon,
VerifiedUser as VerifiedIcon,
Info as InfoIcon,
} from '@mui/icons-material';
import type {Theme} from '@mui/material';
import type {FieldHelperProps, FieldInputProps, FieldMetaProps} from 'formik';
Expand All @@ -16,6 +17,7 @@ type ChangeHandler<TChangeEvent> = (

type UseFormParam<TChangeEvent> = {
name: string;
informationalText?: string;
onBlur?: React.FocusEventHandler;
onChange?: ChangeHandler<TChangeEvent>;
};
Expand Down Expand Up @@ -91,6 +93,7 @@ export function useForm<TValue, TChangeEvent>({
name,
onBlur,
onChange,
informationalText,
}: UseFormParam<TChangeEvent>): UseFormReturn<TValue, TChangeEvent> {
_handleError(name);

Expand Down Expand Up @@ -119,6 +122,7 @@ export function useForm<TValue, TChangeEvent>({
const isFieldRequired = getFieldStatus() === 'REQUIRED';
const isFieldError = getFieldStatus() === 'ERROR';
const isFulfilled = getFieldStatus() === 'USER_FULFILLED';
const isFieldInfo = getFieldStatus() === 'FULFILLED';

const handleChange: ChangeHandler<TChangeEvent> = React.useCallback(
(event) => {
Expand Down Expand Up @@ -170,8 +174,28 @@ export function useForm<TValue, TChangeEvent>({
/>
);
}
if (isFieldInfo && informationalText) {
return (
<>
<InfoIcon sx={SUCCESS_ICON_STYLES} />
<Typography
component="span"
sx={(theme: Theme) => theme.typography.helper}
>
{informationalText}
</Typography>
</>
);
}
return ' '; // return something so UI space always exists
}, [isFieldError, isFieldRequired, isFulfilled, errorMessage]);
}, [
isFieldError,
isFieldRequired,
isFulfilled,
isFieldInfo,
informationalText,
errorMessage,
]);

return {
formikField: {field, meta, helpers},
Expand Down
6 changes: 6 additions & 0 deletions stories/SQFormDropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ WithValidation.parameters = {
controls: {exclude: 'schema'},
};

export const WithInformationalText = Template.bind({});
WithInformationalText.args = {
...defaultArgs,
informationalText: 'Helper Text Here',
};

export default meta;
6 changes: 6 additions & 0 deletions stories/SQFormTextField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ WithValidation.args = {
WithValidation.parameters = {
controls: {exclude: 'schema'},
};

export const WithInformationalText = Template.bind({});
WithInformationalText.args = {
...defaultArgs,
informationalText: 'Helper Text Here',
};