fix create more specific component

This commit is contained in:
karenvicent committed 2025-10-14 12:22:20 -04:00
1 parent b9afca3608
commit 104cf194ac
1 file changed
+31 -24
+31 -24
View File
@@ -1,34 +1,16 @@
import { Typography, Select } from "@mui/material"; import { Typography, Select } from "@mui/material";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";
import { forwardRef } from "react";
import type { SelectProps } from "@mui/material/Select"; import type { SelectProps } from "@mui/material/Select";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"; import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
type ItemId = string | number;
interface SelectItem {
_id: ItemId;
name: string;
}
export type CustomSelectProps = SelectProps<ItemId> & {
items: SelectItem[];
placeholder?: string;
isHidden?: boolean;
hasError?: boolean;
};
export const SelectInput = forwardRef<HTMLDivElement, CustomSelectProps>( export const SelectInput: React.FC<SelectProps> = ({ ...props }) => {
function SelectInput(
{ items, placeholder, isHidden = false, hasError = false, ...props },
ref
) {
const theme = useTheme(); const theme = useTheme();
return ( return (
<Select <Select
{...props}
sx={{ sx={{
height: "34px", height: "34px",
"& .MuiSelect-select": {
padding: "0",
},
"& .MuiOutlinedInput-notchedOutline": { "& .MuiOutlinedInput-notchedOutline": {
borderRadius: theme.shape.borderRadius, borderRadius: theme.shape.borderRadius,
borderColor: theme.palette.primary.lowContrast, borderColor: theme.palette.primary.lowContrast,
@@ -37,8 +19,32 @@ export const SelectInput = forwardRef<HTMLDivElement, CustomSelectProps>(
borderColor: theme.palette.primary.lowContrast, borderColor: theme.palette.primary.lowContrast,
}, },
}} }}
/>
);
};
type ItemTypes = string | number;
interface SelectItem {
_id: ItemTypes;
name: string;
}
export type CustomSelectProps = SelectProps & {
items: SelectItem[];
placeholder?: string;
isHidden?: boolean;
hasError?: boolean;
};
export const SelectFromItems: React.FC<CustomSelectProps> = ({
items,
placeholder,
isHidden = false,
hasError = false,
...props
}) => {
return (
<SelectInput
error={hasError} error={hasError}
ref={ref}
IconComponent={KeyboardArrowDownIcon} IconComponent={KeyboardArrowDownIcon}
displayEmpty displayEmpty
MenuProps={{ disableScrollLock: true }} MenuProps={{ disableScrollLock: true }}
@@ -74,8 +80,9 @@ export const SelectInput = forwardRef<HTMLDivElement, CustomSelectProps>(
{item.name} {item.name}
</MenuItem> </MenuItem>
))} ))}
</Select> </SelectInput>
);
}
); );
};
SelectInput.displayName = "SelectInput"; SelectInput.displayName = "SelectInput";
SelectFromItems.displayName = "SelectFromItems";