Skip to content

feat: add system style - #48757

Closed
Sboonny wants to merge 40 commits into
freeCodeCamp:mainfrom
Sboonny:add/system-style-refactor
Closed

Sboonny wants to merge 40 commits into
freeCodeCamp:mainfrom
Sboonny:add/system-style-refactor

Conversation

@Sboonny

@Sboonny Sboonny commented Dec 14, 2022 •

Copy link
Copy Markdown
Member

Checklist:

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the main branch of freeCodeCamp.
  • I have tested these changes either locally on my machine, or GitPod.

Ref #47299

This aims to add the ability to opt in default system mode. by allowing the theme to be null, so it will move to system.


This won't close the issue, because I know at least, that I won't create the local storage logic in the PR.

@github-actions github-actions Bot added the platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. label Dec 14, 2022
@ghost

ghost commented Dec 14, 2022 •

Copy link
Copy Markdown

👀 Review this PR in a CodeSee Review Map

View the CodeSee Map of this change

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@ahmaxed

ahmaxed commented Dec 15, 2022

Copy link
Copy Markdown
Member

Thanks for putting together this pull request.
Could please provide more context. I am not sure I understood the issue.
Also can't we use one of the current variable sets instead of introducing new ones?

@Sboonny

Sboonny commented Dec 15, 2022 •

Copy link
Copy Markdown
Member Author

Thanks for putting together this pull request. Could please provide more context. I am not sure I understood the issue?

We are using a system, that stops respecting the preferred camper color scheme when they are logged in (although improvement from previous system, it still an issue and bad UX). To respect the camper choices, I had to add variables that change based on the camper system, but stop applying when the Camper changes to dark or light mode. That's caused the creation of system-variables.

After creating the system variables, I need a way to make campers opt in the system (like setting the theme value to null), so I may change the functionality of the toggle system, haven't applied it yet, because I am getting side tracked of the amount of forms and divs in the setting page.

can't we use one of the current variable sets instead of introducing new ones

Maybe I have no idea, I have to look into this after I am done refactor the theme and introducing a system button.

Edit: BTW, I have no idea how big this will be or how to make it cleaner yet.

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Just to make sure I understand the objective. This PR should allow the user to switch between three theme states: light, dark and system settings?

@Sboonny

Sboonny commented Dec 15, 2022

Copy link
Copy Markdown
Member Author

yeab, no local storage stuff and no changing theme while logged out

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Reading through the original discussion, I thought the consensus was to move away from storing this in the database in favour of local storage.

Before anything is implemented, there needs to be a clear goal.

  • Where are we storing the data?
  • How many settings do we want? (system until the user clicks then light, dark), (light, dark, system) or something completely different.

Finally, irrespective of what we chose, there are only two palettes (dark and light), so we don't need more variables.

@github-actions github-actions Bot added the platform: api Server application that needs familiarity with Express, Fastify, MongoDB etc. label Dec 15, 2022
@Sboonny

Sboonny commented Dec 15, 2022

Copy link
Copy Markdown
Member Author

Reading through the original discussion, I thought the consensus was to move away from storing this in the database in favour of local storage.

Before anything is implemented, there needs to be a clear goal.

  • Where are we storing the data?
  • How many settings do we want? (system until the user clicks then light, dark), (light, dark, system) or something completely different.

Finally, irrespective of what we chose, there are only two palettes (dark and light), so we don't need more variables.

We have discussed this in issue triage, and Naomi put valid points about storing it in the database, so it gets carried between devices. if someone prefer dark mode and pick dark mode once, they don't have to pick dark mode in every device that camper use.

I am in favor of local storage as I use multiple devices at different times of day at different environment, so I want the system to be respected always, but the issue triage meeting ended with keeping the database as is.

@Sboonny

Sboonny commented Dec 15, 2022

Copy link
Copy Markdown
Member Author

Finally, irrespective of what we chose, there are only two palettes (dark and light), so we don't need more variables.

Do you guys know something, I don't? well of course you do, but that not what I mean. I have actually no idea how to do preferred-color-scheme without adding more variables. I will try to meet with Ahmad and talk it out. Hopefully I am missing something. 👍

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

how to do preferred-color-scheme without adding more variables.

#48568 already had that behaviour for logged out users. That can be reused.

Anyways, all I was trying to say is that we need to be clear about what we actually want before writing code. If there was a consensus reached in the meeting, that's great, but it doesn't seem to have been documented.

From memory, Mrugesh proposed something similar to GitHub's approach i.e. have three settings

  1. respect browser/os settings
  2. dark
  3. light

By default (and when the user is logged out) we want 1. Otherwise we want whatever the user chooses via the settings or menu.

That seems fine to me, and builds on #47299 (comment) but I'm curious what @raisedadead, @ahmadabdolsaheb and @naomi-lgbt think.

