Merge branch 'refactor/button-input-styling' into feat/account-team-modals
This commit is contained in:
commit
a6204b7bf5
4 files changed
+70
-38
No files matched your search
@@ -1,19 +1,43 @@
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import type { ButtonProps } from "@mui/material/Button";
|
import type { ButtonProps } from "@mui/material/Button";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme, darken } from "@mui/material/styles";
|
||||||
|
import { HOVER } from "@/Utils/Theme/constants";
|
||||||
|
|
||||||
|
const PALETTE_COLORS = [
|
||||||
|
"primary",
|
||||||
|
"secondary",
|
||||||
|
"error",
|
||||||
|
"warning",
|
||||||
|
"info",
|
||||||
|
"success",
|
||||||
|
] as const;
|
||||||
|
type PaletteColor = (typeof PALETTE_COLORS)[number];
|
||||||
|
|
||||||
export const ButtonInput = ({ sx, ...props }: ButtonProps) => {
|
export const ButtonInput = ({ sx, ...props }: ButtonProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const outlinedSx =
|
|
||||||
|
const hoverOverrides: Record<string, unknown> = { boxShadow: "none" };
|
||||||
|
|
||||||
|
if (props.variant === "outlined") {
|
||||||
|
hoverOverrides.borderColor = theme.palette.text.secondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.variant === "contained") {
|
||||||
|
const colorKey = (props.color ?? "primary") as PaletteColor;
|
||||||
|
const palette = theme.palette[colorKey];
|
||||||
|
if (palette && typeof palette === "object" && "main" in palette) {
|
||||||
|
hoverOverrides.backgroundColor = darken(palette.main, HOVER.DARKEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const variantSx =
|
||||||
props.variant === "outlined"
|
props.variant === "outlined"
|
||||||
? {
|
? {
|
||||||
color: theme.palette.text.primary,
|
color: theme.palette.text.primary,
|
||||||
borderColor: theme.palette.divider,
|
borderColor: theme.palette.divider,
|
||||||
"&:hover": {
|
|
||||||
borderColor: theme.palette.text.secondary,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
: {};
|
: {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
{...props}
|
{...props}
|
||||||
@@ -26,10 +50,8 @@ export const ButtonInput = ({ sx, ...props }: ButtonProps) => {
|
|||||||
textOverflow: "ellipsis",
|
textOverflow: "ellipsis",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
boxShadow: "none",
|
boxShadow: "none",
|
||||||
"&:hover": {
|
"&:hover": hoverOverrides,
|
||||||
boxShadow: "none",
|
...variantSx,
|
||||||
},
|
|
||||||
...outlinedSx,
|
|
||||||
...sx,
|
...sx,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ export const FieldLabel = ({ children, required = false, htmlFor }: FieldLabelPr
|
|||||||
return (
|
return (
|
||||||
<Typography
|
<Typography
|
||||||
component="label"
|
component="label"
|
||||||
|
variant="body1"
|
||||||
htmlFor={htmlFor}
|
htmlFor={htmlFor}
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: "14px",
|
|
||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
color: theme.palette.text.secondary,
|
color: theme.palette.text.secondary,
|
||||||
marginBottom: theme.spacing(2),
|
marginBottom: theme.spacing(2),
|
||||||
|
|||||||
@@ -12,47 +12,53 @@ interface TextInputProps extends Omit<TextFieldProps, "label"> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(function TextInput(
|
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(function TextInput(
|
||||||
{ fieldLabel, required, ...props },
|
{ fieldLabel, required, sx, ...props },
|
||||||
ref
|
ref
|
||||||
) {
|
) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const innerSx = {
|
||||||
|
width: "100%",
|
||||||
|
"& .MuiOutlinedInput-root": {
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
height: 34,
|
||||||
|
fontSize: typographyLevels.base,
|
||||||
|
overflow: "hidden",
|
||||||
|
},
|
||||||
|
"& .MuiOutlinedInput-notchedOutline": {
|
||||||
|
borderColor: theme.palette.divider,
|
||||||
|
},
|
||||||
|
"&:hover .MuiOutlinedInput-notchedOutline": {
|
||||||
|
borderColor: theme.palette.divider,
|
||||||
|
},
|
||||||
|
"& .MuiFormHelperText-root": {
|
||||||
|
marginLeft: 0,
|
||||||
|
marginRight: 0,
|
||||||
|
marginTop: theme.spacing(1),
|
||||||
|
},
|
||||||
|
"& input:-webkit-autofill, & input:-webkit-autofill:hover, & input:-webkit-autofill:focus, & input:-webkit-autofill:active":
|
||||||
|
{
|
||||||
|
WebkitBoxShadow: `0 0 0 100px ${theme.palette.background.default} inset !important`,
|
||||||
|
WebkitTextFillColor: `${theme.palette.text.primary} !important`,
|
||||||
|
caretColor: theme.palette.text.primary,
|
||||||
|
transition: "background-color 5000s ease-in-out 0s",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const input = (
|
const input = (
|
||||||
<TextField
|
<TextField
|
||||||
{...props}
|
{...props}
|
||||||
inputRef={ref}
|
inputRef={ref}
|
||||||
sx={{
|
sx={fieldLabel ? innerSx : { ...innerSx, ...sx }}
|
||||||
"& .MuiOutlinedInput-root": {
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
height: 34,
|
|
||||||
fontSize: typographyLevels.base,
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
"& .MuiOutlinedInput-notchedOutline": {
|
|
||||||
borderColor: theme.palette.divider,
|
|
||||||
},
|
|
||||||
"&:hover .MuiOutlinedInput-notchedOutline": {
|
|
||||||
borderColor: theme.palette.divider,
|
|
||||||
},
|
|
||||||
"& .MuiFormHelperText-root": {
|
|
||||||
marginLeft: 0,
|
|
||||||
marginRight: 0,
|
|
||||||
marginTop: theme.spacing(1),
|
|
||||||
},
|
|
||||||
"& input:-webkit-autofill, & input:-webkit-autofill:hover, & input:-webkit-autofill:focus, & input:-webkit-autofill:active":
|
|
||||||
{
|
|
||||||
WebkitBoxShadow: `0 0 0 100px ${theme.palette.background.default} inset !important`,
|
|
||||||
WebkitTextFillColor: `${theme.palette.text.primary} !important`,
|
|
||||||
caretColor: theme.palette.text.primary,
|
|
||||||
transition: "background-color 5000s ease-in-out 0s",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fieldLabel) {
|
if (fieldLabel) {
|
||||||
return (
|
return (
|
||||||
<Stack spacing={theme.spacing(2)}>
|
<Stack
|
||||||
|
spacing={theme.spacing(2)}
|
||||||
|
sx={sx}
|
||||||
|
>
|
||||||
<FieldLabel required={required}>{fieldLabel}</FieldLabel>
|
<FieldLabel required={required}>{fieldLabel}</FieldLabel>
|
||||||
{input}
|
{input}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -15,3 +15,7 @@ export const LAYOUT = {
|
|||||||
XL: 12,
|
XL: 12,
|
||||||
XXL: 16,
|
XXL: 16,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const HOVER = {
|
||||||
|
DARKEN: 0.06,
|
||||||
|
} as const;
|
||||||
Reference in new issue
Block a user