Skip to content

Commit 2e99c31

Browse files
committed
Add text input for hex value to kol-input-color
Refs: #7164
1 parent c8fc316 commit 2e99c31

File tree

7 files changed

+370
-115
lines changed

7 files changed

+370
-115
lines changed

packages/components/src/components/input-color/shadow.tsx

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ import { InputColorController } from './controller';
4040
})
4141
export class KolInputColor implements InputColorAPI, FocusableElement {
4242
@Element() private readonly host?: HTMLKolInputColorElement;
43-
private inputRef?: HTMLInputElement;
43+
private refInputText?: HTMLInputElement;
44+
private refInputColor?: HTMLInputElement;
4445

4546
private readonly catchRef = (ref?: HTMLInputElement) => {
46-
this.inputRef = ref;
47+
this.refInputText = ref;
48+
};
49+
private readonly catchColorRef = (ref?: HTMLInputElement) => {
50+
this.refInputColor = ref;
4751
};
48-
4952
private readonly onBlur = (event: FocusEvent) => {
5053
this.controller.onFacade.onBlur(event);
5154
this.inputHasFocus = false;
@@ -56,51 +59,75 @@ export class KolInputColor implements InputColorAPI, FocusableElement {
5659
this.inputHasFocus = true;
5760
};
5861

59-
private readonly onInput = (event: InputEvent) => {
60-
this._value = this.inputRef?.value ?? '';
62+
private readonly onColorInput = (event: InputEvent) => {
63+
const value = (event.target as HTMLInputElement).value;
64+
this._value = value;
65+
if (this.refInputText) {
66+
this.refInputText.value = value;
67+
}
68+
this.controller.onFacade.onInput(event);
69+
};
70+
private readonly onTextInput = (event: InputEvent) => {
71+
const value = (event.target as HTMLInputElement).value;
72+
this._value = value;
73+
if (this.refInputColor) {
74+
this.refInputColor.value = value;
75+
}
6176
this.controller.onFacade.onInput(event);
6277
};
63-
6478
@Method()
6579
// eslint-disable-next-line @typescript-eslint/require-await
6680
public async getValue(): Promise<string | undefined> {
67-
return this.inputRef?.value;
81+
return this.refInputText?.value;
6882
}
6983

7084
@Method()
7185
// eslint-disable-next-line @typescript-eslint/require-await
7286
public async kolFocus() {
73-
this.inputRef?.focus();
87+
this.refInputText?.focus();
7488
}
7589

7690
private getFormFieldProps(): FormFieldStateWrapperProps {
7791
return {
7892
state: this.state,
7993
class: 'kol-input-color',
8094
tooltipAlign: this._tooltipAlign,
81-
onClick: () => this.inputRef?.focus(),
95+
onClick: () => this.refInputText?.focus(),
8296
alert: this.showAsAlert(),
8397
};
8498
}
8599

86-
private getInputProps(): InputStateWrapperProps {
100+
private getInputColorProps(): InputStateWrapperProps {
87101
return {
88-
ref: this.catchRef,
102+
ref: this.catchColorRef,
89103
type: 'color',
90-
slot: 'input',
104+
name: this.state._name ? `${this.state._name}-color` : undefined,
105+
'aria-hidden': 'true',
91106
state: this.state,
92107
...this.controller.onFacade,
108+
onInput: this.onColorInput,
109+
};
110+
}
111+
private getInputTextProps(): InputStateWrapperProps {
112+
return {
113+
ref: this.catchRef,
114+
type: 'text',
115+
name: this.state._name ? `${this.state._name}-text` : undefined,
116+
state: this.state,
117+
...this.controller.onFacade,
118+
onInput: this.onTextInput,
93119
onBlur: this.onBlur,
94120
onFocus: this.onFocus,
95-
onInput: this.onInput,
96121
};
97122
}
98-
99123
public render(): JSX.Element {
100124
return (
101125
<KolFormFieldStateWrapperFc {...this.getFormFieldProps()}>
102-
<KolInputContainerFc state={this.state}>
103-
<KolInputStateWrapperFc {...this.getInputProps()} />
126+
<KolInputContainerFc state={this.state} class="kol-input-color__inputs-wrapper">
127+
<div class="kol-input-color__inputs-wrapper">
128+
<KolInputStateWrapperFc class="kol-input-color__input kol-input-color__input--color" {...this.getInputColorProps()} />
129+
<KolInputStateWrapperFc class="kol-input-color__input kol-input-color__input--text" {...this.getInputTextProps()} />
130+
</div>
104131
</KolInputContainerFc>
105132
</KolFormFieldStateWrapperFc>
106133
);

packages/components/src/components/input-color/style.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@
99
@include kol-form-field;
1010
@include kol-input-container;
1111
@include kol-input;
12+
13+
.kol-input-color {
14+
&__input--color {
15+
cursor: pointer;
16+
}
17+
18+
&__inputs-wrapper {
19+
align-items: center;
20+
display: flex;
21+
flex-direction: row;
22+
flex-grow: 1;
23+
gap: rem(6) !important;
24+
}
25+
}

0 commit comments

Comments
 (0)