-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demos): Add example themes & load theme from URL (#1967)
To test, visit the following URL: http://localhost:8080/theme/index.html?theme=dark The `theme` param must be one of `baseline`, `black`, `dark`, `white`, or `yellow`. This only works on the theme demo page; all other demo pages are unaffected.
- Loading branch information
Showing
9 changed files
with
346 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* @license | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
(function() { | ||
var TRUSTED_THEMES = ['baseline', 'black', 'dark', 'white', 'yellow']; | ||
var DEFAULT_THEME = TRUSTED_THEMES[0]; | ||
var PRIVATE_TYPE_MARKER = {}; | ||
|
||
/** | ||
* A strongly-typed wrapper around a string that is guaranteed to be safe to inject into HTML. | ||
* Inspired by the Closure library's SafeHtml class: | ||
* https://google.github.io/closure-library/api/goog.html.SafeHtml.html | ||
* @struct | ||
* @final | ||
* @private | ||
*/ | ||
function SafeTheme() { | ||
/** @type {!Object} */ | ||
this.PRIVATE_TYPE_MARKER_ = PRIVATE_TYPE_MARKER; | ||
|
||
/** @type {string} */ | ||
this.PRIVATE_SAFE_VALUE_ = ''; | ||
} | ||
|
||
/** @return {string} */ | ||
SafeTheme.prototype.toString = function() { | ||
return 'SafeTheme{' + this.PRIVATE_SAFE_VALUE_ + '}'; | ||
}; | ||
|
||
function createSafeTheme(unsafeValue) { | ||
var safeValue = TRUSTED_THEMES.indexOf(unsafeValue) > -1 ? unsafeValue : DEFAULT_THEME; | ||
var safeTheme = new SafeTheme(); | ||
safeTheme.PRIVATE_SAFE_VALUE_ = safeValue; | ||
return safeTheme; | ||
} | ||
|
||
/** | ||
* @param {string} unsafeThemeName | ||
* @return {!SafeTheme} | ||
*/ | ||
window.getSafeDemoTheme = function(unsafeThemeName) { | ||
return createSafeTheme(unsafeThemeName); | ||
}; | ||
|
||
/** | ||
* @param {string|undefined=} opt_uri | ||
* @return {!SafeTheme} | ||
*/ | ||
window.getSafeDemoThemeFromUri = function(opt_uri) { | ||
return getSafeDemoTheme(parseQueryString(opt_uri).getLast('theme')); | ||
}; | ||
|
||
/** | ||
* @param {!SafeTheme} safeTheme | ||
* @return {string} | ||
*/ | ||
window.unwrapSafeDemoTheme = function(safeTheme) { | ||
if (safeTheme instanceof SafeTheme && | ||
safeTheme.constructor === SafeTheme && | ||
safeTheme.PRIVATE_TYPE_MARKER_ === PRIVATE_TYPE_MARKER) { | ||
return safeTheme.PRIVATE_SAFE_VALUE_; | ||
} | ||
console.error('Expected object of type SafeTheme, but got', safeTheme); | ||
return 'type_error:SafeTheme'; | ||
}; | ||
|
||
/** @type {string} */ | ||
var unwrappedTheme = unwrapSafeDemoTheme(getSafeDemoThemeFromUri()); | ||
|
||
// Avoid a FOUC by injecting the stylesheet directly into the HTML stream while the browser is parsing the page. | ||
// This causes the browser to block page rendering until the CSS has finished loading. | ||
document.write( | ||
'<link rel="stylesheet" href="/assets/theme/theme-' + unwrappedTheme + '.css" id="theme-stylesheet" data-hot>'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@import "../../packages/mdc-theme/color-palette"; | ||
|
||
// TODO: Use theme mixin(s) instead | ||
$demo-toolbar-progress-bar-color: secondary-light; | ||
|
||
@import "./theme-shared"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@import "../../packages/mdc-theme/color-palette"; | ||
|
||
// TODO: Use theme mixin(s) instead | ||
$mdc-theme-primary: $material-color-grey-900; | ||
$mdc-theme-secondary: $material-color-light-green-a700; | ||
|
||
@import "./theme-shared"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@import "../../packages/mdc-theme/color-palette"; | ||
|
||
// TODO: Use theme mixin(s) instead | ||
$mdc-theme-primary: $material-color-amber-300; | ||
$mdc-theme-secondary: $material-color-pink-400; | ||
$mdc-theme-background: $material-color-grey-900; | ||
|
||
@import "./theme-shared"; | ||
@import "../../packages/mdc-checkbox/mixins"; | ||
@import "../../packages/mdc-radio/mixins"; | ||
@import "../../packages/mdc-textfield/mixins"; | ||
|
||
// TODO: Call theme mixins for mdc-select | ||
|
||
.demo-checkbox { | ||
@include mdc-checkbox-container-colors(text-secondary-on-dark); | ||
} | ||
|
||
.demo-radio { | ||
@include mdc-radio-unchecked-stroke-color(text-secondary-on-dark); | ||
} | ||
|
||
.demo-text-field { | ||
@include mdc-text-field-ink-color(text-primary-on-dark); | ||
@include mdc-text-field-label-color(text-secondary-on-dark); | ||
@include mdc-text-field-bottom-line-color(text-hint-on-dark); | ||
} | ||
|
||
.demo-checkbox-wrapper, | ||
.demo-radio-form-field { | ||
@include mdc-theme-prop(color, text-primary-on-dark); | ||
} | ||
|
||
.demo-tab { | ||
@include mdc-tab-label-ink-color(text-secondary-on-dark); | ||
@include mdc-tab-icon-ink-color(text-icon-on-dark); | ||
|
||
&:hover { | ||
@include mdc-tab-label-ink-color(text-primary-on-dark); | ||
@include mdc-tab-icon-ink-color(text-secondary-on-dark); | ||
} | ||
} |
Oops, something went wrong.