wisesplit/components/Person.tsx

37 lines
831 B
TypeScript
Raw Normal View History

2022-10-24 18:27:34 +00:00
import { Atom, useAtom, WritableAtom } from "jotai";
import { Badge, ListGroup } 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-24 19:00:16 +00:00
name: Atom<string>;
2022-10-24 07:10:52 +00:00
}
export interface Props {
personAtom: Atom<IPerson>;
2022-10-24 19:00:16 +00:00
splitBetweenAtom: Atom<Atom<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);
const removeSelf = (_) => {
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
}