Skip to content

Commit

Permalink
feat(color-picker): automatically add # to color
Browse files Browse the repository at this point in the history
Closes 52
  • Loading branch information
tiaguinho committed Dec 27, 2018
1 parent 5c42e46 commit bb0434d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib/color-picker/color-picker-selector.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { BehaviorSubject, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { EMPTY_COLOR, coerceHexaColor, isValidColor } from './color-picker';

interface ColorOption {
Expand Down Expand Up @@ -306,11 +307,13 @@ export class MccColorPickerSelectorComponent
*/
private _onChanges() {
// validate digited code and update when digitation is finished
this._hexValuesSub = this.hexForm.get('hexCode').valueChanges.subscribe(value => {
if (!this._isPressed && isValidColor(value)) {
this._tmpSelectedColor.next(coerceHexaColor(value) || this.emptyColor);
}
});
this._hexValuesSub = this.hexForm.get('hexCode').valueChanges
.pipe(map(color => color !== this.emptyColor ? coerceHexaColor(color) : color))
.subscribe(value => {
if (!this._isPressed && isValidColor(value)) {
this._tmpSelectedColor.next(value || this.emptyColor);
}
});

this._rgbValuesSub = this.rgbForm.valueChanges.subscribe(controls => {
const data: string[] = [];
Expand Down

0 comments on commit bb0434d

Please sign in to comment.