@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
49 lines (48 loc) • 1.17 kB
JavaScript
"use client";
import useTheme from "./useTheme.js";
export default function VisibilityByTheme({
children,
visible,
hidden
}) {
const theme = useTheme();
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 = useTheme();
if (theme?.isCarnegie) {
return 'Carnegie';
}
if (theme.isEiendom) {
return 'Eiendom';
}
if (theme.isSbanken) {
return 'Sbanken';
}
if (theme.isUi) {
return 'DNB';
}
};
//# sourceMappingURL=VisibilityByTheme.js.map