Skip to content

Commit 65f08ac

Browse files
committed
refactor(color-range-slider): move component to shared features
1 parent a0b447f commit 65f08ac

12 files changed

+91
-94
lines changed

src/app/editor/editor.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h2 class="font-semibold">{{ color().name }}</h2>
1313
/>
1414

1515
<section class="flex flex-col gap-2">
16-
<rp-editor-range
16+
<rp-color-range-slider
1717
[label]="'common.hue' | translate"
1818
[tooltip]="'editor.properties.hue' | translate"
1919
[value]="shade().hsl.H"
@@ -24,7 +24,7 @@ <h2 class="font-semibold">{{ color().name }}</h2>
2424
min="0"
2525
/>
2626

27-
<rp-editor-range
27+
<rp-color-range-slider
2828
[label]="'common.saturation' | translate"
2929
[tooltip]="'editor.properties.saturation' | translate"
3030
[value]="shade().hsl.S"
@@ -33,7 +33,7 @@ <h2 class="font-semibold">{{ color().name }}</h2>
3333
key="saturation"
3434
/>
3535

36-
<rp-editor-range
36+
<rp-color-range-slider
3737
[label]="'common.lightness' | translate"
3838
[tooltip]="'editor.properties.lightness' | translate"
3939
[value]="shade().hsl.L"

src/app/editor/editor.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { TranslateModule, TranslateService } from '@ngx-translate/core';
55
import { ColorService } from '../shared/data-access/color.service';
66
import { Color, Shade } from '../shared/model';
77
import { ColorInputComponent } from '../shared/ui/color-input/color-input.component';
8+
import { ColorRangeSliderComponent } from '../shared/ui/color-range-slider/color-range-slider.component';
89
import { textColor } from '../shared/utils/text-color';
9-
import { EditorRangeComponent } from './ui/editor-range/editor-range.component';
1010

1111
/**
1212
* Data for the editor dialog.
@@ -32,7 +32,7 @@ export enum UpdateType {
3232
@Component({
3333
selector: 'rp-editor',
3434
standalone: true,
35-
imports: [ColorInputComponent, TranslateModule, DecimalPipe, EditorRangeComponent],
35+
imports: [ColorInputComponent, TranslateModule, DecimalPipe, ColorRangeSliderComponent],
3636
templateUrl: './editor.component.html'
3737
})
3838
export class EditorComponent {

src/app/editor/ui/editor-range/editor-range.component.css

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/app/editor/ui/editor-range/editor-range.component.html

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
:host {
2+
display: block;
3+
}
4+
5+
input[type='range']::-webkit-slider-thumb {
6+
background-color: hsl(var(--editor-hue), var(--editor-saturation), var(--editor-lightness));
7+
}
8+
9+
input[type='range']::-moz-range-thumb {
10+
background-color: hsl(var(--editor-hue), var(--editor-saturation), var(--editor-lightness));
11+
}
12+
13+
input[type='range'] {
14+
&.hue {
15+
background: linear-gradient(90deg,
16+
hsl(0, var(--editor-saturation), var(--editor-lightness)) 0%,
17+
hsl(60, var(--editor-saturation), var(--editor-lightness)) 33.3%,
18+
hsl(120, var(--editor-saturation), var(--editor-lightness)) 50%,
19+
hsl(180, var(--editor-saturation), var(--editor-lightness)) 58.3%,
20+
hsl(240, var(--editor-saturation), var(--editor-lightness)) 66.6%,
21+
hsl(300, var(--editor-saturation), var(--editor-lightness)) 83.4%,
22+
hsl(360, var(--editor-saturation), var(--editor-lightness)) 100%);
23+
}
24+
25+
&.saturation {
26+
background: linear-gradient(90deg,
27+
hsl(var(--editor-hue), 0%, var(--editor-lightness)) 0%,
28+
hsl(var(--editor-hue), 100%, var(--editor-lightness)) 100%);
29+
}
30+
31+
&.lightness {
32+
background: linear-gradient(90deg,
33+
hsl(var(--editor-hue), var(--editor-saturation), 100%) 0%,
34+
hsl(var(--editor-hue), var(--editor-saturation), 50%) 50%,
35+
hsl(var(--editor-hue), var(--editor-saturation), 0%) 100%);
36+
}
37+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<label
2+
[for]="key()"
3+
class="flex justify-between"
4+
>
5+
<span class="font-semibold">
6+
{{ label() }}
7+
</span>
8+
9+
<span>
10+
{{ value() | number: '1.0-0' }}
11+
</span>
12+
</label>
13+
14+
<input
15+
#input
16+
[class]="key()"
17+
[id]="key()"
18+
[max]="max()"
19+
[min]="min()"
20+
[title]="tooltip()"
21+
[value]="transformedValue()"
22+
(input)="updateValue(input.value)"
23+
step="1"
24+
type="range"
25+
/>

src/app/editor/ui/editor-range/editor-range.component.spec.ts renamed to src/app/shared/ui/color-range-slider/color-range-slider.component.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { signal } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
3-
import { EditorRangeComponent } from './editor-range.component';
3+
import { ColorRangeSliderComponent } from './color-range-slider.component';
44

5-
describe('EditorRangeComponent', () => {
6-
let component: EditorRangeComponent;
7-
let fixture: ComponentFixture<EditorRangeComponent>;
5+
describe('ColorRangeSliderComponent', () => {
6+
let component: ColorRangeSliderComponent;
7+
let fixture: ComponentFixture<ColorRangeSliderComponent>;
88

99
beforeEach(async () => {
1010
await TestBed.configureTestingModule({
11-
imports: [EditorRangeComponent]
11+
imports: [ColorRangeSliderComponent]
1212
}).compileComponents();
1313

14-
fixture = TestBed.createComponent(EditorRangeComponent);
14+
fixture = TestBed.createComponent(ColorRangeSliderComponent);
1515
component = fixture.componentInstance;
1616

1717
// @ts-expect-error - Bind required input signal

src/app/editor/ui/editor-range/editor-range.component.stories.ts renamed to src/app/shared/ui/color-range-slider/color-range-slider.component.stories.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Meta, argsToTemplate } from '@storybook/angular';
2-
import { createStory } from '../../../shared/utils/storybook';
3-
import { EditorRangeComponent } from './editor-range.component';
2+
import { createStory } from '../../utils/storybook';
3+
import { ColorRangeSliderComponent } from './color-range-slider.component';
44

5-
const meta: Meta<EditorRangeComponent> = {
6-
title: 'Editor/Range',
7-
component: EditorRangeComponent,
5+
const meta: Meta<ColorRangeSliderComponent> = {
6+
title: 'Shared/Color Range Slider',
7+
component: ColorRangeSliderComponent,
88
tags: ['autodocs'],
99
argTypes: {
1010
key: {
@@ -24,7 +24,7 @@ const meta: Meta<EditorRangeComponent> = {
2424
};
2525
export default meta;
2626

27-
export const Hue = createStory<EditorRangeComponent>({
27+
export const Hue = createStory<ColorRangeSliderComponent>({
2828
args: {
2929
label: 'Hue',
3030
tooltip: 'Adjust the hue',
@@ -35,11 +35,11 @@ export const Hue = createStory<EditorRangeComponent>({
3535
render: (args) => ({
3636
template: `
3737
<div #parent style="--editor-hue: ${args.value}; --editor-saturation: 100%; --editor-lightness: 50%">
38-
<rp-editor-range ${argsToTemplate(args)} (valueChange)="parent.style.setProperty('--editor-hue', $event)" />
38+
<rp-color-range-slider ${argsToTemplate(args)} (valueChange)="parent.style.setProperty('--editor-hue', $event)" />
3939
</div>`
4040
})
4141
});
42-
export const Saturation = createStory<EditorRangeComponent>({
42+
export const Saturation = createStory<ColorRangeSliderComponent>({
4343
args: {
4444
label: 'Saturation',
4545
tooltip: 'Adjust the saturation',
@@ -49,11 +49,11 @@ export const Saturation = createStory<EditorRangeComponent>({
4949
render: (args) => ({
5050
template: `
5151
<div #parent style="--editor-hue: 180; --editor-saturation: ${args.value}%; --editor-lightness: 50%">
52-
<rp-editor-range ${argsToTemplate(args)} (valueChange)="parent.style.setProperty('--editor-saturation', $event + '%')" />
52+
<rp-color-range-slider ${argsToTemplate(args)} (valueChange)="parent.style.setProperty('--editor-saturation', $event + '%')" />
5353
</div>`
5454
})
5555
});
56-
export const Lightness = createStory<EditorRangeComponent>({
56+
export const Lightness = createStory<ColorRangeSliderComponent>({
5757
args: {
5858
label: 'Lightness',
5959
tooltip: 'Adjust the lightness',
@@ -63,7 +63,7 @@ export const Lightness = createStory<EditorRangeComponent>({
6363
render: (args) => ({
6464
template: `
6565
<div #parent style="--editor-hue: 180; --editor-saturation: 100%; --editor-lightness: ${args.value}%">
66-
<rp-editor-range ${argsToTemplate(args)} (valueChange)="parent.style.setProperty('--editor-lightness', $event + '%')" />
66+
<rp-color-range-slider ${argsToTemplate(args)} (valueChange)="parent.style.setProperty('--editor-lightness', $event + '%')" />
6767
</div>`
6868
})
6969
});

src/app/editor/ui/editor-range/editor-range.component.ts renamed to src/app/shared/ui/color-range-slider/color-range-slider.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Component, computed, input, model, numberAttribute } from '@angular/cor
33
import { hueToWheel, wheelToHue } from '../../utils/color-wheel';
44

55
@Component({
6-
selector: 'rp-editor-range',
6+
selector: 'rp-color-range-slider',
77
standalone: true,
88
imports: [DecimalPipe],
9-
templateUrl: './editor-range.component.html',
10-
styleUrl: './editor-range.component.css'
9+
templateUrl: './color-range-slider.component.html',
10+
styleUrl: './color-range-slider.component.css'
1111
})
12-
export class EditorRangeComponent {
12+
export class ColorRangeSliderComponent {
1313
/**
1414
* Label to display above the range input
1515
*/
File renamed without changes.

0 commit comments

Comments
 (0)