igniteui-webcomponents 7.3.0-beta.1 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/components/color-picker/color-picker.d.ts +261 -0
- package/components/color-picker/color-picker.js +620 -0
- package/components/color-picker/color-picker.js.map +1 -0
- package/components/color-picker/common.d.ts +37 -0
- package/components/color-picker/common.js +55 -0
- package/components/color-picker/common.js.map +1 -0
- package/components/color-picker/converters.d.ts +18 -0
- package/components/color-picker/converters.js +173 -0
- package/components/color-picker/converters.js.map +1 -0
- package/components/color-picker/model.d.ts +120 -0
- package/components/color-picker/model.js +174 -0
- package/components/color-picker/model.js.map +1 -0
- package/components/color-picker/picker-canvas.d.ts +95 -0
- package/components/color-picker/picker-canvas.js +154 -0
- package/components/color-picker/picker-canvas.js.map +1 -0
- package/components/color-picker/themes/color-picker.base.css.d.ts +1 -0
- package/components/color-picker/themes/color-picker.base.css.js +3 -0
- package/components/color-picker/themes/color-picker.base.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.bootstrap.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.bootstrap.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.bootstrap.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.fluent.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.fluent.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.fluent.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.indigo.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.indigo.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.indigo.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.material.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.material.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.material.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.bootstrap.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.bootstrap.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.bootstrap.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.fluent.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.fluent.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.fluent.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.indigo.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.indigo.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.indigo.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.material.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.material.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.material.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.shared.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.shared.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.shared.css.js.map +1 -0
- package/components/color-picker/themes/picker-canvas.base.css.d.ts +1 -0
- package/components/color-picker/themes/picker-canvas.base.css.js +3 -0
- package/components/color-picker/themes/picker-canvas.base.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.bootstrap.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.bootstrap.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.bootstrap.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.common.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.common.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.common.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.fluent.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.fluent.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.fluent.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.indigo.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.indigo.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.indigo.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.material.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.material.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.material.css.js.map +1 -0
- package/components/color-picker/themes/themes.d.ts +2 -0
- package/components/color-picker/themes/themes.js +50 -0
- package/components/color-picker/themes/themes.js.map +1 -0
- package/components/color-picker/validators.d.ts +3 -0
- package/components/color-picker/validators.js +5 -0
- package/components/color-picker/validators.js.map +1 -0
- package/components/date-picker/date-picker.base.d.ts +1 -1
- package/components/icon/icon-references.js +1 -0
- package/components/icon/icon-references.js.map +1 -1
- package/components/icon/internal-icons-lib.js +3 -0
- package/components/icon/internal-icons-lib.js.map +1 -1
- package/components/input/themes/shared/input.material.css.js +1 -1
- package/components/input/themes/shared/input.material.css.js.map +1 -1
- package/components/types.d.ts +2 -0
- package/components/types.js.map +1 -1
- package/custom-elements.json +25877 -22839
- package/igniteui-webcomponents.css-data.json +1 -1
- package/igniteui-webcomponents.html-data.json +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/internals/definitions/defineAllComponents.js +2 -0
- package/internals/definitions/defineAllComponents.js.map +1 -1
- package/package.json +3 -1
- package/web-types.json +2 -2
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var IgcColorPickerComponent_1;
|
|
8
|
+
import { html, nothing } from 'lit';
|
|
9
|
+
import { property, query } from 'lit/decorators.js';
|
|
10
|
+
import { cache } from 'lit/directives/cache.js';
|
|
11
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
12
|
+
import { live } from 'lit/directives/live.js';
|
|
13
|
+
import { createRef, ref } from 'lit/directives/ref.js';
|
|
14
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
15
|
+
import { addAriaProjector } from '#internals/controllers/aria-projection.js';
|
|
16
|
+
import { addKeybindings, altKey, arrowDown, arrowRight, arrowUp, endKey, escapeKey, } from '#internals/controllers/key-bindings.js';
|
|
17
|
+
import { addRootClickController } from '#internals/controllers/root-click.js';
|
|
18
|
+
import { addSlotController, setSlots } from '#internals/controllers/slot.js';
|
|
19
|
+
import { shadowOptions } from '#internals/decorators/shadow-options.js';
|
|
20
|
+
import { registerComponent } from '#internals/definitions/register.js';
|
|
21
|
+
import { IgcBaseComboBoxComponent } from '#internals/mixins/combo-box.js';
|
|
22
|
+
import { EventEmitterMixin } from '#internals/mixins/event-emitter.js';
|
|
23
|
+
import { FormAssociatedRequiredMixin } from '#internals/mixins/forms/associated-required.js';
|
|
24
|
+
import { createFormValueState } from '#internals/mixins/forms/form-value.js';
|
|
25
|
+
import { partMap } from '#internals/part-map.js';
|
|
26
|
+
import { isEmpty } from '#internals/utils/arrays.js';
|
|
27
|
+
import { addSafeEventListener, focusLeftHost, getElementFromPath, stopPropagation, } from '#internals/utils/events.js';
|
|
28
|
+
import { bindIf } from '#internals/utils/lit.js';
|
|
29
|
+
import { asNumber, clamp } from '#internals/utils/math.js';
|
|
30
|
+
import { addThemingController } from '#theming/theming-controller.js';
|
|
31
|
+
import IgcButtonComponent from '../button/button.js';
|
|
32
|
+
import IgcIconButtonComponent from '../button/icon-button.js';
|
|
33
|
+
import IgcDividerComponent from '../divider/divider.js';
|
|
34
|
+
import IgcFocusTrapComponent from '../focus-trap/focus-trap.js';
|
|
35
|
+
import IgcInputComponent from '../input/input.js';
|
|
36
|
+
import IgcPopoverComponent from '../popover/popover.js';
|
|
37
|
+
import IgcSelectComponent from '../select/select.js';
|
|
38
|
+
import IgcValidationContainerComponent from '../validation-container/validation-container.js';
|
|
39
|
+
import IgcVisuallyHiddenComponent from '../visually-hidden/visually-hidden.js';
|
|
40
|
+
import { isValidColor, normalizeColor } from './common.js';
|
|
41
|
+
import { ColorModel, getContext } from './model.js';
|
|
42
|
+
import IgcPickerCanvasComponent from './picker-canvas.js';
|
|
43
|
+
import { styles } from './themes/color-picker.base.css.js';
|
|
44
|
+
import { styles as shared } from './themes/shared/color-picker.common.css.js';
|
|
45
|
+
import { all } from './themes/themes.js';
|
|
46
|
+
import { colorPickerValidators } from './validators.js';
|
|
47
|
+
const Slots = setSlots('value-missing', 'custom-error', 'invalid', 'helper-text');
|
|
48
|
+
const formatPlaceholders = {
|
|
49
|
+
hex: '#rrggbb',
|
|
50
|
+
rgb: 'rgb(r g b)',
|
|
51
|
+
hsl: 'hsl(h s% l%)',
|
|
52
|
+
};
|
|
53
|
+
const nonDigits = /\D/g;
|
|
54
|
+
function caretLimit(text) {
|
|
55
|
+
return Math.max(text.length - 1, 0);
|
|
56
|
+
}
|
|
57
|
+
function getEyeDropper() {
|
|
58
|
+
return globalThis.EyeDropper;
|
|
59
|
+
}
|
|
60
|
+
let IgcColorPickerComponent = class IgcColorPickerComponent extends FormAssociatedRequiredMixin(EventEmitterMixin(IgcBaseComboBoxComponent)) {
|
|
61
|
+
static { IgcColorPickerComponent_1 = this; }
|
|
62
|
+
static { this.tagName = 'igc-color-picker'; }
|
|
63
|
+
static { this.styles = [styles, shared]; }
|
|
64
|
+
static register() {
|
|
65
|
+
registerComponent(IgcColorPickerComponent_1, IgcInputComponent, IgcPopoverComponent, IgcFocusTrapComponent, IgcSelectComponent, IgcPickerCanvasComponent, IgcDividerComponent, IgcButtonComponent, IgcIconButtonComponent, IgcValidationContainerComponent, IgcVisuallyHiddenComponent);
|
|
66
|
+
}
|
|
67
|
+
get __validators() {
|
|
68
|
+
return colorPickerValidators;
|
|
69
|
+
}
|
|
70
|
+
get _isInputMode() {
|
|
71
|
+
return this.mode === 'input';
|
|
72
|
+
}
|
|
73
|
+
set value(value) {
|
|
74
|
+
this._color = ColorModel.parse(value);
|
|
75
|
+
this._updateColor();
|
|
76
|
+
}
|
|
77
|
+
get value() {
|
|
78
|
+
return this._formValue.value;
|
|
79
|
+
}
|
|
80
|
+
constructor() {
|
|
81
|
+
super();
|
|
82
|
+
this._slots = addSlotController(this, { slots: Slots });
|
|
83
|
+
this._rootClickController = addRootClickController(this, {
|
|
84
|
+
onHide: this._handleClosing,
|
|
85
|
+
});
|
|
86
|
+
this._formValue = createFormValueState(this, {
|
|
87
|
+
initialValue: '',
|
|
88
|
+
});
|
|
89
|
+
this._alphaRef = createRef();
|
|
90
|
+
this._alphaInputRef = createRef();
|
|
91
|
+
this._canvasRef = createRef();
|
|
92
|
+
this._hueRef = createRef();
|
|
93
|
+
this._anchorRef = createRef();
|
|
94
|
+
this._supportsEyeDropper = Boolean(getEyeDropper());
|
|
95
|
+
this._color = ColorModel.empty();
|
|
96
|
+
this._oldValue = '';
|
|
97
|
+
this._appliedProperties = new Map();
|
|
98
|
+
this.format = 'hex';
|
|
99
|
+
this.hideFormats = false;
|
|
100
|
+
this.showAlpha = false;
|
|
101
|
+
this.mode = 'default';
|
|
102
|
+
this.swatches = [];
|
|
103
|
+
addThemingController(this, all);
|
|
104
|
+
addSafeEventListener(this, 'focusin', this._handleFocusIn);
|
|
105
|
+
addSafeEventListener(this, 'focusout', this._handleFocusOut);
|
|
106
|
+
addKeybindings(this, { skip: () => this.disabled })
|
|
107
|
+
.set(escapeKey, this._handleKeyboardClosing)
|
|
108
|
+
.set([altKey, arrowDown], this._handleAnchorClick)
|
|
109
|
+
.set([altKey, arrowUp], this._handleKeyboardClosing);
|
|
110
|
+
addKeybindings(this, {
|
|
111
|
+
skip: () => this.disabled || !this._alphaInputRef.value,
|
|
112
|
+
ref: this._alphaInputRef,
|
|
113
|
+
bindingDefaults: { repeat: true },
|
|
114
|
+
})
|
|
115
|
+
.set(arrowUp, () => this._handleAlphaInputSpin(1))
|
|
116
|
+
.set(arrowDown, () => this._handleAlphaInputSpin(-1))
|
|
117
|
+
.set(arrowRight, this._handleAlphaInputCaretForward, {
|
|
118
|
+
preventDefault: false,
|
|
119
|
+
})
|
|
120
|
+
.set(endKey, this._handleAlphaInputCaretForward, {
|
|
121
|
+
preventDefault: false,
|
|
122
|
+
});
|
|
123
|
+
addAriaProjector(this, {
|
|
124
|
+
target: () => (this._isInputMode ? this._anchorRef.value : null),
|
|
125
|
+
state: () => ({
|
|
126
|
+
hasPopup: 'dialog',
|
|
127
|
+
expanded: `${this.open}`,
|
|
128
|
+
labelledBy: this._internals.labels,
|
|
129
|
+
describedBy: this._helperText ? [this._helperText] : null,
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
update(props) {
|
|
134
|
+
if (props.has('open')) {
|
|
135
|
+
this._rootClickController.update();
|
|
136
|
+
}
|
|
137
|
+
if (this.hasUpdated && props.has('format')) {
|
|
138
|
+
this._formValue.setValueAndFormState(this._color.asString(this.format));
|
|
139
|
+
}
|
|
140
|
+
this._applyColorProperties();
|
|
141
|
+
super.update(props);
|
|
142
|
+
}
|
|
143
|
+
updated(props) {
|
|
144
|
+
super.updated(props);
|
|
145
|
+
if (props.has('open') || props.has('value')) {
|
|
146
|
+
requestAnimationFrame(() => this._syncCanvasPosition());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
formResetCallback() {
|
|
150
|
+
super.formResetCallback();
|
|
151
|
+
if (this._isInputMode) {
|
|
152
|
+
const input = this._anchorRef.value;
|
|
153
|
+
input?.['formResetCallback']();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
_handleClosing() {
|
|
157
|
+
this._hide(true);
|
|
158
|
+
}
|
|
159
|
+
async _handleKeyboardClosing() {
|
|
160
|
+
if (await this._hide(true)) {
|
|
161
|
+
this._anchorRef.value?.focus();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
_handleFocusIn(event) {
|
|
165
|
+
if (focusLeftHost(this, event)) {
|
|
166
|
+
this._oldValue = this._alphaColor;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
_handleFocusOut(event) {
|
|
170
|
+
if (!focusLeftHost(this, event)) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this._handleBlur();
|
|
174
|
+
if (this._alphaColor !== this._oldValue) {
|
|
175
|
+
this._oldValue = this._alphaColor;
|
|
176
|
+
this.emitEvent('igcChange', { detail: this.value });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
_handleCanvasColorPicked(event) {
|
|
180
|
+
this._color.setSaturationAndValue(event.detail.x, 100 - event.detail.y);
|
|
181
|
+
this._updateColor();
|
|
182
|
+
this._emitInputEvent();
|
|
183
|
+
}
|
|
184
|
+
_handleHueValueChange(event) {
|
|
185
|
+
stopPropagation(event);
|
|
186
|
+
this._color.h = asNumber(this._hueRef.value?.value);
|
|
187
|
+
this._updateColor();
|
|
188
|
+
this._emitInputEvent();
|
|
189
|
+
}
|
|
190
|
+
_handleAlphaSliderValueChange(event) {
|
|
191
|
+
stopPropagation(event);
|
|
192
|
+
this._setAlpha(asNumber(this._alphaRef.value?.value));
|
|
193
|
+
}
|
|
194
|
+
_handleAlphaInputEdit(event) {
|
|
195
|
+
const input = this._alphaInputRef.value;
|
|
196
|
+
const native = getElementFromPath('input', event);
|
|
197
|
+
if (!input || !native)
|
|
198
|
+
return;
|
|
199
|
+
const caret = native.selectionStart ?? native.value.length;
|
|
200
|
+
const typed = native.value.slice(0, caret).replace(nonDigits, '').length;
|
|
201
|
+
const digits = native.value.replace(nonDigits, '');
|
|
202
|
+
const percent = clamp(asNumber(digits), 0, 100);
|
|
203
|
+
const text = digits ? `${percent}%` : '';
|
|
204
|
+
this._writeAlphaText(input, text, Math.min(typed, caretLimit(text)));
|
|
205
|
+
if (digits) {
|
|
206
|
+
this._setAlpha(percent);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
_handleAlphaInputCaret(event) {
|
|
210
|
+
const native = getElementFromPath('input', event);
|
|
211
|
+
if (!native)
|
|
212
|
+
return;
|
|
213
|
+
const limit = caretLimit(native.value);
|
|
214
|
+
native.setSelectionRange(Math.min(native.selectionStart ?? 0, limit), Math.min(native.selectionEnd ?? 0, limit));
|
|
215
|
+
}
|
|
216
|
+
_handleAlphaInputSpin(increment) {
|
|
217
|
+
const input = this._alphaInputRef.value;
|
|
218
|
+
const percent = clamp(this._alphaPercent + increment, 0, 100);
|
|
219
|
+
if (!input || percent === this._alphaPercent)
|
|
220
|
+
return;
|
|
221
|
+
this._writeAlphaText(input, `${percent}%`);
|
|
222
|
+
this._setAlpha(percent);
|
|
223
|
+
}
|
|
224
|
+
_handleAlphaInputCaretForward(event) {
|
|
225
|
+
const native = getElementFromPath('input', event);
|
|
226
|
+
if (!native)
|
|
227
|
+
return;
|
|
228
|
+
const limit = caretLimit(native.value);
|
|
229
|
+
if (event.key === endKey || (native.selectionEnd ?? 0) >= limit) {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
native.setSelectionRange(limit, limit);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
_handleAlphaInputChange(event) {
|
|
235
|
+
stopPropagation(event);
|
|
236
|
+
const input = event.target;
|
|
237
|
+
if (!input.value) {
|
|
238
|
+
input.value = `${this._alphaPercent}%`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
_handleFormatChange(event) {
|
|
242
|
+
stopPropagation(event);
|
|
243
|
+
this.format = event.detail.value;
|
|
244
|
+
}
|
|
245
|
+
_handleColorInputChange(event) {
|
|
246
|
+
stopPropagation(event);
|
|
247
|
+
const input = event.target;
|
|
248
|
+
const value = normalizeColor(event.detail);
|
|
249
|
+
const cleared = !value;
|
|
250
|
+
if (!cleared && !isValidColor(value, getContext())) {
|
|
251
|
+
input.value = this._color.asString(this.format);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
this._color = cleared ? ColorModel.empty() : ColorModel.parse(value);
|
|
255
|
+
this._updateColor();
|
|
256
|
+
this._syncCanvasPosition();
|
|
257
|
+
}
|
|
258
|
+
_handleEyeDropperClick() {
|
|
259
|
+
const EyeDropper = getEyeDropper();
|
|
260
|
+
if (!EyeDropper)
|
|
261
|
+
return;
|
|
262
|
+
new EyeDropper()
|
|
263
|
+
.open()
|
|
264
|
+
.then((result) => {
|
|
265
|
+
this.value = result.sRGBHex;
|
|
266
|
+
this._emitInputEvent();
|
|
267
|
+
})
|
|
268
|
+
.catch(() => { });
|
|
269
|
+
}
|
|
270
|
+
_handleCopy() {
|
|
271
|
+
navigator.clipboard?.writeText(this.value).catch(() => { });
|
|
272
|
+
}
|
|
273
|
+
_handleSwatchClick(event) {
|
|
274
|
+
const swatch = getElementFromPath('button[part="swatch"]', event);
|
|
275
|
+
const color = swatch?.dataset.color;
|
|
276
|
+
if (color) {
|
|
277
|
+
this.value = color;
|
|
278
|
+
this._emitInputEvent();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
get _alphaColor() {
|
|
282
|
+
return this._color.asString('rgb', true);
|
|
283
|
+
}
|
|
284
|
+
get _opaqueColor() {
|
|
285
|
+
return new ColorModel(this._color.toRGB()).asString('rgb');
|
|
286
|
+
}
|
|
287
|
+
get _alphaPercent() {
|
|
288
|
+
return Math.round(this._color.alpha * 100);
|
|
289
|
+
}
|
|
290
|
+
get _currentColor() {
|
|
291
|
+
return `hsl(${this._color.h} 100% 50%)`;
|
|
292
|
+
}
|
|
293
|
+
_applyColorProperties() {
|
|
294
|
+
const properties = {
|
|
295
|
+
'--_current-color': this._currentColor,
|
|
296
|
+
'--_selected-color': this._opaqueColor,
|
|
297
|
+
};
|
|
298
|
+
for (const [name, value] of Object.entries(properties)) {
|
|
299
|
+
if (this._appliedProperties.get(name) !== value) {
|
|
300
|
+
this._appliedProperties.set(name, value);
|
|
301
|
+
this.style.setProperty(name, value);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
_writeAlphaText(input, text, caret = caretLimit(text)) {
|
|
306
|
+
input.setRangeText(text, 0, input.value.length);
|
|
307
|
+
input.setSelectionRange(caret, caret);
|
|
308
|
+
}
|
|
309
|
+
_setAlpha(percent) {
|
|
310
|
+
const alpha = clamp(percent, 0, 100) / 100;
|
|
311
|
+
if (this._color.alpha === alpha) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this._color.alpha = alpha;
|
|
315
|
+
this._updateColor();
|
|
316
|
+
this._emitInputEvent();
|
|
317
|
+
}
|
|
318
|
+
_updateColor() {
|
|
319
|
+
this._formValue.setValueAndFormState(this._color.asString(this.format));
|
|
320
|
+
this.requestUpdate();
|
|
321
|
+
}
|
|
322
|
+
_syncCanvasPosition() {
|
|
323
|
+
if (!this._canvasRef.value || !this.open)
|
|
324
|
+
return;
|
|
325
|
+
const rect = this._canvasRef.value.getBoundingClientRect();
|
|
326
|
+
const { width: markerWidth, height: markerHeight } = this._canvasRef.value.getMarkerDimensions();
|
|
327
|
+
const [, s, v] = this._color.toHSV();
|
|
328
|
+
const x = (s / 100) * rect.width - markerWidth;
|
|
329
|
+
const y = ((100 - v) / 100) * rect.height - markerHeight;
|
|
330
|
+
this._canvasRef.value.x = x;
|
|
331
|
+
this._canvasRef.value.y = y;
|
|
332
|
+
}
|
|
333
|
+
_emitInputEvent() {
|
|
334
|
+
this.emitEvent('igcInput', { detail: this.value });
|
|
335
|
+
}
|
|
336
|
+
_renderCanvasGradient() {
|
|
337
|
+
const [, saturation, brightness] = this._color.toHSV();
|
|
338
|
+
return html `
|
|
339
|
+
<igc-picker-canvas
|
|
340
|
+
exportparts="marker, dragging"
|
|
341
|
+
part="picker-canvas"
|
|
342
|
+
${ref(this._canvasRef)}
|
|
343
|
+
@igcColorPicked=${this._handleCanvasColorPicked}
|
|
344
|
+
currentColor=${this._currentColor}
|
|
345
|
+
markerColor=${this._opaqueColor}
|
|
346
|
+
.saturation=${saturation}
|
|
347
|
+
.brightness=${brightness}
|
|
348
|
+
>
|
|
349
|
+
</igc-picker-canvas>
|
|
350
|
+
`;
|
|
351
|
+
}
|
|
352
|
+
_renderHueSlider() {
|
|
353
|
+
return html `
|
|
354
|
+
<input
|
|
355
|
+
${ref(this._hueRef)}
|
|
356
|
+
aria-label="Hue"
|
|
357
|
+
type="range"
|
|
358
|
+
part="hue"
|
|
359
|
+
min="0"
|
|
360
|
+
max="360"
|
|
361
|
+
.value=${String(Math.round(this._color.h))}
|
|
362
|
+
@input=${this._handleHueValueChange}
|
|
363
|
+
@change=${stopPropagation}
|
|
364
|
+
/>
|
|
365
|
+
`;
|
|
366
|
+
}
|
|
367
|
+
_renderIconButton(part, icon, label, handler, disabled = false) {
|
|
368
|
+
return html `
|
|
369
|
+
<igc-icon-button
|
|
370
|
+
part=${part}
|
|
371
|
+
variant="flat"
|
|
372
|
+
name=${icon}
|
|
373
|
+
?disabled=${disabled}
|
|
374
|
+
@click=${handler}
|
|
375
|
+
>
|
|
376
|
+
<igc-visually-hidden>${label}</igc-visually-hidden>
|
|
377
|
+
</igc-icon-button>
|
|
378
|
+
`;
|
|
379
|
+
}
|
|
380
|
+
_renderPickerButtons() {
|
|
381
|
+
return html `
|
|
382
|
+
<div part="buttons">
|
|
383
|
+
${this._renderIconButton('copy', 'copy_content', 'Copy color value to clipboard', this._handleCopy)}
|
|
384
|
+
${this._renderIconButton('eye-dropper', 'eye_dropper', 'Pick a color from the screen', this._handleEyeDropperClick, !this._supportsEyeDropper)}
|
|
385
|
+
</div>
|
|
386
|
+
`;
|
|
387
|
+
}
|
|
388
|
+
_renderAlphaRow() {
|
|
389
|
+
return html `
|
|
390
|
+
<input
|
|
391
|
+
${ref(this._alphaRef)}
|
|
392
|
+
aria-label="Alpha slider"
|
|
393
|
+
type="range"
|
|
394
|
+
part="alpha"
|
|
395
|
+
min="0"
|
|
396
|
+
max="100"
|
|
397
|
+
.value=${String(this._alphaPercent)}
|
|
398
|
+
@input=${this._handleAlphaSliderValueChange}
|
|
399
|
+
@change=${stopPropagation}
|
|
400
|
+
/>
|
|
401
|
+
|
|
402
|
+
<igc-visually-hidden>
|
|
403
|
+
<label for="alpha">Alpha value</label>
|
|
404
|
+
</igc-visually-hidden>
|
|
405
|
+
|
|
406
|
+
<igc-input
|
|
407
|
+
${ref(this._alphaInputRef)}
|
|
408
|
+
id="alpha"
|
|
409
|
+
name="alpha"
|
|
410
|
+
placeholder="Alpha value"
|
|
411
|
+
inputmode="numeric"
|
|
412
|
+
part="alpha-input"
|
|
413
|
+
outlined
|
|
414
|
+
type="text"
|
|
415
|
+
.value=${live(`${this._alphaPercent}%`)}
|
|
416
|
+
@input=${this._handleAlphaInputEdit}
|
|
417
|
+
@focusin=${this._handleAlphaInputCaret}
|
|
418
|
+
@click=${this._handleAlphaInputCaret}
|
|
419
|
+
@keyup=${this._handleAlphaInputCaret}
|
|
420
|
+
@igcChange=${this._handleAlphaInputChange}
|
|
421
|
+
></igc-input>
|
|
422
|
+
`;
|
|
423
|
+
}
|
|
424
|
+
_renderSelect() {
|
|
425
|
+
return html `
|
|
426
|
+
<igc-visually-hidden>
|
|
427
|
+
<label for="format-select">Color format</label>
|
|
428
|
+
</igc-visually-hidden>
|
|
429
|
+
|
|
430
|
+
<igc-select
|
|
431
|
+
id="format-select"
|
|
432
|
+
part="format-select"
|
|
433
|
+
placeholder="Color format"
|
|
434
|
+
name="format"
|
|
435
|
+
outlined
|
|
436
|
+
.value=${this.format}
|
|
437
|
+
@igcChange=${this._handleFormatChange}
|
|
438
|
+
>
|
|
439
|
+
<igc-select-item value="hex">Hex</igc-select-item>
|
|
440
|
+
<igc-select-item value="rgb">RGB</igc-select-item>
|
|
441
|
+
<igc-select-item value="hsl">HSL</igc-select-item>
|
|
442
|
+
</igc-select>
|
|
443
|
+
`;
|
|
444
|
+
}
|
|
445
|
+
_renderInputsRow() {
|
|
446
|
+
return html `
|
|
447
|
+
${cache(this.hideFormats ? nothing : this._renderSelect())}
|
|
448
|
+
<igc-visually-hidden>
|
|
449
|
+
<label for="color-input"> Color value input </label>
|
|
450
|
+
</igc-visually-hidden>
|
|
451
|
+
|
|
452
|
+
<igc-input
|
|
453
|
+
id="color-input"
|
|
454
|
+
name="color-input"
|
|
455
|
+
placeholder=${formatPlaceholders[this.format]}
|
|
456
|
+
outlined
|
|
457
|
+
.value=${live(this._color.asString(this.format))}
|
|
458
|
+
@igcChange=${this._handleColorInputChange}
|
|
459
|
+
></igc-input>
|
|
460
|
+
`;
|
|
461
|
+
}
|
|
462
|
+
_renderSwatches() {
|
|
463
|
+
return !isEmpty(this.swatches)
|
|
464
|
+
? html `
|
|
465
|
+
<igc-divider></igc-divider>
|
|
466
|
+
<div part="swatches" @click=${this._handleSwatchClick}>
|
|
467
|
+
${this.swatches.map((color) => html `
|
|
468
|
+
<button
|
|
469
|
+
type="button"
|
|
470
|
+
part="swatch"
|
|
471
|
+
data-color=${color}
|
|
472
|
+
aria-label=${color}
|
|
473
|
+
style="background-color: ${color}"
|
|
474
|
+
></button>
|
|
475
|
+
`)}
|
|
476
|
+
</div>
|
|
477
|
+
`
|
|
478
|
+
: nothing;
|
|
479
|
+
}
|
|
480
|
+
get _anchorParts() {
|
|
481
|
+
return partMap({
|
|
482
|
+
anchor: true,
|
|
483
|
+
empty: this._color.isEmpty,
|
|
484
|
+
'input-mode': this._isInputMode,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
_previewStyle() {
|
|
488
|
+
const color = this._alphaColor;
|
|
489
|
+
return bindIf(color, styleMap({
|
|
490
|
+
'--_alpha-preview': color,
|
|
491
|
+
'--_color-preview': this._opaqueColor,
|
|
492
|
+
}));
|
|
493
|
+
}
|
|
494
|
+
_renderButtonAnchor() {
|
|
495
|
+
return html `
|
|
496
|
+
<button
|
|
497
|
+
${ref(this._anchorRef)}
|
|
498
|
+
id="trigger"
|
|
499
|
+
type="button"
|
|
500
|
+
aria-haspopup="dialog"
|
|
501
|
+
aria-controls="picker"
|
|
502
|
+
aria-expanded=${this.open}
|
|
503
|
+
aria-describedby="helper-text"
|
|
504
|
+
part=${this._anchorParts}
|
|
505
|
+
slot="anchor"
|
|
506
|
+
style=${this._previewStyle()}
|
|
507
|
+
?disabled=${this.disabled}
|
|
508
|
+
@click=${this._handleAnchorClick}
|
|
509
|
+
>
|
|
510
|
+
<igc-visually-hidden>Open color picker</igc-visually-hidden>
|
|
511
|
+
</button>
|
|
512
|
+
`;
|
|
513
|
+
}
|
|
514
|
+
_renderInputAnchor() {
|
|
515
|
+
return html `
|
|
516
|
+
<igc-input
|
|
517
|
+
${ref(this._anchorRef)}
|
|
518
|
+
slot="anchor"
|
|
519
|
+
outlined
|
|
520
|
+
placeholder=${formatPlaceholders[this.format]}
|
|
521
|
+
label=${ifDefined(this.label)}
|
|
522
|
+
?required=${this.required}
|
|
523
|
+
?disabled=${this.disabled}
|
|
524
|
+
.value=${live(this.value)}
|
|
525
|
+
.invalid=${this.invalid}
|
|
526
|
+
@igcChange=${this._handleColorInputChange}
|
|
527
|
+
>
|
|
528
|
+
<div slot="prefix">
|
|
529
|
+
<button
|
|
530
|
+
type="button"
|
|
531
|
+
part=${this._anchorParts}
|
|
532
|
+
aria-label="Open color picker"
|
|
533
|
+
aria-haspopup="dialog"
|
|
534
|
+
aria-controls="picker"
|
|
535
|
+
aria-expanded=${this.open}
|
|
536
|
+
style=${this._previewStyle()}
|
|
537
|
+
?disabled=${this.disabled}
|
|
538
|
+
@click=${this._handleAnchorClick}
|
|
539
|
+
></button>
|
|
540
|
+
</div>
|
|
541
|
+
</igc-input>
|
|
542
|
+
`;
|
|
543
|
+
}
|
|
544
|
+
_renderAnchor() {
|
|
545
|
+
return this._isInputMode
|
|
546
|
+
? this._renderInputAnchor()
|
|
547
|
+
: this._renderButtonAnchor();
|
|
548
|
+
}
|
|
549
|
+
_renderHelperText() {
|
|
550
|
+
return this._renderValidationContainer({
|
|
551
|
+
id: 'helper-text',
|
|
552
|
+
hasHelperText: true,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
_renderPicker() {
|
|
556
|
+
return html `
|
|
557
|
+
<igc-focus-trap ?disabled=${!this.open} .inert=${!this.open}>
|
|
558
|
+
<div
|
|
559
|
+
id="picker"
|
|
560
|
+
part="picker"
|
|
561
|
+
role="dialog"
|
|
562
|
+
aria-label="Color picker"
|
|
563
|
+
aria-modal="false"
|
|
564
|
+
>
|
|
565
|
+
${this._renderCanvasGradient()}
|
|
566
|
+
<div part="main-row">
|
|
567
|
+
${this._renderHueSlider()}${this._renderPickerButtons()}
|
|
568
|
+
</div>
|
|
569
|
+
${this.showAlpha
|
|
570
|
+
? html `<div part="alpha-row">${this._renderAlphaRow()}</div>`
|
|
571
|
+
: nothing}
|
|
572
|
+
<div part="inputs-row">${this._renderInputsRow()}</div>
|
|
573
|
+
${this._renderSwatches()}
|
|
574
|
+
</div>
|
|
575
|
+
</igc-focus-trap>
|
|
576
|
+
`;
|
|
577
|
+
}
|
|
578
|
+
render() {
|
|
579
|
+
return html `
|
|
580
|
+
<div part="color-picker">
|
|
581
|
+
<igc-popover ?open=${this.open} shift flip>
|
|
582
|
+
${this._renderAnchor()}${this._renderPicker()}
|
|
583
|
+
</igc-popover>
|
|
584
|
+
${!this._isInputMode && this.label
|
|
585
|
+
? html `<label part="label" for="trigger">${this.label}</label>`
|
|
586
|
+
: nothing}
|
|
587
|
+
${this._renderHelperText()}
|
|
588
|
+
</div>
|
|
589
|
+
`;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
__decorate([
|
|
593
|
+
query('#helper-text')
|
|
594
|
+
], IgcColorPickerComponent.prototype, "_helperText", void 0);
|
|
595
|
+
__decorate([
|
|
596
|
+
property()
|
|
597
|
+
], IgcColorPickerComponent.prototype, "label", void 0);
|
|
598
|
+
__decorate([
|
|
599
|
+
property()
|
|
600
|
+
], IgcColorPickerComponent.prototype, "value", null);
|
|
601
|
+
__decorate([
|
|
602
|
+
property()
|
|
603
|
+
], IgcColorPickerComponent.prototype, "format", void 0);
|
|
604
|
+
__decorate([
|
|
605
|
+
property({ type: Boolean, reflect: true, attribute: 'hide-formats' })
|
|
606
|
+
], IgcColorPickerComponent.prototype, "hideFormats", void 0);
|
|
607
|
+
__decorate([
|
|
608
|
+
property({ type: Boolean, reflect: true, attribute: 'show-alpha' })
|
|
609
|
+
], IgcColorPickerComponent.prototype, "showAlpha", void 0);
|
|
610
|
+
__decorate([
|
|
611
|
+
property({ reflect: true })
|
|
612
|
+
], IgcColorPickerComponent.prototype, "mode", void 0);
|
|
613
|
+
__decorate([
|
|
614
|
+
property({ attribute: false })
|
|
615
|
+
], IgcColorPickerComponent.prototype, "swatches", void 0);
|
|
616
|
+
IgcColorPickerComponent = IgcColorPickerComponent_1 = __decorate([
|
|
617
|
+
shadowOptions({ delegatesFocus: true })
|
|
618
|
+
], IgcColorPickerComponent);
|
|
619
|
+
export default IgcColorPickerComponent;
|
|
620
|
+
//# sourceMappingURL=color-picker.js.map
|