UNPKG

app-base-react

Version:
51 lines (42 loc) 1.84 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; exports.default = html; var _react = require('react'); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function html(_ref) { var value = _ref.value, _ref$schema = _ref.schema, schema = _ref$schema === undefined ? {} : _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 === 'undefined' ? 'undefined' : _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 = value[0] + ' - ' + value[1]; } else if (value && ['number', 'string'].indexOf(value) === -1) { __html = JSON.stringify(value); } return _react2.default.createElement('div', { dangerouslySetInnerHTML: { __html: __html } }); }