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
+26 -53

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,
+25 -19
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,24 +48,28 @@ 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={
const { key, ...optionProps } = props; customRenderOption ||
return ( ((props, option, { selected }) => {
<ListItem const { key, ...optionProps } = props;
key={key} return (
{...optionProps} <ListItem
> key={key}
<Stack {...optionProps}
direction={"row"}
alignItems={"center"}
gap={theme.spacing(2)}
> >
{multiple && <Checkbox checked={selected} />} <Stack
{option.name} direction={"row"}
</Stack> alignItems={"center"}
</ListItem> gap={theme.spacing(2)}
); width="100%"
}} >
{multiple && <Checkbox checked={selected} />}
{renderOptionContent ? renderOptionContent(option) : option.name}
</Stack>
</ListItem>
);
})
}
sx={{ sx={{
"&.MuiAutocomplete-root .MuiAutocomplete-input": { "&.MuiAutocomplete-root .MuiAutocomplete-input": {
padding: `0 ${theme.spacing(5)}`, padding: `0 ${theme.spacing(5)}`,