2022-10-25 18:26:48 +00:00
|
|
|
import { PrimitiveAtom, useAtom } from "jotai";
|
|
|
|
import { Badge } from "react-bootstrap";
|
2022-10-24 19:00:16 +00:00
|
|
|
import EditBox from "./EditBox";
|
2022-10-24 07:10:52 +00:00
|
|
|
|
|
|
|
export interface IPerson {
|
2022-10-25 18:26:48 +00:00
|
|
|
name: PrimitiveAtom<string>;
|
2022-10-24 07:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Props {
|
2022-10-25 18:26:48 +00:00
|
|
|
personAtom: PrimitiveAtom<IPerson>;
|
|
|
|
splitBetweenAtom: PrimitiveAtom<PrimitiveAtom<IPerson>[]>;
|
2022-10-24 07:10:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 08:49:22 +00:00
|
|
|
export default function Person({ personAtom, splitBetweenAtom }: Props) {
|
|
|
|
const [person] = useAtom(personAtom);
|
|
|
|
const [splitBetween, setSplitBetween] = useAtom(splitBetweenAtom);
|
|
|
|
|
2022-10-25 18:26:48 +00:00
|
|
|
const removeSelf = (_: any) => {
|
2022-10-24 08:49:22 +00:00
|
|
|
setSplitBetween([...splitBetween.filter((x) => x != personAtom)]);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-10-24 19:00:16 +00:00
|
|
|
<>
|
|
|
|
<EditBox valueAtom={person.name} validator={(s) => s} />
|
|
|
|
|
2022-10-24 08:49:22 +00:00
|
|
|
<Badge
|
|
|
|
bg="danger"
|
|
|
|
pill
|
|
|
|
onClick={removeSelf}
|
|
|
|
style={{ cursor: "pointer" }}
|
|
|
|
>
|
|
|
|
×
|
|
|
|
</Badge>
|
2022-10-24 19:00:16 +00:00
|
|
|
</>
|
2022-10-24 08:49:22 +00:00
|
|
|
);
|
2022-10-24 07:10:52 +00:00
|
|
|
}
|