react-icons/bs#BsMoon JavaScript Examples
The following examples show how to use
react-icons/bs#BsMoon.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Header.js From hackertab.dev with Apache License 2.0 | 5 votes |
function Header({ state, dispatcher, showSideBar, setShowSideBar, showSettings, setShowSettings }) {
const [themeIcon, setThemeIcon] = useState(<BsMoon />)
const isFirstRun = useRef(true)
useEffect(() => {
document.documentElement.classList.add(state.theme)
}, [])
useEffect(() => {
if (isFirstRun.current) {
isFirstRun.current = false
} else {
if (!document.documentElement.classList.contains('transitionBgColor')) {
document.documentElement.classList.add('transitionBgColor')
}
trackThemeChange(state.theme)
}
if (state.theme === 'light') {
document.documentElement.classList.replace('dark', state.theme)
setThemeIcon(<BsMoon />)
} else if (state.theme === 'dark') {
document.documentElement.classList.replace('light', state.theme)
setThemeIcon(<IoMdSunny />)
}
}, [state?.theme])
const onThemeChange = () => {
dispatcher({ type: 'toggleTheme' })
}
const onSettingsClick = () => {
setShowSettings(true)
}
const BookmarksBadgeCount = () => {
return state.userBookmarks.length > 0 ? (
state.userBookmarks.length < 10 ? (
<span className="badgeCount">{state.userBookmarks.length}</span>
) : (
<span className="badgeCount">+9</span>
)
) : null
}
return (
<>
<SettingsModal showSettings={showSettings} setShowSettings={setShowSettings} />
<header className="AppHeader">
<span className="AppName">
<i className="logo">
<CgTab />
</i>{' '}
<HackertabLogo className="logoText" />
<Changelog />
</span>
<SearchBar state={state} />
<div className="extras">
<button className="extraBtn" onClick={onSettingsClick}>
<BsFillGearFill />
</button>
<button className="extraBtn darkModeBtn" onClick={onThemeChange}>
{themeIcon}
</button>
<button className="extraBtn" onClick={() => setShowSideBar(!showSideBar)}>
<BsFillBookmarksFill />
<BookmarksBadgeCount />
</button>
</div>
<div className="break"></div>
<UserTags userSelectedTags={state.userSelectedTags} onAddClicked={onSettingsClick} />
</header>
</>
)
}
Example #2
Source File: darktoggle.js From HealthBridge with GNU General Public License v3.0 | 5 votes |
DarkToggle = () => {
const [isDark, setIsDark] = useState(false);
useEffect(() => {
try {
// console.log("checking dark ls")
const dark = localStorage.getItem('prevState')
// console.log('prevState', dark)
// console.log("typeof dark",typeof(dark))
if(dark != null) {
setIsDark(dark==='true')
if (dark) {
document.documentElement.classList.add(DARK_CLASS)
} else {
document.documentElement.classList.remove(DARK_CLASS)
}
}
}
catch(e) {
}
}, [])
useEffect(() => {
// console.log("changin dark",isDark)
if (isDark) {
document.documentElement.classList.add(DARK_CLASS)
} else {
document.documentElement.classList.remove(DARK_CLASS)
}
}, [isDark]);
// console.log("isDark", isDark)
return (
<Toggle
className="DarkToggle"
onChange={event => {
setIsDark(event.target.checked)
localStorage.setItem('prevState', event.target.checked)
}}
checked={isDark}
icons={{checked: <BsMoon color="white" />, unchecked: <BsSun color="yellow"/>}}
aria-label="Dark mode"
/>
);
}