Skip to content

[CSS-localStorage-rule] CSS needs rule references to localStorage values, to be responsive to user input. #4933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Dorson opened this issue Apr 9, 2020 · 3 comments

Comments

@Dorson
Copy link

Dorson commented Apr 9, 2020

[css-localStorage-rule]

CSS needs to be able to set style rules in reference to the values that were saved in the localStorage of the browser. Like for color settings, or text size settings, or position settings.

Here is an example to understand why.

CSS rule example for the user-set color preferences.
Similar as we do in the attribute selector rules :

html[localStorage( ColorTheme == dark )] { background: black ; }
..or...
html[localStorage( ColorTheme == green )] { background: green ; }

OR as we do in the media rules :

@localStorage( ColorTheme == dark ) {
      body { background: black ;  }
}

Such rules would be able to set the black background for the html tag, if the localStorage cell list of ColorTheme had the "dark" entry value in the list.

The read-only access to the localStorage of the browser would make the CSS truly dynamic and responsive to the user input. Users apps would be able allow to set and remember the personal style settings. Positions of the movable page elements would be possible to be remembered, if the user wanted to do so.

The write access changes should be still left to the JavaScript side.

Good Day fellow travelers !

@Dorson Dorson changed the title CSS needs rule references to localMemory values, to be responsive to user input. [css-localMemory-rule] CSS needs rule references to localMemory values, to be responsive to user input. Apr 9, 2020
@Dorson Dorson changed the title [css-localMemory-rule] CSS needs rule references to localMemory values, to be responsive to user input. [CSS-localMemory-rule] CSS needs rule references to localMemory values, to be responsive to user input. Apr 9, 2020
@emilio
Copy link
Collaborator

emilio commented Apr 9, 2020

I assume localMemory means localStorage?

@tabatkins
Copy link
Member

This should be addressed when we add custom media queries; on page load you can query localStorage yourself and set the MQs accordingly.

It wouldn't be appropriate for CSS to directly interface with localStorage; that is one of many ways to store local state in a page. (And in general, one of the less good ones, due to it providing sync access to a potentially-slow storage backend.)

@Dorson
Copy link
Author

Dorson commented Apr 9, 2020

Yes, CSS should directly interface with localStorage values OR similar, alternative settings memory, because user style settings are set in there. Read-only access is OK for that.

It's the job of the CSS to comply with the style rules that the user selected and saved.

In the current state, we are left to use the JavaScript to do the job of the CSS, when we need to remember and set the same CSS class rules for user preferences, and set them again on every page load by JavaScript, instead of directly making style rules that refer to the localStorage values for the user style settings.

It's NOT about the localStorage itself. Could be any other memory storage. It's about the access to style setting values that were made by the user.

@Dorson Dorson changed the title [CSS-localMemory-rule] CSS needs rule references to localMemory values, to be responsive to user input. [CSS-localStorage-rule] CSS needs rule references to localStorage values, to be responsive to user input. Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants