decentraland-ui
Version:
Decentraland's UI components and styles
116 lines (115 loc) • 4.7 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Blockie = void 0;
var React = __importStar(require("react"));
var blockies = __importStar(require("ethereum-blockies/blockies"));
require("./Blockie.css");
var classnames_1 = __importDefault(require("classnames"));
/**
* @deprecated Should start using the same component migrated to UI2.
*/
var Blockie = /** @class */ (function (_super) {
__extends(Blockie, _super);
function Blockie() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.canvas = React.createRef();
return _this;
}
Blockie.prototype.componentDidMount = function () {
this.draw();
};
Blockie.prototype.componentDidUpdate = function () {
this.draw();
};
Blockie.prototype.getOpts = function () {
var _a = this.props, seed = _a.seed, color = _a.color, spotcolor = _a.spotcolor, bgcolor = _a.bgcolor, size = _a.size, scale = _a.scale;
return {
seed: seed ? seed.toLowerCase() : '',
color: color,
spotcolor: spotcolor,
bgcolor: bgcolor,
size: size,
scale: scale
};
};
Blockie.prototype.draw = function () {
if (!this.canvas || !this.canvas.current) {
return '🦄';
}
var _a = this.props, size = _a.size, scale = _a.scale;
var ctx = this.canvas.current.getContext('2d');
ctx.clearRect(0, 0, size * scale, size * scale);
blockies.render(this.getOpts(), this.canvas.current);
};
Blockie.prototype.render = function () {
var _a = this.props, size = _a.size, scale = _a.scale, shape = _a.shape, children = _a.children, className = _a.className;
var scaleClass = '';
if (scale * size <= 16) {
scaleClass += ' mini';
}
else if (scale * size <= 24) {
scaleClass += ' tiny';
}
else if (scale * size <= 36) {
scaleClass += ' small';
}
var canvas = (React.createElement("canvas", { className: (0, classnames_1.default)('dcl blockie', className, shape === 'circle' && 'circle', shape !== 'circle' && scaleClass), ref: this.canvas }));
if (children) {
return (React.createElement("span", { className: "dcl blockie-wrapper" },
canvas,
React.createElement("span", { className: "dcl blockie-children" }, children)));
}
return canvas;
};
Blockie.defaultProps = {
color: '#e449c2',
bgcolor: '#3149de',
spotcolor: '#e449c2',
size: 6,
scale: 6,
className: ''
};
return Blockie;
}(React.PureComponent));
exports.Blockie = Blockie;