rmwc
Version:
A thin React wrapper for Material Design (Web) Components
49 lines (35 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getIconStrategy = undefined;
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; };
var _react = require('react');
var React = _interopRequireWildcard(_react);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/**
* Given content, tries to figure out an appropriate strategy for it
*/
// prettier-ignore
var processAutoStrategy = function processAutoStrategy(content) {
// check for URLS
if (typeof content === 'string' && (content.startsWith('/') || content.startsWith('http://') || content.startsWith('https://'))) {
return 'url';
}
// handle JSX components
if ((typeof content === 'undefined' ? 'undefined' : _typeof(content)) === 'object') {
return 'component';
}
// we dont know what it is, default to ligature for compat with material icons
return 'ligature';
};
/**
* Get the actual icon strategy to use
*/
var getIconStrategy = exports.getIconStrategy = function getIconStrategy(content, strategy, defaultStrategy) {
strategy = strategy || defaultStrategy;
if (strategy === 'auto') {
return processAutoStrategy(content);
}
return strategy;
};