Skip to content

Commit 45f4bfe

Browse files
committed
Adjustments
1 parent f9a8d48 commit 45f4bfe

File tree

3 files changed

+54
-23
lines changed

3 files changed

+54
-23
lines changed

packages/uui-input-color/lib/uui-input-color.element.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
22
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
33
import { css, html } from 'lit';
44
import { InputType, UUIInputElement } from '@umbraco-ui/uui-input/lib';
5-
import { property, state } from 'lit/decorators.js';
5+
import { property, query, state } from 'lit/decorators.js';
6+
import type { UUIColorPickerElement } from '@umbraco-ui/uui-color-picker/lib';
67

78
/**
89
* @element uui-input-color
@@ -13,7 +14,27 @@ export class UUIInputColorElement extends UUIInputElement {
1314
@state()
1415
private inputType: InputType = 'text';
1516

16-
// this overrides the inherited type property, and moves the input's type handling to the passwordType state.
17+
@state()
18+
private _valueHex = '';
19+
20+
@query('#color')
21+
protected _colorPicker!: UUIColorPickerElement;
22+
23+
@property({ type: String })
24+
public override set value(value: string) {
25+
if (value.startsWith('#')) {
26+
this._valueHex = value;
27+
super.value = value.substring(1);
28+
} else {
29+
super.value = value;
30+
this._valueHex = `#${value}`;
31+
}
32+
}
33+
public override get value() {
34+
return super.value as string;
35+
}
36+
37+
// this overrides the inherited type property, and moves the input's type handling to the inputType state.
1738
@property()
1839
get type() {
1940
return this.inputType;
@@ -22,9 +43,13 @@ export class UUIInputColorElement extends UUIInputElement {
2243
this.inputType = newValue;
2344
}
2445

25-
onChange(e: Event): void {
26-
const target = e.target as HTMLInputElement;
27-
this.value = target.value;
46+
#onColorClick() {
47+
this._colorPicker.click();
48+
}
49+
50+
#onColorChange(event: Event) {
51+
event.stopPropagation();
52+
this.value = this._colorPicker.value;
2853
}
2954

3055
connectedCallback(): void {
@@ -34,20 +59,21 @@ export class UUIInputColorElement extends UUIInputElement {
3459
}
3560

3661
renderPrepend() {
37-
return html`<label id="color-picker">
62+
return html`<div class="color-wrapper">
3863
<uui-color-swatch
3964
?disabled=${this.disabled}
4065
?readonly=${this.readonly}
41-
.value=${this.value}>
42-
</uui-color-swatch>
66+
value=${this._valueHex}
67+
@click=${this.#onColorClick}></uui-color-swatch>
4368
<input
4469
type="color"
45-
id="color-input"
46-
.value="${this.value}"
70+
id="color"
71+
value="${this.value}"
4772
?disabled=${this.disabled}
4873
?readonly=${this.readonly}
74+
@change=${this.#onColorChange}
4975
aria-hidden="true" />
50-
</label>`;
76+
</div>`;
5177
}
5278

5379
static styles = [
@@ -56,16 +82,21 @@ export class UUIInputColorElement extends UUIInputElement {
5682
:host {
5783
}
5884
59-
#color-picker {
85+
.color-wrapper {
6086
cursor: pointer;
87+
display: inline-flex;
6188
position: relative;
6289
border-right: var(--uui-input-border-width, 1px) solid
6390
var(--uui-input-border-color, var(--uui-color-border));
6491
}
6592
66-
#color-input {
67-
visibility: hidden;
93+
input[type='color'] {
6894
appearance: none;
95+
visibility: hidden;
96+
width: 0px;
97+
padding: 0;
98+
margin: 0;
99+
position: absolute;
69100
}
70101
71102
uui-color-swatch {

packages/uui-input-color/lib/uui-input-color.story.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import './uui-input-color.element';
44
import type { UUIInputColorElement } from './uui-input-color.element';
55
import readme from '../README.md?raw';
66
import { html } from 'lit';
7-
import { renderSlots, spread } from '../../../storyhelpers';
7+
import { spread } from '../../../storyhelpers';
88

99
/**
1010
* uui-input-color extends uui-input. See [uui-input](/docs/uui-input--docs) for more details.
@@ -13,13 +13,7 @@ const meta: Meta<UUIInputColorElement> = {
1313
id: 'uui-input-color',
1414
title: 'Inputs/Input Color',
1515
component: 'uui-input-color',
16-
args: {
17-
label: 'Label',
18-
},
19-
render: args =>
20-
html`<uui-input-color ${spread(args)}
21-
>${renderSlots(args)}</uui-input-color
22-
>`,
16+
render: args => html`<uui-input-color ${spread(args)}></uui-input-color>`,
2317
parameters: {
2418
readme: {
2519
markdown: readme,
@@ -38,6 +32,12 @@ export const Empty: Story = {
3832
},
3933
};
4034

35+
export const Color: Story = {
36+
args: {
37+
value: '#f00',
38+
},
39+
};
40+
4141
export const Disabled: Story = {
4242
args: {
4343
disabled: true,

packages/uui-input-password/lib/uui-input-password.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class UUIInputPasswordElement extends UUIInputElement {
1717
@state()
1818
private inputType: InputType = 'password';
1919

20-
// this overrides the inherited type property, and moves the input's type handling to the passwordType state.
20+
// this overrides the inherited type property, and moves the input's type handling to the inputType state.
2121
@property()
2222
get type() {
2323
return this.inputType;

0 commit comments

Comments
 (0)