Skip to content

Commit c11c7d3

Browse files
committed
Fix bugs in color pickers, add a input colorpicker as well
1 parent 3406132 commit c11c7d3

File tree

7 files changed

+781
-87
lines changed

7 files changed

+781
-87
lines changed

projects/design-system/src/app/ship/color-pickers/examples/base-color-picker/base-color-picker.html

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<sh-button-group [(value)]="renderingType">
1+
<sh-button-group [(value)]="renderingType" class="type-b">
22
<button value="hsl">
33
<sh-icon>circle</sh-icon>
44
HSL Wheel
@@ -19,6 +19,10 @@
1919
<sh-icon>circle</sh-icon>
2020
Saturation
2121
</button>
22+
<button value="alpha">
23+
<sh-icon>circle</sh-icon>
24+
Alpha
25+
</button>
2226
</sh-button-group>
2327

2428
@if (renderingType() === 'hsl') {
@@ -32,14 +36,10 @@
3236
</sh-range-slider>
3337
-->
3438

35-
<sh-color-picker renderingType="hue" (currentColor)="selectedHue.set($event.hue)"></sh-color-picker>
36-
}
37-
38-
@if (renderingType() === 'hue') {
39-
<sh-toggle [(checked)]="direction" color="primary" variant="raised">Direction</sh-toggle>
39+
<sh-color-picker renderingType="hue" (currentColor)="selectedHue.set($event.hue)" />
4040
}
4141

42-
@if (renderingType() === 'saturation') {
42+
@if (renderingType() === 'hue' || renderingType() === 'saturation' || renderingType() === 'alpha') {
4343
<sh-toggle [(checked)]="direction" color="primary" variant="raised">Direction</sh-toggle>
4444
}
4545

@@ -48,17 +48,43 @@
4848
[showDarkColors]="showDarkColors()"
4949
[direction]="direction() ? 'vertical' : 'horizontal'"
5050
[hue]="selectedHue()"
51-
(currentColor)="currentColor.set($event)"></sh-color-picker>
51+
(currentColor)="currentColor.set($event)" />
5252

5353
<div class="colors">
5454
<div class="swatch" [style.background]="currentColor()?.hex"></div>
5555

5656
<div class="color-text">
5757
<p>RGB: {{ currentColor()?.rgb }}</p>
58+
<p>RGBA: {{ currentColor()?.rgba }}</p>
5859
<p>HEX: {{ currentColor()?.hex }}</p>
60+
<p>HEX8: {{ currentColor()?.hex8 }}</p>
5961
<p>HSL: {{ currentColor()?.hsl }}</p>
62+
<p>HSLA: {{ currentColor()?.hsla }}</p>
6063
<p>Hue: {{ currentColor()?.hue }}</p>
6164
<p>Saturation: {{ currentColor()?.saturation }}</p>
65+
<p>Alpha: {{ currentColor()?.alpha }}</p>
6266
</div>
6367
</div>
6468
<!-- <pre>{{ currentColor() | json }}</pre> -->
69+
70+
<div class="example-element">
71+
<h3>Color Picker Input Demo</h3>
72+
<sh-toggle [(checked)]="showAlpha" color="primary" variant="raised">Enable Alpha</sh-toggle>
73+
<sh-button-group [(value)]="inputRenderType" class="type-b">
74+
<button value="hsl">HSL</button>
75+
<button value="rgb">
76+
<sh-icon>circle</sh-icon>
77+
RGB
78+
</button>
79+
<button value="hex">
80+
<sh-icon>circle</sh-icon>
81+
Hex
82+
</button>
83+
</sh-button-group>
84+
85+
<sh-color-picker-input [format]="computedRenderType()" [renderingType]="inputRenderType() === 'hsl' ? 'hsl' : 'rgb'">
86+
<label>Pick a color</label>
87+
<input type="text" [value]="inputValue()" (input)="inputValue.set($any($event.target).value)" />
88+
</sh-color-picker-input>
89+
<p>Input Value: {{ inputValue() }}</p>
90+
</div>

projects/design-system/src/app/ship/color-pickers/examples/base-color-picker/base-color-picker.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@
2929
width: 100%;
3030
}
3131
}
32+
33+
.example-element {
34+
display: flex;
35+
flex-direction: column;
36+
gap: p2r(12);
37+
}
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1-
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
2-
import { ShipButtonGroup, ShipColorPicker, ShipIcon, ShipToggle } from 'ship-ui';
1+
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
2+
import { ShipButtonGroup, ShipColorPicker, ShipColorPickerInput, ShipIcon, ShipToggle } from 'ship-ui';
33

44
@Component({
55
selector: 'app-base-color-picker',
6-
imports: [ShipColorPicker, ShipButtonGroup, ShipIcon, ShipToggle],
6+
imports: [ShipColorPicker, ShipButtonGroup, ShipIcon, ShipToggle, ShipColorPickerInput],
77
templateUrl: './base-color-picker.html',
88
styleUrl: './base-color-picker.scss',
99
changeDetection: ChangeDetectionStrategy.OnPush,
1010
})
1111
export class BaseColorPicker {
12-
renderingType = signal<'hsl' | 'rgb' | 'grid' | 'hue' | 'saturation'>('hsl');
13-
aColor = signal<[number, number, number]>([255, 255, 255]);
14-
currentColor = signal<{ rgb: string; hex: string; hsl: string; hue: number; saturation: number } | null>(null);
12+
renderingType = signal<'hsl' | 'rgb' | 'grid' | 'hue' | 'saturation' | 'alpha'>('hsl');
13+
aColor = signal<[number, number, number, number?]>([255, 255, 255]);
14+
currentColor = signal<{
15+
rgb: string;
16+
rgba: string;
17+
hex: string;
18+
hex8: string;
19+
hsl: string;
20+
hsla: string;
21+
hue: number;
22+
saturation: number;
23+
alpha: number;
24+
} | null>(null);
1525
showDarkColors = signal(false);
1626
direction = signal(false);
1727
selectedHue = signal(0);
28+
inputValue = signal('rgba(255, 0, 0, 0.5)');
29+
30+
inputRenderType = signal<'hsl' | 'rgb' | 'hex'>('rgb');
31+
showAlpha = signal(true);
32+
computedRenderType = computed(() => {
33+
const inputRenderType = this.inputRenderType();
34+
const showAlpha = this.showAlpha();
35+
if (inputRenderType === 'hsl') {
36+
return showAlpha ? 'hsla' : 'hsl';
37+
}
38+
if (inputRenderType === 'rgb') {
39+
return showAlpha ? 'rgba' : 'rgb';
40+
}
41+
if (inputRenderType === 'hex') {
42+
return showAlpha ? 'hex8' : 'hex';
43+
}
44+
45+
return 'hsl';
46+
});
1847
}

0 commit comments

Comments
 (0)