@proca/widget
Version:
Proca is an open-source campaign toolkit designed to empower activists and organisations in their digital advocacy efforts. It provides a flexible and customisable platform for creating and managing online petitions, email campaigns, and other forms of di
37 lines (34 loc) • 1.01 kB
JavaScript
import React from "react";
import { ListItemSecondaryAction, Checkbox } from "@material-ui/core";
export const toggleSelection = (key, setSelection) => {
setSelection(prev => {
const selection = [...prev];
const index = selection.indexOf(key);
// select(index === -1);
if (index > -1) {
selection.splice(index, 1);
} else {
selection.push(key);
}
return selection;
});
};
const Selectable = props => {
const key = props.profile.procaid;
const selected = props.selection && props.selection.indexOf(key) !== -1;
//const [selected, select] = useState (props.selection && props.selection.indexOf(key) !== -1);
if (!props.selection) return null;
return (
<ListItemSecondaryAction>
<Checkbox
edge="end"
onChange={() => event => {
event.stopPropagation();
toggleSelection(key, props.setSelection);
}}
checked={selected}
/>
</ListItemSecondaryAction>
);
};
export default Selectable;