@wener/console
Version:
Base console UI toolkit
78 lines (77 loc) • 2.6 kB
JavaScript
function _object_without_properties(source, excluded) {
if (source == null)
return {};
var target = {}, sourceKeys, key, i;
if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
sourceKeys = Reflect.ownKeys(source);
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0)
continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key))
continue;
target[key] = source[key];
}
return target;
}
target = _object_without_properties_loose(source, excluded);
if (Object.getOwnPropertySymbols) {
sourceKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0)
continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key))
continue;
target[key] = source[key];
}
}
return target;
}
function _object_without_properties_loose(source, excluded) {
if (source == null)
return {};
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0)
continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key))
continue;
target[key] = source[key];
}
return target;
}
import React, { useMemo } from "react";
import { dayjs } from "@wener/common/dayjs";
import { EmptyPlaceholder } from "./EmptyPlaceholder.js";
export var DateFormat = function (_0) {
var value = _0.value, _0_placeholder = _0.placeholder, placeholder = _0_placeholder === void 0 ? /*#__PURE__*/ React.createElement(EmptyPlaceholder, null) : _0_placeholder, _0_format = _0.format, format = _0_format === void 0 ? "YYYY-MM-DD" : _0_format, props = _object_without_properties(_0, [
"value",
"placeholder",
"format"
]);
var o = useMemo(function () {
return formatDate({
value: value,
format: format
});
}, [
value,
format
]);
if (!o) {
return placeholder;
}
return /*#__PURE__*/ React.createElement("span", props, o);
};
function formatDate(param) {
var value = param.value, format = param.format;
if (!value)
return "";
var d = dayjs(value);
if (!d.isValid()) {
return "";
}
return d.format(format);
}