MCPcopy Create free account
hub / github.com/EsperoTech/yaade / GroupsInput

Function GroupsInput

client/src/components/groupsInput/GroupsInput.tsx:19–79  ·  view source on GitHub ↗
({
  groups,
  setGroups,
  isRounded,
  className,
})

Source from the content-addressed store, hash-verified

17};
18
19const GroupsInput: FunctionComponent<GroupsInputProps> = ({
20 groups,
21 setGroups,
22 isRounded,
23 className,
24}) => {
25 const [newGroup, setNewGroup] = useState('');
26
27 const { colorMode } = useColorMode();
28
29 function setNewGroupInput(value: string, force = false) {
30 if (value.endsWith(' ') || force) {
31 const removedDuplicates = Array.from(new Set([...groups, value.trim()]));
32 if (value !== ' ') {
33 setGroups(removedDuplicates);
34 }
35 setNewGroup('');
36 } else {
37 setNewGroup(value);
38 }
39 }
40
41 function deleteGroup(name: string) {
42 const newGroups = groups.filter((el) => el !== name);
43 setGroups(newGroups);
44 }
45
46 return (
47 <VStack alignItems="start" width="100%" className={className}>
48 <Input
49 size={isRounded ? 'md' : 'sm'}
50 borderRadius={isRounded ? '20px' : undefined}
51 placeholder="Groups"
52 value={newGroup}
53 onChange={(e) => setNewGroupInput(e.target.value)}
54 backgroundColor={colorMode === 'light' ? 'white' : undefined}
55 onKeyPress={(e) => {
56 if (e.key === 'Enter') {
57 setNewGroupInput(newGroup, true);
58 }
59 }}
60 />
61 <Wrap>
62 {groups.map((group) => (
63 <Tag
64 size="sm"
65 key={`collection-group-list-${group}`}
66 borderRadius="full"
67 variant="solid"
68 colorScheme="green"
69 mx="0.25rem"
70 my="0.2rem"
71 >
72 <TagLabel>{group}</TagLabel>
73 <TagCloseButton onClick={() => deleteGroup(group)} />
74 </Tag>
75 ))}
76 </Wrap>

Callers

nothing calls this directly

Calls 2

setNewGroupInputFunction · 0.85
deleteGroupFunction · 0.85

Tested by

no test coverage detected