BlackMagic-js simplifies the implementation of dark mode in web applications. This powerful JavaScript framework ensures automatic color adjustments and provides accessibility features compliant with WCAG standards. With no external dependencies, it is easy to integrate using CDN or NPM, making dark mode accessible for all modern browsers. https://blackmagic.lucangevare.nl/
BlackMagic is a robust JavaScript framework designed for seamless integration of intelligent dark mode features into web applications. This framework not only facilitates automatic color adjustments but also ensures compliance with accessibility standards through its built-in WCAG contrast optimization.
To get started with BlackMagic, incorporate it into your project via CDN or NPM:
<script src="https://cdn.jsdelivr.net/npm/blackmagic-js@0.1.0/dist/blackmagic.min.js"></script>
npm install blackmagic-js
Initialize BlackMagic with customizable options:
// Initialize BlackMagic
const blackMagic = new BlackMagic({
cookieName: 'my-theme',
backgroundColor: '#1a1a1a',
factor: 0.4
});
// Add toggle functionality
document.getElementById('toggleBtn').addEventListener('click', () => {
blackMagic.toggle();
});
Users can tailor their implementation using these configuration options:
| Option | Type | Default | Description |
|---|---|---|---|
cookieName | string | 'darkmode' | Name for storing theme preference |
backgroundColor | string | '#000' | Background color for dark mode |
localStorageKey | string | 'darkmode' | Key for localStorage theme storage |
themeClass | string | undefined | CSS class for toggling instead of dynamic colors |
cookieDuration | number | 365 | Theme preference cookie expiration in days |
autoSwitch | boolean | true | Automatically apply saved theme on page load |
factor | number | 0.4 | Intensity of color adjustments (0.1-0.8) |
toggle(): Switches between light and dark themes.getCurrentTheme(): Returns the current theme ('light' or 'dark').applyTheme(theme): Applies a specified theme, either 'light' or 'dark'.getStoredTheme(): Retrieves the stored theme preference from cookies or localStorage.Utilize advanced features for custom implementations:
const blackMagic = new BlackMagic({
themeClass: 'dark-theme',
autoSwitch: true
});
Customize background and color adjustment intensities as needed:
const blackMagic = new BlackMagic({
backgroundColor: '#2d2d2d',
factor: 0.6,
cookieDuration: 30
});
Every color adjustment prioritizes WCAG AA adherence, ensuring:
BlackMagic guarantees functionality across:
Contribution to the BlackMagic project is welcomed. Interested parties can fork the repository, create a feature branch, make necessary changes, and submit a pull request for consideration.
Comprehensive documentation and support options are available, alongside community discussions and issue reporting on the project's GitHub page.
Explore various examples provided to enhance understanding of functionality and use cases.
No comments yet.
Sign in to be the first to comment.