Comments (7)
Fair enough! You know, this struck me as something that is so obvious to do initially, I hadn't considered that there may be a good reason you couldn't.
I'll close. Thanks for educating me!
from halfmoon.
@edadams yes cookies and localStorage
can only store Strings, but you could parse/serialize the bool in the isDarkModeOn
/setDarkModeOn
methods. Which is a lot cleaner than for the user to check for yes
and know the name of the cookie (darkMode
).
Example (cookie, could also be implemented with localStorage 😉):
function isDarkModeOn() {
return this.readCookie('darkModeOn') == 'yes';
}
function setDarkModeOn(darkMode) {
this.createCookie('darkModeOn', darkMode ? 'yes' : 'no', 365);
}
I would use theme
, which is generally used in application/other UI frameworks.
from halfmoon.
@edadams @TheKingDave
The dark mode cookie implementation has been overhauled in v1.1.0. There is a new method that returns the preferred mode. Again, this returns a string and not a boolean because there are 3 possible values, not just true or false.
Moreover, the setDarkModeOn
method is not needed, because there is already halfmoon.toggleDarkMode()
. Please refer to this page: https://www.gethalfmoon.com/docs/core-javascript-library/
The docs have been fleshed out, and hopefully everything should be clear now. Regarding the localStorage, I explained my reasoning why that will not be implemented here: #30 (comment)
I will go ahead and close this issue. You can re-open it if you think the issue is still not resolved, or open another issue.
from halfmoon.
Hey thanks for bringing this up. Cookie values can only be string. Libraries often allow cookies to store JSON and other data types (such as boolean), but that requires extra parsing before storage and after retrieval. For that reason, "yes"
and "no"
strings are used. This way, no parsing is required, and the cookie can be read directly.
from halfmoon.
I understand the reasoning that the readCookie
method returns a string but I would at least create a isDarkModeOn
method that returns a boolean
. Perhaps also a setDarkModeOn
method. These could be used internally. I would not store the darkMode in a String
but in a bool
. Only in the exception that you would implement themes in the future but then I would rename it to theme
and store light
and dark
.
from halfmoon.
@TheKingDave Correct me if I've got this wrong but isn't the whole thing that you literally can't store a boolean value in a cookie? My understanding of the answer I got is that a cookie must return a string.
👍 +1 for theme
that returns either light
or dark
. Could be uiTheme
or some other more specific name, e.g,m mode
or uiMode
. (Is the accepted language "dark theme" or "dark mode"?)
That would be a separate issue, I think.
Edit: Guess you could even make an argument for using localStorage instead of cookies at this point, eh? 😉
from halfmoon.
Riiight! I'm with you now. I've reopened this issue in the hopes it gets looked at since I agree now that you've explained it this way. Hopefully that'll get someone's attention.
from halfmoon.
Related Issues (20)
- Modal close event HOT 3
- Select does not work properly in mobile
- set color mode instead of toggle js HOT 2
- [Feature request] Put label before switch
- Sidebar, darkmode and modals are not automatically toggled as expected. HOT 5
- halfmoon doesn't support rtl? HOT 2
- require problem while using with sveltekit. HOT 1
- this.stickyAlerts is undefined HOT 1
- Will the project continue? HOT 2
- Text centering inside buttons
- Default sidebar with small screen results in offscreen content HOT 2
- Halfmoon documentation isn't available anymore HOT 37
- is this project dead? HOT 27
- Version update messed up page layout completely HOT 3
- Provide CSS only alternatives using Dialog and Popover API.
- CSS only form validation HOT 1
- Website is down HOT 1
- Typo in dropdowns page code snippet
- input type = date, just use this that way?
- Docs website for v1.x.x is down HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from halfmoon.