@hig/timestamp
Advanced tools
Comparing version 2.1.0 to 2.2.0
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css, cx } from 'emotion'; | ||
import { cx, css } from 'emotion'; | ||
import ThemeContext from '@hig/theme-context'; | ||
var sequences = Object.freeze({ | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
const sequences = Object.freeze({ | ||
ABC: "abc", | ||
@@ -14,9 +50,9 @@ ACB: "acb", | ||
}); | ||
const availableSequences = Object.freeze(Object.values(sequences)); | ||
var availableSequences = Object.freeze(Object.values(sequences)); | ||
function stylesheet(props, themeData) { | ||
var customStylesheet = props.stylesheet; | ||
var styles = { | ||
const { | ||
stylesheet: customStylesheet | ||
} = props; | ||
const styles = { | ||
timestamp: { | ||
@@ -31,37 +67,41 @@ color: themeData["timestamp.fontColor"], | ||
}; | ||
return customStylesheet ? customStylesheet(styles, props, themeData) : styles; | ||
} | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
const _excluded = ["stylesheet"]; | ||
var pluralize = function pluralize(word, count) { | ||
return count === 1 ? word : word + "s"; | ||
}; | ||
var Timestamp = function Timestamp(props) { | ||
var getTimestampSequence = function getTimestampSequence(distance, ellapsedDescriptor) { | ||
var timeDescriptors = props.timeDescriptors, | ||
timestampSequence = props.timestampSequence, | ||
wordSpace = props.wordSpace; | ||
const pluralize = (word, count) => count === 1 ? word : `${word}s`; | ||
var userTimestamp = void 0; | ||
const Timestamp = props => { | ||
const getTimestampSequence = (distance, ellapsedDescriptor) => { | ||
const { | ||
timeDescriptors, | ||
timestampSequence, | ||
wordSpace | ||
} = props; | ||
let userTimestamp; | ||
switch (timestampSequence) { | ||
case "acb": | ||
userTimestamp = wordSpace ? distance + " " + timeDescriptors.ago + " " + ellapsedDescriptor : "" + distance + timeDescriptors.ago + ellapsedDescriptor; | ||
userTimestamp = wordSpace ? `${distance} ${timeDescriptors.ago} ${ellapsedDescriptor}` : `${distance}${timeDescriptors.ago}${ellapsedDescriptor}`; | ||
break; | ||
case "bac": | ||
userTimestamp = wordSpace ? ellapsedDescriptor + " " + distance + " " + timeDescriptors.ago : "" + ellapsedDescriptor + distance + timeDescriptors.ago; | ||
userTimestamp = wordSpace ? `${ellapsedDescriptor} ${distance} ${timeDescriptors.ago}` : `${ellapsedDescriptor}${distance}${timeDescriptors.ago}`; | ||
break; | ||
case "bca": | ||
userTimestamp = wordSpace ? ellapsedDescriptor + " " + timeDescriptors.ago + " " + distance : "" + ellapsedDescriptor + timeDescriptors.ago + distance; | ||
userTimestamp = wordSpace ? `${ellapsedDescriptor} ${timeDescriptors.ago} ${distance}` : `${ellapsedDescriptor}${timeDescriptors.ago}${distance}`; | ||
break; | ||
case "cab": | ||
userTimestamp = wordSpace ? timeDescriptors.ago + " " + distance + " " + ellapsedDescriptor : "" + timeDescriptors.ago + distance + ellapsedDescriptor; | ||
userTimestamp = wordSpace ? `${timeDescriptors.ago} ${distance} ${ellapsedDescriptor}` : `${timeDescriptors.ago}${distance}${ellapsedDescriptor}`; | ||
break; | ||
case "cba": | ||
userTimestamp = wordSpace ? timeDescriptors.ago + " " + ellapsedDescriptor + " " + distance : "" + timeDescriptors.ago + ellapsedDescriptor + distance; | ||
userTimestamp = wordSpace ? `${timeDescriptors.ago} ${ellapsedDescriptor} ${distance}` : `${timeDescriptors.ago}${ellapsedDescriptor}${distance}`; | ||
break; | ||
default: | ||
userTimestamp = wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago; | ||
userTimestamp = wordSpace ? `${distance} ${ellapsedDescriptor} ${timeDescriptors.ago}` : `${distance}${ellapsedDescriptor}${timeDescriptors.ago}`; | ||
} | ||
@@ -72,14 +112,15 @@ | ||
var humanizeTimestamp = function humanizeTimestamp() { | ||
var plural = props.plural, | ||
timeDescriptors = props.timeDescriptors, | ||
timestamp = props.timestamp; | ||
const humanizeTimestamp = () => { | ||
const { | ||
plural, | ||
timeDescriptors, | ||
timestamp | ||
} = props; | ||
const asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input? | ||
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input? | ||
var nowAsSeconds = new Date().valueOf() / 1000; | ||
const nowAsSeconds = new Date().valueOf() / 1000; | ||
const timeDifference = nowAsSeconds - asSeconds; | ||
let distance; | ||
let ellapsedDescriptor; | ||
var timeDifference = nowAsSeconds - asSeconds; | ||
var distance = void 0; | ||
var ellapsedDescriptor = void 0; | ||
if (timeDifference < 60) { | ||
@@ -117,26 +158,26 @@ distance = Math.round(timeDifference); | ||
return React.createElement( | ||
ThemeContext.Consumer, | ||
null, | ||
function (_ref) { | ||
var resolvedRoles = _ref.resolvedRoles, | ||
metadata = _ref.metadata; | ||
return /*#__PURE__*/React.createElement(ThemeContext.Consumer, null, _ref => { | ||
let { | ||
resolvedRoles, | ||
metadata | ||
} = _ref; | ||
var customStylesheet = props.stylesheet, | ||
otherProps = _objectWithoutProperties(props, ["stylesheet"]); | ||
const { | ||
stylesheet: customStylesheet | ||
} = props, | ||
otherProps = _objectWithoutProperties(props, _excluded); | ||
var className = otherProps.className; | ||
var styles = stylesheet({ stylesheet: customStylesheet }, resolvedRoles, metadata.colorSchemeId); | ||
return React.createElement( | ||
"div", | ||
{ className: cx(css(styles.timestamp), className) }, | ||
humanizeTimestamp() | ||
); | ||
} | ||
); | ||
const { | ||
className | ||
} = otherProps; | ||
const styles = stylesheet({ | ||
stylesheet: customStylesheet | ||
}, resolvedRoles, metadata.colorSchemeId); | ||
return /*#__PURE__*/React.createElement("div", { | ||
className: cx(css(styles.timestamp), className) | ||
}, humanizeTimestamp()); | ||
}); | ||
}; | ||
Timestamp.displayName = "Timestamp"; | ||
Timestamp.propTypes = { | ||
@@ -148,2 +189,3 @@ /** | ||
plural: PropTypes.bool, | ||
/** | ||
@@ -153,2 +195,3 @@ * Adds custom/overriding styles | ||
stylesheet: PropTypes.func, | ||
/** | ||
@@ -169,2 +212,3 @@ * An object that allows for localization of all the time words used | ||
}), | ||
/** | ||
@@ -174,2 +218,3 @@ * ISO date string | ||
timestamp: PropTypes.string, | ||
/** | ||
@@ -180,2 +225,3 @@ * The sequence in which the timestamp is displayed | ||
timestampSequence: PropTypes.oneOf(availableSequences), | ||
/** | ||
@@ -186,3 +232,2 @@ * If you want a space between words | ||
}; | ||
Timestamp.defaultProps = { | ||
@@ -266,3 +311,3 @@ plural: true, | ||
"defaultValue": { | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\"\n}", | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\",\n}", | ||
"computed": false | ||
@@ -305,3 +350,2 @@ } | ||
export default Timestamp; | ||
export { sequences, availableSequences }; | ||
export { availableSequences, Timestamp as default, sequences }; |
@@ -5,10 +5,50 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var React = _interopDefault(require('react')); | ||
var PropTypes = _interopDefault(require('prop-types')); | ||
var React = require('react'); | ||
var PropTypes = require('prop-types'); | ||
var emotion = require('emotion'); | ||
var ThemeContext = _interopDefault(require('@hig/theme-context')); | ||
var ThemeContext = require('@hig/theme-context'); | ||
var sequences = Object.freeze({ | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); | ||
var ThemeContext__default = /*#__PURE__*/_interopDefaultLegacy(ThemeContext); | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
const sequences = Object.freeze({ | ||
ABC: "abc", | ||
@@ -21,9 +61,9 @@ ACB: "acb", | ||
}); | ||
const availableSequences = Object.freeze(Object.values(sequences)); | ||
var availableSequences = Object.freeze(Object.values(sequences)); | ||
function stylesheet(props, themeData) { | ||
var customStylesheet = props.stylesheet; | ||
var styles = { | ||
const { | ||
stylesheet: customStylesheet | ||
} = props; | ||
const styles = { | ||
timestamp: { | ||
@@ -38,37 +78,41 @@ color: themeData["timestamp.fontColor"], | ||
}; | ||
return customStylesheet ? customStylesheet(styles, props, themeData) : styles; | ||
} | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
const _excluded = ["stylesheet"]; | ||
var pluralize = function pluralize(word, count) { | ||
return count === 1 ? word : word + "s"; | ||
}; | ||
var Timestamp = function Timestamp(props) { | ||
var getTimestampSequence = function getTimestampSequence(distance, ellapsedDescriptor) { | ||
var timeDescriptors = props.timeDescriptors, | ||
timestampSequence = props.timestampSequence, | ||
wordSpace = props.wordSpace; | ||
const pluralize = (word, count) => count === 1 ? word : `${word}s`; | ||
var userTimestamp = void 0; | ||
const Timestamp = props => { | ||
const getTimestampSequence = (distance, ellapsedDescriptor) => { | ||
const { | ||
timeDescriptors, | ||
timestampSequence, | ||
wordSpace | ||
} = props; | ||
let userTimestamp; | ||
switch (timestampSequence) { | ||
case "acb": | ||
userTimestamp = wordSpace ? distance + " " + timeDescriptors.ago + " " + ellapsedDescriptor : "" + distance + timeDescriptors.ago + ellapsedDescriptor; | ||
userTimestamp = wordSpace ? `${distance} ${timeDescriptors.ago} ${ellapsedDescriptor}` : `${distance}${timeDescriptors.ago}${ellapsedDescriptor}`; | ||
break; | ||
case "bac": | ||
userTimestamp = wordSpace ? ellapsedDescriptor + " " + distance + " " + timeDescriptors.ago : "" + ellapsedDescriptor + distance + timeDescriptors.ago; | ||
userTimestamp = wordSpace ? `${ellapsedDescriptor} ${distance} ${timeDescriptors.ago}` : `${ellapsedDescriptor}${distance}${timeDescriptors.ago}`; | ||
break; | ||
case "bca": | ||
userTimestamp = wordSpace ? ellapsedDescriptor + " " + timeDescriptors.ago + " " + distance : "" + ellapsedDescriptor + timeDescriptors.ago + distance; | ||
userTimestamp = wordSpace ? `${ellapsedDescriptor} ${timeDescriptors.ago} ${distance}` : `${ellapsedDescriptor}${timeDescriptors.ago}${distance}`; | ||
break; | ||
case "cab": | ||
userTimestamp = wordSpace ? timeDescriptors.ago + " " + distance + " " + ellapsedDescriptor : "" + timeDescriptors.ago + distance + ellapsedDescriptor; | ||
userTimestamp = wordSpace ? `${timeDescriptors.ago} ${distance} ${ellapsedDescriptor}` : `${timeDescriptors.ago}${distance}${ellapsedDescriptor}`; | ||
break; | ||
case "cba": | ||
userTimestamp = wordSpace ? timeDescriptors.ago + " " + ellapsedDescriptor + " " + distance : "" + timeDescriptors.ago + ellapsedDescriptor + distance; | ||
userTimestamp = wordSpace ? `${timeDescriptors.ago} ${ellapsedDescriptor} ${distance}` : `${timeDescriptors.ago}${ellapsedDescriptor}${distance}`; | ||
break; | ||
default: | ||
userTimestamp = wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago; | ||
userTimestamp = wordSpace ? `${distance} ${ellapsedDescriptor} ${timeDescriptors.ago}` : `${distance}${ellapsedDescriptor}${timeDescriptors.ago}`; | ||
} | ||
@@ -79,14 +123,15 @@ | ||
var humanizeTimestamp = function humanizeTimestamp() { | ||
var plural = props.plural, | ||
timeDescriptors = props.timeDescriptors, | ||
timestamp = props.timestamp; | ||
const humanizeTimestamp = () => { | ||
const { | ||
plural, | ||
timeDescriptors, | ||
timestamp | ||
} = props; | ||
const asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input? | ||
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input? | ||
var nowAsSeconds = new Date().valueOf() / 1000; | ||
const nowAsSeconds = new Date().valueOf() / 1000; | ||
const timeDifference = nowAsSeconds - asSeconds; | ||
let distance; | ||
let ellapsedDescriptor; | ||
var timeDifference = nowAsSeconds - asSeconds; | ||
var distance = void 0; | ||
var ellapsedDescriptor = void 0; | ||
if (timeDifference < 60) { | ||
@@ -124,26 +169,26 @@ distance = Math.round(timeDifference); | ||
return React.createElement( | ||
ThemeContext.Consumer, | ||
null, | ||
function (_ref) { | ||
var resolvedRoles = _ref.resolvedRoles, | ||
metadata = _ref.metadata; | ||
return /*#__PURE__*/React__default["default"].createElement(ThemeContext__default["default"].Consumer, null, _ref => { | ||
let { | ||
resolvedRoles, | ||
metadata | ||
} = _ref; | ||
var customStylesheet = props.stylesheet, | ||
otherProps = _objectWithoutProperties(props, ["stylesheet"]); | ||
const { | ||
stylesheet: customStylesheet | ||
} = props, | ||
otherProps = _objectWithoutProperties(props, _excluded); | ||
var className = otherProps.className; | ||
var styles = stylesheet({ stylesheet: customStylesheet }, resolvedRoles, metadata.colorSchemeId); | ||
return React.createElement( | ||
"div", | ||
{ className: emotion.cx(emotion.css(styles.timestamp), className) }, | ||
humanizeTimestamp() | ||
); | ||
} | ||
); | ||
const { | ||
className | ||
} = otherProps; | ||
const styles = stylesheet({ | ||
stylesheet: customStylesheet | ||
}, resolvedRoles, metadata.colorSchemeId); | ||
return /*#__PURE__*/React__default["default"].createElement("div", { | ||
className: emotion.cx(emotion.css(styles.timestamp), className) | ||
}, humanizeTimestamp()); | ||
}); | ||
}; | ||
Timestamp.displayName = "Timestamp"; | ||
Timestamp.propTypes = { | ||
@@ -154,7 +199,9 @@ /** | ||
*/ | ||
plural: PropTypes.bool, | ||
plural: PropTypes__default["default"].bool, | ||
/** | ||
* Adds custom/overriding styles | ||
*/ | ||
stylesheet: PropTypes.func, | ||
stylesheet: PropTypes__default["default"].func, | ||
/** | ||
@@ -165,16 +212,18 @@ * An object that allows for localization of all the time words used | ||
*/ | ||
timeDescriptors: PropTypes.shape({ | ||
second: PropTypes.string, | ||
minute: PropTypes.string, | ||
hour: PropTypes.string, | ||
day: PropTypes.string, | ||
week: PropTypes.string, | ||
month: PropTypes.string, | ||
year: PropTypes.string, | ||
ago: PropTypes.string | ||
timeDescriptors: PropTypes__default["default"].shape({ | ||
second: PropTypes__default["default"].string, | ||
minute: PropTypes__default["default"].string, | ||
hour: PropTypes__default["default"].string, | ||
day: PropTypes__default["default"].string, | ||
week: PropTypes__default["default"].string, | ||
month: PropTypes__default["default"].string, | ||
year: PropTypes__default["default"].string, | ||
ago: PropTypes__default["default"].string | ||
}), | ||
/** | ||
* ISO date string | ||
*/ | ||
timestamp: PropTypes.string, | ||
timestamp: PropTypes__default["default"].string, | ||
/** | ||
@@ -184,9 +233,9 @@ * The sequence in which the timestamp is displayed | ||
*/ | ||
timestampSequence: PropTypes.oneOf(availableSequences), | ||
timestampSequence: PropTypes__default["default"].oneOf(availableSequences), | ||
/** | ||
* If you want a space between words | ||
*/ | ||
wordSpace: PropTypes.bool | ||
wordSpace: PropTypes__default["default"].bool | ||
}; | ||
Timestamp.defaultProps = { | ||
@@ -270,3 +319,3 @@ plural: true, | ||
"defaultValue": { | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\"\n}", | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\",\n}", | ||
"computed": false | ||
@@ -309,4 +358,4 @@ } | ||
exports.default = Timestamp; | ||
exports.availableSequences = availableSequences; | ||
exports["default"] = Timestamp; | ||
exports.sequences = sequences; | ||
exports.availableSequences = availableSequences; |
@@ -0,1 +1,8 @@ | ||
# [@hig/timestamp-v2.2.0](https://github.com/Autodesk/hig/compare/@hig/timestamp@2.1.0...@hig/timestamp@2.2.0) (2022-09-05) | ||
### Features | ||
* update theme-data dependency ([c46edd2](https://github.com/Autodesk/hig/commit/c46edd2)) | ||
# [@hig/timestamp-v2.1.0](https://github.com/Autodesk/hig/compare/@hig/timestamp@2.0.0...@hig/timestamp@2.1.0) (2022-01-24) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@hig/timestamp", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "HIG Timestamp", | ||
@@ -33,4 +33,4 @@ "author": "Autodesk Inc.", | ||
"peerDependencies": { | ||
"@hig/theme-context": "^4.1.0", | ||
"@hig/theme-data": "^2.22.1", | ||
"@hig/theme-context": "^4.2.0", | ||
"@hig/theme-data": "^3.2.0", | ||
"react": "^17.0.0" | ||
@@ -37,0 +37,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27868
616