@fluentui/react
Version:
Reusable React components for building web experiences.
25 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getColorFromString = void 0;
var tslib_1 = require("tslib");
var utilities_1 = require("@fluentui/utilities");
var cssColor_1 = require("./cssColor");
var getColorFromRGBA_1 = require("./getColorFromRGBA");
/**
* Converts a CSS color string to a color object.
* Note that hex colors *must* be prefixed with # to be considered valid.
*
* `inputColor` will be used unmodified as the `str` property of the returned object.
* Alpha defaults to 100 if not specified in `inputColor`.
* Returns undefined if the color string is invalid/not recognized.
*/
function getColorFromString(inputColor, doc) {
var theDoc = doc !== null && doc !== void 0 ? doc : (0, utilities_1.getDocument)();
var color = (0, cssColor_1.cssColor)(inputColor, theDoc);
if (!color) {
return;
}
return tslib_1.__assign(tslib_1.__assign({}, (0, getColorFromRGBA_1.getColorFromRGBA)(color)), { str: inputColor });
}
exports.getColorFromString = getColorFromString;
//# sourceMappingURL=getColorFromString.js.map