UNPKG

react-currency-flags

Version:
66 lines (65 loc) 2.47 kB
"use strict"; var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; Object.defineProperty(exports, "__esModule", { value: true }); var styled_components_1 = __importDefault(require("styled-components")); var flags_1 = __importDefault(require("./flags")); var types_1 = require("./types"); var RATIO = 1.6; var DEFAULT_DIMENSION = { height: 16, width: 24, }; var calculateDimension = function (width, height) { if (!width && !height) { return DEFAULT_DIMENSION; } var w = width; var h = height; if (!width && height) { w = height * RATIO; } else if (!height && width) { h = width / RATIO; } return { height: h, width: w, }; }; var getCurrencyImage = function (ccy) { return flags_1.default[ccy.toLowerCase()] || flags_1.default.$$$; }; exports.currencyFlagDims = (_a = {}, _a[types_1.CurrencyFlagSizes.SMALL] = { height: 10, width: 16, }, _a[types_1.CurrencyFlagSizes.MEDIUM] = DEFAULT_DIMENSION, _a[types_1.CurrencyFlagSizes.LARGE] = { height: 24, width: 36, }, _a[types_1.CurrencyFlagSizes.XLARGE] = { height: 32, width: 48, }, _a); exports.CurrencyFlag = styled_components_1.default.span(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: inline-block;\n ", "\n background-size: cover;\n"], ["\n display: inline-block;\n ", "\n background-size: cover;\n"])), function (_a) { var height = _a.height, size = _a.size, width = _a.width; var _b = size ? exports.currencyFlagDims[size] : calculateDimension(width, height), h = _b.height, w = _b.width; return "\n height: " + h + "px;\n width: " + w + "px;\n "; }); var CurrencyFlagImage = styled_components_1.default(exports.CurrencyFlag)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-image: url(\"", "\");\n"], ["\n background-image: url(\"", "\");\n"])), function (_a) { var currency = _a.currency; return getCurrencyImage(currency); }); exports.default = CurrencyFlagImage; var templateObject_1, templateObject_2;