Skip to content

marcus-hugo/social-media-dashboard-with-theme-switcher-master

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - Social media dashboard with theme switcher solution

This is a solution to the Social media dashboard with theme switcher challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the site depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Toggle color theme to their preference

Screenshot

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • CSS Grid
  • Mobile-first workflow
  • Sass
  • Vanilla JS

What I learned

Setting up a Sass folder structure. Set up Sass to output to CSS and watch for file changes with Sass CLI. Also, used VS Code extension Live Server. Importing partials with @use. Created a simple mixin. Using namespaces to reference mixins with @include namespace.mixin.

Creating a dark theme that can be switched on and off with a toggle button made with an input checkbox. Having a prefers-color-scheme based on user's OS settings. Each of these on their own are prettty simple, but, when both are implimented I needed to add a dark-theme class as well as a light-theme class. I wanted the toggle position to stay the same for either mode wether prefers-color-scheme was overiding or the manual switching. That's where window.matchMedia.matches came in handy to identify the OS preference. Then I had a problem on reload, where the toggle position would stay in the same position and the toggling would be backwards. So I researched window.onload and made a function:

function togglePosition() {
  if(mediaQueryList.matches === true || body.className === 'light-theme') {
    checkbox.checked = true;
  } else {
    checkbox.checked = false;
  }
} 

Also, found that using the checkbox method gave acces to checkbox.checked to set the checkbox position on reload.

Continued development

Refactoring JS. Learning more about Sass.

Useful resources

Author

Acknowledgments

About

Social media dashboard with OS prefers-color-scheme or can manually toggle a switch to override.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published