remove chip, add coloredlabel, add render options to autocomplete

This commit is contained in:
Alex Holliday committed 2026-05-20 11:36:03 -07:00
1 parent b981427d8d
commit 67bba1479c
3 files changed
+12 -39

No files matched your search

@@ -1,30 +0,0 @@
import MuiChip from "@mui/material/Chip";
import Typography from "@mui/material/Typography";
import { useTheme } from "@mui/material";
interface ChipProps {
text: string;
color?: string;
}
export const Chip = ({ text, color }: ChipProps) => {
const theme = useTheme();
const textColor = color
? theme.palette.getContrastText(color)
: theme.palette.text.primary;
return (
<MuiChip
size="small"
label={
<Typography
variant="body2"
color={textColor}
>
{text}
</Typography>
}
sx={{
backgroundColor: color,
}}
/>
);
};
@@ -100,10 +100,7 @@ export const ColoredLabel = ({ text, color }: { text: string; color: string }) =
return ( return (
<BaseBox <BaseBox
sx={{ sx={{
display: "inline-flex", width: "fit-content",
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
padding: theme.spacing(1, 3), padding: theme.spacing(1, 3),
color: color, color: color,
borderColor: color, borderColor: color,
+11 -5
View File
@@ -14,17 +14,19 @@ type AutoCompleteInputProps = Omit<
renderInput?: AutocompleteProps<any, boolean, boolean, boolean>["renderInput"]; renderInput?: AutocompleteProps<any, boolean, boolean, boolean>["renderInput"];
fieldLabel?: string; fieldLabel?: string;
required?: boolean; required?: boolean;
renderOptionContent?: (option: any) => React.ReactNode;
}; };
export const AutoCompleteInput = ({ export const AutoCompleteInput = ({
fieldLabel, fieldLabel,
required, required,
renderInput, renderInput,
renderOptionContent,
...props ...props
}: AutoCompleteInputProps) => { }: AutoCompleteInputProps) => {
const theme = useTheme(); const theme = useTheme();
const multiple = props.multiple; const multiple = props.multiple;
const { renderOption: customRenderOption, ...autocompleteProps } = props;
const defaultRenderInput = (params: any) => ( const defaultRenderInput = (params: any) => (
<TextField <TextField
{...params} {...params}
@@ -34,7 +36,7 @@ export const AutoCompleteInput = ({
const autocomplete = ( const autocomplete = (
<Autocomplete <Autocomplete
{...props} {...autocompleteProps}
disableCloseOnSelect={!!multiple} disableCloseOnSelect={!!multiple}
popupIcon={ popupIcon={
<ChevronDown <ChevronDown
@@ -46,7 +48,9 @@ export const AutoCompleteInput = ({
renderInput={renderInput || defaultRenderInput} renderInput={renderInput || defaultRenderInput}
getOptionKey={(option) => option.id} getOptionKey={(option) => option.id}
renderTags={() => null} renderTags={() => null}
renderOption={(props, option, { selected }) => { renderOption={
customRenderOption ||
((props, option, { selected }) => {
const { key, ...optionProps } = props; const { key, ...optionProps } = props;
return ( return (
<ListItem <ListItem
@@ -57,13 +61,15 @@ export const AutoCompleteInput = ({
direction={"row"} direction={"row"}
alignItems={"center"} alignItems={"center"}
gap={theme.spacing(2)} gap={theme.spacing(2)}
width="100%"
> >
{multiple && <Checkbox checked={selected} />} {multiple && <Checkbox checked={selected} />}
{option.name} {renderOptionContent ? renderOptionContent(option) : option.name}
</Stack> </Stack>
</ListItem> </ListItem>
); );
}} })
}
sx={{ sx={{
"&.MuiAutocomplete-root .MuiAutocomplete-input": { "&.MuiAutocomplete-root .MuiAutocomplete-input": {
padding: `0 ${theme.spacing(5)}`, padding: `0 ${theme.spacing(5)}`,