Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | 8x 8x 8x 3x 3x 3x 3x 3x 8x 32x 3x 8x 3x 195x 32x | import { Box, BoxProps } from "@mui/material";
import { GiveInput } from "@shared/GiveInputs/GiveInput";
import GiveText from "@shared/Text/GiveText";
import { styled } from "@theme/v2/Provider";
import { Dispatch, SetStateAction, useState } from "react";
import { selectUser } from "@redux/slices/auth/auth";
import { useAppSelector } from "@redux/hooks";
import {
SIGNATURE_FONTS,
generateSignatureFile,
type SignatureFontName,
} from "./generateSignature";
interface Props {
setFileToUpload: Dispatch<SetStateAction<File | null>>;
}
function Generate({ setFileToUpload }: Props) {
const { globalName } = useAppSelector(selectUser);
const [values, setValues] = useState<{
textValue: string;
fontId: null | number;
}>({
textValue: `${globalName.firstName} ${globalName.lastName}`.trim(),
fontId: null,
});
const onHandleSelect = async (fontId: number) => {
const font = SIGNATURE_FONTS.find((f) => f.id === fontId)?.name;
Iif (!font) return;
const file = await generateSignatureFile(values.textValue, font);
setValues((prev) => ({
...prev,
fontId: fontId,
}));
setFileToUpload(file);
};
return (
<Box mt="16px">
<GiveInput
value={values.textValue}
onChange={(e) =>
setValues((p) => ({ ...p, textValue: e.target.value }))
}
label="Full Name"
name="Full"
/>
<SuggestionsContainer>
{SIGNATURE_FONTS.map((font) => (
<Suggestion
key={font.id}
sx={{
fontFamily: font.name,
}}
disabled={!values.textValue}
onClick={() => onHandleSelect(font.id)}
selected={font.id === values.fontId}
data-testid={`generate-suggestion-${font.name}`}
>
<GiveText
variant="bodyL"
color="primary"
sx={{ userSelect: "none", wordBreak: "break-all" }}
>
{values.textValue}
</GiveText>
</Suggestion>
))}
</SuggestionsContainer>
</Box>
);
}
export default Generate;
const SuggestionsContainer = styled(Box)(({ theme }) => ({
display: "flex",
gap: "16px",
marginTop: "16px",
[theme.breakpoints.down("sm")]: {
flexDirection: "column",
},
}));
const Suggestion = styled(Box, {
shouldForwardProp: (prop) => prop !== "selected" && prop !== "disabled",
})<BoxProps & { selected: boolean; disabled?: boolean }>(
({ selected, disabled, theme }) => ({
display: "flex",
alignItems: "center",
justifyContent: "center",
padding: "12px",
borderRadius: "6px",
background: theme.palette.surface?.secondary,
minHeight: "108px",
flex: 1,
cursor: disabled ? "default" : "pointer",
...(selected && {
border: `2px solid ${theme.palette.primitive?.blue[100]}`,
}),
...(disabled && { pointerEvents: "none", opacity: 0.7 }),
}),
);
|