Uh oh!
There was an error while loading. Please reload this page.
feat(navbar): Add themepicker component with lazy loaded themes - #136
Conversation
6857c10 to
7f6cd6cCompareThere was a problem hiding this comment.
Pulled this down and tried it out- this is a good start!
Let's keep this PR scoped as-is but omit the theme-picker from the navbar until we get these follow-ups done:
- Show the currently selected theme in the picker (similar to fonts.google.com)
- Use inline SVGs instead of
img/background-imageso that we can manipulate their colors (could usemd-iconfor this). - Fix text and background color on all pages when switching to a dark theme
- Remember selected theme in local storage (including updating on change)
- Load different highlight.js files based on whether we're in a light or dark theme
| * @param key The key for the slot whose element we want. | ||
| * @param create Whether to create the element if it doesn't exist. | ||
| * @returns {HTMLLinkElement} The `<link.` element. | ||
| * @private |
There was a problem hiding this comment.
Omit @private and type information from JsDoc since that's captured in the TypeScript code.
| document.head.appendChild(linkEl); | ||
| } | ||
| return linkEl as HTMLLinkElement; | ||
| } |
There was a problem hiding this comment.
Rather than having one function perform two behaviors with an option, I generally prefer breaking it up into separate functions. Also, most of these can be module-level functions since they are pure functions, e.g.
classStyleManager{setStyle(key: string,href: string){getLinkElementForKey(key).setAttribute('href',href);}removeStyle(key: string){constexistingLinkElement=getExistingLinkElementByKey(key);if(existingLinkElement){document.head.removeChild(existingLinkElement);}}}functiongetLinkElementForKey(key: string){returngetExistingLinkElementByKey(key)||createLinkElementWithKey(key);}functiongetExistingLinkElementByKey(key: string){returndocument.head.querySelector(`link[rel="stylesheet"].${getClassNameForKey(key)}`);}functioncreateLinkElementWithKey(key: string){constlinkEl=document.createElement('link');linkEl.setAttribute('rel','stylesheet');linkEl.classList.add(getClassNameForKey(key));document.head.appendChild(linkEl);returnlinkEl;}functiongetClassNameForKey(key: string){return`style-manager-${key}`;}| $theme-chooser-accent-stripe-size: 6px; | ||
| .theme-chooser-menu { |
| import {Component, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core'; | ||
| import {StyleManager} from '../style-manager/style-manager'; | ||
| @Component({ |
There was a problem hiding this comment.
We should make the theme chooser aria-hidden="true" and ensure that the button is not in the tab order since a screen-reader user won't get any benefit from changing the app colors.
| { | ||
| primary: '#673AB7', | ||
| accent: '#FFC107', | ||
| href: 'assets/deeppurple-amber.css' |
There was a problem hiding this comment.
We should omit assets/ on each entry and add it in the function call.
| {"input": "assets/pink-bluegrey.css", "lazy": true}, | ||
| {"input": "assets/deeppurple-amber.css", "lazy": true}, | ||
| {"input": "assets/indigo-pink.css", "lazy": true}, | ||
| {"input": "assets/purple-green.css", "lazy": true} |
There was a problem hiding this comment.
Can these be referenced directly from node_modules rather than copying them to assets?
| .theme-chooser-accent { | ||
| position: absolute; | ||
| bottom: $theme-chooser-accent-stripe-size; |
There was a problem hiding this comment.
How do you feel about the accent stripe? I'm not particularly fond of it.
46e1553 to
74eb084Compared586c1e to
f9b7669Compare9dcc56b to
1cfa71fCompareee4b628 to
db8f833Compare
jelbourn
left a comment
There was a problem hiding this comment.
I pulled down the PR and tried it out- looks great!
| Footer, | ||
| ], | ||
| schemas: [ | ||
| CUSTOM_ELEMENTS_SCHEMA, |
There was a problem hiding this comment.
CUSTOM_ELEMENTS_SCHEMA ideally shouldn't be here; why was this needed?
| MaterialModule, | ||
| MdNativeDateModule, | ||
| routing, | ||
| InlineSVGModule, |
There was a problem hiding this comment.
InlineSvgModule (camelCase even for acronyms)
| import {Component, ViewEncapsulation} from '@angular/core'; | ||
| import {Router, NavigationStart} from '@angular/router'; | ||
| // import {ThemeStorage} from './shared/theme-chooser/theme-storage/theme-storage'; |
| // public _setIsDarkTheme(theme) { | ||
| // this.isDarkTheme = theme ? theme.isDark : this.isDarkTheme; | ||
| // } |
| background-size: contain; | ||
| background-repeat: no-repeat; | ||
| background-position: center; | ||
| :host /deep/ .docs-component-category-list-card-image svg { |
There was a problem hiding this comment.
I'd like to avoid /deep/ completely, instead preferring to add a global style (or, barring that, turning off view encapsulation for the component)
| const Color = require('color'); | ||
| export interface IThemeColors { |
There was a problem hiding this comment.
We prefer not to prefix interfaces with I (here and elsewhere)
| import {IDocsSiteTheme} from '../theme-chooser/theme-storage/theme-storage'; | ||
| const Color = require('color'); |
There was a problem hiding this comment.
What's this require doing here?
| public ngAfterViewInit() { | ||
| if (this.currTheme) { | ||
| setTimeout(this.swapTheme.bind(this, this.currTheme)); |
There was a problem hiding this comment.
Prefer arrow functions to using bind
| <div class="docs-theme-chooser-swatch"> | ||
| <md-icon class="docs-theme-chosen-icon" *ngIf="currentTheme === theme">check_circle</md-icon> | ||
| <div class="docs-theme-chooser-primary" [style.background]="theme.primary"></div> | ||
| <!--<div class="docs-theme-chooser-accent" [style.background]="theme.accent"></div>--> |
| <md-icon>format_color_fill</md-icon> | ||
| </button> | ||
| <md-menu class="docs-theme-chooser-menu" #themeMenu="mdMenu" x-position="before"> |
There was a problem hiding this comment.
Add a TODO here like
<!-- TODO: replace use of `md-menu` here with a custom overlay -->798538e to
1649a41Compare@jelbourn I'm looking at
Am I missing something? |
Picking up the theme picker feature from where it was left off.