@enact/core
Version:
Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.
43 lines (41 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports.usePublicClassNames = usePublicClassNames;
var _util = require("../util");
/**
* A hook for supporting `publicClassNames` to functional components.
* It returns merged CSS of given two CSS objects according to `publicClassNames` option.
*
* @param {Object.<string, string>} [componentCss] The CSS of the component
* @param {Object.<string, string>} [customCss] The supplied collection of CSS class names to the
* corresponding internal elements and states of the component
* @param {Boolean|String|String[]} [publicClassNames] The keys of public class names of the component
* If this value is `true`, all the keys from the component
* CSS will become public class names.
* @returns {Object} A merged CSS
* @private
*/
function usePublicClassNames(_ref) {
var componentCss = _ref.componentCss,
customCss = _ref.customCss,
publicClassNames = _ref.publicClassNames;
var allowedClassNames = publicClassNames;
var mergedCss = componentCss;
if (!componentCss || !customCss) {
return mergedCss;
}
if (allowedClassNames === true) {
allowedClassNames = Object.keys(componentCss);
} else if (typeof allowedClassNames === 'string') {
allowedClassNames = allowedClassNames.split(/\s+/);
}
// if the config includes a css map, merge them together now
if (allowedClassNames) {
mergedCss = (0, _util.mergeClassNameMaps)(componentCss, customCss, allowedClassNames);
}
return mergedCss;
}
var _default = exports["default"] = usePublicClassNames;