ui5-smart-access
Version:
A custom accessibility popover for SAP UI5 applications.
76 lines (65 loc) • 2.49 kB
JavaScript
let isDarkMode = false;
// Apply dark mode styles to popover
const applyPopoverDarkMode = () => {
const style = document.createElement('style');
style.id = 'popover-dark-mode-styles';
style.textContent = `
.abicsAccessibilityPopover * {
background-color:
color:
border-color:
}
.abicsAccessibilityPopover .sapMPanel .sapMTB.sapMPanelHeaderTB {
background-color:
color:
}
.abicsAccessibilityPopover .sapMPanel .sapMTB.sapMPanelHeaderTB .sapMTitle,
.abicsAccessibilityPopover .sapMPanel .sapMTB.sapMPanelHeaderTB .sapUiIcon {
color:
background-color:
}
.abicsAccessibilityPopover .sapMPopoverHeader .sapMBarContainer *,
.abicsAccessibilityPopover .sapMPopoverHeader .sapMBarContainer {
background-color:
color:
}
.abicsAccessibilityPopover .sapMSwtLabel {
background-color:
color:
}
.abicsAccessibilityPopover .sapMSwtInner .sapMSwtHandle {
background-color:
}
.abicsAccessibilityPopover .sapMSliderProgress,
.abicsAccessibilityPopover .sapMSliderInner {
background-color:
}
`;
document.head.appendChild(style);
};
// Remove dark mode styles from popover
const removePopoverDarkMode = () => {
const existingStyle = document.getElementById('popover-dark-mode-styles');
if (existingStyle) {
existingStyle.remove();
}
};
export const toggleNightMode = () => {
isDarkMode = !isDarkMode;
if (isDarkMode) {
sap.ui.getCore().applyTheme("sap_horizon_dark");
applyPopoverDarkMode();
} else {
sap.ui.getCore().applyTheme("sap_horizon");
removePopoverDarkMode();
}
return isDarkMode;
};
export const disableNightMode = () => {
if (isDarkMode) {
sap.ui.getCore().applyTheme("sap_horizon");
removePopoverDarkMode();
isDarkMode = false;
}
};
export const isNightModeActive = () => isDarkMode;