html.js
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = html;
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function html(_ref) {
var value = _ref.value,
_ref$schema = _ref.schema,
schema = _ref$schema === void 0 ? {} : _ref$schema;
var __html = '-';
if (schema.type === 'boolean') {
__html = value === true ? '✔' : '✘';
} else if (Array.isArray(schema.enum) && Array.isArray(schema.enumNames)) {
if (['string', 'number'].indexOf(_typeof(value)) > -1) {
var idx = schema.enum.indexOf(value);
__html = schema.enumNames[idx] || '-';
} else if (Array.isArray(value)) {
var idxStr = '-';
value.forEach(function (v) {
var idx = schema.enum.indexOf(v);
var name = schema.enumNames[idx];
if (name) {
idxStr += ',' + name;
}
});
__html = idxStr.replace('-,', '');
}
} else if (typeof value === 'number') {
__html = String(value);
} else if (typeof value === 'string') {
__html = value;
} else if (schema.type === 'range' && Array.isArray(value) && value[0] && value[1]) {
__html = "".concat(value[0], " - ").concat(value[1]);
} else if (value && ['number', 'string'].indexOf(value) === -1) {
__html = JSON.stringify(value);
}
return /*#__PURE__*/_react.default.createElement("div", {
dangerouslySetInnerHTML: {
__html: __html
}
});
}