@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
55 lines (54 loc) • 1.45 kB
JavaScript
;
"use client";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = VisibilityByTheme;
var _useTheme = _interopRequireDefault(require("./useTheme.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function VisibilityByTheme({
children,
visible,
hidden
}) {
const theme = (0, _useTheme.default)();
const visibleList = Array.isArray(visible) ? visible : [visible];
const hiddenList = Array.isArray(hidden) ? hidden : [hidden];
if (visible) {
if (!visibleList.some(match(theme))) {
return null;
}
} else if (hidden) {
if (hiddenList.some(match(theme))) {
return null;
}
}
return children;
function match(theme) {
return themeItem => {
return typeof themeItem === 'string' ? theme.name === themeItem : matchObject(theme, themeItem);
};
}
function matchObject(theme, themeItem) {
const themeItemKeys = Object.keys(themeItem);
return themeItemKeys.every(key => {
return theme[key] === themeItem[key];
});
}
}
VisibilityByTheme.Name = function ThemeName() {
const theme = (0, _useTheme.default)();
if (theme !== null && theme !== void 0 && theme.isCarnegie) {
return 'Carnegie';
}
if (theme.isEiendom) {
return 'Eiendom';
}
if (theme.isSbanken) {
return 'Sbanken';
}
if (theme.isUi) {
return 'DNB';
}
};
//# sourceMappingURL=VisibilityByTheme.js.map