Skip to content

Commit

Permalink
Add the component for #44
Browse files Browse the repository at this point in the history
  • Loading branch information
hampelm committed Mar 22, 2018
1 parent 14cee74 commit 84cf0ca
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/RecentGrants.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.RecentGrants h1,
.RecentGrants .grant {
padding: 10px 20px;
}

.RecentGrants h1 {
font-size: 16px;
}

.RecentGrants h2 {
font-size: 16px;
font-weight: normal;
}

.RecentGrants .metadata {
color: #666;
}
66 changes: 66 additions & 0 deletions src/components/RecentGrants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

import './RecentGrants.css';

class RecentGrants extends Component {
constructor(props) {
super(props);
this.renderGrant = this.renderGrant.bind(this);
}

static propTypes = {
grants: PropTypes.array.isRequired,
};

formatDate(date) {
const options = {
year: 'numeric',
month: 'short',
day: 'numeric',
};
return date.toLocaleDateString('en-US', options);
}

renderGrant({ from, to, start, end, amount }) {
return (
<div className="grant">
<h2>
<span className="orgname">{from}</span> to{' '}
<span className="orgname">{to}</span>
</h2>
<div className="metadata">${amount.toLocaleString()}</div>
<div className="metadata">
{this.formatDate(start)} - {this.formatDate(end)}
</div>
</div>
);
}

render() {
const grants = [
{
from: 'Comerica Charitable Foundation',
to: 'Detroit Ledger',
start: new Date('1/1/1918'),
end: new Date('1/12/1919'),
amount: 5,
},
{
from: 'Comerica Charitable Foundation',
to: 'Detroit Ledger',
start: new Date('1/1/2027'),
end: new Date('1/12/2028'),
amount: 100000,
},
];
return (
<div className="RecentGrants">
<h1>Recent grants</h1>
{grants.map(this.renderGrant)}
</div>
);
}
}

export default RecentGrants;

0 comments on commit 84cf0ca

Please sign in to comment.