refactor(label): move label to its own folder and move mode specific styles for label to new files

closes #712
This commit is contained in:
Brandy Carney
2015-12-17 16:14:15 -05:00
parent 92f0584b7f
commit b2fd889914
11 changed files with 117 additions and 90 deletions

View File

@@ -1,42 +0,0 @@
@import "../../globals.core";
// Label
// --------------------------------------------------
ion-label {
display: block;
max-width: 200px;
font-size: inherit;
white-space: nowrap;
pointer-events: none;
}
// Stacked & Floating Inputs
// --------------------------------------------------
.fixed-label {
width: 30%;
min-width: 100px;
max-width: 200px;
}
[stacked-label],
[floating-label] {
flex-direction: column;
align-items: flex-start;
}
.stacked-label,
.floating-label {
align-self: stretch;
margin-bottom: 0;
max-width: 100%;
}
.stacked-input,
.floating-input {
align-self: stretch;
width: auto;
}

View File

@@ -1,100 +0,0 @@
import {Directive, Optional, ElementRef, Renderer} from 'angular2/core';
import {Config} from '../../config/config';
import {TextInput} from './text-input';
import {pointerCoord, hasPointerMoved} from '../../util/dom';
import {Form} from '../../util/form';
/**
* @name Label
* @description
* Labels describe the data that the user should enter in to an input element.
* @usage
* ```html
* <ion-input>
* <ion-label>Username</ion-label>
* <input type="text" value="">
* </ion-input>
* ```
*
* @demo /docs/v2/demos/label/
* @see {@link ../../../../components#inputs Input Component Docs}
* @see {@link ../Input Input API Docs}
*
*/
@Directive({
selector: 'ion-label',
inputs: [
'id'
],
host: {
'[attr.id]': 'id',
'(touchstart)': 'pointerStart($event)',
'(touchend)': 'pointerEnd($event)',
'(mousedown)': 'pointerStart($event)',
'(mouseup)': 'pointerEnd($event)'
}
})
export class Label {
constructor(
config: Config,
@Optional() container: TextInput,
private form: Form,
private elementRef: ElementRef,
private renderer: Renderer
) {
this.scrollAssist = config.get('scrollAssist');
this.container = container;
}
/**
* @private
*/
ngOnInit() {
if (!this.id) {
this.id = 'lbl-' + this.form.nextId();
}
this.container && this.container.registerLabel(this);
}
/**
* @private
*/
pointerStart(ev) {
if (this.scrollAssist) {
// remember where the touchstart/mousedown started
this.startCoord = pointerCoord(ev);
}
}
/**
* @private
*/
pointerEnd(ev) {
if (this.container) {
// get where the touchend/mouseup ended
let endCoord = pointerCoord(ev);
// focus this input if the pointer hasn't moved XX pixels
if (!hasPointerMoved(20, this.startCoord, endCoord)) {
ev.preventDefault();
ev.stopPropagation();
this.container.initFocus();
}
this.startCoord = null;
}
}
/**
* @private
*/
addClass(className) {
this.renderer.setElementClass(this.elementRef, className, true);
}
}

View File

@@ -1,12 +1,10 @@
@import "../../globals.ios";
@import "./label";
@import "./text-input";
// iOS Text Input
// --------------------------------------------------
$text-input-ios-background-color: $list-ios-background-color !default;
$text-input-ios-label-color: #7f7f7f !default;
// Default Input
@@ -18,15 +16,6 @@ $text-input-ios-label-color: #7f7f7f !default;
background-color: $text-input-ios-background-color;
}
ion-label {
margin: $item-ios-padding-top ($item-ios-padding-right / 2) $item-ios-padding-bottom 0;
color: $text-input-ios-label-color;
}
ion-label + .item-input {
margin-left: $item-ios-padding-left;
}
// Inset Input
// --------------------------------------------------
@@ -40,40 +29,8 @@ ion-label + .item-input {
// Stacked & Floating Inputs
// --------------------------------------------------
.stacked-label {
font-size: 1.2rem;
margin-bottom: 4px;
}
.floating-label {
margin-bottom: 0;
transform-origin: left top;
transform: translate3d(0, 27px, 0);
transition: transform 150ms ease-in-out;
}
.stacked-input,
.floating-input {
margin-top: 8px;
margin-bottom: 8px;
}
.input-focused .floating-label,
.input-has-value .floating-label {
transform: translate3d(0, 0, 0) scale(0.8);
}
ion-label + .stacked-input,
ion-label + .floating-input {
margin-left: 0;
}
// Generate iOS label colors
// --------------------------------------------------
@each $color-name, $color-value in $colors-ios {
ion-label[#{$color-name}] {
color: $color-value !important;
}
}

View File

@@ -1,12 +1,10 @@
@import "../../globals.md";
@import "./label";
@import "./text-input";
// Material Design Text Input
// --------------------------------------------------
$text-input-md-background-color: $list-md-background-color !default;
$text-input-md-label-color: #999 !default;
$text-input-md-highlight-color: map-get($colors-md, primary) !default;
$text-input-md-hightlight-color-valid: map-get($colors-md, secondary) !default;
$text-input-md-hightlight-color-invalid: map-get($colors-md, danger) !default;
@@ -21,11 +19,6 @@ $text-input-md-hightlight-color-invalid: map-get($colors-md, danger) !default
background-color: $text-input-md-background-color;
}
ion-label {
margin: $item-md-padding-top ($item-md-padding-right / 2) $item-md-padding-bottom ($item-md-padding-left / 2);
color: $text-input-md-label-color;
}
// Inset Input
// --------------------------------------------------
@@ -66,45 +59,9 @@ ion-input.ng-invalid.ng-touched:after {
// Stacked & Floating Inputs
// --------------------------------------------------
.stacked-label {
font-size: 1.2rem;
}
.floating-label {
transform-origin: left top;
transform: translate3d(0, 27px, 0);
transition: transform 150ms ease-in-out;
}
.stacked-label,
.floating-label {
margin-left: 0;
margin-bottom: 0;
}
.stacked-input,
.floating-input {
margin-left: 0;
margin-top: 8px;
margin-bottom: 8px;
}
.input-focused .stacked-label,
.input-focused .floating-label {
color: $text-input-md-highlight-color;
}
.input-focused .floating-label,
.input-has-value .floating-label {
transform: translate3d(0, 0, 0) scale(0.8);
}
// Generate Material Design label colors
// --------------------------------------------------
@each $color-name, $color-value in $colors-md {
ion-label[#{$color-name}] {
color: $color-value !important;
}
}