@etsoo/materialui
Version:
TypeScript Material-UI Implementation
32 lines (31 loc) • 1.14 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DateText = DateText;
const jsx_runtime_1 = require("react/jsx-runtime");
const shared_1 = require("@etsoo/shared");
const Typography_1 = __importDefault(require("@mui/material/Typography"));
/**
* Date text
* @param props Props
* @returns Component
*/
function DateText(props) {
// Destruct
const { nearDays, locale = "lookup", options, timeZone, value, ...rest } = props;
// Format date
const date = shared_1.DateUtils.parse(value);
// Formatted value
const localValue = date == null
? undefined
: shared_1.DateUtils.format(value, locale, options, timeZone);
if (nearDays != null &&
date != null &&
Math.abs(new Date().substract(date).totalDays) <= nearDays) {
rest.color = "error";
}
// Layout
return ((0, jsx_runtime_1.jsx)(Typography_1.default, { component: "span", fontSize: "inherit", ...rest, children: localValue }));
}