1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update shared components

This commit is contained in:
Luke Pulverenti 2016-03-09 12:40:22 -05:00
parent fb269362ff
commit 71811cb9e3
221 changed files with 32936 additions and 101 deletions

View file

@ -0,0 +1,218 @@
/**
* Copyright 2015 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 "../variables";
@import "../mixins";
// The container for the whole component.
.mdl-textfield {
position: relative;
font-size: $input-text-font-size;
display: inline-block;
box-sizing: border-box;
width: 300px;
max-width: 100%;
margin: 0;
padding: $input-text-vertical-spacing 0;
// Align buttons, if used.
& .mdl-button {
position: absolute;
bottom: $input-text-vertical-spacing;
}
}
// Optional class to align right.
.mdl-textfield--align-right {
text-align: right;
}
// Optional class to display at full width.
.mdl-textfield--full-width {
width: 100%;
}
// Optional class to make the text field expandable.
.mdl-textfield--expandable {
min-width: $input-text-button-size;
width: auto;
min-height: $input-text-button-size;
}
// Styling for the input element.
.mdl-textfield__input {
border: none;
border-bottom: 1px solid $input-text-bottom-border-color;
display: block;
font-size: $input-text-font-size;
font-family: $performance_font;
margin: 0;
padding: $input-text-padding 0;
width: $input-text-width;
background: none;
text-align: left;
color: inherit;
&[type="number"] {
-moz-appearance: textfield;
}
&[type="number"]::-webkit-inner-spin-button,
&[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
.mdl-textfield.is-focused & {
outline: none;
}
.mdl-textfield.is-invalid & {
border-color: $input-text-error-color;
box-shadow: none;
}
fieldset[disabled] .mdl-textfield &,
.mdl-textfield.is-disabled & {
background-color: transparent;
border-bottom: 1px dotted $input-text-disabled-color;
color: $input-text-disabled-text-color;
}
}
.mdl-textfield textarea.mdl-textfield__input {
display: block;
}
// Styling for the label / floating label.
.mdl-textfield__label {
bottom: 0;
color: $input-text-label-color;
font-size: $input-text-font-size;
left: 0;
right: 0;
pointer-events: none;
position: absolute;
display: block;
top: ($input-text-padding + $input-text-vertical-spacing);
width: 100%;
overflow: hidden;
white-space: nowrap;
text-align: left;
.mdl-textfield.is-dirty &,
.mdl-textfield.has-placeholder & {
visibility: hidden;
}
// Floating Label
.mdl-textfield--floating-label & {
@include material-animation-default();
}
.mdl-textfield--floating-label.has-placeholder & {
transition: none;
}
fieldset[disabled] .mdl-textfield &,
.mdl-textfield.is-disabled.is-disabled & {
color: $input-text-disabled-text-color;
}
.mdl-textfield--floating-label.is-focused &,
.mdl-textfield--floating-label.is-dirty &,
.mdl-textfield--floating-label.has-placeholder & {
color: $input-text-highlight-color;
font-size : $input-text-floating-label-fontsize;
top: $input-text-vertical-spacing - ($input-text-floating-label-fontsize + $input-text-padding);
visibility: visible;
}
.mdl-textfield--floating-label.is-focused .mdl-textfield__expandable-holder &,
.mdl-textfield--floating-label.is-dirty .mdl-textfield__expandable-holder &,
.mdl-textfield--floating-label.has-placeholder .mdl-textfield__expandable-holder & {
top: -($input-text-floating-label-fontsize + $input-text-padding);
}
.mdl-textfield--floating-label.is-invalid & {
color: $input-text-error-color;
font-size: $input-text-floating-label-fontsize;
}
// The after label is the colored underline for the TextField.
&:after {
background-color: $input-text-highlight-color;
bottom: $input-text-vertical-spacing;
content: '';
height: 2px;
left: 45%;
position: absolute;
@include material-animation-default();
visibility: hidden;
width: 10px;
}
.mdl-textfield.is-focused &:after {
left: 0;
visibility: visible;
width: 100%;
}
.mdl-textfield.is-invalid &:after {
background-color: $input-text-error-color;
}
}
// TextField Error.
.mdl-textfield__error {
color: $input-text-error-color;
position: absolute;
font-size: $input-text-floating-label-fontsize;
margin-top: 3px;
visibility: hidden;
display: block;
.mdl-textfield.is-invalid & {
visibility: visible;
}
}
// Expandable Holder.
.mdl-textfield__expandable-holder {
display: inline-block;
position: relative;
margin-left: $input-text-button-size;
@include material-animation-default();
display: inline-block;
// Safari (possibly others) need to be convinced that this field is actually
// visible, otherwise it cannot be tabbed to nor focused via a <label>.
// TODO: In some cases (Retina displays), this is big enough to render the
// inner element :(
max-width: 0.1px;
.mdl-textfield.is-focused &, .mdl-textfield.is-dirty & {
// This is an unfortunate hack. Animating between widths in percent (%)
// in many browsers (Chrome, Firefox) only animates the inner visual style
// of the input - the outer bounding box still 'jumps'.
// Thus assume a sensible maximum, and animate to/from that value.
max-width: 600px;
}
.mdl-textfield__label:after {
bottom: 0;
}
}

View file

@ -0,0 +1,7 @@
<style>
.demo-textfield__textfield-expanding .mdl-textfield {
width: 100px;
}
</style>
{% include "textfield-expanding.html" %}

View file

@ -0,0 +1,12 @@
<!-- Expandable Textfield -->
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable">
<label class="mdl-button mdl-js-button mdl-button--icon" for="sample6">
<i class="material-icons">search</i>
</label>
<div class="mdl-textfield__expandable-holder">
<input class="mdl-textfield__input" type="text" id="sample6">
<label class="mdl-textfield__label" for="sample-expandable">Expandable Input</label>
</div>
</div>
</form>

View file

@ -0,0 +1,7 @@
<style>
.demo-textfield__textfield-floating-numeric .mdl-textfield {
width: 100px;
}
</style>
{% include "textfield-floating-numeric.html" %}

View file

@ -0,0 +1,8 @@
<!-- Numeric Textfield with Floating Label -->
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="sample4">
<label class="mdl-textfield__label" for="sample4">Number...</label>
<span class="mdl-textfield__error">Input is not a number!</span>
</div>
</form>

View file

@ -0,0 +1,7 @@
<style>
.demo-textfield__textfield-floating-text .mdl-textfield {
width: 100px;
}
</style>
{% include "textfield-floating-text.html" %}

View file

@ -0,0 +1,8 @@
<!-- Textfield with Floating Label -->
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
</form>

View file

@ -0,0 +1,7 @@
<style>
.demo-textfield__textfield-multi-line .mdl-textfield {
width: 100px;
}
</style>
{% include "textfield-multi-line.html" %}

View file

@ -0,0 +1,7 @@
<!-- Floating Multiline Textfield -->
<form action="#">
<div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows= "3" id="sample5" ></textarea>
<label class="mdl-textfield__label" for="sample5">Text lines...</label>
</div>
</form>

View file

@ -0,0 +1,7 @@
<style>
.demo-textfield__textfield-numeric .mdl-textfield {
width: 100px;
}
</style>
{% include "textfield-numeric.html" %}

View file

@ -0,0 +1,8 @@
<!-- Numeric Textfield -->
<form action="#">
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="sample2">
<label class="mdl-textfield__label" for="sample2">Number...</label>
<span class="mdl-textfield__error">Input is not a number!</span>
</div>
</form>

View file

@ -0,0 +1,7 @@
<style>
.demo-textfield__textfield-text .mdl-textfield {
width: 100px;
}
</style>
{% include "textfield-text.html" %}

View file

@ -0,0 +1,7 @@
<!-- Simple Textfield -->
<form action="#">
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" id="sample1">
<label class="mdl-textfield__label" for="sample1">Text...</label>
</div>
</form>

View file

@ -0,0 +1,284 @@
/**
* @license
* Copyright 2015 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() {
'use strict';
/**
* Class constructor for Textfield MDL component.
* Implements MDL component design pattern defined at:
* https://github.com/jasonmayes/mdl-component-design-pattern
*
* @constructor
* @param {HTMLElement} element The element that will be upgraded.
*/
var MaterialTextfield = function MaterialTextfield(element) {
this.element_ = element;
this.maxRows = this.Constant_.NO_MAX_ROWS;
// Initialize instance.
this.init();
};
window['MaterialTextfield'] = MaterialTextfield;
/**
* Store constants in one place so they can be updated easily.
*
* @enum {string | number}
* @private
*/
MaterialTextfield.prototype.Constant_ = {
NO_MAX_ROWS: -1,
MAX_ROWS_ATTRIBUTE: 'maxrows'
};
/**
* Store strings for class names defined by this component that are used in
* JavaScript. This allows us to simply change it in one place should we
* decide to modify at a later date.
*
* @enum {string}
* @private
*/
MaterialTextfield.prototype.CssClasses_ = {
LABEL: 'mdl-textfield__label',
INPUT: 'mdl-textfield__input',
IS_DIRTY: 'is-dirty',
IS_FOCUSED: 'is-focused',
IS_DISABLED: 'is-disabled',
IS_INVALID: 'is-invalid',
IS_UPGRADED: 'is-upgraded',
HAS_PLACEHOLDER: 'has-placeholder'
};
/**
* Handle input being entered.
*
* @param {Event} event The event that fired.
* @private
*/
MaterialTextfield.prototype.onKeyDown_ = function(event) {
var currentRowCount = event.target.value.split('\n').length;
if (event.keyCode === 13) {
if (currentRowCount >= this.maxRows) {
event.preventDefault();
}
}
};
/**
* Handle focus.
*
* @param {Event} event The event that fired.
* @private
*/
MaterialTextfield.prototype.onFocus_ = function(event) {
this.element_.classList.add(this.CssClasses_.IS_FOCUSED);
};
/**
* Handle lost focus.
*
* @param {Event} event The event that fired.
* @private
*/
MaterialTextfield.prototype.onBlur_ = function(event) {
this.element_.classList.remove(this.CssClasses_.IS_FOCUSED);
};
/**
* Handle reset event from out side.
*
* @param {Event} event The event that fired.
* @private
*/
MaterialTextfield.prototype.onReset_ = function(event) {
this.updateClasses_();
};
/**
* Handle class updates.
*
* @private
*/
MaterialTextfield.prototype.updateClasses_ = function() {
this.checkDisabled();
this.checkValidity();
this.checkDirty();
this.checkFocus();
};
// Public methods.
/**
* Check the disabled state and update field accordingly.
*
* @public
*/
MaterialTextfield.prototype.checkDisabled = function() {
if (this.input_.disabled) {
this.element_.classList.add(this.CssClasses_.IS_DISABLED);
} else {
this.element_.classList.remove(this.CssClasses_.IS_DISABLED);
}
};
MaterialTextfield.prototype['checkDisabled'] =
MaterialTextfield.prototype.checkDisabled;
/**
* Check the focus state and update field accordingly.
*
* @public
*/
MaterialTextfield.prototype.checkFocus = function() {
if (Boolean(this.element_.querySelector(':focus'))) {
this.element_.classList.add(this.CssClasses_.IS_FOCUSED);
} else {
this.element_.classList.remove(this.CssClasses_.IS_FOCUSED);
}
};
MaterialTextfield.prototype['checkFocus'] =
MaterialTextfield.prototype.checkFocus;
/**
* Check the validity state and update field accordingly.
*
* @public
*/
MaterialTextfield.prototype.checkValidity = function() {
if (this.input_.validity) {
if (this.input_.validity.valid) {
this.element_.classList.remove(this.CssClasses_.IS_INVALID);
} else {
this.element_.classList.add(this.CssClasses_.IS_INVALID);
}
}
};
MaterialTextfield.prototype['checkValidity'] =
MaterialTextfield.prototype.checkValidity;
/**
* Check the dirty state and update field accordingly.
*
* @public
*/
MaterialTextfield.prototype.checkDirty = function() {
if (this.input_.value && this.input_.value.length > 0) {
this.element_.classList.add(this.CssClasses_.IS_DIRTY);
} else {
this.element_.classList.remove(this.CssClasses_.IS_DIRTY);
}
};
MaterialTextfield.prototype['checkDirty'] =
MaterialTextfield.prototype.checkDirty;
/**
* Disable text field.
*
* @public
*/
MaterialTextfield.prototype.disable = function() {
this.input_.disabled = true;
this.updateClasses_();
};
MaterialTextfield.prototype['disable'] = MaterialTextfield.prototype.disable;
/**
* Enable text field.
*
* @public
*/
MaterialTextfield.prototype.enable = function() {
this.input_.disabled = false;
this.updateClasses_();
};
MaterialTextfield.prototype['enable'] = MaterialTextfield.prototype.enable;
/**
* Update text field value.
*
* @param {string} value The value to which to set the control (optional).
* @public
*/
MaterialTextfield.prototype.change = function(value) {
this.input_.value = value || '';
this.updateClasses_();
};
MaterialTextfield.prototype['change'] = MaterialTextfield.prototype.change;
/**
* Initialize element.
*/
MaterialTextfield.prototype.init = function() {
if (this.element_) {
this.label_ = this.element_.querySelector('.' + this.CssClasses_.LABEL);
this.input_ = this.element_.querySelector('.' + this.CssClasses_.INPUT);
if (this.input_) {
if (this.input_.hasAttribute(
/** @type {string} */ (this.Constant_.MAX_ROWS_ATTRIBUTE))) {
this.maxRows = parseInt(this.input_.getAttribute(
/** @type {string} */ (this.Constant_.MAX_ROWS_ATTRIBUTE)), 10);
if (isNaN(this.maxRows)) {
this.maxRows = this.Constant_.NO_MAX_ROWS;
}
}
if (this.input_.hasAttribute('placeholder')) {
this.element_.classList.add(this.CssClasses_.HAS_PLACEHOLDER);
}
this.boundUpdateClassesHandler = this.updateClasses_.bind(this);
this.boundFocusHandler = this.onFocus_.bind(this);
this.boundBlurHandler = this.onBlur_.bind(this);
this.boundResetHandler = this.onReset_.bind(this);
this.input_.addEventListener('input', this.boundUpdateClassesHandler);
this.input_.addEventListener('focus', this.boundFocusHandler);
this.input_.addEventListener('blur', this.boundBlurHandler);
this.input_.addEventListener('reset', this.boundResetHandler);
if (this.maxRows !== this.Constant_.NO_MAX_ROWS) {
// TODO: This should handle pasting multi line text.
// Currently doesn't.
this.boundKeyDownHandler = this.onKeyDown_.bind(this);
this.input_.addEventListener('keydown', this.boundKeyDownHandler);
}
var invalid = this.element_.classList
.contains(this.CssClasses_.IS_INVALID);
this.updateClasses_();
this.element_.classList.add(this.CssClasses_.IS_UPGRADED);
if (invalid) {
this.element_.classList.add(this.CssClasses_.IS_INVALID);
}
if (this.input_.hasAttribute('autofocus')) {
this.element_.focus();
this.checkFocus();
}
}
}
};
// The component registers itself. It can assume componentHandler is available
// in the global scope.
componentHandler.register({
constructor: MaterialTextfield,
classAsString: 'MaterialTextfield',
cssClass: 'mdl-js-textfield',
widget: true
});
})();