@atlaskit/theme
Version:
Theme contains solutions for global theming, colors, and other useful mixins.
46 lines (44 loc) • 1.44 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = themed;
var _getTheme = _interopRequireDefault(require("./get-theme"));
// Unpack custom variants, and get correct value for the current theme
function themedVariants(variantProp, variants) {
return function (props) {
var theme = (0, _getTheme.default)(props);
if (props && props[variantProp] && variants) {
var modes = variants[props[variantProp]];
if (modes && modes[theme.mode]) {
var value = modes[theme.mode];
if (value) {
return value;
} // TS believes value can be undefined
}
}
return '';
};
}
/**
* @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-4693 Internal documentation for deprecation (no external access)}
*/
function themed(modesOrVariant, variantModes) {
if (typeof modesOrVariant === 'string') {
return themedVariants(modesOrVariant, variantModes);
}
var modes = modesOrVariant;
return function (props) {
// Get theme from the user's props
var theme = (0, _getTheme.default)(props);
// User isn't required to provide both light and dark values
if (theme.mode in modes) {
var value = modes[theme.mode]; // TS believes value can be undefined
if (value) {
return value;
}
}
return '';
};
}