UNPKG

keystone

Version:

Web Application Framework and Admin GUI / Content Management System built on Express.js and Mongoose

41 lines (37 loc) 1.07 kB
import React from 'react'; import moment from 'moment'; import ItemsTableCell from '../../components/ItemsTableCell'; import ItemsTableValue from '../../components/ItemsTableValue'; var DateColumn = React.createClass({ displayName: 'DateColumn', propTypes: { col: React.PropTypes.object, data: React.PropTypes.object, linkTo: React.PropTypes.string, }, toMoment (value) { if (this.props.col.field.isUTC) { return moment.utc(value); } else { return moment(value); } }, getValue () { const value = this.props.data.fields[this.props.col.path]; if (!value) return null; const format = (this.props.col.type === 'datetime') ? 'MMMM Do YYYY, h:mm:ss a' : 'MMMM Do YYYY'; return this.toMoment(value).format(format); }, render () { const value = this.getValue(); const empty = !value && this.props.linkTo ? true : false; return ( <ItemsTableCell> <ItemsTableValue field={this.props.col.type} to={this.props.linkTo} empty={empty}> {value} </ItemsTableValue> </ItemsTableCell> ); }, }); module.exports = DateColumn;