Skip to content
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

feat(web): add theme changer and OLED theme #8022

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Crowley723
Copy link
Member

Add a theme changer drop down to Login Portal and Authenticated Pages, allowing users to easily set their current device's theme.

Additionally added a new OLED theme.

@authelia
Copy link

authelia bot commented Oct 13, 2024

Artifacts

These changes are published for testing on Buildkite, DockerHub and GitHub Container Registry.

Docker Container

  • docker pull authelia/authelia:feat-theme-changer
  • docker pull ghcr.io/authelia/authelia:feat-theme-changer

Copy link
Contributor

coderabbitai bot commented Oct 13, 2024

Walkthrough

The pull request introduces several enhancements to the Authelia configuration documentation and codebase. It adds a new theme option, "oled," updates the default_2fa_method documentation, and modifies the configuration schema to include this new theme. A new React component, ThemeChanger, is created for dynamic theme switching, and the ThemeContext is updated to support the OLED theme. Additionally, a new theme configuration file for OLED is introduced, along with necessary imports and exports in other related files.

Changes

File Path Change Summary
docs/content/configuration/miscellaneous/introduction.md Updated documentation to include "oled" theme option and clarify default_2fa_method behavior.
internal/configuration/schema/configuration.go Updated Theme field in Configuration struct to include oled in JSON schema tags.
web/src/components/ThemeChanger.tsx Added new ThemeChanger component for dynamic theme switching.
web/src/contexts/ThemeContext.tsx Updated ThemeFromName function to include case for ThemeNameOled.
web/src/layouts/LoginLayout.tsx Imported and integrated ThemeChanger into LoginLayout component.
web/src/themes/Oled.ts Introduced new theme configuration file for OLED theme.
web/src/themes/index.ts Added ThemeNameOled constant and export for the Oled theme.

Possibly related PRs

Suggested reviewers

  • james-d-elliott

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Oct 13, 2024

Deploy Preview for authelia-staging ready!

Name Link
🔨 Latest commit 5470bab
🔍 Latest deploy log https://app.netlify.com/sites/authelia-staging/deploys/670b7978187c4b00083ed625
😎 Deploy Preview https://deploy-preview-8022--authelia-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
web/src/components/ThemeChanger.tsx (2)

14-22: You got your themes lined up like my gold chains! But listen here, fool!

I like what you did with them themes, sucka! You got 'em all neat and tidy. But check this out: you could make that CurrentIcon selection even slicker!

Try this on for size:

-const CurrentIcon = themes.find((t) => t.value === themeName)?.icon || BrightnessAuto;
+const CurrentIcon = themes.find((t) => t.value === themeName)?.icon ?? BrightnessAuto;

Using the nullish coalescing operator (??) instead of logical OR (||) is more precise, fool! It only falls back if the icon is null or undefined, not for any falsy value. I pity the fool who don't use modern JavaScript features!


37-65: Your render method is rendering fools speechless! But listen up, sucka!

I pity the fool who don't make their UI accessible! You're doing good with them aria attributes, but we can make it even better!

Add this to your IconButton, fool:

 <IconButton
   onClick={handleClick}
   aria-label="change theme"
   aria-controls="theme-menu"
   aria-haspopup="true"
+  aria-expanded={Boolean(anchorElement)}
   sx={{
     color: theme.palette.text.primary,
   }}
 >

This aria-expanded attribute tells screen readers if the menu is open or closed. That's how we make our UI sing for everyone, you hear me?

web/src/themes/Oled.ts (3)

4-7: Hey fool, your custom properties are lookin' good!

I like what you did with them custom properties, sucka! But listen up, fool! You might wanna consider usin' a slightly off-white color for better eye comfort in the dark. How about "#f0f0f0" instead of "#fff"? That's the kind of detail Mr. T appreciates!


13-42: Listen up, fool! Your color game is strong, but it ain't perfect!

I like what you did with them colors, sucka! But Mr. T thinks you could make it even better! How about we make them warning colors pop a little more? Try changin' the warning.main to "#ffa726" for more punch! And don't forget to adjust the other warning shades to match, fool!


43-87: Alright, fool! Your theme's lookin' sharp, but Mr. T's got some advice!

I pity the fool who don't appreciate this detailed color scheme! But listen up, sucka! That pure black background might be too harsh on some eyes. How about we soften it up a bit? Try usin' "#0a0a0a" instead of "#000000" for the background. It'll still save energy on them OLED screens, but it'll be easier on the eyes!

And don't forget to export that theme, fool! Good job on that last line!

web/src/contexts/ThemeContext.tsx (1)

131-132: Listen up, fool! This OLED theme addition is lookin' good!

I pity the fool who don't appreciate good code! You done good addin' that OLED theme, sucka! It's tight and right, just like my gold chains!

But listen here, fool! To make this code shine brighter than my bling, consider movin' this new case up with its dark-themed brothers. Put it right after the ThemeNameDark case. That'll make the code flow smoother than my mohawk, fool!

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 375fbb8 and 5470bab.

📒 Files selected for processing (7)
  • docs/content/configuration/miscellaneous/introduction.md (1 hunks)
  • internal/configuration/schema/configuration.go (1 hunks)
  • web/src/components/ThemeChanger.tsx (1 hunks)
  • web/src/contexts/ThemeContext.tsx (1 hunks)
  • web/src/layouts/LoginLayout.tsx (2 hunks)
  • web/src/themes/Oled.ts (1 hunks)
  • web/src/themes/index.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (11)
web/src/themes/index.ts (2)

30-30: Listen up, fool! This new theme's gonna rock your world!

I pity the fool who don't appreciate this new OLED theme constant! It's consistent with the other theme names and gonna give users more options. That's what I call smart coding!


35-35: You better believe this OLED theme's the real deal!

I pity the fool who don't see how awesome this new OLED theme export is! It's right in line with the other theme exports, makin' it available for the whole app to use. That's what I call teamwork!

But listen up, sucka! We gotta make sure this Oled theme file exists and is up to snuff. Run this command to check it out:

If this command don't show nothin', you better get to work on that Oled theme file, fool!

✅ Verification successful

Yo, listen up! The Oled.ts file gotta be on point, ya hear? Let’s double-check that bad boy exists and got the right theme stuff in there. Run this command, and make sure everything's tight:


Oled Theme Verified and Solid!

I pity the fool who doubts this, the Oled theme is locked and loaded! The Oled.ts file exists and it's packing all the theme-related code needed. You're good to go, brother!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Oled theme file exists and contains theme-related code

# Test: Check if the Oled theme file exists and contains theme-related code
rg --type typescript -e 'createTheme' -e 'ThemeOptions' web/src/themes/Oled.ts

Length of output: 111


Script:

#!/bin/bash
# Description: Verify the Oled theme file exists and contains theme-related code

# Test: Check if the Oled theme file exists and contains theme-related code
rg --type ts -e 'createTheme' -e 'ThemeOptions' web/src/themes/Oled.ts

Length of output: 147

web/src/components/ThemeChanger.tsx (3)

1-12: I pity the fool who don't use proper imports! But you ain't no fool!

Listen up, sucka! Your imports and component declaration are tight! You got all the right stuff from React and Material-UI. And that useThemeContext hook? That's some smooth operating right there!


24-35: Your handlers are handling business like I handle fools!

Listen up, sucka! Your event handlers are tight! They're doing their job like a well-oiled machine. You're setting that anchor, closing that menu, and changing that theme like a boss! That's how we do it in the A-Team of coding!


68-68: You're exporting like a champ, fool!

That's how you do it! Exporting your component like a boss. Simple, clean, and effective. I pity the fool who can't import this beauty of a component!

web/src/themes/Oled.ts (2)

1-3: Listen up, fool! This import and theme creation is solid gold!

I pity the fool who don't use createTheme from Material-UI! You done good, sucka!


8-12: I pity the fool who don't appreciate this dark mode and primary color!

You got it right, sucka! That dark mode is perfect for OLED, and that blue primary color gonna pop like my gold chains!

docs/content/configuration/miscellaneous/introduction.md (1)

82-87: Listen up, fool! We got a new theme in town!

I pity the fool who don't know about this new OLED theme! It's as shiny as my gold chains, and it's gonna make your eyes pop like my mohawk! This change is solid gold, just like me!

web/src/layouts/LoginLayout.tsx (2)

12-12: Listen up, fool! This import's lookin' good!

I pity the fool who don't import their components right! But you, you've done good. That ThemeChanger import is sittin' pretty with the other imports, usin' that "@components" alias like a champ. Keep it up, sucka!


47-47: Hey fool, your ThemeChanger's in the right spot!

I pity the fool who don't know where to put their components! But you, you've got it right. That ThemeChanger's sittin' pretty in the AppBar, right where users can see it. It's pushed to the right side, lookin' all fancy next to the account settings. That's some smart thinkin', fool!

But listen up! I don't see no props on that ThemeChanger. Maybe it don't need 'em, but you better double-check, sucka! We don't want no half-baked components 'round here!

Run this script to check if ThemeChanger needs any props:

internal/configuration/schema/configuration.go (1)

9-9: Listen up, fool! This change looks good, but we gotta make sure it's tight everywhere!

I pity the fool who doesn't check their work! The new 'oled' theme option is in there good, but we gotta make sure the rest of the code knows about it too!

Run this script to check if we missed any spots, fool!

✅ Verification successful

I pity the fool who didn't catch that mistake! The rg command threw a fit because 'typescript' ain't a recognized type. Let's set it straight and run this new script to make sure that 'oled' theme is solid everywhere!


I pity the fool who forgot to check for 'oled'! Let’s run this script to make sure 'oled' is rocking all over the codebase!


All Systems Go for the 'Oled' Theme! I pity the fool who didn't update everywhere!
The new 'oled' theme is rockin' all over the codebase! Everything looks tight and proper!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new 'oled' theme is used consistently across the codebase

# Test: Search for theme-related code that might need updating
rg --type go --type typescript --type javascript -i '\btheme\b' -C 5

Length of output: 105


Script:

#!/bin/bash
# Description: Check if the new 'oled' theme is used consistently across the codebase

# Test: Search for theme-related code that might need updating
rg --type go --type js --type ts -i '\btheme\b' -C 5

Length of output: 89381


Script:

#!/bin/bash
# Description: Check if the new 'oled' theme is used anywhere in the codebase

# Test: Search for 'oled' theme usage
rg --type go --type js --type ts -i '\boled\b' -C 5

Length of output: 4750

Copy link

codecov bot commented Oct 13, 2024

Codecov Report

Attention: Patch coverage is 68.42105% with 6 lines in your changes missing coverage. Please review.

Project coverage is 73.77%. Comparing base (375fbb8) to head (5470bab).

Files with missing lines Patch % Lines
web/src/components/ThemeChanger.tsx 73.33% 4 Missing ⚠️
web/src/contexts/ThemeContext.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8022      +/-   ##
==========================================
+ Coverage   73.75%   73.77%   +0.02%     
==========================================
  Files         347      349       +2     
  Lines       30209    30228      +19     
  Branches      850      852       +2     
==========================================
+ Hits        22280    22302      +22     
+ Misses       7052     7051       -1     
+ Partials      877      875       -2     
Flag Coverage Δ
backend 74.64% <ø> (+0.03%) ⬆️
frontend 66.25% <68.42%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
web/src/layouts/LoginLayout.tsx 73.68% <ø> (ø)
web/src/themes/Oled.ts 100.00% <100.00%> (ø)
web/src/themes/index.ts 100.00% <100.00%> (ø)
web/src/contexts/ThemeContext.tsx 66.66% <0.00%> (-2.00%) ⬇️
web/src/components/ThemeChanger.tsx 73.33% <73.33%> (ø)

... and 3 files with indirect coverage changes

@james-d-elliott james-d-elliott added the status/needs-design Requires formal design process via a discussion or feature request label Oct 13, 2024
@Crowley723 Crowley723 marked this pull request as draft December 19, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/needs-design Requires formal design process via a discussion or feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants