input entities
This commit is contained in:
1 parent
878035e748
commit
996626f9af
27 files changed
+596
-92
No files matched your search
@@ -5,28 +5,36 @@ import { FC } from "react";
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
value: string | string[];
|
||||
value?: string | string[];
|
||||
options?: string[];
|
||||
onChange: (v: string[]) => void;
|
||||
maxAllowed?: number;
|
||||
}
|
||||
export default function InputTextBubble({
|
||||
value = "",
|
||||
label,
|
||||
options = [],
|
||||
onChange,
|
||||
maxAllowed,
|
||||
}: Props) {
|
||||
|
||||
const selected = Array.isArray(value) ? value : [value];
|
||||
const selected = Array.isArray(value) ? value : value ? [value] : [];
|
||||
|
||||
return <Autocomplete
|
||||
multiple
|
||||
freeSolo
|
||||
value={selected}
|
||||
options={options}
|
||||
onChange={(_e, v) => onChange(
|
||||
v === null ? [] :
|
||||
onChange={(_e, v) => {
|
||||
let cleanValue = v === null ? [] :
|
||||
Array.isArray(v) ? v : [v]
|
||||
)}
|
||||
|
||||
if (maxAllowed) {
|
||||
cleanValue = cleanValue.slice(0, maxAllowed);
|
||||
}
|
||||
|
||||
onChange(cleanValue)
|
||||
}}
|
||||
renderInput={params => <TextField
|
||||
{...params}
|
||||
variant="filled"
|
||||
@@ -42,15 +50,3 @@ export default function InputTextBubble({
|
||||
}
|
||||
/>
|
||||
}
|
||||
|
||||
export const InputEntity: FC<{
|
||||
value: string | string[];
|
||||
onChange: (v: string[]) => void;
|
||||
}> = ({
|
||||
value,
|
||||
onChange,
|
||||
}) => <InputTextBubble
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
label="Entity ID"
|
||||
/>
|
||||
Reference in new issue
Block a user