@emeraldpay/hashicon-react
Version:
Hashicon React - React component for a visual representation of a hash value, as a hexagon
64 lines (63 loc) • 2.45 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
exports.Hashicon = void 0;
var react_1 = __importDefault(require("react"));
var react_2 = require("react");
var hashicon_1 = require("@emeraldpay/hashicon");
var Hashicon = /** @class */ (function (_super) {
__extends(Hashicon, _super);
function Hashicon() {
return _super !== null && _super.apply(this, arguments) || this;
}
Hashicon.prototype.render = function () {
var value = this.props.value;
var options = {};
if (typeof options != "undefined") {
options = __assign(__assign({}, options), this.props.options);
}
if (typeof this.props.size == "number") {
options = __assign(__assign({}, options), { size: this.props.size });
}
if (typeof this.props.hasher == "string") {
options = __assign(__assign({}, options), { hasher: this.props.hasher });
}
var icon = hashicon_1.hashicon(value, options).toDataURL();
var attributes = {
src: icon,
alt: value
};
if (typeof this.props.size == 'number') {
attributes["width"] = this.props.size;
}
return react_1["default"].createElement("img", __assign({}, attributes));
};
return Hashicon;
}(react_2.Component));
exports.Hashicon = Hashicon;