1
1
import { DIALOG_DATA , DialogRef } from '@angular/cdk/dialog' ;
2
2
import { DecimalPipe } from '@angular/common' ;
3
- import { Component , ElementRef , computed , effect , inject , signal , viewChild } from '@angular/core' ;
3
+ import { Component , computed , effect , inject , signal } from '@angular/core' ;
4
4
import { TranslateModule , TranslateService } from '@ngx-translate/core' ;
5
5
import { ColorService } from '../shared/data-access/color.service' ;
6
6
import { Color , Shade } from '../shared/model' ;
@@ -33,19 +33,24 @@ export enum UpdateType {
33
33
selector : 'rp-editor' ,
34
34
standalone : true ,
35
35
imports : [ ColorInputComponent , TranslateModule , DecimalPipe , ColorRangeSliderComponent ] ,
36
- templateUrl : './editor.component.html'
36
+ templateUrl : './editor.component.html' ,
37
+ host : {
38
+ '[style.--editor-saturation]' : 'shade().hsl.S + "%"' ,
39
+ '[style.--editor-lightness]' : 'shade().hsl.L + "%"' ,
40
+ '[style.--editor-hue]' : 'shade().hsl.H'
41
+ }
37
42
} )
38
43
export class EditorComponent {
39
44
protected readonly UpdateType = UpdateType ;
40
45
protected readonly textColor = textColor ;
41
46
42
- private readonly _data = inject < EditorData > ( DIALOG_DATA ) ;
43
- private readonly _dialogRef = inject ( DialogRef ) ;
44
- private readonly _colorService = inject ( ColorService ) ;
45
- private readonly _translateService = inject ( TranslateService ) ;
47
+ readonly #data = inject < EditorData > ( DIALOG_DATA ) ;
48
+ readonly #dialogRef = inject ( DialogRef ) ;
49
+ readonly #colorService = inject ( ColorService ) ;
50
+ readonly #translateService = inject ( TranslateService ) ;
46
51
47
- protected readonly color = signal ( this . _data . color . copy ( ) ) ;
48
- protected readonly shadeIndex = signal ( this . _data . shadeIndex ?? 0 ) ;
52
+ protected readonly color = signal ( this . #data . color . copy ( ) ) ;
53
+ protected readonly shadeIndex = signal ( this . #data . shadeIndex ?? 0 ) ;
49
54
50
55
protected readonly shade = computed < Shade > ( ( ) => {
51
56
const selectedShade = this . color ( ) . shades . find ( ( shade ) => shade . index === this . shadeIndex ( ) ) ;
@@ -62,20 +67,12 @@ export class EditorComponent {
62
67
} ) ;
63
68
64
69
protected readonly hasUnsavedChanges = computed < boolean > (
65
- ( ) => this . _data . color . toString ( ) !== this . color ( ) . toString ( )
70
+ ( ) => this . #data . color . toString ( ) !== this . color ( ) . toString ( )
66
71
) ;
67
72
68
- private readonly _editor = viewChild . required < ElementRef < HTMLElement > > ( 'editor' ) ;
69
-
70
73
public constructor ( ) {
71
74
effect ( ( ) => {
72
- this . _editor ( ) . nativeElement . style . setProperty ( '--editor-hue' , `${ this . shade ( ) . hsl . H } ` ) ;
73
- this . _editor ( ) . nativeElement . style . setProperty ( '--editor-saturation' , `${ this . shade ( ) . hsl . S } %` ) ;
74
- this . _editor ( ) . nativeElement . style . setProperty ( '--editor-lightness' , `${ this . shade ( ) . hsl . L } %` ) ;
75
- } ) ;
76
-
77
- effect ( ( ) => {
78
- this . _dialogRef . disableClose = this . hasUnsavedChanges ( ) ;
75
+ this . #dialogRef. disableClose = this . hasUnsavedChanges ( ) ;
79
76
} ) ;
80
77
}
81
78
@@ -100,7 +97,7 @@ export class EditorComponent {
100
97
}
101
98
102
99
shade . fixed = false ;
103
- this . _updateColor ( ) ;
100
+ this . updateColor ( ) ;
104
101
}
105
102
106
103
public update ( type : UpdateType , value : string | number ) : void {
@@ -122,36 +119,36 @@ export class EditorComponent {
122
119
break ;
123
120
}
124
121
125
- this . _updateColor ( ) ;
122
+ this . updateColor ( ) ;
126
123
127
124
const editedShade = this . color ( ) . shades . find ( ( s ) => s . hex === shade . hex ) ;
128
125
this . shadeIndex . set ( editedShade ?. index ?? - 1 ) ;
129
126
}
130
127
131
128
protected cancel ( ) : void {
132
- this . _dialogRef . close ( undefined ) ;
133
- this . color . set ( this . _data . color . copy ( ) ) ;
129
+ this . #dialogRef . close ( undefined ) ;
130
+ this . color . set ( this . #data . color . copy ( ) ) ;
134
131
}
135
132
136
133
protected save ( ) : void {
137
- this . _dialogRef . close ( this . color ( ) ) ;
134
+ this . #dialogRef . close ( this . color ( ) ) ;
138
135
}
139
136
140
- private _updateColor ( ) : void {
137
+ private updateColor ( ) : void {
141
138
const updatedColor = this . color ( ) . copy ( ) ;
142
- this . _colorService . regenerateShades ( updatedColor ) ;
139
+ this . #colorService . regenerateShades ( updatedColor ) ;
143
140
this . color . set ( updatedColor ) ;
144
141
}
145
142
146
143
protected getTooltip ( shade : Shade , selected : boolean ) : string {
147
144
const tooltips : Array < string > = [ ] ;
148
145
149
146
if ( ! selected ) {
150
- tooltips . push ( this . _translateService . instant ( 'editor.shades' ) ) ;
147
+ tooltips . push ( this . #translateService . instant ( 'editor.shades' ) ) ;
151
148
}
152
149
153
150
if ( shade . fixed ) {
154
- tooltips . push ( this . _translateService . instant ( 'editor.unfix' ) ) ;
151
+ tooltips . push ( this . #translateService . instant ( 'editor.unfix' ) ) ;
155
152
}
156
153
157
154
return tooltips . join ( '\n' ) ;
0 commit comments