-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCustomAttributesList.js
More file actions
63 lines (59 loc) · 1.82 KB
/
CustomAttributesList.js
File metadata and controls
63 lines (59 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from "react";
import PropTypes from "prop-types";
const CustomAttributesList = ({
availableAttributes,
selectedAttributes,
onAttributeSelect,
searchQuery,
onSearchChange,
}) => {
return (
<div className="border border-light">
<div className="bg-light text-bold p-2">Available Custom Attributes</div>
<input
type="search"
className="form-control mb-2"
placeholder="Search Attribute Here"
onChange={(e) => onSearchChange(e.target.value)}
value={searchQuery}
aria-label="Search custom attributes"
/>
<ul className="list-group" role="listbox">
{availableAttributes.map((attribute) => {
const name = attribute.toLowerCase();
const alreadyAdded = selectedAttributes.includes(attribute);
if (
(name.includes(searchQuery.toLowerCase()) || !searchQuery) &&
!alreadyAdded
) {
return (
<li
className="list-group-item"
key={attribute}
role="option"
aria-selected={false}
>
<button
className="btn btn-link p-0"
onClick={() => onAttributeSelect(attribute)}
title="Click to add to the form"
>
{attribute}
</button>
</li>
);
}
return null;
})}
</ul>
</div>
);
};
CustomAttributesList.propTypes = {
availableAttributes: PropTypes.arrayOf(PropTypes.string).isRequired,
selectedAttributes: PropTypes.arrayOf(PropTypes.string).isRequired,
onAttributeSelect: PropTypes.func.isRequired,
searchQuery: PropTypes.string.isRequired,
onSearchChange: PropTypes.func.isRequired,
};
export default CustomAttributesList;