mirror of https://github.com/Squidex/squidex.git
13 changed files with 248 additions and 16 deletions
@ -0,0 +1,17 @@ |
|||
<input class="form-control" type="text" #input |
|||
[style.background]="snapshot.value" |
|||
[style.color]="snapshot.foreground" |
|||
[placeholder]="placeholder" |
|||
[ngModel]="snapshot.value" |
|||
(ngModelChange)="writeValue($event)" |
|||
(focus)="modal.show()" (blur)="blur()" /> |
|||
|
|||
<div *sqxModalView="modal" [sqxModalTarget]="input" position="bottom-left"> |
|||
<div [style.background]="snapshot.value" |
|||
[cpToggle]="true" |
|||
[cpDialogDisplay]="'inline'" |
|||
[cpCancelButton]="false" |
|||
[colorPicker]="snapshot.value" |
|||
(colorPickerChange)="writeValue($event)"> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,18 @@ |
|||
@import '_mixins'; |
|||
@import '_vars'; |
|||
|
|||
:host /deep/ { |
|||
.color-picker { |
|||
& { |
|||
border-color: $color-border; |
|||
} |
|||
|
|||
.hex-text { |
|||
.box { |
|||
input { |
|||
border-color: $color-input; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input } from '@angular/core'; |
|||
import { NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
|
|||
import { |
|||
MathHelper, |
|||
ModalModel, |
|||
StatefulControlComponent |
|||
} from '@app/framework/internal'; |
|||
|
|||
export const SQX_COLOR_PICKER_CONTROL_VALUE_ACCESSOR: any = { |
|||
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ColorPickerComponent), multi: true |
|||
}; |
|||
|
|||
interface State { |
|||
value?: string; |
|||
|
|||
foreground: string; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'sqx-color-picker', |
|||
styleUrls: ['./color-picker.component.scss'], |
|||
templateUrl: './color-picker.component.html', |
|||
providers: [SQX_COLOR_PICKER_CONTROL_VALUE_ACCESSOR], |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class ColorPickerComponent extends StatefulControlComponent<State, string> { |
|||
@Input() |
|||
public placeholder = ''; |
|||
|
|||
public modal = new ModalModel(); |
|||
|
|||
constructor(changeDetector: ChangeDetectorRef) { |
|||
super(changeDetector, { foreground: 'black' }); |
|||
} |
|||
|
|||
public writeValue(obj: any) { |
|||
let foreground = 'black'; |
|||
|
|||
if (MathHelper.toLuminance(MathHelper.parseColor(obj)!) < .5) { |
|||
foreground = 'white'; |
|||
} |
|||
|
|||
this.next(s => ({ ...s, value: obj, foreground })); |
|||
|
|||
this.callChange(obj); |
|||
} |
|||
|
|||
public blur() { |
|||
this.callTouched(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue