-
-
Notifications
You must be signed in to change notification settings - Fork 64
feat: Adicionei a nova feature de dark-mode #669
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||||||||||
| import angular from "angular"; | ||||||||||||||||
|
|
||||||||||||||||
| const themeService = function ($window, $document) { | ||||||||||||||||
| const service = this; | ||||||||||||||||
| const storageKey = "brmw-theme"; | ||||||||||||||||
| const themes = { | ||||||||||||||||
| light: "light", | ||||||||||||||||
| dark: "dark", | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| const getBody = () => $document[0].body; | ||||||||||||||||
|
|
||||||||||||||||
| service.getTheme = () => { | ||||||||||||||||
| return $window.localStorage.getItem(storageKey) || themes.light; | ||||||||||||||||
| }; | ||||||||||||||||
|
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If 🛡️ Proposed fix — validate against known themes service.getTheme = () => {
- return $window.localStorage.getItem(storageKey) || themes.light;
+ const stored = $window.localStorage.getItem(storageKey);
+ return Object.values(themes).includes(stored) ? stored : themes.light;
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| service.applyTheme = (theme) => { | ||||||||||||||||
| const selectedTheme = theme === themes.dark ? themes.dark : themes.light; | ||||||||||||||||
| const body = getBody(); | ||||||||||||||||
|
|
||||||||||||||||
| body.classList.toggle("theme-dark", selectedTheme === themes.dark); | ||||||||||||||||
| body.classList.toggle("theme-light", selectedTheme === themes.light); | ||||||||||||||||
| $window.localStorage.setItem(storageKey, selectedTheme); | ||||||||||||||||
|
|
||||||||||||||||
| return selectedTheme; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| service.toggleTheme = () => { | ||||||||||||||||
| const nextTheme = service.getTheme() === themes.dark ? themes.light : themes.dark; | ||||||||||||||||
| return service.applyTheme(nextTheme); | ||||||||||||||||
| }; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| export default angular.module("app.themeService", []).service("ThemeService", themeService).name; | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
aria-pressedso screen readers can announce the active theme.Per the WAI-ARIA Authoring Practices Guide, if the button is a toggle button, it must carry an
aria-pressedstate. Currently only the visual.activeclass communicates which theme is selected; state changes fail completely when you rely on visual-only indicators like colour changes.♿ Proposed fix — add
aria-pressedto both buttons<button type="button" ng-class="{active: $ctrl.theme === 'light'}" + ng-attr-aria-pressed="{{ $ctrl.theme === 'light' }}" ng-click="$ctrl.setTheme('light')" > {{ 'Light' | translate }} </button> <button type="button" ng-class="{active: $ctrl.theme === 'dark'}" + ng-attr-aria-pressed="{{ $ctrl.theme === 'dark' }}" ng-click="$ctrl.setTheme('dark')" > {{ 'Dark' | translate }} </button>ng-attr-aria-pressedis used instead ofaria-presseddirectly to emit the attribute with the correct boolean string ("true"/"false"), which AngularJS expression interpolation alone would leave as the JS boolean value.📝 Committable suggestion
🤖 Prompt for AI Agents