list.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. const { DOM: dom, createClass, PropTypes } = require("devtools/client/shared/vendor/react");
  5. /**
  6. * Generic list component that takes another react component to represent
  7. * the children nodes as `itemComponent`, and a list of items to render
  8. * as that component with a click handler.
  9. */
  10. const List = module.exports = createClass({
  11. displayName: "List",
  12. propTypes: {
  13. itemComponent: PropTypes.any.isRequired,
  14. onClick: PropTypes.func,
  15. items: PropTypes.array.isRequired,
  16. },
  17. render() {
  18. let { items, onClick, itemComponent: Item } = this.props;
  19. return (
  20. dom.ul({ className: "list" }, ...items.map((item, index) => {
  21. return Item(Object.assign({}, this.props, {
  22. key: index,
  23. item,
  24. index,
  25. onClick: () => onClick(item),
  26. }));
  27. }))
  28. );
  29. }
  30. });