@nuralyui/input 0.0.3 → 0.0.5

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.
@@ -10,14 +10,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
10
10
  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;
11
11
  return c > 3 && r && Object.defineProperty(target, key, r), r;
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
13
22
  import { LitElement, html, nothing } from 'lit';
14
23
  import { customElement, property, query, state } from 'lit/decorators.js';
15
24
  import { styles } from './input.style.js';
16
25
  import { EMPTY_STRING } from './input.constant.js';
17
26
  import { choose } from 'lit/directives/choose.js';
18
- let HyInputElement = class HyInputElement extends LitElement {
27
+ import { NuralyUIBaseMixin } from '../../shared/base-mixin.js';
28
+ import '../icon/icon.component.js';
29
+ let NrInputElement = class NrInputElement extends NuralyUIBaseMixin(LitElement) {
19
30
  constructor() {
20
- // W3C standards
21
31
  super(...arguments);
22
32
  this.disabled = false;
23
33
  this.state = "default" /* INPUT_STATE.Default */;
@@ -28,54 +38,158 @@ let HyInputElement = class HyInputElement extends LitElement {
28
38
  this.autocomplete = 'off';
29
39
  this.withCopy = false;
30
40
  this.inputType = EMPTY_STRING;
41
+ /**
42
+ * Required components that must be registered for this component to work properly
43
+ */
44
+ this.requiredComponents = ['hy-icon'];
45
+ }
46
+ /**
47
+ * Check for required dependencies when component is connected to DOM
48
+ */
49
+ connectedCallback() {
50
+ super.connectedCallback();
51
+ this.validateDependencies();
31
52
  }
32
53
  willUpdate(_changedProperties) {
33
54
  if (_changedProperties.has('type')) {
34
55
  this.inputType = this.type;
35
- if (this.inputType == "number" /* INPUT_TYPE.NUMBER */)
36
- if (this.min && !this.value)
37
- this.value = this.min;
56
+ if (this.inputType === "number" /* INPUT_TYPE.NUMBER */ && this.min && !this.value) {
57
+ this.value = this.min;
58
+ }
59
+ }
60
+ }
61
+ updated(_changedProperties) {
62
+ if (_changedProperties.has('step') || _changedProperties.has('min') || _changedProperties.has('max')) {
63
+ const input = this.input;
64
+ if (input) {
65
+ if (this.step)
66
+ input.setAttribute('step', this.step);
67
+ else
68
+ input.removeAttribute('step');
69
+ if (this.min)
70
+ input.setAttribute('min', this.min);
71
+ else
72
+ input.removeAttribute('min');
73
+ if (this.max)
74
+ input.setAttribute('max', this.max);
75
+ else
76
+ input.removeAttribute('max');
77
+ }
38
78
  }
39
79
  }
40
80
  _increment() {
41
81
  this.input.stepUp();
42
- this.dispatchEvent(new CustomEvent('valueChange', {
43
- detail: this.input,
82
+ this.value = this.input.value; // Sync the property
83
+ this.dispatchEvent(new CustomEvent('nr-input', {
84
+ detail: {
85
+ value: this.value,
86
+ target: this.input,
87
+ action: 'increment'
88
+ },
89
+ bubbles: true
44
90
  }));
45
91
  }
46
92
  _decrement() {
47
93
  this.input.stepDown();
48
- this.dispatchEvent(new CustomEvent('valueChange', {
49
- detail: this.input,
94
+ this.value = this.input.value; // Sync the property
95
+ this.dispatchEvent(new CustomEvent('nr-input', {
96
+ detail: {
97
+ value: this.value,
98
+ target: this.input,
99
+ action: 'decrement'
100
+ },
101
+ bubbles: true
50
102
  }));
51
103
  }
52
104
  _valueChange(e) {
53
- this.dispatchEvent(new CustomEvent('valueChange', {
54
- detail: e.target,
105
+ const target = e.target;
106
+ this.value = target.value;
107
+ this.dispatchEvent(new CustomEvent('nr-input', {
108
+ detail: {
109
+ value: this.value,
110
+ target: target,
111
+ originalEvent: e
112
+ },
113
+ bubbles: true
55
114
  }));
56
115
  }
57
116
  handleKeyDown(keyDownEvent) {
58
117
  if (keyDownEvent.key === 'Enter') {
59
- this.dispatchEvent(new CustomEvent('enter-pressed', {
60
- detail: keyDownEvent.target,
118
+ this.dispatchEvent(new CustomEvent('nr-enter', {
119
+ detail: {
120
+ target: keyDownEvent.target,
121
+ value: this.value,
122
+ originalEvent: keyDownEvent
123
+ },
124
+ bubbles: true
61
125
  }));
62
126
  }
63
127
  }
128
+ _handleIconKeydown(keyDownEvent) {
129
+ if (keyDownEvent.key === 'Enter' || keyDownEvent.key === ' ') {
130
+ keyDownEvent.preventDefault();
131
+ const target = keyDownEvent.target;
132
+ if (target.id === 'copy-icon') {
133
+ this.onCopy();
134
+ }
135
+ else if (target.id === 'password-icon') {
136
+ this._togglePasswordIcon();
137
+ }
138
+ else if (target.closest('#number-icons')) {
139
+ if (target.getAttribute('name') === 'plus') {
140
+ this._increment();
141
+ }
142
+ else if (target.getAttribute('name') === 'minus') {
143
+ this._decrement();
144
+ }
145
+ }
146
+ }
147
+ }
64
148
  onCopy() {
65
- const input = this.shadowRoot.getElementById('input');
66
- input.select();
67
- navigator.clipboard.writeText(input.value);
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ try {
151
+ const input = this.shadowRoot.getElementById('input');
152
+ input.select();
153
+ yield navigator.clipboard.writeText(input.value);
154
+ this.dispatchEvent(new CustomEvent('nr-copy-success', {
155
+ detail: { value: input.value },
156
+ bubbles: true
157
+ }));
158
+ }
159
+ catch (error) {
160
+ this.dispatchEvent(new CustomEvent('nr-copy-error', {
161
+ detail: { error },
162
+ bubbles: true
163
+ }));
164
+ }
165
+ });
166
+ }
167
+ _getAriaDescribedBy() {
168
+ var _a;
169
+ const describedBy = [];
170
+ // Check if helper text slot has content
171
+ const helperSlot = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot[name="helper-text"]');
172
+ if (helperSlot && helperSlot.assignedNodes().length > 0) {
173
+ describedBy.push('helper-text');
174
+ }
175
+ return describedBy.join(' ') || '';
68
176
  }
69
177
  _focusEvent(e) {
70
- this.dispatchEvent(new CustomEvent('focused', {
71
- detail: e.target,
178
+ this.dispatchEvent(new CustomEvent('nr-focus', {
179
+ detail: {
180
+ target: e.target,
181
+ value: this.value
182
+ },
183
+ bubbles: true
72
184
  }));
73
185
  }
74
186
  _togglePasswordIcon() {
75
- if (this.inputType == "password" /* INPUT_TYPE.PASSWORD */)
187
+ if (this.inputType === "password" /* INPUT_TYPE.PASSWORD */) {
76
188
  this.inputType = "text" /* INPUT_TYPE.TEXT */;
77
- else if (this.inputType == "text" /* INPUT_TYPE.TEXT */)
189
+ }
190
+ else if (this.inputType === "text" /* INPUT_TYPE.TEXT */ && this.type === "password" /* INPUT_TYPE.PASSWORD */) {
78
191
  this.inputType = "password" /* INPUT_TYPE.PASSWORD */;
192
+ }
79
193
  }
80
194
  render() {
81
195
  return html `
@@ -86,11 +200,10 @@ let HyInputElement = class HyInputElement extends LitElement {
86
200
  .disabled=${this.disabled}
87
201
  .value=${this.value}
88
202
  .placeholder=${this.placeholder}
89
- .step=${this.step ? this.step : nothing}
90
- .min=${this.min ? this.min : nothing}
91
- .max=${this.max ? this.max : nothing}
92
203
  .type="${this.inputType}"
93
204
  .autocomplete=${this.autocomplete}
205
+ aria-invalid=${this.state === "error" /* INPUT_STATE.Error */ ? 'true' : 'false'}
206
+ aria-describedby=${this._getAriaDescribedBy()}
94
207
  @input=${this._valueChange}
95
208
  @focus=${this._focusEvent}
96
209
  @keydown=${this.handleKeyDown}
@@ -100,7 +213,11 @@ let HyInputElement = class HyInputElement extends LitElement {
100
213
  name="copy"
101
214
  type="regular"
102
215
  id="copy-icon"
216
+ role="button"
217
+ aria-label="Copy input value"
218
+ tabindex="0"
103
219
  @click=${!this.disabled ? this.onCopy : nothing}
220
+ @keydown=${this._handleIconKeydown}
104
221
  ></hy-icon>`
105
222
  : nothing}
106
223
  ${choose(this.state, [
@@ -119,7 +236,11 @@ let HyInputElement = class HyInputElement extends LitElement {
119
236
  name="eye-slash"
120
237
  type="regular"
121
238
  id="password-icon"
239
+ role="button"
240
+ aria-label="Hide password"
241
+ tabindex="0"
122
242
  @click=${!this.disabled ? this._togglePasswordIcon : nothing}
243
+ @keydown=${this._handleIconKeydown}
123
244
  ></hy-icon>`,
124
245
  ],
125
246
  [
@@ -128,7 +249,11 @@ let HyInputElement = class HyInputElement extends LitElement {
128
249
  name="eye"
129
250
  type="regular"
130
251
  id="password-icon"
252
+ role="button"
253
+ aria-label="Show password"
254
+ tabindex="0"
131
255
  @click=${!this.disabled ? this._togglePasswordIcon : nothing}
256
+ @keydown=${this._handleIconKeydown}
132
257
  ></hy-icon>`,
133
258
  ],
134
259
  ])
@@ -147,48 +272,48 @@ let HyInputElement = class HyInputElement extends LitElement {
147
272
  `;
148
273
  }
149
274
  };
150
- HyInputElement.styles = styles;
275
+ NrInputElement.styles = styles;
151
276
  __decorate([
152
277
  property({ type: Boolean, reflect: true })
153
- ], HyInputElement.prototype, "disabled", void 0);
278
+ ], NrInputElement.prototype, "disabled", void 0);
154
279
  __decorate([
155
280
  property({ type: String, reflect: true })
156
- ], HyInputElement.prototype, "state", void 0);
281
+ ], NrInputElement.prototype, "state", void 0);
157
282
  __decorate([
158
283
  property({ type: String })
159
- ], HyInputElement.prototype, "value", void 0);
284
+ ], NrInputElement.prototype, "value", void 0);
160
285
  __decorate([
161
286
  property({ type: String })
162
- ], HyInputElement.prototype, "size", void 0);
287
+ ], NrInputElement.prototype, "size", void 0);
163
288
  __decorate([
164
289
  property({ reflect: true })
165
- ], HyInputElement.prototype, "type", void 0);
290
+ ], NrInputElement.prototype, "type", void 0);
166
291
  __decorate([
167
292
  property({ type: String })
168
- ], HyInputElement.prototype, "step", void 0);
293
+ ], NrInputElement.prototype, "step", void 0);
169
294
  __decorate([
170
295
  property({ type: String })
171
- ], HyInputElement.prototype, "min", void 0);
296
+ ], NrInputElement.prototype, "min", void 0);
172
297
  __decorate([
173
298
  property({ type: String })
174
- ], HyInputElement.prototype, "max", void 0);
299
+ ], NrInputElement.prototype, "max", void 0);
175
300
  __decorate([
176
301
  property({ type: String })
177
- ], HyInputElement.prototype, "placeholder", void 0);
302
+ ], NrInputElement.prototype, "placeholder", void 0);
178
303
  __decorate([
179
304
  property({ type: String })
180
- ], HyInputElement.prototype, "autocomplete", void 0);
305
+ ], NrInputElement.prototype, "autocomplete", void 0);
181
306
  __decorate([
182
- property()
183
- ], HyInputElement.prototype, "withCopy", void 0);
307
+ property({ type: Boolean, reflect: true })
308
+ ], NrInputElement.prototype, "withCopy", void 0);
184
309
  __decorate([
185
310
  state()
186
- ], HyInputElement.prototype, "inputType", void 0);
311
+ ], NrInputElement.prototype, "inputType", void 0);
187
312
  __decorate([
188
313
  query('#input')
189
- ], HyInputElement.prototype, "input", void 0);
190
- HyInputElement = __decorate([
191
- customElement('hy-input')
192
- ], HyInputElement);
193
- export { HyInputElement };
314
+ ], NrInputElement.prototype, "input", void 0);
315
+ NrInputElement = __decorate([
316
+ customElement('nr-input')
317
+ ], NrInputElement);
318
+ export { NrInputElement };
194
319
  //# sourceMappingURL=input.component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"input.component.js","sourceRoot":"","sources":["../../../src/components/input/input.component.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;;;GAIG;;;;;;;AAEH,OAAO,EAAC,UAAU,EAAkB,IAAI,EAAE,OAAO,EAAC,MAAM,KAAK,CAAC;AAC9D,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAsC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAGhD,IAAa,cAAc,GAA3B,MA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CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO;;aAE3E;gBACD,CAAC,CAAC,OAAO;;;KAGhB,CAAC;IACJ,CAAC;CAGF,CAAA;AADiB,qBAAM,GAAG,MAAO,CAAA;AAzKhC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gDACxB;AAGjB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CACZ;AAG5B;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;6CACJ;AAGrB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;4CACA;AAGzB;IADC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;4CACH;AAGvB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;4CACX;AAGd;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;2CACZ;AAGb;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;2CACZ;AAGb;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;mDACE;AAG3B;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;oDACJ;AAGrB;IADC,QAAQ,EAAE;gDACM;AAGjB;IADC,KAAK,EAAE;iDACiB;AAGzB;IADC,KAAK,CAAC,QAAQ,CAAC;6CACS;AAxCd,cAAc;IAD1B,aAAa,CAAC,UAAU,CAAC;GACb,cAAc,CA8K1B;SA9KY,cAAc","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * @license\n * Copyright 2023 Google Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport {LitElement, PropertyValues, html, nothing} from 'lit';\nimport {customElement, property, query, state} from 'lit/decorators.js';\nimport {styles} from './input.style.js';\nimport {INPUT_TYPE, INPUT_STATE, INPUT_SIZE, EMPTY_STRING} from './input.constant.js';\nimport {choose} from 'lit/directives/choose.js';\n\n@customElement('hy-input')\nexport class HyInputElement extends LitElement {\n // W3C standards\n\n @property({type: Boolean, reflect: true})\n disabled = false;\n\n @property({type: String, reflect: true})\n state = INPUT_STATE.Default;\n\n @property({type: String})\n value = EMPTY_STRING;\n\n @property({type: String})\n size = INPUT_SIZE.Medium;\n\n @property({reflect: true})\n type = INPUT_TYPE.TEXT;\n\n @property({type: String})\n step!: string;\n\n @property({type: String})\n min!: string;\n\n @property({type: String})\n max!: string;\n\n @property({type: String})\n placeholder = EMPTY_STRING;\n\n @property({type: String})\n autocomplete = 'off';\n\n @property()\n withCopy = false;\n\n @state()\n inputType = EMPTY_STRING;\n\n @query('#input')\n input!: HTMLInputElement;\n\n override willUpdate(_changedProperties: PropertyValues): void {\n if (_changedProperties.has('type')) {\n this.inputType = this.type;\n if (this.inputType == INPUT_TYPE.NUMBER) if (this.min && !this.value) this.value = this.min;\n }\n }\n\n private _increment() {\n this.input.stepUp();\n this.dispatchEvent(\n new CustomEvent('valueChange', {\n detail: this.input,\n })\n );\n }\n private _decrement() {\n this.input.stepDown();\n this.dispatchEvent(\n new CustomEvent('valueChange', {\n detail: this.input,\n })\n );\n }\n\n private _valueChange(e: Event) {\n this.dispatchEvent(\n new CustomEvent('valueChange', {\n detail: e.target,\n })\n );\n }\n private handleKeyDown(keyDownEvent: KeyboardEvent) {\n if (keyDownEvent.key === 'Enter') {\n this.dispatchEvent(\n new CustomEvent('enter-pressed', {\n detail: keyDownEvent.target,\n })\n );\n }\n }\n private onCopy() {\n const input = this.shadowRoot!.getElementById('input')! as HTMLInputElement;\n input.select();\n navigator.clipboard.writeText(input.value);\n }\n\n private _focusEvent(e: Event) {\n this.dispatchEvent(\n new CustomEvent('focused', {\n detail: e.target,\n })\n );\n }\n\n _togglePasswordIcon() {\n if (this.inputType == INPUT_TYPE.PASSWORD) this.inputType = INPUT_TYPE.TEXT;\n else if (this.inputType == INPUT_TYPE.TEXT) this.inputType = INPUT_TYPE.PASSWORD;\n }\n\n override render() {\n return html`\n <slot name=\"label\"></slot>\n <div data-size=${this.size} id=\"input-container\">\n <input\n id=\"input\"\n .disabled=${this.disabled}\n .value=${this.value}\n .placeholder=${this.placeholder}\n .step=${this.step ? this.step : nothing}\n .min=${this.min ? this.min : nothing}\n .max=${this.max ? this.max : nothing}\n .type=\"${this.inputType}\"\n .autocomplete=${this.autocomplete}\n @input=${this._valueChange}\n @focus=${this._focusEvent}\n @keydown=${this.handleKeyDown}\n />\n ${this.withCopy\n ? html`<hy-icon\n name=\"copy\"\n type=\"regular\"\n id=\"copy-icon\"\n @click=${!this.disabled ? this.onCopy : nothing}\n ></hy-icon>`\n : nothing}\n ${choose(this.state, [\n [INPUT_STATE.Default, () => undefined],\n [INPUT_STATE.Warning, () => html`<hy-icon name=\"warning\" id=\"warning-icon\"></hy-icon>`],\n [INPUT_STATE.Error, () => html`<hy-icon name=\"exclamation-circle\" id=\"error-icon\"></hy-icon>`],\n ])}\n ${this.state == INPUT_STATE.Default && this.type == INPUT_TYPE.CALENDAR\n ? html`<hy-icon name=\"calendar\" type=\"regular\" id=\"calendar-icon\"></hy-icon>`\n : nothing}\n ${this.type == INPUT_TYPE.PASSWORD\n ? choose(this.inputType, [\n [\n INPUT_TYPE.TEXT,\n () =>\n html`<hy-icon\n name=\"eye-slash\"\n type=\"regular\"\n id=\"password-icon\"\n @click=${!this.disabled ? this._togglePasswordIcon : nothing}\n ></hy-icon>`,\n ],\n [\n INPUT_TYPE.PASSWORD,\n () =>\n html`<hy-icon\n name=\"eye\"\n type=\"regular\"\n id=\"password-icon\"\n @click=${!this.disabled ? this._togglePasswordIcon : nothing}\n ></hy-icon>`,\n ],\n ])\n : this.type == INPUT_TYPE.NUMBER\n ? html`\n <div id=\"number-icons\">\n ${this.state != INPUT_STATE.Default ? html`<span id=\"icons-separator\">|</span>` : nothing}\n <hy-icon name=\"minus\" @click=${!this.disabled ? this._decrement : nothing}></hy-icon>\n <span id=\"icons-separator\">|</span>\n <hy-icon name=\"plus\" @click=${!this.disabled ? this._increment : nothing}></hy-icon>\n </div>\n `\n : nothing}\n </div>\n <slot name=\"helper-text\"></slot>\n `;\n }\n\n static override styles = styles;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'hy-input': HyInputElement;\n }\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'hy-input':\n | React.DetailedHTMLProps<React.HTMLAttributes<HyInputElement>, HyInputElement>\n | Partial<HyInputElement>;\n }\n }\n}"]}
1
+ {"version":3,"file":"input.component.js","sourceRoot":"","sources":["../../../src/components/input/input.component.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;;;GAIG;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,UAAU,EAAkB,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAuC,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,2BAA2B,CAAC;AAGnC,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,iBAAiB,CAAC,UAAU,CAAC;IAAjE;;QAGE,aAAQ,GAAG,KAAK,CAAC;QAGjB,UAAK,uCAAuB;QAG5B,UAAK,GAAG,YAAY,CAAC;QAGrB,SAAI,oCAAqB;QAGzB,SAAI,gCAAmB;QAYvB,gBAAW,GAAG,YAAY,CAAC;QAG3B,iBAAY,GAAG,KAAK,CAAC;QAGrB,aA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AC,CAAC;mDACE;AAG3B;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;oDACJ;AAGrB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gDACxB;AAGjB;IADC,KAAK,EAAE;iDACiB;AAGzB;IADC,KAAK,CAAC,QAAQ,CAAC;6CACS;AAvCd,cAAc;IAD1B,aAAa,CAAC,UAAU,CAAC;GACb,cAAc,CAkS1B;SAlSY,cAAc","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * @license\n * Copyright 2023 Google Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { LitElement, PropertyValues, html, nothing } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { styles } from './input.style.js';\nimport { INPUT_TYPE, INPUT_STATE, INPUT_SIZE, EMPTY_STRING } from './input.constant.js';\nimport { choose } from 'lit/directives/choose.js';\nimport { NuralyUIBaseMixin } from '../../shared/base-mixin.js';\nimport '../icon/icon.component.js';\n\n@customElement('nr-input')\nexport class NrInputElement extends NuralyUIBaseMixin(LitElement) {\n\n @property({type: Boolean, reflect: true})\n disabled = false;\n\n @property({type: String, reflect: true})\n state = INPUT_STATE.Default;\n\n @property({type: String})\n value = EMPTY_STRING;\n\n @property({type: String})\n size = INPUT_SIZE.Medium;\n\n @property({reflect: true})\n type = INPUT_TYPE.TEXT;\n\n @property({type: String})\n step?: string;\n\n @property({type: String})\n min?: string;\n\n @property({type: String})\n max?: string;\n\n @property({type: String})\n placeholder = EMPTY_STRING;\n\n @property({type: String})\n autocomplete = 'off';\n\n @property({type: Boolean, reflect: true})\n withCopy = false;\n\n @state()\n inputType = EMPTY_STRING;\n\n @query('#input')\n input!: HTMLInputElement;\n\n /**\n * Required components that must be registered for this component to work properly\n */\n override requiredComponents = ['hy-icon'];\n\n /**\n * Check for required dependencies when component is connected to DOM\n */\n override connectedCallback() {\n super.connectedCallback();\n this.validateDependencies();\n }\n\n override willUpdate(_changedProperties: PropertyValues): void {\n if (_changedProperties.has('type')) {\n this.inputType = this.type;\n if (this.inputType === INPUT_TYPE.NUMBER && this.min && !this.value) {\n this.value = this.min;\n }\n }\n }\n\n override updated(_changedProperties: PropertyValues): void {\n if (_changedProperties.has('step') || _changedProperties.has('min') || _changedProperties.has('max')) {\n const input = this.input;\n if (input) {\n if (this.step) input.setAttribute('step', this.step);\n else input.removeAttribute('step');\n \n if (this.min) input.setAttribute('min', this.min);\n else input.removeAttribute('min');\n \n if (this.max) input.setAttribute('max', this.max);\n else input.removeAttribute('max');\n }\n }\n }\n\n private _increment() {\n this.input.stepUp();\n this.value = this.input.value; // Sync the property\n this.dispatchEvent(\n new CustomEvent('nr-input', {\n detail: { \n value: this.value, \n target: this.input,\n action: 'increment'\n },\n bubbles: true\n })\n );\n }\n private _decrement() {\n this.input.stepDown();\n this.value = this.input.value; // Sync the property\n this.dispatchEvent(\n new CustomEvent('nr-input', {\n detail: { \n value: this.value, \n target: this.input,\n action: 'decrement'\n },\n bubbles: true\n })\n );\n }\n\n private _valueChange(e: Event) {\n const target = e.target as HTMLInputElement;\n this.value = target.value;\n \n this.dispatchEvent(\n new CustomEvent('nr-input', {\n detail: { \n value: this.value, \n target: target,\n originalEvent: e \n },\n bubbles: true\n })\n );\n }\n private handleKeyDown(keyDownEvent: KeyboardEvent) {\n if (keyDownEvent.key === 'Enter') {\n this.dispatchEvent(\n new CustomEvent('nr-enter', {\n detail: {\n target: keyDownEvent.target,\n value: this.value,\n originalEvent: keyDownEvent\n },\n bubbles: true\n })\n );\n }\n }\n\n private _handleIconKeydown(keyDownEvent: KeyboardEvent) {\n if (keyDownEvent.key === 'Enter' || keyDownEvent.key === ' ') {\n keyDownEvent.preventDefault();\n const target = keyDownEvent.target as HTMLElement;\n \n if (target.id === 'copy-icon') {\n this.onCopy();\n } else if (target.id === 'password-icon') {\n this._togglePasswordIcon();\n } else if (target.closest('#number-icons')) {\n if (target.getAttribute('name') === 'plus') {\n this._increment();\n } else if (target.getAttribute('name') === 'minus') {\n this._decrement();\n }\n }\n }\n }\n private async onCopy() {\n try {\n const input = this.shadowRoot!.getElementById('input')! as HTMLInputElement;\n input.select();\n await navigator.clipboard.writeText(input.value);\n \n this.dispatchEvent(new CustomEvent('nr-copy-success', {\n detail: { value: input.value },\n bubbles: true\n }));\n } catch (error) {\n this.dispatchEvent(new CustomEvent('nr-copy-error', {\n detail: { error },\n bubbles: true\n }));\n }\n }\n\n private _getAriaDescribedBy(): string {\n const describedBy: string[] = [];\n \n // Check if helper text slot has content\n const helperSlot = this.shadowRoot?.querySelector('slot[name=\"helper-text\"]');\n if (helperSlot && (helperSlot as HTMLSlotElement).assignedNodes().length > 0) {\n describedBy.push('helper-text');\n }\n \n return describedBy.join(' ') || '';\n }\n\n private _focusEvent(e: Event) {\n this.dispatchEvent(\n new CustomEvent('nr-focus', {\n detail: {\n target: e.target,\n value: this.value\n },\n bubbles: true\n })\n );\n }\n\n _togglePasswordIcon() {\n if (this.inputType === INPUT_TYPE.PASSWORD) {\n this.inputType = INPUT_TYPE.TEXT;\n } else if (this.inputType === INPUT_TYPE.TEXT && this.type === INPUT_TYPE.PASSWORD) {\n this.inputType = INPUT_TYPE.PASSWORD;\n }\n }\n\n override render() {\n return html`\n <slot name=\"label\"></slot>\n <div data-size=${this.size} id=\"input-container\">\n <input\n id=\"input\"\n .disabled=${this.disabled}\n .value=${this.value}\n .placeholder=${this.placeholder}\n .type=\"${this.inputType}\"\n .autocomplete=${this.autocomplete}\n aria-invalid=${this.state === INPUT_STATE.Error ? 'true' : 'false'}\n aria-describedby=${this._getAriaDescribedBy()}\n @input=${this._valueChange}\n @focus=${this._focusEvent}\n @keydown=${this.handleKeyDown}\n />\n ${this.withCopy\n ? html`<hy-icon\n name=\"copy\"\n type=\"regular\"\n id=\"copy-icon\"\n role=\"button\"\n aria-label=\"Copy input value\"\n tabindex=\"0\"\n @click=${!this.disabled ? this.onCopy : nothing}\n @keydown=${this._handleIconKeydown}\n ></hy-icon>`\n : nothing}\n ${choose(this.state, [\n [INPUT_STATE.Default, () => undefined],\n [INPUT_STATE.Warning, () => html`<hy-icon name=\"warning\" id=\"warning-icon\"></hy-icon>`],\n [INPUT_STATE.Error, () => html`<hy-icon name=\"exclamation-circle\" id=\"error-icon\"></hy-icon>`],\n ])}\n ${this.state == INPUT_STATE.Default && this.type == INPUT_TYPE.CALENDAR\n ? html`<hy-icon name=\"calendar\" type=\"regular\" id=\"calendar-icon\"></hy-icon>`\n : nothing}\n ${this.type == INPUT_TYPE.PASSWORD\n ? choose(this.inputType, [\n [\n INPUT_TYPE.TEXT,\n () =>\n html`<hy-icon\n name=\"eye-slash\"\n type=\"regular\"\n id=\"password-icon\"\n role=\"button\"\n aria-label=\"Hide password\"\n tabindex=\"0\"\n @click=${!this.disabled ? this._togglePasswordIcon : nothing}\n @keydown=${this._handleIconKeydown}\n ></hy-icon>`,\n ],\n [\n INPUT_TYPE.PASSWORD,\n () =>\n html`<hy-icon\n name=\"eye\"\n type=\"regular\"\n id=\"password-icon\"\n role=\"button\"\n aria-label=\"Show password\"\n tabindex=\"0\"\n @click=${!this.disabled ? this._togglePasswordIcon : nothing}\n @keydown=${this._handleIconKeydown}\n ></hy-icon>`,\n ],\n ])\n : this.type == INPUT_TYPE.NUMBER\n ? html`\n <div id=\"number-icons\">\n ${this.state != INPUT_STATE.Default ? html`<span id=\"icons-separator\">|</span>` : nothing}\n <hy-icon name=\"minus\" @click=${!this.disabled ? this._decrement : nothing}></hy-icon>\n <span id=\"icons-separator\">|</span>\n <hy-icon name=\"plus\" @click=${!this.disabled ? this._increment : nothing}></hy-icon>\n </div>\n `\n : nothing}\n </div>\n <slot name=\"helper-text\"></slot>\n `;\n }\n\n static override styles = styles;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nr-input': NrInputElement;\n }\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'nr-input':\n | React.DetailedHTMLProps<React.HTMLAttributes<NrInputElement>, NrInputElement>\n | Partial<NrInputElement>;\n }\n }\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"input.style.d.ts","sourceRoot":"","sources":["../../../src/components/input/input.style.ts"],"names":[],"mappings":"AA2MA,eAAO,MAAM,MAAM,2BAA+C,CAAC"}
1
+ {"version":3,"file":"input.style.d.ts","sourceRoot":"","sources":["../../../src/components/input/input.style.ts"],"names":[],"mappings":"AA0VA,eAAO,MAAM,MAAM,2BAA+C,CAAC"}