@raisedadead

raisedadead commented Dec 16, 2022 •

Copy link
Copy Markdown
Member

Whatever Oliver said is accurate and should be the flow.

In addition, and only for signed-in users, the theme value should be stored/replicated in their DB record and local storage. Any theme change in the settings should happen in this order:

User changes setting --> Update DB --> Update the Local Storage.

The CSS should then use the local storage value as the source of truth for the signed-in user. This will avoid any "flash" of theme change during page navigation and reloads because the CSS would avoid reading the DB values directly.

For non-signed-in users, all the above can go down the drain, and only a simple preference hierarchy can be followed (assuming we let them do this in the menu or something):

  1. OS Setting
  2. Dark
  3. Light

Which can get dropped in the local storage (preferably a different key than the signed-in user) for revisits and reloads etc.

In both cases the CSS should always check the local storage for it's rendering.

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Thanks for clarifying the spec @raisedadead. That seems solid.

@Sboonny Sboonny added the status: PR in works Work in Progress (WIP) Issues. label Dec 16, 2022
@bbsmooth

bbsmooth commented Jan 7, 2023

Copy link
Copy Markdown
Contributor

@Sboonny This is getting very close. Just a few things that need to be addressed.

  • We should get rid of the "Toggle Checkmark" sr-only text. The aria-pressed attribute will tell screen reader users that the button is currently active. This sr-only text is just duplicate, unneeded information for them. The checkmark is only for the benefit of sighted users. Also, the sr-only text is added to the accessible name of the button but it is not really intended to be part of the accessible name. UPDATE: Ahh, I see that all of the toggle buttons on this page have the "Toggle Checkmark" sr-only text. So perhaps this is a wider issue than just this one component. If fixing this would take you out of scope of this PR then don't worry about it now and I will fix it in a separate PR.
  • If a user clicks a button that is already pressed then nothing should happen. As it is now, the updated flash message appears on the screen when a currently pressed button is clicked. Again, if fixing this is out of scope then I will fix it in a separate PR.

Also, I'm not sure the aria-disabled attribute is needed. I understand why it seems like it would be a good idea, but all of the accessible patterns I have seen for this widget do not use it. I am going to do a little more research and I'll get back to you with my recommendation.

@ojeytonwilliams ojeytonwilliams added the status: blocked In a transient & temporary hold. label Jan 9, 2023
@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Blocked until #48974 is in. Also, per #48974 (comment), we want to add tests to make sure that the editor's theme is in sync with the rest of the site.

@Sboonny
Sboonny marked this pull request as draft January 9, 2023 17:15
@bbsmooth

Copy link
Copy Markdown
Contributor

@Sboonny Concerning aria-disabled, after reading up on suggested patterns for exclusive toggle button groups, looking at real world implementations, and getting feedback from accessibility professionals who are much more seasoned than me, it basically comes down to aria-disabled is probably not essential here, but it probably doesn't hurt either.

Ideally, we would do testing with screen reader users to determine whether aria-disabled is preferred. I tried to find others who have already done testing on this but couldn't find anything. And the ARIA Authoring Practices Guide doesn't have anything on this particular pattern. So until we can get some definitive data we are really just guessing.

If I had to pick, I would choose to remove aria-disabled from the buttons based on:

  • Every exclusive toggle button group implementation I looked at in the "real world" does not use aria-disabled. So if this is the most common pattern then screen reader users may be more comfortable with it.
  • No articles I found about implementing this pattern used aria-disabled, reinforcing that this might be the generally accepted pattern.
  • It is generally considered a good practice to use the minimum amount of ARIA needed and since aria-disabled basically just mimics aria-pressed it could be seen as unnecessary duplicate information.

But really, without testing we can't know for sure which would be preferred (and there is a possibility that testing could give us ambiguous results). So if we want to leave aria-disabled on these buttons then you will not get any push back from me (at least not at the moment).

@Sboonny Sboonny left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's delete it 👍

@github-actions github-actions Bot added the scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. label Jan 25, 2023
@Sboonny Sboonny added the status: on the roadmap Long term plans and features. label Mar 9, 2023
@Sboonny

Sboonny commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

I haven't abandoned this, there is too much part that require changes and I am planning to open issues gradually that reduce the needs for that much change.

@raisedadead raisedadead removed the status: on the roadmap Long term plans and features. label Mar 21, 2023
@Sboonny Sboonny mentioned this pull request Mar 30, 2023
4 tasks done
@Sboonny Sboonny closed this May 28, 2023
@Sboonny
Sboonny deleted the add/system-style-refactor branch May 28, 2023 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: api Server application that needs familiarity with Express, Fastify, MongoDB etc. platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: i18n language translation/internationalization. Often combined with language type label scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. status: blocked In a transient & temporary hold.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants