Skip to content

Commit 449eb66

Browse files
committed
fix: Implement working color picker with Angular
Material integration - Add ViewContainerRef to AppComponent for ngx-color-picker root container support - Replace color picker input integration with proper button-based triggers - Fix layout shift issue by adding permanent scrollbar - Add button spacing using fxLayoutGap for better UX
1 parent 7ecca03 commit 449eb66

File tree

3 files changed

+83
-34
lines changed

3 files changed

+83
-34
lines changed

src/app/app.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, ViewContainerRef } from '@angular/core';
22

33
import { DemoService } from './demo.service';
44

@@ -11,5 +11,8 @@ export class AppComponent {
1111
/**
1212
* Constructor
1313
*/
14-
constructor(public demoService: DemoService) {}
14+
constructor(
15+
public demoService: DemoService,
16+
public vcRef: ViewContainerRef
17+
) {}
1518
}

src/app/master-configuration/master-configuration.component.html

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,26 @@
3232
>
3333
<mat-form-field>
3434
<input
35-
[(colorPicker)]="demoService.config.fgsColor"
3635
matInput
3736
placeholder="Foreground Spinner Color (fgsColor)"
3837
[(ngModel)]="demoService.config.fgsColor"
38+
readonly
3939
/>
40-
<mat-icon
40+
<button
41+
mat-icon-button
4142
matSuffix
42-
[style.color]="demoService.config.fgsColor"
43-
fontIcon="mdi-palette"
44-
fontSet="mdi"
45-
></mat-icon>
43+
[(colorPicker)]="demoService.config.fgsColor"
44+
[cpPosition]="'bottom'"
45+
[cpUseRootViewContainer]="true"
46+
(click)="$event.stopPropagation()"
47+
type="button"
48+
>
49+
<mat-icon
50+
[style.color]="demoService.config.fgsColor"
51+
fontIcon="mdi-palette"
52+
fontSet="mdi"
53+
></mat-icon>
54+
</button>
4655
</mat-form-field>
4756

4857
<mat-form-field>
@@ -95,18 +104,27 @@
95104

96105
<mat-form-field>
97106
<input
98-
[(colorPicker)]="demoService.config.overlayColor"
99-
cpOutputFormat="rgba"
100107
matInput
101108
placeholder="Overlay Color (overlayColor)"
102109
[(ngModel)]="demoService.config.overlayColor"
110+
readonly
103111
/>
104-
<mat-icon
112+
<button
113+
mat-icon-button
105114
matSuffix
106-
[style.color]="demoService.config.overlayColor"
107-
fontIcon="mdi-palette"
108-
fontSet="mdi"
109-
></mat-icon>
115+
[(colorPicker)]="demoService.config.overlayColor"
116+
cpOutputFormat="rgba"
117+
[cpPosition]="'bottom'"
118+
[cpUseRootViewContainer]="true"
119+
(click)="$event.stopPropagation()"
120+
type="button"
121+
>
122+
<mat-icon
123+
[style.color]="demoService.config.overlayColor"
124+
fontIcon="mdi-palette"
125+
fontSet="mdi"
126+
></mat-icon>
127+
</button>
110128
</mat-form-field>
111129

112130
<div style="margin-top: 21px; margin-bottom: 20px">
@@ -119,17 +137,26 @@
119137

120138
<mat-form-field *ngIf="demoService.config.hasProgressBar">
121139
<input
122-
[(colorPicker)]="demoService.config.pbColor"
123140
matInput
124141
placeholder="Progress Bar Color (pbColor)"
125142
[(ngModel)]="demoService.config.pbColor"
143+
readonly
126144
/>
127-
<mat-icon
145+
<button
146+
mat-icon-button
128147
matSuffix
129-
[style.color]="demoService.config.pbColor"
130-
fontIcon="mdi-palette"
131-
fontSet="mdi"
132-
></mat-icon>
148+
[(colorPicker)]="demoService.config.pbColor"
149+
[cpPosition]="'bottom'"
150+
[cpUseRootViewContainer]="true"
151+
(click)="$event.stopPropagation()"
152+
type="button"
153+
>
154+
<mat-icon
155+
[style.color]="demoService.config.pbColor"
156+
fontIcon="mdi-palette"
157+
fontSet="mdi"
158+
></mat-icon>
159+
</button>
133160
</mat-form-field>
134161

135162
<div style="margin-top: 21px; margin-bottom: 20px">
@@ -176,17 +203,26 @@
176203
>
177204
<mat-form-field>
178205
<input
179-
[(colorPicker)]="demoService.config.bgsColor"
180206
matInput
181207
placeholder="Background Spinner Color (bgsColor)"
182208
[(ngModel)]="demoService.config.bgsColor"
209+
readonly
183210
/>
184-
<mat-icon
211+
<button
212+
mat-icon-button
185213
matSuffix
186-
[style.color]="demoService.config.bgsColor"
187-
fontIcon="mdi-palette"
188-
fontSet="mdi"
189-
></mat-icon>
214+
[(colorPicker)]="demoService.config.bgsColor"
215+
[cpPosition]="'bottom'"
216+
[cpUseRootViewContainer]="true"
217+
(click)="$event.stopPropagation()"
218+
type="button"
219+
>
220+
<mat-icon
221+
[style.color]="demoService.config.bgsColor"
222+
fontIcon="mdi-palette"
223+
fontSet="mdi"
224+
></mat-icon>
225+
</button>
190226
</mat-form-field>
191227

192228
<mat-form-field>
@@ -300,21 +336,30 @@
300336

301337
<mat-form-field *ngIf="demoService.config.text">
302338
<input
303-
[(colorPicker)]="demoService.config.textColor"
304339
matInput
305340
placeholder="Loading Text Color (textColor)"
306341
[(ngModel)]="demoService.config.textColor"
342+
readonly
307343
/>
308-
<mat-icon
344+
<div
309345
matSuffix
310-
[style.color]="demoService.config.textColor"
311-
fontIcon="mdi-palette"
312-
fontSet="mdi"
313-
></mat-icon>
346+
[(colorPicker)]="demoService.config.textColor"
347+
[cpPosition]="'bottom'"
348+
[cpUseRootViewContainer]="true"
349+
(click)="$event.stopPropagation()"
350+
>
351+
<button mat-icon-button type="button">
352+
<mat-icon
353+
[style.color]="demoService.config.textColor"
354+
fontIcon="mdi-palette"
355+
fontSet="mdi"
356+
></mat-icon>
357+
</button>
358+
</div>
314359
</mat-form-field>
315360
</div>
316361
<!-- Background }}}-->
317-
<div fxFlex="100" fxLayout="row wrap" fxLayoutAlign="center">
362+
<div fxFlex="100" fxLayout="row wrap" fxLayoutAlign="center" fxLayoutGap="12px">
318363
<button mat-raised-button color="accent" (click)="reset()">
319364
Reset Configuration
320365
</button>

src/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ body {
77
body {
88
margin: 0;
99
font-family: Roboto, "Helvetica Neue", sans-serif;
10+
overflow-y: scroll; /* Always show scrollbar to prevent layout shift */
1011
}

0 commit comments

Comments
 (0)