@redocly/theme
Version:
Shared UI components lib
93 lines (92 loc) • 4.26 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LastUpdated = LastUpdated;
const react_1 = __importStar(require("react"));
const styled_components_1 = __importDefault(require("styled-components"));
const constants_1 = require("../../core/constants");
const hooks_1 = require("../../core/hooks");
function LastUpdated(props) {
const { markdown: { lastUpdatedBlock = {} } = {} } = (0, hooks_1.useThemeConfig)();
const { useTranslate, useL10nConfig } = (0, hooks_1.useThemeHooks)();
const { format: timeagoFormat } = (0, hooks_1.useTimeAgo)();
const { translate } = useTranslate();
const { currentLocale } = useL10nConfig();
const formats = (0, react_1.useMemo)(() => ({
timeago: (date) => timeagoFormat(date),
iso: (date) => date.toISOString().split('T')[0],
short: (date, locale) => date.toLocaleDateString(locale, { month: 'short', day: 'numeric', year: 'numeric' }),
long: (date, locale) => date.toLocaleDateString(locale, { month: 'long', day: 'numeric', year: 'numeric' }),
}), [timeagoFormat]);
if (lastUpdatedBlock === null || lastUpdatedBlock === void 0 ? void 0 : lastUpdatedBlock.hide) {
return null;
}
const lastModified = props.lastModified;
const format = props.format || lastUpdatedBlock.format || 'timeago';
const locale = props.locale ||
lastUpdatedBlock.locale ||
(currentLocale !== constants_1.DEFAULT_LOCALE_PLACEHOLDER ? currentLocale || 'en-US' : 'en-US');
const isoDate = lastModified.toISOString().split('T')[0];
const lastUpdatedString = formats[format](lastModified, locale);
const translationKey = format === 'timeago' ? 'page.lastUpdated.timeago' : 'page.lastUpdated.on';
const text = format === 'timeago'
? translate(translationKey, 'Last updated') + ' '
: translate(translationKey, 'Last updated on');
return (react_1.default.createElement(LastUpdatedWrapper, { className: props.className, "data-component-name": "LastUpdated/LastUpdated", rawOnPrint: format === 'timeago', "data-print-datetime": isoDate, "data-translation-key": translationKey },
text,
" ",
react_1.default.createElement("time", { dateTime: isoDate }, lastUpdatedString)));
}
const LastUpdatedWrapper = styled_components_1.default.div `
color: var(--last-updated-text-color);
font-size: var(--last-updated-font-size);
font-family: var(--last-updated-font-family);
line-height: var(--last-updated-line-height);
padding-bottom: 30px;
${({ rawOnPrint }) => rawOnPrint &&
`@media print {
time {
display: none;
}
&::after {
content: attr(data-print-datetime);
}
}
`}
`;
//# sourceMappingURL=LastUpdated.js.map