wisesplit/components/Person.tsx

37 lines
856 B
TypeScript
Raw Normal View History

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
}
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) => {
setSplitBetween([...splitBetween.filter((x) => x != personAtom)]);
};
return (
2022-10-24 19:00:16 +00:00
<>
<EditBox valueAtom={person.name} validator={(s) => s} />
<Badge
bg="danger"
pill
onClick={removeSelf}
style={{ cursor: "pointer" }}
>
&times;
</Badge>
2022-10-24 19:00:16 +00:00
</>
);
2022-10-24 07:10:52 +00:00
}