-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
21 changed files
with
578 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Typography } from "@mui/material"; | ||
|
||
import { FormHelpfulTextProps } from "./types"; | ||
|
||
export const FormHelpfulText = ({ | ||
helpfulText, | ||
helpfulTextStyle, | ||
}: FormHelpfulTextProps) => { | ||
return ( | ||
helpfulText && ( | ||
<Typography | ||
color="#9792B5" | ||
data-testid={`${helpfulText.replace(/\s+/g, "-").toLowerCase()}-error`} | ||
fontSize={12} | ||
fontWeight={400} | ||
sx={{ mt: 0.5 }} | ||
{...helpfulTextStyle} | ||
> | ||
{helpfulText} | ||
</Typography> | ||
) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { InfoTextProps, Typography } from "."; | ||
|
||
export const InfoText = ({ label, sx }: InfoTextProps) => { | ||
return ( | ||
<Typography color="#FF833B" sx={sx} variant="body1"> | ||
{label.toLocaleUpperCase()} | ||
</Typography> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { forwardRef, useCallback, useImperativeHandle, useRef } from "react"; | ||
import { TextareaAutosize, styled } from "@mui/material"; | ||
|
||
import { useScreenDimension } from "@hooks"; | ||
|
||
import { TextAreaProps } from "./types"; | ||
|
||
const TextAreaBase = styled(TextareaAutosize)( | ||
() => ` | ||
font-family: "Poppins"; | ||
font-size: 16px; | ||
font-weight: 400; | ||
::placeholder { | ||
font-family: "Poppins"; | ||
font-size: 16px; | ||
font-weight: 400; | ||
color: #a6a6a6; | ||
} | ||
` | ||
); | ||
|
||
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>( | ||
({ errorMessage, maxLength = 500, onBlur, onFocus, ...props }, ref) => { | ||
const { isMobile } = useScreenDimension(); | ||
const textAraeRef = useRef<HTMLTextAreaElement>(null); | ||
|
||
const handleFocus = useCallback( | ||
(e: React.FocusEvent<HTMLTextAreaElement>) => { | ||
onFocus?.(e); | ||
textAraeRef.current?.focus(); | ||
}, | ||
[] | ||
); | ||
|
||
const handleBlur = useCallback( | ||
(e: React.FocusEvent<HTMLTextAreaElement>) => { | ||
onBlur?.(e); | ||
textAraeRef.current?.blur(); | ||
}, | ||
[] | ||
); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => | ||
({ | ||
focus: handleFocus, | ||
blur: handleBlur, | ||
...textAraeRef.current, | ||
} as unknown as HTMLTextAreaElement), | ||
[handleBlur, handleFocus] | ||
); | ||
|
||
return ( | ||
<TextAreaBase | ||
style={{ | ||
border: `1px solid ${errorMessage ? "red" : "#6F99FF"}`, | ||
borderRadius: "24px", | ||
height: isMobile ? "104px" : "128px", | ||
outline: "none", | ||
padding: "12px 14px", | ||
resize: "none", | ||
}} | ||
maxLength={maxLength} | ||
ref={textAraeRef} | ||
{...props} | ||
/> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
govtool/frontend/src/components/molecules/Field/TextArea.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { Box } from "@mui/material"; | ||
|
||
import { | ||
FormErrorMessage, | ||
FormHelpfulText, | ||
TextArea as TextAreaBase, | ||
Typography, | ||
} from "@atoms"; | ||
|
||
import { TextAreaFieldProps } from "./types"; | ||
import { forwardRef, useCallback, useImperativeHandle, useRef } from "react"; | ||
|
||
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaFieldProps>( | ||
( | ||
{ | ||
errorMessage, | ||
errorStyles, | ||
helpfulText, | ||
helpfulTextStyle, | ||
label, | ||
labelStyles, | ||
layoutStyles, | ||
maxLength = 500, | ||
onBlur, | ||
onFocus, | ||
...props | ||
}, | ||
ref | ||
) => { | ||
const textAreaRef = useRef<HTMLTextAreaElement>(null); | ||
|
||
const handleFocus = useCallback( | ||
(e: React.FocusEvent<HTMLTextAreaElement>) => { | ||
onFocus?.(e); | ||
textAreaRef.current?.focus(); | ||
}, | ||
[] | ||
); | ||
|
||
const handleBlur = useCallback( | ||
(e: React.FocusEvent<HTMLTextAreaElement>) => { | ||
onBlur?.(e); | ||
textAreaRef.current?.blur(); | ||
}, | ||
[] | ||
); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => | ||
({ | ||
focus: handleFocus, | ||
blur: handleBlur, | ||
...textAreaRef.current, | ||
} as unknown as HTMLTextAreaElement), | ||
[handleBlur, handleFocus] | ||
); | ||
return ( | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
width: "100%", | ||
position: "relative", | ||
...layoutStyles, | ||
}} | ||
> | ||
{label && ( | ||
<Typography | ||
fontWeight={400} | ||
sx={{ mb: 0.5 }} | ||
variant="body2" | ||
{...labelStyles} | ||
> | ||
{label} | ||
</Typography> | ||
)} | ||
<TextAreaBase maxLength={maxLength} {...props} ref={textAreaRef} /> | ||
<FormHelpfulText | ||
helpfulText={helpfulText} | ||
helpfulTextStyle={helpfulTextStyle} | ||
/> | ||
<FormErrorMessage | ||
errorMessage={errorMessage} | ||
errorStyles={errorStyles} | ||
/> | ||
<Typography | ||
color="#8E908E" | ||
sx={{ bottom: 35, position: "absolute", right: 15 }} | ||
variant="caption" | ||
> | ||
{props?.value?.toString()?.length ?? 0}/{maxLength} | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.