nativecorejs 0.1.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/README.md +22 -0
- package/dist/components/builtinRegistry.d.ts +2 -0
- package/dist/components/builtinRegistry.js +72 -0
- package/dist/components/index.d.ts +59 -0
- package/dist/components/index.js +59 -0
- package/dist/components/loading-spinner.d.ts +5 -0
- package/dist/components/loading-spinner.js +48 -0
- package/dist/components/nc-a.d.ts +45 -0
- package/dist/components/nc-a.js +290 -0
- package/dist/components/nc-accordion.d.ts +36 -0
- package/dist/components/nc-accordion.js +186 -0
- package/dist/components/nc-alert.d.ts +11 -0
- package/dist/components/nc-alert.js +127 -0
- package/dist/components/nc-animation.d.ts +117 -0
- package/dist/components/nc-animation.js +1053 -0
- package/dist/components/nc-autocomplete.d.ts +41 -0
- package/dist/components/nc-autocomplete.js +275 -0
- package/dist/components/nc-avatar-group.d.ts +7 -0
- package/dist/components/nc-avatar-group.js +85 -0
- package/dist/components/nc-avatar.d.ts +9 -0
- package/dist/components/nc-avatar.js +127 -0
- package/dist/components/nc-badge.d.ts +7 -0
- package/dist/components/nc-badge.js +63 -0
- package/dist/components/nc-bottom-nav.d.ts +53 -0
- package/dist/components/nc-bottom-nav.js +198 -0
- package/dist/components/nc-breadcrumb.d.ts +10 -0
- package/dist/components/nc-breadcrumb.js +71 -0
- package/dist/components/nc-button.d.ts +38 -0
- package/dist/components/nc-button.js +293 -0
- package/dist/components/nc-card.d.ts +11 -0
- package/dist/components/nc-card.js +74 -0
- package/dist/components/nc-checkbox.d.ts +16 -0
- package/dist/components/nc-checkbox.js +194 -0
- package/dist/components/nc-chip.d.ts +8 -0
- package/dist/components/nc-chip.js +89 -0
- package/dist/components/nc-code.d.ts +37 -0
- package/dist/components/nc-code.js +315 -0
- package/dist/components/nc-collapsible.d.ts +33 -0
- package/dist/components/nc-collapsible.js +148 -0
- package/dist/components/nc-color-picker.d.ts +33 -0
- package/dist/components/nc-color-picker.js +265 -0
- package/dist/components/nc-copy-button.d.ts +10 -0
- package/dist/components/nc-copy-button.js +94 -0
- package/dist/components/nc-date-picker.d.ts +41 -0
- package/dist/components/nc-date-picker.js +443 -0
- package/dist/components/nc-div.d.ts +53 -0
- package/dist/components/nc-div.js +270 -0
- package/dist/components/nc-divider.d.ts +7 -0
- package/dist/components/nc-divider.js +57 -0
- package/dist/components/nc-drawer.d.ts +40 -0
- package/dist/components/nc-drawer.js +217 -0
- package/dist/components/nc-dropdown.d.ts +41 -0
- package/dist/components/nc-dropdown.js +170 -0
- package/dist/components/nc-empty-state.d.ts +5 -0
- package/dist/components/nc-empty-state.js +76 -0
- package/dist/components/nc-file-upload.d.ts +40 -0
- package/dist/components/nc-file-upload.js +336 -0
- package/dist/components/nc-form.d.ts +70 -0
- package/dist/components/nc-form.js +273 -0
- package/dist/components/nc-image.d.ts +10 -0
- package/dist/components/nc-image.js +139 -0
- package/dist/components/nc-input.d.ts +25 -0
- package/dist/components/nc-input.js +302 -0
- package/dist/components/nc-kbd.d.ts +5 -0
- package/dist/components/nc-kbd.js +34 -0
- package/dist/components/nc-menu-item.d.ts +43 -0
- package/dist/components/nc-menu-item.js +182 -0
- package/dist/components/nc-menu.d.ts +76 -0
- package/dist/components/nc-menu.js +360 -0
- package/dist/components/nc-modal.d.ts +51 -0
- package/dist/components/nc-modal.js +231 -0
- package/dist/components/nc-nav-item.d.ts +35 -0
- package/dist/components/nc-nav-item.js +142 -0
- package/dist/components/nc-number-input.d.ts +22 -0
- package/dist/components/nc-number-input.js +270 -0
- package/dist/components/nc-otp-input.d.ts +41 -0
- package/dist/components/nc-otp-input.js +227 -0
- package/dist/components/nc-pagination.d.ts +28 -0
- package/dist/components/nc-pagination.js +171 -0
- package/dist/components/nc-popover.d.ts +58 -0
- package/dist/components/nc-popover.js +301 -0
- package/dist/components/nc-progress-circular.d.ts +7 -0
- package/dist/components/nc-progress-circular.js +67 -0
- package/dist/components/nc-progress.d.ts +7 -0
- package/dist/components/nc-progress.js +109 -0
- package/dist/components/nc-radio.d.ts +13 -0
- package/dist/components/nc-radio.js +169 -0
- package/dist/components/nc-rating.d.ts +19 -0
- package/dist/components/nc-rating.js +187 -0
- package/dist/components/nc-rich-text.d.ts +43 -0
- package/dist/components/nc-rich-text.js +310 -0
- package/dist/components/nc-scroll-top.d.ts +28 -0
- package/dist/components/nc-scroll-top.js +103 -0
- package/dist/components/nc-select.d.ts +51 -0
- package/dist/components/nc-select.js +425 -0
- package/dist/components/nc-skeleton.d.ts +7 -0
- package/dist/components/nc-skeleton.js +90 -0
- package/dist/components/nc-slider.d.ts +41 -0
- package/dist/components/nc-slider.js +268 -0
- package/dist/components/nc-snackbar.d.ts +51 -0
- package/dist/components/nc-snackbar.js +200 -0
- package/dist/components/nc-splash.d.ts +25 -0
- package/dist/components/nc-splash.js +296 -0
- package/dist/components/nc-stepper.d.ts +50 -0
- package/dist/components/nc-stepper.js +236 -0
- package/dist/components/nc-switch.d.ts +14 -0
- package/dist/components/nc-switch.js +194 -0
- package/dist/components/nc-tab-item.d.ts +39 -0
- package/dist/components/nc-tab-item.js +127 -0
- package/dist/components/nc-table.d.ts +44 -0
- package/dist/components/nc-table.js +265 -0
- package/dist/components/nc-tabs.d.ts +79 -0
- package/dist/components/nc-tabs.js +519 -0
- package/dist/components/nc-tag-input.d.ts +49 -0
- package/dist/components/nc-tag-input.js +268 -0
- package/dist/components/nc-textarea.d.ts +15 -0
- package/dist/components/nc-textarea.js +164 -0
- package/dist/components/nc-time-picker.d.ts +51 -0
- package/dist/components/nc-time-picker.js +452 -0
- package/dist/components/nc-timeline.d.ts +53 -0
- package/dist/components/nc-timeline.js +171 -0
- package/dist/components/nc-tooltip.d.ts +27 -0
- package/dist/components/nc-tooltip.js +135 -0
- package/dist/core/component.d.ts +33 -0
- package/dist/core/component.js +208 -0
- package/dist/core/gpu-animation.d.ts +141 -0
- package/dist/core/gpu-animation.js +474 -0
- package/dist/core/lazyComponents.d.ts +13 -0
- package/dist/core/lazyComponents.js +73 -0
- package/dist/core/router.d.ts +55 -0
- package/dist/core/router.js +424 -0
- package/dist/core/state.d.ts +18 -0
- package/dist/core/state.js +153 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +11 -0
- package/dist/utils/cacheBuster.d.ts +9 -0
- package/dist/utils/cacheBuster.js +12 -0
- package/dist/utils/dom.d.ts +16 -0
- package/dist/utils/dom.js +70 -0
- package/dist/utils/events.d.ts +20 -0
- package/dist/utils/events.js +80 -0
- package/dist/utils/templates.d.ts +2 -0
- package/dist/utils/templates.js +2 -0
- package/package.json +53 -0
- package/src/styles/base.css +40 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NcColorPicker Component
|
|
3
|
+
*
|
|
4
|
+
* Attributes:
|
|
5
|
+
* - name: string
|
|
6
|
+
* - value: string - current hex color (default: '#10b981')
|
|
7
|
+
* - swatches: JSON string array of hex colors - quick-pick palette
|
|
8
|
+
* - show-input: boolean - show hex text input (default: true)
|
|
9
|
+
* - disabled: boolean
|
|
10
|
+
* - size: 'sm'|'md'|'lg' (default: 'md')
|
|
11
|
+
*
|
|
12
|
+
* Events:
|
|
13
|
+
* - change: CustomEvent<{ value: string; name: string }>
|
|
14
|
+
* - input: CustomEvent<{ value: string; name: string }>
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* <nc-color-picker name="bg" value="#3b82f6"></nc-color-picker>
|
|
18
|
+
* <nc-color-picker name="accent" swatches='["#ef4444","#f59e0b","#10b981","#3b82f6","#8b5cf6"]'></nc-color-picker>
|
|
19
|
+
*/
|
|
20
|
+
import { Component, defineComponent } from '../core/component.js';
|
|
21
|
+
const DEFAULT_SWATCHES = [
|
|
22
|
+
'#ef4444', '#f97316', '#f59e0b', '#eab308',
|
|
23
|
+
'#84cc16', '#22c55e', '#10b981', '#14b8a6',
|
|
24
|
+
'#06b6d4', '#3b82f6', '#6366f1', '#8b5cf6',
|
|
25
|
+
'#a855f7', '#ec4899', '#f43f5e', '#64748b',
|
|
26
|
+
'#000000', '#ffffff',
|
|
27
|
+
];
|
|
28
|
+
export class NcColorPicker extends Component {
|
|
29
|
+
static useShadowDOM = true;
|
|
30
|
+
static get observedAttributes() {
|
|
31
|
+
return ['name', 'value', 'swatches', 'show-input', 'disabled', 'size'];
|
|
32
|
+
}
|
|
33
|
+
_value = '#10b981';
|
|
34
|
+
constructor() { super(); }
|
|
35
|
+
_getSwatches() {
|
|
36
|
+
const raw = this.getAttribute('swatches');
|
|
37
|
+
if (!raw)
|
|
38
|
+
return DEFAULT_SWATCHES;
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(raw);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return DEFAULT_SWATCHES;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
template() {
|
|
47
|
+
if (!this._mounted) {
|
|
48
|
+
this._value = this.getAttribute('value') || '#10b981';
|
|
49
|
+
}
|
|
50
|
+
const value = this._value;
|
|
51
|
+
const showInput = this.getAttribute('show-input') !== 'false';
|
|
52
|
+
const disabled = this.hasAttribute('disabled');
|
|
53
|
+
const swatches = this._getSwatches();
|
|
54
|
+
return `
|
|
55
|
+
<style>
|
|
56
|
+
:host { display: inline-block; font-family: var(--nc-font-family); }
|
|
57
|
+
|
|
58
|
+
.picker {
|
|
59
|
+
display: inline-flex;
|
|
60
|
+
flex-direction: column;
|
|
61
|
+
gap: var(--nc-spacing-sm);
|
|
62
|
+
opacity: ${disabled ? '0.5' : '1'};
|
|
63
|
+
pointer-events: ${disabled ? 'none' : 'auto'};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.swatches {
|
|
67
|
+
display: grid;
|
|
68
|
+
grid-template-columns: repeat(9, 1fr);
|
|
69
|
+
gap: 4px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.swatch {
|
|
73
|
+
width: 24px;
|
|
74
|
+
height: 24px;
|
|
75
|
+
border-radius: 4px;
|
|
76
|
+
border: 2px solid transparent;
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
transition: transform var(--nc-transition-fast), border-color var(--nc-transition-fast);
|
|
79
|
+
outline: none;
|
|
80
|
+
padding: 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:host([size="sm"]) .swatch { width: 18px; height: 18px; }
|
|
84
|
+
:host([size="lg"]) .swatch { width: 30px; height: 30px; }
|
|
85
|
+
|
|
86
|
+
.swatch:hover { transform: scale(1.15); }
|
|
87
|
+
.swatch:focus-visible { border-color: var(--nc-primary) !important; }
|
|
88
|
+
.swatch.active { border-color: var(--nc-primary) !important; transform: scale(1.1); }
|
|
89
|
+
|
|
90
|
+
/* White swatch needs a border to be visible */
|
|
91
|
+
.swatch--light { border-color: var(--nc-border) !important; }
|
|
92
|
+
.swatch--light.active { border-color: var(--nc-primary) !important; }
|
|
93
|
+
|
|
94
|
+
.input-row {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
gap: var(--nc-spacing-sm);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.preview {
|
|
101
|
+
width: 32px;
|
|
102
|
+
height: 32px;
|
|
103
|
+
border-radius: var(--nc-radius-sm, 4px);
|
|
104
|
+
border: 1px solid var(--nc-border);
|
|
105
|
+
flex-shrink: 0;
|
|
106
|
+
position: relative;
|
|
107
|
+
overflow: hidden;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Native color input - hidden but triggered by clicking the preview */
|
|
112
|
+
.native-input {
|
|
113
|
+
position: absolute;
|
|
114
|
+
inset: 0;
|
|
115
|
+
opacity: 0;
|
|
116
|
+
cursor: pointer;
|
|
117
|
+
width: 100%;
|
|
118
|
+
height: 100%;
|
|
119
|
+
padding: 0;
|
|
120
|
+
border: none;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.hex-input {
|
|
124
|
+
flex: 1;
|
|
125
|
+
padding: 4px 8px;
|
|
126
|
+
background: var(--nc-bg);
|
|
127
|
+
border: var(--nc-input-border);
|
|
128
|
+
border-radius: var(--nc-input-radius);
|
|
129
|
+
color: var(--nc-text);
|
|
130
|
+
font-size: var(--nc-font-size-sm);
|
|
131
|
+
font-family: var(--nc-font-family);
|
|
132
|
+
font-variant-numeric: tabular-nums;
|
|
133
|
+
outline: none;
|
|
134
|
+
width: 90px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.hex-input:focus { border-color: var(--nc-input-focus-border); box-shadow: 0 0 0 2px rgba(16,185,129,.15); }
|
|
138
|
+
</style>
|
|
139
|
+
<div class="picker">
|
|
140
|
+
<div class="swatches" role="listbox" aria-label="Color swatches">
|
|
141
|
+
${swatches.map(color => {
|
|
142
|
+
const isLight = this._isLight(color);
|
|
143
|
+
const active = color.toLowerCase() === value.toLowerCase();
|
|
144
|
+
return `<button
|
|
145
|
+
class="swatch${active ? ' active' : ''}${isLight ? ' swatch--light' : ''}"
|
|
146
|
+
style="background:${color}"
|
|
147
|
+
data-color="${color}"
|
|
148
|
+
aria-label="${color}"
|
|
149
|
+
aria-selected="${active}"
|
|
150
|
+
role="option"
|
|
151
|
+
type="button"
|
|
152
|
+
title="${color}"
|
|
153
|
+
></button>`;
|
|
154
|
+
}).join('')}
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
${showInput ? `
|
|
158
|
+
<div class="input-row">
|
|
159
|
+
<div class="preview" style="background:${value}" title="Click to open color picker">
|
|
160
|
+
<input class="native-input" type="color" value="${value}" aria-label="Color picker" />
|
|
161
|
+
</div>
|
|
162
|
+
<input class="hex-input" type="text" value="${value}" maxlength="7" placeholder="#rrggbb" aria-label="Hex color value" />
|
|
163
|
+
</div>` : ''}
|
|
164
|
+
|
|
165
|
+
<input type="hidden" name="${this.getAttribute('name') || ''}" value="${value}" />
|
|
166
|
+
</div>
|
|
167
|
+
`;
|
|
168
|
+
}
|
|
169
|
+
_isLight(hex) {
|
|
170
|
+
const c = hex.replace('#', '');
|
|
171
|
+
const r = parseInt(c.slice(0, 2), 16);
|
|
172
|
+
const g = parseInt(c.slice(2, 4), 16);
|
|
173
|
+
const b = parseInt(c.slice(4, 6), 16);
|
|
174
|
+
return (r * 299 + g * 587 + b * 114) / 1000 > 200;
|
|
175
|
+
}
|
|
176
|
+
onMount() {
|
|
177
|
+
this._bindEvents();
|
|
178
|
+
}
|
|
179
|
+
_bindEvents() {
|
|
180
|
+
// Swatch clicks
|
|
181
|
+
this.$('.swatches').addEventListener('click', (e) => {
|
|
182
|
+
const btn = e.target.closest('[data-color]');
|
|
183
|
+
if (btn)
|
|
184
|
+
this._commit(btn.dataset.color);
|
|
185
|
+
});
|
|
186
|
+
// Native color input
|
|
187
|
+
const native = this.$('.native-input');
|
|
188
|
+
if (native) {
|
|
189
|
+
native.addEventListener('input', () => {
|
|
190
|
+
this._commit(native.value, false);
|
|
191
|
+
const hex = this.$('.hex-input');
|
|
192
|
+
if (hex)
|
|
193
|
+
hex.value = native.value;
|
|
194
|
+
});
|
|
195
|
+
native.addEventListener('change', () => this._commit(native.value));
|
|
196
|
+
}
|
|
197
|
+
// Hex text input
|
|
198
|
+
const hexIn = this.$('.hex-input');
|
|
199
|
+
if (hexIn) {
|
|
200
|
+
hexIn.addEventListener('input', () => {
|
|
201
|
+
const v = hexIn.value.trim();
|
|
202
|
+
if (/^#[0-9a-fA-F]{6}$/.test(v)) {
|
|
203
|
+
this._commit(v, false);
|
|
204
|
+
const nat = this.$('.native-input');
|
|
205
|
+
if (nat)
|
|
206
|
+
nat.value = v;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
hexIn.addEventListener('change', () => {
|
|
210
|
+
const v = hexIn.value.trim();
|
|
211
|
+
if (/^#[0-9a-fA-F]{6}$/.test(v))
|
|
212
|
+
this._commit(v);
|
|
213
|
+
else
|
|
214
|
+
hexIn.value = this._value; // revert invalid
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
_commit(value, fireChange = true) {
|
|
219
|
+
this._value = value;
|
|
220
|
+
this.setAttribute('value', value);
|
|
221
|
+
// Update swatch active states
|
|
222
|
+
this.$$('.swatch').forEach(s => {
|
|
223
|
+
const active = s.dataset.color?.toLowerCase() === value.toLowerCase();
|
|
224
|
+
s.classList.toggle('active', active);
|
|
225
|
+
s.setAttribute('aria-selected', String(active));
|
|
226
|
+
});
|
|
227
|
+
// Update preview
|
|
228
|
+
const preview = this.$('.preview');
|
|
229
|
+
if (preview)
|
|
230
|
+
preview.style.background = value;
|
|
231
|
+
// Update hidden input
|
|
232
|
+
const hidden = this.$('input[type="hidden"]');
|
|
233
|
+
if (hidden)
|
|
234
|
+
hidden.value = value;
|
|
235
|
+
const name = this.getAttribute('name') || '';
|
|
236
|
+
const eventType = fireChange ? 'change' : 'input';
|
|
237
|
+
this.dispatchEvent(new CustomEvent(eventType, {
|
|
238
|
+
bubbles: true, composed: true,
|
|
239
|
+
detail: { value, name }
|
|
240
|
+
}));
|
|
241
|
+
if (fireChange) {
|
|
242
|
+
this.dispatchEvent(new CustomEvent('input', {
|
|
243
|
+
bubbles: true, composed: true,
|
|
244
|
+
detail: { value, name }
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
249
|
+
if (oldValue === newValue)
|
|
250
|
+
return;
|
|
251
|
+
if (name === 'value' && this._mounted) {
|
|
252
|
+
this._value = newValue;
|
|
253
|
+
this._commit(newValue, false);
|
|
254
|
+
const hex = this.$('.hex-input');
|
|
255
|
+
if (hex)
|
|
256
|
+
hex.value = newValue;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (this._mounted) {
|
|
260
|
+
this.render();
|
|
261
|
+
this._bindEvents();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
defineComponent('nc-color-picker', NcColorPicker);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Component, defineComponent } from '../core/component.js';
|
|
2
|
+
export class NcCopyButton extends Component {
|
|
3
|
+
static useShadowDOM = true;
|
|
4
|
+
timer = null;
|
|
5
|
+
copied = false;
|
|
6
|
+
template() {
|
|
7
|
+
const label = this.getAttribute('label') ?? 'Copy';
|
|
8
|
+
const copiedLabel = this.getAttribute('copied-label') ?? 'Copied!';
|
|
9
|
+
const variant = this.getAttribute('variant') ?? 'outline';
|
|
10
|
+
const size = this.getAttribute('size') ?? 'md';
|
|
11
|
+
const iconOnly = this.hasAttribute('icon-only');
|
|
12
|
+
const isCopied = this.copied;
|
|
13
|
+
const padding = size === 'sm' ? '4px 8px' : size === 'lg' ? '8px 20px' : '6px 14px';
|
|
14
|
+
const fontSize = size === 'sm' ? 'var(--nc-font-size-xs, 0.75rem)' : size === 'lg' ? 'var(--nc-font-size-base, 1rem)' : 'var(--nc-font-size-sm, 0.875rem)';
|
|
15
|
+
const iconSize = size === 'sm' ? 14 : size === 'lg' ? 20 : 16;
|
|
16
|
+
const copyIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="${iconSize}" height="${iconSize}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>`;
|
|
17
|
+
const checkIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="${iconSize}" height="${iconSize}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>`;
|
|
18
|
+
const variantColors = {
|
|
19
|
+
outline: 'var(--nc-border, #e5e7eb)',
|
|
20
|
+
primary: 'var(--nc-primary, #10b981)',
|
|
21
|
+
ghost: 'transparent'
|
|
22
|
+
};
|
|
23
|
+
const border = variantColors[variant] ?? variantColors.outline;
|
|
24
|
+
const background = variant === 'primary' ? 'var(--nc-primary, #10b981)' : 'transparent';
|
|
25
|
+
const color = isCopied
|
|
26
|
+
? 'var(--nc-success, #10b981)'
|
|
27
|
+
: variant === 'primary' ? 'var(--nc-white, #ffffff)' : 'var(--nc-text, #111827)';
|
|
28
|
+
return `
|
|
29
|
+
<style>
|
|
30
|
+
:host { display: inline-block; }
|
|
31
|
+
button {
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 6px;
|
|
35
|
+
font-family: var(--nc-font-family);
|
|
36
|
+
font-size: ${fontSize};
|
|
37
|
+
font-weight: var(--nc-font-weight-medium, 500);
|
|
38
|
+
color: ${color};
|
|
39
|
+
background: ${background};
|
|
40
|
+
border: 1px solid ${border};
|
|
41
|
+
border-radius: var(--nc-radius-md, 0.5rem);
|
|
42
|
+
padding: ${padding};
|
|
43
|
+
cursor: pointer;
|
|
44
|
+
transition: color var(--nc-transition-fast, 160ms ease), background var(--nc-transition-fast, 160ms ease), border-color var(--nc-transition-fast, 160ms ease), opacity var(--nc-transition-fast, 160ms ease);
|
|
45
|
+
outline: none;
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
}
|
|
48
|
+
button:hover:not(:disabled) { opacity: 0.8; }
|
|
49
|
+
button:focus-visible { outline: 2px solid var(--nc-primary, #10b981); outline-offset: 2px; }
|
|
50
|
+
button:disabled { opacity: 0.5; cursor: default; }
|
|
51
|
+
.icon { flex-shrink: 0; display: flex; }
|
|
52
|
+
</style>
|
|
53
|
+
<button type="button" aria-label="${isCopied ? copiedLabel : label}" ${isCopied ? 'disabled' : ''}>
|
|
54
|
+
<span class="icon">${isCopied ? checkIcon : copyIcon}</span>
|
|
55
|
+
${!iconOnly ? `<span>${isCopied ? copiedLabel : label}</span>` : ''}
|
|
56
|
+
</button>
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
onMount() {
|
|
60
|
+
this.shadowRoot?.addEventListener('click', () => this.copy());
|
|
61
|
+
}
|
|
62
|
+
async copy() {
|
|
63
|
+
const value = this.getAttribute('value') ?? '';
|
|
64
|
+
const timeout = parseInt(this.getAttribute('timeout') ?? '2000', 10);
|
|
65
|
+
try {
|
|
66
|
+
await navigator.clipboard.writeText(value);
|
|
67
|
+
this.copied = true;
|
|
68
|
+
this.render();
|
|
69
|
+
if (this.timer)
|
|
70
|
+
clearTimeout(this.timer);
|
|
71
|
+
this.timer = setTimeout(() => {
|
|
72
|
+
this.copied = false;
|
|
73
|
+
this.render();
|
|
74
|
+
}, timeout);
|
|
75
|
+
this.dispatchEvent(new CustomEvent('copy', {
|
|
76
|
+
detail: { value },
|
|
77
|
+
bubbles: true,
|
|
78
|
+
composed: true
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.dispatchEvent(new CustomEvent('error', {
|
|
83
|
+
detail: { error },
|
|
84
|
+
bubbles: true,
|
|
85
|
+
composed: true
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
onUnmount() {
|
|
90
|
+
if (this.timer)
|
|
91
|
+
clearTimeout(this.timer);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
defineComponent('nc-copy-button', NcCopyButton);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NcDatePicker Component
|
|
3
|
+
*
|
|
4
|
+
* Attributes:
|
|
5
|
+
* - name: string
|
|
6
|
+
* - value: string - ISO date string YYYY-MM-DD
|
|
7
|
+
* - min: string - minimum selectable date (YYYY-MM-DD)
|
|
8
|
+
* - max: string - maximum selectable date (YYYY-MM-DD)
|
|
9
|
+
* - placeholder: string (default: 'Select date')
|
|
10
|
+
* - disabled: boolean
|
|
11
|
+
* - readonly: boolean
|
|
12
|
+
* - size: 'sm'|'md'|'lg' (default: 'md')
|
|
13
|
+
* - variant: 'default'|'filled' (default: 'default')
|
|
14
|
+
* - first-day: 0|1 - 0=Sunday, 1=Monday (default: 0)
|
|
15
|
+
*
|
|
16
|
+
* Events:
|
|
17
|
+
* - change: CustomEvent<{ value: string; date: Date | null; name: string }>
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* <nc-date-picker name="dob" value="2024-03-15"></nc-date-picker>
|
|
21
|
+
* <nc-date-picker name="from" min="2024-01-01" max="2024-12-31"></nc-date-picker>
|
|
22
|
+
*/
|
|
23
|
+
import { Component } from '../core/component.js';
|
|
24
|
+
export declare class NcDatePicker extends Component {
|
|
25
|
+
static useShadowDOM: boolean;
|
|
26
|
+
static get observedAttributes(): string[];
|
|
27
|
+
private _open;
|
|
28
|
+
private _selected;
|
|
29
|
+
private _viewYear;
|
|
30
|
+
private _viewMonth;
|
|
31
|
+
constructor();
|
|
32
|
+
template(): string;
|
|
33
|
+
private _renderCalendar;
|
|
34
|
+
onMount(): void;
|
|
35
|
+
private _bindEvents;
|
|
36
|
+
private _outsideClick;
|
|
37
|
+
private _select;
|
|
38
|
+
private _refreshCalendar;
|
|
39
|
+
onUnmount(): void;
|
|
40
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
41
|
+
}
|