Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Social Media Dashboard toggle

Berta Plumaโ€ข 40

@bertapsan

Desktop design screenshot for the Social media dashboard with theme switcher coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hi, please check my "solution", any feedback will be more than welcome, appreciate any testing suggestion ;-) Note: take into account I have had no access to the sketch or the Figma file.

Community feedback

Mike Haydenโ€ข 1,005

@mickyginger

Posted

Hi Berta, this looks great! ๐Ÿ˜„

I like your approach for setting the theme by loading in different stylesheets but I wonder if it would be more performant to set a class on the HTML when the user toggles the theme, then apply different styles based on that class... Something like:

function handleToggle(e) {
  const htmlElem = document.querySelector('html')
  htmlElem.classList.remove('light', 'dark');
  htmlElem.classList.add(e.target.checked ? 'dark' : 'light');
}

Then in your SCSS:

/* base styles here */

html.dark {
  /* dark styles here */
}

html.light {
  /* light styles here */
}

Hope that's helpful!

Marked as helpful

0
Berta Plumaโ€ข 40

@bertapsan

Posted

Hi Mike, really appreciate your feedback. Your proposal was my first option, but it was not working, being honest I was trying to use .body, I will try it with .html. ;-)

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord