-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/fe/refactor/input #1174
Feat/fe/refactor/input #1174
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Stack, Typography, InputAdornment, IconButton } from "@mui/material"; | ||
import { useTheme } from "@mui/material/styles"; | ||
import { useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import VisibilityOff from "@mui/icons-material/VisibilityOff"; | ||
import Visibility from "@mui/icons-material/Visibility"; | ||
export const HttpAdornment = ({ https }) => { | ||
const theme = useTheme(); | ||
return ( | ||
<Stack | ||
direction="row" | ||
alignItems="center" | ||
height="100%" | ||
sx={{ | ||
borderRight: `solid 1px ${theme.palette.border.dark}`, | ||
backgroundColor: theme.palette.background.accent, | ||
pl: theme.spacing(6), | ||
}} | ||
> | ||
<Typography | ||
component="h5" | ||
paddingRight={"var(--env-var-spacing-1-minus)"} | ||
color={theme.palette.text.secondary} | ||
sx={{ lineHeight: 1, opacity: 0.8 }} | ||
> | ||
{https ? "https" : "http"}:// | ||
</Typography> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export const PasswordEndAdornment = ({ fieldType, setFieldType }) => { | ||
const theme = useTheme(); | ||
return ( | ||
<InputAdornment position="end"> | ||
<IconButton | ||
aria-label="toggle password visibility" | ||
onClick={() => setFieldType(fieldType === "password" ? "text" : "password")} | ||
sx={{ | ||
color: theme.palette.border.dark, | ||
padding: theme.spacing(1), | ||
"&:focus-visible": { | ||
outline: `2px solid ${theme.palette.primary.main}`, | ||
outlineOffset: `2px`, | ||
}, | ||
"& .MuiTouchRipple-root": { | ||
pointerEvents: "none", | ||
display: "none", | ||
}, | ||
}} | ||
> | ||
{fieldType === "password" ? <VisibilityOff /> : <Visibility />} | ||
</IconButton> | ||
</InputAdornment> | ||
); | ||
}; | ||
Comment on lines
+32
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Lose yourself in the PropTypes, the moment, you better never let it go! The component is missing PropTypes validation for Add PropTypes: PasswordEndAdornment.propTypes = {
fieldType: PropTypes.oneOf(['password', 'text']).isRequired,
setFieldType: PropTypes.func.isRequired,
}; Optimize with memo: +import { memo } from 'react';
-export const PasswordEndAdornment = ({ fieldType, setFieldType }) => {
+export const PasswordEndAdornment = memo(({ fieldType, setFieldType }) => {
// ... component code ...
-};
+}); |
||
|
||
HttpAdornment.propTypes = { | ||
https: PropTypes.bool.isRequired, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo dawg, you've got an unused import there!
The
useState
import isn't being used in either component. Let's keep our code clean like mom's spaghetti!-import { useState } from "react";
📝 Committable suggestion