Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

create list component #1553

Benjamin King550954831ba7
diff --git a/web/css/list.css b/web/css/list.css
new file mode 100644
index 000000000..202e91c75
--- /dev/null
+++ b/web/css/list.css
@@ -0,0 +1,23 @@
+.list-group-item {
+ background: #282828;
+ color: #eee;
+ text-align: left
+}
+.list-group-item.active {
+ background: #888;
+ border-color: #888;
+}
+.list-group-item:hover {
+ background: #eee;
+ color: #282828;
+}
+.list-group-item i {
+ margin-right: 4px;
+ line-height: 1.5;
+}
+button.list-group-item {
+ cursor: pointer;
+}
+.list-group-item.small-item {
+ padding: 5px
+}
\ No newline at end of file
diff --git a/web/js/components/util/list.js b/web/js/components/util/list.js
new file mode 100644
index 000000000..1f3cde8f3
--- /dev/null
+++ b/web/js/components/util/list.js
@@ -0,0 +1,54 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { ListGroup, ListGroupItem, Badge } from 'reactstrap';
+
+/*
+ * A react reuseable list component
+ *
+ * @class List
+ * @extends React.Component
+ */
+export default class List extends React.Component {
+ render() {
+ const { list, listClass, active, disabled, onClick, size } = this.props;
+ return (
+ <ListGroup className={listClass}>
+ {list.map(item => {
+ const iconClass = item.iconClass;
+ const isActive = item.key && active ? item.key === active : false;
+ const isDisabled =
+ item.key && disabled ? item.key === disabled : false;
+ const badge = item.badge;
+ const className = item.className ? item.className : '';
+ return (
+ <ListGroupItem
+ tag="button"
+ active={isActive}
+ className={className + ' ' + size + '-item'}
+ onClick={
+ item.onClick
+ ? item.onClick
+ : onClick
+ ? () => {
+ onClick(item.key);
+ }
+ : null
+ }
+ disabled={isDisabled}
+ >
+ {iconClass ? <i className={iconClass} /> : ''}
+ {item.text || ''}
+ {badge ? <Badge pill>{item.badge}</Badge> : ''}
+ </ListGroupItem>
+ );
+ })}
+ </ListGroup>
+ );
+ }
+}
+List.defaultProps = {
+ size: 'medium'
+};
+List.propTypes = {
+ list: PropTypes.array
+};