loginflow-pro / components /theme-toggle.js
seifshehata's picture
ุนุงูŠุฒูƒ ุชุถูŠู ููˆู‚ ุงู„ุตูุญู‡ ุฒุฑุงุฑ ู„ุชุณุฌูŠู„ ุงู„ุฏุฎูˆู„ ูˆุฌูˆุงู‡ ูŠุจู‚ูŠ ููŠ ุตูุญุชูŠู† ูˆุงุญุฏู‡ ู„ูˆ ู‡ูˆุง ู…ุนุงู‡ ุญุณุงุจ ูˆุงู„ุซุงู†ูŠุฉ ู„ูˆ ู‡ูŠุณุฌู„ ุฌุฏูŠุฏ ูˆูŠูƒูˆู† ููŠู‡ ุชุณุฌูŠู„ ุจุญุณุงุจ ุฌูˆุฌู„ ูˆูŠูƒูˆู† ููŠู‡ ุฒุฑุงุฑ ูŠูƒูˆู† ู„ูˆู† ุงู„ุตูุญู‡ ุบุงู…ู‚ ุงูˆ ูุงุชุญ ูˆุชุดูŠู„ ุงู„ู‚ู„ุจ ุงู„ูŠ ู…ุนุงู‡ู… ููˆู‚ ู…ุด ุนุงูŠุฒู‡
c0face1 verified
Raw History Blame Contribute Delete
1.87 kB
class ThemeToggle extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.render();
this.setupEventListeners();
}
render() {
this.shadowRoot.innerHTML = `
<style>
button {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: transparent;
border: none;
cursor: pointer;
color: inherit;
}
button:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.dark button:hover {
background-color: rgba(255, 255, 255, 0.05);
}
</style>
<button aria-label="ุชุจุฏูŠู„ ุงู„ูˆุถุน ุงู„ู„ูŠู„ูŠ">
<i data-feather="moon"></i>
</button>
`;
}
setupEventListeners() {
const button = this.shadowRoot.querySelector('button');
button.addEventListener('click', this.toggleTheme.bind(this));
}
toggleTheme() {
const html = document.documentElement;
if (html.classList.contains('dark')) {
html.classList.remove('dark');
localStorage.setItem('theme', 'light');
this.shadowRoot.querySelector('i').setAttribute('data-feather', 'moon');
} else {
html.classList.add('dark');
localStorage.setItem('theme', 'dark');
this.shadowRoot.querySelector('i').setAttribute('data-feather', 'sun');
}
feather.replace();
}
}
customElements.define('theme-toggle', ThemeToggle);