@nuralyui/colorpicker 0.0.4 → 0.0.6
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/bundle.js +1621 -0
- package/color-holder.component.d.ts +44 -3
- package/color-holder.component.js +96 -10
- package/color-holder.component.js.map +1 -1
- package/color-holder.style.js +30 -6
- package/color-holder.style.js.map +1 -1
- package/color-picker.component.d.ts +165 -12
- package/color-picker.component.js +316 -93
- package/color-picker.component.js.map +1 -1
- package/color-picker.style.d.ts +7 -0
- package/color-picker.style.js +49 -38
- package/color-picker.style.js.map +1 -1
- package/color-picker.types.d.ts +54 -0
- package/color-picker.types.js.map +1 -1
- package/default-color-sets.component.d.ts +40 -4
- package/default-color-sets.component.js +90 -12
- package/default-color-sets.component.js.map +1 -1
- package/default-color-sets.style.js +21 -3
- package/default-color-sets.style.js.map +1 -1
- package/package.json +16 -2
- package/react.js +1 -1
- package/react.js.map +1 -1
- package/color-holder.component.d.ts.map +0 -1
- package/color-holder.style.d.ts.map +0 -1
- package/color-picker.component.d.ts.map +0 -1
- package/color-picker.style.d.ts.map +0 -1
- package/color-picker.types.d.ts.map +0 -1
- package/default-color-sets.component.d.ts.map +0 -1
- package/default-color-sets.style.d.ts.map +0 -1
- package/demo/color-picker-demo.d.ts +0 -18
- package/demo/color-picker-demo.d.ts.map +0 -1
- package/demo/color-picker-demo.js +0 -157
- package/demo/color-picker-demo.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/react.d.ts.map +0 -1
|
@@ -1,134 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
1
6
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
7
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
8
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
9
|
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
10
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
11
|
};
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
12
|
import { LitElement, html, nothing } from 'lit';
|
|
17
13
|
import { customElement, property, state } from 'lit/decorators.js';
|
|
14
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
15
|
+
import { NuralyUIBaseMixin } from '@nuralyui/common/mixins';
|
|
16
|
+
import '../input/index.js';
|
|
17
|
+
// Import child components
|
|
18
18
|
import './color-holder.component.js';
|
|
19
19
|
import './default-color-sets.component.js';
|
|
20
|
+
// Import styles and types
|
|
20
21
|
import styles from './color-picker.style.js';
|
|
21
|
-
|
|
22
|
+
// Import controllers
|
|
23
|
+
import { ColorPickerDropdownController, ColorPickerEventController, } from './controllers/index.js';
|
|
24
|
+
/**
|
|
25
|
+
* Advanced color picker component with dropdown positioning, validation, and accessibility.
|
|
26
|
+
*
|
|
27
|
+
* Supports multiple color formats, default color sets, custom triggers, keyboard navigation,
|
|
28
|
+
* and various display configurations.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```html
|
|
32
|
+
* <!-- Basic color picker -->
|
|
33
|
+
* <nr-color-picker color="#3498db"></nr-color-picker>
|
|
34
|
+
*
|
|
35
|
+
* <!-- With default colors -->
|
|
36
|
+
* <nr-color-picker
|
|
37
|
+
* color="#3498db"
|
|
38
|
+
* .defaultColorSets="${['#3498db', '#e74c3c', '#2ecc71']}">
|
|
39
|
+
* </nr-color-picker>
|
|
40
|
+
*
|
|
41
|
+
* <!-- With custom configuration -->
|
|
42
|
+
* <nr-color-picker
|
|
43
|
+
* color="#3498db"
|
|
44
|
+
* trigger="click"
|
|
45
|
+
* placement="top"
|
|
46
|
+
* size="large"
|
|
47
|
+
* show-input="true"
|
|
48
|
+
* show-copy-button="true">
|
|
49
|
+
* </nr-color-picker>
|
|
50
|
+
*
|
|
51
|
+
* <!-- Disabled -->
|
|
52
|
+
* <nr-color-picker color="#3498db" disabled></nr-color-picker>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @fires hy-color-change - Color value changed
|
|
56
|
+
* @fires nr-colorpicker-open - Dropdown opened
|
|
57
|
+
* @fires nr-colorpicker-close - Dropdown closed
|
|
58
|
+
* @fires color-changed - Legacy event for backwards compatibility
|
|
59
|
+
*
|
|
60
|
+
* @slot - Default slot for custom content
|
|
61
|
+
*
|
|
62
|
+
* @cssproperty --colorpicker-trigger-size - Size of the color trigger box
|
|
63
|
+
* @cssproperty --colorpicker-dropdown-width - Width of the dropdown panel
|
|
64
|
+
* @cssproperty --colorpicker-dropdown-background - Background color of dropdown
|
|
65
|
+
* @cssproperty --colorpicker-dropdown-shadow - Shadow of dropdown panel
|
|
66
|
+
* @cssproperty --colorpicker-dropdown-border-radius - Border radius of dropdown
|
|
67
|
+
*/
|
|
68
|
+
let ColorPicker = class ColorPicker extends NuralyUIBaseMixin(LitElement) {
|
|
22
69
|
constructor() {
|
|
23
70
|
super();
|
|
24
|
-
this.
|
|
71
|
+
this.requiredComponents = ['nr-input', 'nr-icon'];
|
|
72
|
+
/** Current color value */
|
|
73
|
+
this.color = '#3498db';
|
|
74
|
+
/** Controls dropdown visibility */
|
|
25
75
|
this.show = false;
|
|
76
|
+
/** Array of preset colors to display */
|
|
26
77
|
this.defaultColorSets = [];
|
|
78
|
+
/** Disables the color picker */
|
|
27
79
|
this.disabled = false;
|
|
80
|
+
/** Color picker size (small, default, large) */
|
|
28
81
|
this.size = "default" /* ColorPickerSize.Default */;
|
|
82
|
+
/** Trigger mode for opening dropdown */
|
|
83
|
+
this.trigger = "click" /* ColorPickerTrigger.Click */;
|
|
84
|
+
/** Dropdown placement */
|
|
85
|
+
this.placement = "auto" /* ColorPickerPlacement.Auto */;
|
|
86
|
+
/** Animation style for dropdown */
|
|
87
|
+
this.animation = "fade" /* ColorPickerAnimation.Fade */;
|
|
88
|
+
/** Close dropdown when a color is selected */
|
|
89
|
+
this.closeOnSelect = false;
|
|
90
|
+
/** Close dropdown on outside click */
|
|
91
|
+
this.closeOnOutsideClick = true;
|
|
92
|
+
/** Close dropdown on escape key */
|
|
93
|
+
this.closeOnEscape = true;
|
|
94
|
+
/** Show color input field */
|
|
95
|
+
this.showInput = true;
|
|
96
|
+
/** Show copy button on input */
|
|
97
|
+
this.showCopyButton = true;
|
|
98
|
+
/** Color format (hex, rgb, rgba, hsl, hsla) */
|
|
99
|
+
this.format = "hex" /* ColorFormat.Hex */;
|
|
100
|
+
/** Placeholder text for color input */
|
|
101
|
+
this.inputPlaceholder = 'Enter color';
|
|
102
|
+
/** Label text */
|
|
103
|
+
this.label = '';
|
|
104
|
+
/** Helper text */
|
|
105
|
+
this.helperText = '';
|
|
106
|
+
/** Validation state for color value */
|
|
29
107
|
this.isValidColor = true;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
108
|
+
/** Manages dropdown visibility and positioning */
|
|
109
|
+
this.dropdownController = new ColorPickerDropdownController(this);
|
|
110
|
+
/** Handles all event management */
|
|
111
|
+
this.eventController = new ColorPickerEventController(this);
|
|
112
|
+
/**
|
|
113
|
+
* Handles trigger click to toggle dropdown
|
|
114
|
+
*/
|
|
115
|
+
this.handleTriggerClick = (event) => {
|
|
116
|
+
this.eventController.handleTriggerClick(event);
|
|
34
117
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const viewportWidth = window.innerWidth;
|
|
44
|
-
// Check if the dropdown is going out of the viewport vertically
|
|
45
|
-
if (colorHolderRect.bottom + dropdownRect.height > viewportHeight) {
|
|
46
|
-
// Move the dropdown upwards if it goes out of the viewport
|
|
47
|
-
dropdownContainer.style.top = `${colorHolderRect.top - dropdownRect.height}px`;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Otherwise, position it below the color holder
|
|
51
|
-
dropdownContainer.style.top = `${colorHolderRect.bottom}px`;
|
|
52
|
-
}
|
|
53
|
-
// Check if the dropdown is going out of the viewport horizontally
|
|
54
|
-
if (colorHolderRect.right + dropdownRect.width > viewportWidth) {
|
|
55
|
-
// Move the dropdown to the left if it goes out of the viewport
|
|
56
|
-
dropdownContainer.style.left = `${viewportWidth - dropdownRect.width}px`;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// Otherwise, position it to the right of the color holder
|
|
60
|
-
dropdownContainer.style.left = `${colorHolderRect.left}px`;
|
|
61
|
-
}
|
|
118
|
+
/**
|
|
119
|
+
* Handles color selection from hex-color-picker or default colors
|
|
120
|
+
*/
|
|
121
|
+
this.handleColorChanged = (event) => {
|
|
122
|
+
const newColor = event.detail.value;
|
|
123
|
+
this.eventController.handleColorChange(newColor);
|
|
124
|
+
if (this.closeOnSelect) {
|
|
125
|
+
this.dropdownController.close();
|
|
62
126
|
}
|
|
63
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* Handles input change from text input
|
|
130
|
+
*/
|
|
131
|
+
this.handleInputChange = (event) => {
|
|
132
|
+
this.eventController.handleInputChange(event);
|
|
133
|
+
};
|
|
134
|
+
// Dynamically import vanilla-colorful for color picker UI
|
|
64
135
|
if (typeof window !== 'undefined') {
|
|
65
136
|
import('vanilla-colorful');
|
|
66
137
|
}
|
|
67
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Component connected to DOM - initialize base functionality
|
|
141
|
+
*/
|
|
68
142
|
connectedCallback() {
|
|
69
143
|
super.connectedCallback();
|
|
70
|
-
// Mark the scroll listener as passive:
|
|
71
|
-
document.addEventListener('scroll', this.calculateDropDownPosition, {
|
|
72
|
-
passive: true,
|
|
73
|
-
});
|
|
74
|
-
document.addEventListener('click', this.onClickOutside);
|
|
75
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Component disconnected from DOM - cleanup event listeners
|
|
147
|
+
*/
|
|
148
|
+
disconnectedCallback() {
|
|
149
|
+
super.disconnectedCallback();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Called after component updates
|
|
153
|
+
*/
|
|
76
154
|
updated(changedProperties) {
|
|
155
|
+
super.updated(changedProperties);
|
|
77
156
|
if (changedProperties.has('color')) {
|
|
78
|
-
this.
|
|
157
|
+
this.validateColor();
|
|
79
158
|
}
|
|
80
159
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
handleColorChanged(colorChangedEvent) {
|
|
89
|
-
if (this.color != colorChangedEvent.detail.value) {
|
|
90
|
-
this.color = colorChangedEvent.detail.value;
|
|
91
|
-
this.dispatchColorChange();
|
|
92
|
-
}
|
|
160
|
+
// === Public API Methods ===
|
|
161
|
+
/**
|
|
162
|
+
* Opens the color picker dropdown
|
|
163
|
+
*/
|
|
164
|
+
open() {
|
|
165
|
+
this.dropdownController.open();
|
|
93
166
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Closes the color picker dropdown
|
|
169
|
+
*/
|
|
170
|
+
close() {
|
|
171
|
+
this.dropdownController.close();
|
|
99
172
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}));
|
|
173
|
+
/**
|
|
174
|
+
* Toggles the color picker dropdown
|
|
175
|
+
*/
|
|
176
|
+
toggle() {
|
|
177
|
+
this.dropdownController.toggle();
|
|
106
178
|
}
|
|
107
|
-
|
|
108
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Validates the current color value
|
|
181
|
+
*/
|
|
182
|
+
validateColor() {
|
|
183
|
+
this.isValidColor = this.eventController.isValidColor(this.color);
|
|
184
|
+
return this.isValidColor;
|
|
109
185
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Sets up global event listeners (called by dropdown controller)
|
|
188
|
+
*/
|
|
189
|
+
setupEventListeners() {
|
|
190
|
+
if (this.closeOnOutsideClick || this.closeOnEscape) {
|
|
191
|
+
this.eventController.setupEventListeners();
|
|
192
|
+
}
|
|
113
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Removes global event listeners (called by dropdown controller)
|
|
196
|
+
*/
|
|
197
|
+
removeEventListeners() {
|
|
198
|
+
this.eventController.removeEventListeners();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Main render method
|
|
202
|
+
*/
|
|
114
203
|
render() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
<div class=
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
<
|
|
204
|
+
const containerClasses = {
|
|
205
|
+
'color-picker-container': true,
|
|
206
|
+
'color-picker-container--disabled': this.disabled,
|
|
207
|
+
'color-picker-container--open': this.show,
|
|
208
|
+
[`color-picker-container--${this.size}`]: true,
|
|
209
|
+
};
|
|
210
|
+
return html `
|
|
211
|
+
<div class="${classMap(containerClasses)}" data-theme="${this.currentTheme}">
|
|
212
|
+
${this.renderLabel()}
|
|
213
|
+
|
|
214
|
+
<nr-colorholder-box
|
|
215
|
+
class="color-holder"
|
|
126
216
|
color="${this.color}"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
217
|
+
.size=${this.size}
|
|
218
|
+
?disabled="${this.disabled}"
|
|
219
|
+
@click=${this.disabled ? nothing : this.handleTriggerClick}
|
|
220
|
+
role="button"
|
|
221
|
+
aria-label="Select color"
|
|
222
|
+
aria-expanded="${this.show}"
|
|
223
|
+
aria-haspopup="dialog"
|
|
224
|
+
tabindex="${this.disabled ? -1 : 0}"
|
|
225
|
+
></nr-colorholder-box>
|
|
226
|
+
|
|
227
|
+
${this.renderDropdown()}
|
|
228
|
+
${this.renderHelperText()}
|
|
229
|
+
</div>
|
|
230
|
+
`;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Renders the label if provided
|
|
234
|
+
*/
|
|
235
|
+
renderLabel() {
|
|
236
|
+
if (!this.label)
|
|
237
|
+
return nothing;
|
|
238
|
+
return html `
|
|
239
|
+
<label class="color-picker-label">
|
|
240
|
+
${this.label}
|
|
241
|
+
</label>
|
|
242
|
+
`;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Renders the dropdown panel with color picker
|
|
246
|
+
*/
|
|
247
|
+
renderDropdown() {
|
|
248
|
+
if (!this.show)
|
|
249
|
+
return nothing;
|
|
250
|
+
return html `
|
|
251
|
+
<div
|
|
252
|
+
class="dropdown-container"
|
|
253
|
+
role="dialog"
|
|
254
|
+
aria-label="Color picker"
|
|
255
|
+
>
|
|
256
|
+
${this.renderDefaultColorSets()}
|
|
257
|
+
${this.renderColorPicker()}
|
|
258
|
+
${this.renderColorInput()}
|
|
259
|
+
</div>
|
|
260
|
+
`;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Renders default color sets if provided
|
|
264
|
+
*/
|
|
265
|
+
renderDefaultColorSets() {
|
|
266
|
+
if (!this.defaultColorSets || this.defaultColorSets.length === 0) {
|
|
267
|
+
return nothing;
|
|
268
|
+
}
|
|
269
|
+
return html `
|
|
270
|
+
<nr-default-color-sets
|
|
271
|
+
.defaultColorSets=${this.defaultColorSets}
|
|
272
|
+
@color-click="${this.handleColorChanged}"
|
|
273
|
+
aria-label="Preset colors">
|
|
274
|
+
</nr-default-color-sets>
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Renders the hex color picker
|
|
279
|
+
*/
|
|
280
|
+
renderColorPicker() {
|
|
281
|
+
return html `
|
|
282
|
+
<hex-color-picker
|
|
283
|
+
color="${this.color}"
|
|
284
|
+
@color-changed="${this.handleColorChanged}"
|
|
285
|
+
aria-label="Color gradient picker">
|
|
286
|
+
</hex-color-picker>
|
|
287
|
+
`;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Renders the color input field
|
|
291
|
+
*/
|
|
292
|
+
renderColorInput() {
|
|
293
|
+
if (!this.showInput)
|
|
294
|
+
return nothing;
|
|
295
|
+
return html `
|
|
296
|
+
<nr-input
|
|
297
|
+
type="text"
|
|
298
|
+
.value="${this.color}"
|
|
299
|
+
placeholder="${this.inputPlaceholder}"
|
|
300
|
+
@nr-input="${this.handleInputChange}"
|
|
301
|
+
?withCopy=${this.showCopyButton}
|
|
302
|
+
.state="${!this.isValidColor ? "error" /* INPUT_STATE.Error */ : "default" /* INPUT_STATE.Default */}"
|
|
303
|
+
aria-label="Color value input"
|
|
304
|
+
aria-invalid="${!this.isValidColor}">
|
|
305
|
+
</nr-input>
|
|
306
|
+
`;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Renders helper text if provided
|
|
310
|
+
*/
|
|
311
|
+
renderHelperText() {
|
|
312
|
+
if (!this.helperText)
|
|
313
|
+
return nothing;
|
|
314
|
+
return html `
|
|
315
|
+
<div class="color-picker-helper-text">
|
|
316
|
+
${this.helperText}
|
|
130
317
|
</div>
|
|
131
|
-
|
|
318
|
+
`;
|
|
132
319
|
}
|
|
133
320
|
};
|
|
134
321
|
ColorPicker.styles = styles;
|
|
@@ -139,7 +326,7 @@ __decorate([
|
|
|
139
326
|
property({ type: Boolean, reflect: true })
|
|
140
327
|
], ColorPicker.prototype, "show", void 0);
|
|
141
328
|
__decorate([
|
|
142
|
-
property({ type: Array })
|
|
329
|
+
property({ type: Array, attribute: 'default-color-sets' })
|
|
143
330
|
], ColorPicker.prototype, "defaultColorSets", void 0);
|
|
144
331
|
__decorate([
|
|
145
332
|
property({ type: Boolean, reflect: true })
|
|
@@ -147,11 +334,47 @@ __decorate([
|
|
|
147
334
|
__decorate([
|
|
148
335
|
property({ type: String, reflect: true })
|
|
149
336
|
], ColorPicker.prototype, "size", void 0);
|
|
337
|
+
__decorate([
|
|
338
|
+
property({ type: String, reflect: true })
|
|
339
|
+
], ColorPicker.prototype, "trigger", void 0);
|
|
340
|
+
__decorate([
|
|
341
|
+
property({ type: String, reflect: true })
|
|
342
|
+
], ColorPicker.prototype, "placement", void 0);
|
|
343
|
+
__decorate([
|
|
344
|
+
property({ type: String, reflect: true })
|
|
345
|
+
], ColorPicker.prototype, "animation", void 0);
|
|
346
|
+
__decorate([
|
|
347
|
+
property({ type: Boolean, attribute: 'close-on-select' })
|
|
348
|
+
], ColorPicker.prototype, "closeOnSelect", void 0);
|
|
349
|
+
__decorate([
|
|
350
|
+
property({ type: Boolean, attribute: 'close-on-outside-click' })
|
|
351
|
+
], ColorPicker.prototype, "closeOnOutsideClick", void 0);
|
|
352
|
+
__decorate([
|
|
353
|
+
property({ type: Boolean, attribute: 'close-on-escape' })
|
|
354
|
+
], ColorPicker.prototype, "closeOnEscape", void 0);
|
|
355
|
+
__decorate([
|
|
356
|
+
property({ type: Boolean, attribute: 'show-input' })
|
|
357
|
+
], ColorPicker.prototype, "showInput", void 0);
|
|
358
|
+
__decorate([
|
|
359
|
+
property({ type: Boolean, attribute: 'show-copy-button' })
|
|
360
|
+
], ColorPicker.prototype, "showCopyButton", void 0);
|
|
361
|
+
__decorate([
|
|
362
|
+
property({ type: String, reflect: true })
|
|
363
|
+
], ColorPicker.prototype, "format", void 0);
|
|
364
|
+
__decorate([
|
|
365
|
+
property({ type: String, attribute: 'input-placeholder' })
|
|
366
|
+
], ColorPicker.prototype, "inputPlaceholder", void 0);
|
|
367
|
+
__decorate([
|
|
368
|
+
property({ type: String })
|
|
369
|
+
], ColorPicker.prototype, "label", void 0);
|
|
370
|
+
__decorate([
|
|
371
|
+
property({ type: String, attribute: 'helper-text' })
|
|
372
|
+
], ColorPicker.prototype, "helperText", void 0);
|
|
150
373
|
__decorate([
|
|
151
374
|
state()
|
|
152
375
|
], ColorPicker.prototype, "isValidColor", void 0);
|
|
153
376
|
ColorPicker = __decorate([
|
|
154
|
-
customElement('
|
|
377
|
+
customElement('nr-color-picker')
|
|
155
378
|
], ColorPicker);
|
|
156
379
|
export { ColorPicker };
|
|
157
380
|
//# sourceMappingURL=color-picker.component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-picker.component.js","sourceRoot":"","sources":["../../../src/components/colorpicker/color-picker.component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAkB,IAAI,EAAE,OAAO,EAAC,MAAM,KAAK,CAAC;AAC9D,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AACjE,OAAO,6BAA6B,CAAC;AACrC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAI7C,IAAa,WAAW,GAAxB,MAAa,WAAY,SAAQ,UAAU;IAqBzC;QACE,KAAK,EAAE,CAAC;QApBV,UAAK,GAAG,aAAa,CAAC;QAGtB,SAAI,GAAG,KAAK,CAAC;QAGb,qBAAgB,GAAkB,EAAE,CAAC;QAGrC,aAAQ,GAAG,KAAK,CAAC;QAGjB,SAAI,2CAA2B;QAG/B,iBAAY,GAAC,IAAI,CAAA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AAC;yCAC5B;AAGb;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC;qDACa;AAGrC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CACxB;AAGjB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;yCACT;AAG/B;IADC,KAAK,EAAE;iDACS;AAjBN,WAAW;IADvB,aAAa,CAAC,iBAAiB,CAAC;GACpB,WAAW,CAsIvB;SAtIY,WAAW","sourcesContent":["import {LitElement, PropertyValues, html, nothing} from 'lit';\nimport {customElement, property, state} from 'lit/decorators.js';\nimport './color-holder.component.js';\nimport './default-color-sets.component.js';\nimport styles from './color-picker.style.js';\nimport {ColorPickerSize} from './color-picker.types.js';\n\n@customElement('hy-color-picker')\nexport class ColorPicker extends LitElement {\n @property({type: String})\n color = 'transparent';\n\n @property({type: Boolean, reflect: true})\n show = false;\n\n @property({type: Array})\n defaultColorSets: Array<string> = [];\n\n @property({type: Boolean, reflect: true})\n disabled = false;\n\n @property({type: String, reflect: true})\n size = ColorPickerSize.Default;\n\n @state()\n isValidColor=true\n\n static override styles = styles;\n\n constructor() {\n super();\n if (typeof window !== 'undefined') {\n import('vanilla-colorful');\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n // Mark the scroll listener as passive:\n document.addEventListener('scroll', this.calculateDropDownPosition, {\n passive: true,\n });\n document.addEventListener('click', this.onClickOutside);\n }\n\n override updated(changedProperties: PropertyValues): void {\n if (changedProperties.has('color')) {\n this.checkIsValidColor()\n }\n }\n private async toggleColorHolder() {\n this.show = !this.show;\n await this.updateComplete;\n this.calculateDropDownPosition();\n }\n private onClickOutside = (onClickEvent: Event) => {\n const outsideClick = !onClickEvent.composedPath().includes(this)\n if(outsideClick)\n this.show =false\n };\n private calculateDropDownPosition = () => {\n const dropdownContainer = this.shadowRoot?.querySelector('.dropdown-container') as HTMLElement;\n const colorHolder = this.shadowRoot?.querySelector('.color-holder') as HTMLElement;\n\n if (dropdownContainer && colorHolder) {\n const dropdownRect = dropdownContainer.getBoundingClientRect();\n const colorHolderRect = colorHolder.getBoundingClientRect();\n const viewportHeight = window.innerHeight;\n const viewportWidth = window.innerWidth;\n\n // Check if the dropdown is going out of the viewport vertically\n if (colorHolderRect.bottom + dropdownRect.height > viewportHeight) {\n // Move the dropdown upwards if it goes out of the viewport\n dropdownContainer.style.top = `${colorHolderRect.top - dropdownRect.height}px`;\n } else {\n // Otherwise, position it below the color holder\n dropdownContainer.style.top = `${colorHolderRect.bottom}px`;\n }\n\n // Check if the dropdown is going out of the viewport horizontally\n if (colorHolderRect.right + dropdownRect.width > viewportWidth) {\n // Move the dropdown to the left if it goes out of the viewport\n dropdownContainer.style.left = `${viewportWidth - dropdownRect.width}px`;\n } else {\n // Otherwise, position it to the right of the color holder\n dropdownContainer.style.left = `${colorHolderRect.left}px`;\n }\n }\n };\n\n private handleColorChanged(colorChangedEvent: CustomEvent) {\n if(this.color !=colorChangedEvent.detail.value){\n this.color = colorChangedEvent.detail.value;\n this.dispatchColorChange()\n }\n }\n\n private onInputChange(inputChangedEvent: CustomEvent) {\n if(this.color != inputChangedEvent.detail.value){\n this.color = inputChangedEvent.detail.value;\n this.dispatchColorChange()\n }\n }\n private dispatchColorChange(){\n this.dispatchEvent(\n new CustomEvent('color-changed', {\n detail: {\n value: this.color,\n },\n })\n );\n\n }\n\n private checkIsValidColor(){\n this.isValidColor = CSS.supports('color',this.color)\n }\n\n override disconnectedCallback(): void {\n document.removeEventListener('click', this.onClickOutside);\n document.removeEventListener('scroll', this.calculateDropDownPosition);\n }\n\n override render() {\n return html`<div class=\"color-picker-container\">\n <hy-colorholder-box\n class=\"color-holder\"\n color=\"${this.color}\"\n .size=${this.size}\n @click=${!this.disabled ? this.toggleColorHolder : nothing}\n ></hy-colorholder-box>\n <div class='dropdown-container'>\n <hy-default-color-sets .defaultColorSets=${this.defaultColorSets} @color-click=\"${this.handleColorChanged}\">\n </hy-default-color-sets>\n <hex-color-picker\n color=\"${this.color}\"\n @color-changed=\"${(colorChangedEvent: CustomEvent) => this.handleColorChanged(colorChangedEvent)}\"\n ></hex-color-picker>\n <hy-input type=\"text\" .value=\"${this.color}\" @valueChange=\"${this.onInputChange}\" withCopy=${true} .state=${!this.isValidColor?'error':nothing}> </hy-input>\n </div>\n </div> `;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"color-picker.component.js","sourceRoot":"","sources":["../../../src/components/colorpicker/color-picker.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;AAEH,OAAO,EAAE,UAAU,EAAkB,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,mBAAmB,CAAC;AAE3B,0BAA0B;AAC1B,OAAO,6BAA6B,CAAC;AACrC,OAAO,mCAAmC,CAAC;AAE3C,0BAA0B;AAC1B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAS7C,qBAAqB;AACrB,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAKhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,IAAa,WAAW,GAAxB,MAAa,WAAY,SAAQ,iBAAiB,CAAC,UAAU,CAAC;IAmF5D;QACE,KAAK,EAAE,CAAC;QAjFD,uBAAkB,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAEtD,0BAA0B;QAE1B,UAAK,GAAG,SAAS,CAAC;QAElB,mCAAmC;QAEnC,SAAI,GAAG,KAAK,CAAC;QAEb,wCAAwC;QAExC,qBAAgB,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AK,EAAE;iDACoB;AA3EjB,WAAW;IADvB,aAAa,CAAC,iBAAiB,CAAC;GACpB,WAAW,CA6TvB;SA7TY,WAAW","sourcesContent":["/**\n * @license\n * Copyright 2023 Nuraly, Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { LitElement, PropertyValues, html, nothing } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { NuralyUIBaseMixin } from '@nuralyui/common/mixins';\nimport { INPUT_STATE } from '../input/input.types.js';\nimport '../input/index.js';\n\n// Import child components\nimport './color-holder.component.js';\nimport './default-color-sets.component.js';\n\n// Import styles and types\nimport styles from './color-picker.style.js';\nimport {\n ColorPickerSize,\n ColorPickerTrigger,\n ColorPickerPlacement,\n ColorPickerAnimation,\n ColorFormat\n} from './color-picker.types.js';\n\n// Import controllers\nimport {\n ColorPickerDropdownController,\n ColorPickerEventController,\n} from './controllers/index.js';\n\n// Import interfaces\nimport type { ColorPickerHost } from './interfaces/index.js';\n\n/**\n * Advanced color picker component with dropdown positioning, validation, and accessibility.\n * \n * Supports multiple color formats, default color sets, custom triggers, keyboard navigation,\n * and various display configurations.\n * \n * @example\n * ```html\n * <!-- Basic color picker -->\n * <nr-color-picker color=\"#3498db\"></nr-color-picker>\n * \n * <!-- With default colors -->\n * <nr-color-picker \n * color=\"#3498db\"\n * .defaultColorSets=\"${['#3498db', '#e74c3c', '#2ecc71']}\">\n * </nr-color-picker>\n * \n * <!-- With custom configuration -->\n * <nr-color-picker\n * color=\"#3498db\"\n * trigger=\"click\"\n * placement=\"top\"\n * size=\"large\"\n * show-input=\"true\"\n * show-copy-button=\"true\">\n * </nr-color-picker>\n * \n * <!-- Disabled -->\n * <nr-color-picker color=\"#3498db\" disabled></nr-color-picker>\n * ```\n * \n * @fires hy-color-change - Color value changed\n * @fires nr-colorpicker-open - Dropdown opened\n * @fires nr-colorpicker-close - Dropdown closed\n * @fires color-changed - Legacy event for backwards compatibility\n * \n * @slot - Default slot for custom content\n * \n * @cssproperty --colorpicker-trigger-size - Size of the color trigger box\n * @cssproperty --colorpicker-dropdown-width - Width of the dropdown panel\n * @cssproperty --colorpicker-dropdown-background - Background color of dropdown\n * @cssproperty --colorpicker-dropdown-shadow - Shadow of dropdown panel\n * @cssproperty --colorpicker-dropdown-border-radius - Border radius of dropdown\n */\n@customElement('nr-color-picker')\nexport class ColorPicker extends NuralyUIBaseMixin(LitElement) implements ColorPickerHost {\n static override styles = styles;\n\n override requiredComponents = ['nr-input', 'nr-icon'];\n\n /** Current color value */\n @property({ type: String }) \n color = '#3498db';\n\n /** Controls dropdown visibility */\n @property({ type: Boolean, reflect: true }) \n show = false;\n\n /** Array of preset colors to display */\n @property({ type: Array, attribute: 'default-color-sets' }) \n defaultColorSets: string[] = [];\n\n /** Disables the color picker */\n @property({ type: Boolean, reflect: true }) \n disabled = false;\n\n /** Color picker size (small, default, large) */\n @property({ type: String, reflect: true }) \n size: ColorPickerSize = ColorPickerSize.Default;\n\n /** Trigger mode for opening dropdown */\n @property({ type: String, reflect: true }) \n trigger: ColorPickerTrigger = ColorPickerTrigger.Click;\n\n /** Dropdown placement */\n @property({ type: String, reflect: true }) \n placement: ColorPickerPlacement = ColorPickerPlacement.Auto;\n\n /** Animation style for dropdown */\n @property({ type: String, reflect: true }) \n animation: ColorPickerAnimation = ColorPickerAnimation.Fade;\n\n /** Close dropdown when a color is selected */\n @property({ type: Boolean, attribute: 'close-on-select' }) \n closeOnSelect = false;\n\n /** Close dropdown on outside click */\n @property({ type: Boolean, attribute: 'close-on-outside-click' }) \n closeOnOutsideClick = true;\n\n /** Close dropdown on escape key */\n @property({ type: Boolean, attribute: 'close-on-escape' }) \n closeOnEscape = true;\n\n /** Show color input field */\n @property({ type: Boolean, attribute: 'show-input' }) \n showInput = true;\n\n /** Show copy button on input */\n @property({ type: Boolean, attribute: 'show-copy-button' }) \n showCopyButton = true;\n\n /** Color format (hex, rgb, rgba, hsl, hsla) */\n @property({ type: String, reflect: true }) \n format: ColorFormat = ColorFormat.Hex;\n\n /** Placeholder text for color input */\n @property({ type: String, attribute: 'input-placeholder' }) \n inputPlaceholder = 'Enter color';\n\n /** Label text */\n @property({ type: String }) \n label = '';\n\n /** Helper text */\n @property({ type: String, attribute: 'helper-text' }) \n helperText = '';\n\n /** Validation state for color value */\n @state() \n private isValidColor = true;\n\n /** Manages dropdown visibility and positioning */\n private dropdownController = new ColorPickerDropdownController(this);\n\n /** Handles all event management */\n private eventController = new ColorPickerEventController(this);\n\n constructor() {\n super();\n // Dynamically import vanilla-colorful for color picker UI\n if (typeof window !== 'undefined') {\n import('vanilla-colorful');\n }\n }\n\n /**\n * Component connected to DOM - initialize base functionality\n */\n override connectedCallback(): void {\n super.connectedCallback();\n }\n\n /**\n * Component disconnected from DOM - cleanup event listeners\n */\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n }\n\n /**\n * Called after component updates\n */\n override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n \n if (changedProperties.has('color')) {\n this.validateColor();\n }\n }\n\n // === Public API Methods ===\n\n /**\n * Opens the color picker dropdown\n */\n open(): void {\n this.dropdownController.open();\n }\n\n /**\n * Closes the color picker dropdown\n */\n close(): void {\n this.dropdownController.close();\n }\n\n /**\n * Toggles the color picker dropdown\n */\n toggle(): void {\n this.dropdownController.toggle();\n }\n\n /**\n * Validates the current color value\n */\n validateColor(): boolean {\n this.isValidColor = this.eventController.isValidColor(this.color);\n return this.isValidColor;\n }\n\n /**\n * Sets up global event listeners (called by dropdown controller)\n */\n setupEventListeners(): void {\n if (this.closeOnOutsideClick || this.closeOnEscape) {\n this.eventController.setupEventListeners();\n }\n }\n\n /**\n * Removes global event listeners (called by dropdown controller)\n */\n removeEventListeners(): void {\n this.eventController.removeEventListeners();\n }\n\n /**\n * Handles trigger click to toggle dropdown\n */\n private handleTriggerClick = (event: Event): void => {\n this.eventController.handleTriggerClick(event);\n };\n\n /**\n * Handles color selection from hex-color-picker or default colors\n */\n private handleColorChanged = (event: CustomEvent): void => {\n const newColor = event.detail.value;\n this.eventController.handleColorChange(newColor);\n \n if (this.closeOnSelect) {\n this.dropdownController.close();\n }\n };\n\n /**\n * Handles input change from text input\n */\n private handleInputChange = (event: CustomEvent): void => {\n this.eventController.handleInputChange(event);\n };\n\n /**\n * Main render method\n */\n override render() {\n const containerClasses = {\n 'color-picker-container': true,\n 'color-picker-container--disabled': this.disabled,\n 'color-picker-container--open': this.show,\n [`color-picker-container--${this.size}`]: true,\n };\n\n return html`\n <div class=\"${classMap(containerClasses)}\" data-theme=\"${this.currentTheme}\">\n ${this.renderLabel()}\n \n <nr-colorholder-box\n class=\"color-holder\"\n color=\"${this.color}\"\n .size=${this.size}\n ?disabled=\"${this.disabled}\"\n @click=${this.disabled ? nothing : this.handleTriggerClick}\n role=\"button\"\n aria-label=\"Select color\"\n aria-expanded=\"${this.show}\"\n aria-haspopup=\"dialog\"\n tabindex=\"${this.disabled ? -1 : 0}\"\n ></nr-colorholder-box>\n \n ${this.renderDropdown()}\n ${this.renderHelperText()}\n </div>\n `;\n }\n\n /**\n * Renders the label if provided\n */\n private renderLabel() {\n if (!this.label) return nothing;\n \n return html`\n <label class=\"color-picker-label\">\n ${this.label}\n </label>\n `;\n }\n\n /**\n * Renders the dropdown panel with color picker\n */\n private renderDropdown() {\n if (!this.show) return nothing;\n\n return html`\n <div \n class=\"dropdown-container\"\n role=\"dialog\"\n aria-label=\"Color picker\"\n >\n ${this.renderDefaultColorSets()}\n ${this.renderColorPicker()}\n ${this.renderColorInput()}\n </div>\n `;\n }\n\n /**\n * Renders default color sets if provided\n */\n private renderDefaultColorSets() {\n if (!this.defaultColorSets || this.defaultColorSets.length === 0) {\n return nothing;\n }\n\n return html`\n <nr-default-color-sets \n .defaultColorSets=${this.defaultColorSets} \n @color-click=\"${this.handleColorChanged}\"\n aria-label=\"Preset colors\">\n </nr-default-color-sets>\n `;\n }\n\n /**\n * Renders the hex color picker\n */\n private renderColorPicker() {\n return html`\n <hex-color-picker\n color=\"${this.color}\"\n @color-changed=\"${this.handleColorChanged}\"\n aria-label=\"Color gradient picker\">\n </hex-color-picker>\n `;\n }\n\n /**\n * Renders the color input field\n */\n private renderColorInput() {\n if (!this.showInput) return nothing;\n\n return html`\n <nr-input \n type=\"text\" \n .value=\"${this.color}\" \n placeholder=\"${this.inputPlaceholder}\"\n @nr-input=\"${this.handleInputChange}\" \n ?withCopy=${this.showCopyButton} \n .state=\"${!this.isValidColor ? INPUT_STATE.Error : INPUT_STATE.Default}\"\n aria-label=\"Color value input\"\n aria-invalid=\"${!this.isValidColor}\">\n </nr-input>\n `;\n }\n\n /**\n * Renders helper text if provided\n */\n private renderHelperText() {\n if (!this.helperText) return nothing;\n \n return html`\n <div class=\"color-picker-helper-text\">\n ${this.helperText}\n </div>\n `;\n }\n}\n"]}
|
package/color-picker.style.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color Picker component styles for the Hybrid UI Library
|
|
3
|
+
* Using shared CSS variables from /src/shared/themes/
|
|
4
|
+
*
|
|
5
|
+
* This file contains all the styling for the nr-colorpicker component with
|
|
6
|
+
* clean CSS variable usage without local fallbacks and proper theme switching support.
|
|
7
|
+
*/
|
|
1
8
|
declare const _default: import("lit").CSSResult;
|
|
2
9
|
export default _default;
|
|
3
10
|
//# sourceMappingURL=color-picker.style.d.ts.map
|
package/color-picker.style.js
CHANGED
|
@@ -1,75 +1,86 @@
|
|
|
1
1
|
import { css } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Color Picker component styles for the Hybrid UI Library
|
|
4
|
+
* Using shared CSS variables from /src/shared/themes/
|
|
5
|
+
*
|
|
6
|
+
* This file contains all the styling for the nr-colorpicker component with
|
|
7
|
+
* clean CSS variable usage without local fallbacks and proper theme switching support.
|
|
8
|
+
*/
|
|
2
9
|
export default css `
|
|
10
|
+
:host {
|
|
11
|
+
display: inline-block;
|
|
12
|
+
vertical-align: middle;
|
|
13
|
+
|
|
14
|
+
/* Force CSS custom property inheritance to ensure theme switching works properly */
|
|
15
|
+
color: var(--nuraly-color-text);
|
|
16
|
+
background-color: var(--nuraly-color-background);
|
|
17
|
+
|
|
18
|
+
/* Ensure clean state transitions when theme changes */
|
|
19
|
+
* {
|
|
20
|
+
transition: all var(--nuraly-transition-fast, 0.15s) ease;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* Force re-evaluation of theme-dependent properties on theme change */
|
|
25
|
+
:host([data-theme]) {
|
|
26
|
+
color: inherit;
|
|
27
|
+
background-color: inherit;
|
|
28
|
+
}
|
|
29
|
+
|
|
3
30
|
.color-picker-container {
|
|
4
31
|
display: inline-flex;
|
|
5
32
|
flex-direction: column;
|
|
6
33
|
}
|
|
34
|
+
|
|
7
35
|
hex-color-picker {
|
|
8
36
|
width: 100%;
|
|
9
37
|
}
|
|
38
|
+
|
|
10
39
|
.dropdown-container {
|
|
11
40
|
display: none;
|
|
12
41
|
}
|
|
42
|
+
|
|
13
43
|
hex-color-picker::part(saturation) {
|
|
14
44
|
border-radius: 0px;
|
|
15
45
|
}
|
|
46
|
+
|
|
16
47
|
hex-color-picker::part(hue) {
|
|
17
48
|
border-radius: 0px;
|
|
18
49
|
}
|
|
50
|
+
|
|
19
51
|
hex-color-picker::part(saturation-pointer),
|
|
20
52
|
hex-color-picker::part(hue-pointer) {
|
|
21
53
|
cursor: pointer;
|
|
22
54
|
}
|
|
55
|
+
|
|
23
56
|
.color-holder {
|
|
24
57
|
cursor: pointer;
|
|
25
58
|
}
|
|
59
|
+
|
|
26
60
|
:host([disabled]) .color-holder {
|
|
27
|
-
opacity: var(--
|
|
61
|
+
opacity: var(--nuraly-opacity-disabled, 0.5);
|
|
28
62
|
cursor: not-allowed;
|
|
29
63
|
}
|
|
30
|
-
:host(:not([disabled])) .color-holder {
|
|
31
|
-
border: var(--hybrid-colorpicker-border-color);
|
|
32
|
-
}
|
|
33
|
-
:host(:not([disabled])) .color-holder:hover {
|
|
34
|
-
opacity: var(--hybrid-colorpicker-hover-opacity);
|
|
35
|
-
}
|
|
36
|
-
:host(:not([disabled])) .color-holder:active {
|
|
37
|
-
border:var(--hybrid-colorpicker-active-border)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
64
|
|
|
41
|
-
:host([show]) .dropdown-container{
|
|
65
|
+
:host([show]) .dropdown-container {
|
|
42
66
|
display: block;
|
|
43
67
|
position: fixed;
|
|
44
68
|
width: 180px;
|
|
45
|
-
z-index:
|
|
46
|
-
padding:
|
|
47
|
-
background-color: var(--
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
|
|
69
|
+
z-index: var(--nuraly-z-index-dropdown, 1000);
|
|
70
|
+
padding: var(--nuraly-spacing-2, 0.5rem);
|
|
71
|
+
background-color: var(--nuraly-color-surface, #ffffff);
|
|
72
|
+
border: 1px solid var(--nuraly-color-border, rgba(0, 0, 0, 0.1));
|
|
73
|
+
border-radius: var(--nuraly-border-radius-medium, 4px);
|
|
74
|
+
box-shadow: var(--nuraly-shadow-dropdown, 0 2px 8px rgba(0, 0, 0, 0.15));
|
|
75
|
+
opacity: 0;
|
|
76
|
+
visibility: hidden;
|
|
77
|
+
transition: opacity var(--nuraly-transition-fast, 0.15s) ease-in-out,
|
|
78
|
+
visibility var(--nuraly-transition-fast, 0.15s) ease-in-out;
|
|
51
79
|
}
|
|
52
80
|
|
|
53
|
-
:host {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
--hybrid-colorpicker-active-border: 1px solid #0f62fe;
|
|
57
|
-
--hybrid-colorpicker-disabled-opacity: 0.5;
|
|
58
|
-
--hybrid-colorpicker-hover-opacity: 0.8;
|
|
59
|
-
--hybrid-colorpicker-default-width: 30px;
|
|
60
|
-
--hybrid-colorpicker-default-height: 25px;
|
|
61
|
-
--hybrid-colorpicker-small-width: 20px;
|
|
62
|
-
--hybrid-colorpicker-small-height: 15px;
|
|
63
|
-
--hybrid-colorpicker-large-width: 35px;
|
|
64
|
-
--hybrid-colorpicker-large-height: 30px;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@media (prefers-color-scheme: dark) {
|
|
68
|
-
:host {
|
|
69
|
-
--hybrid-colorpicker-background-color: #393939;
|
|
70
|
-
--hybrid-colorpicker-border-color: 1px solid #f4f4f4;
|
|
71
|
-
--hybrid-colorpicker-disabled-opacity: 0.2;
|
|
72
|
-
}
|
|
81
|
+
:host([show]) .dropdown-container.positioned {
|
|
82
|
+
opacity: 1;
|
|
83
|
+
visibility: visible;
|
|
73
84
|
}
|
|
74
85
|
`;
|
|
75
86
|
//# sourceMappingURL=color-picker.style.js.map
|