@reliability-design/web 1.4.6 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +246 -49
- package/dist/components/rel-accordion/README.md +133 -132
- package/dist/components/rel-alert/README.md +145 -141
- package/dist/components/rel-autocomplete/README.md +172 -61
- package/dist/components/rel-avatar/README.md +118 -130
- package/dist/components/rel-badge/README.md +97 -93
- package/dist/components/rel-breadcrumb/README.md +96 -102
- package/dist/components/rel-button/README.md +190 -130
- package/dist/components/rel-calendar/README.md +109 -109
- package/dist/components/rel-card/README.md +75 -94
- package/dist/components/rel-cardmedia/README.md +100 -127
- package/dist/components/rel-carousel/README.md +186 -166
- package/dist/components/rel-checkbox/README.md +96 -75
- package/dist/components/rel-chip/README.md +138 -121
- package/dist/components/rel-container/README.md +107 -99
- package/dist/components/rel-date-picker/README.md +200 -289
- package/dist/components/rel-divider/README.md +88 -100
- package/dist/components/rel-drawer/README.md +187 -200
- package/dist/components/rel-kbd/README.md +141 -151
- package/dist/components/rel-layout/README.md +34 -0
- package/dist/components/rel-menu/README.md +180 -151
- package/dist/components/rel-menubar/README.md +218 -329
- package/dist/components/rel-otp/README.md +171 -440
- package/dist/components/rel-pagination/README.md +100 -424
- package/dist/components/rel-popover/README.md +203 -568
- package/dist/components/rel-progress/README.md +88 -110
- package/dist/components/rel-radio/README.md +131 -138
- package/dist/components/rel-range-picker/README.md +165 -0
- package/dist/components/rel-resizable/README.md +199 -140
- package/dist/components/rel-segmented-button/README.md +156 -141
- package/dist/components/rel-select/README.md +156 -93
- package/dist/components/rel-sheet/README.md +168 -224
- package/dist/components/rel-skeleton/README.md +104 -0
- package/dist/components/rel-slider/README.md +131 -135
- package/dist/components/rel-snackbar/README.md +168 -134
- package/dist/components/rel-stepper/README.md +162 -160
- package/dist/components/rel-switch/README.md +117 -102
- package/dist/components/rel-tab/README.md +173 -163
- package/dist/components/rel-textfield/README.md +176 -69
- package/dist/components/rel-time-picker/README.md +122 -157
- package/dist/components/rel-toast/README.md +165 -148
- package/dist/components/rel-tooltip/README.md +119 -111
- package/dist/components/rel-upload/README.md +220 -0
- package/dist/index.d.mts +1726 -447
- package/dist/index.d.ts +1726 -447
- package/dist/index.js +13715 -10870
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14018 -11163
- package/dist/index.mjs.map +1 -1
- package/dist/styles/focus-ring.ts +84 -0
- package/dist/styles/vars.css +892 -866
- package/dist/{vars-XNMTSRVN.css → vars-DXX6QOAG.css} +892 -866
- package/package.json +3 -2
- package/dist/components/rel-accordion/rel-accordion.ts +0 -336
- package/dist/components/rel-alert/rel-alert.ts +0 -305
- package/dist/components/rel-autocomplete/rel-autocomplete.ts +0 -720
- package/dist/components/rel-avatar/rel-avatar.ts +0 -142
- package/dist/components/rel-badge/rel-badge.ts +0 -175
- package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +0 -106
- package/dist/components/rel-button/rel-button.ts +0 -560
- package/dist/components/rel-calendar/index.ts +0 -1
- package/dist/components/rel-calendar/rel-calendar.ts +0 -565
- package/dist/components/rel-card/rel-card.ts +0 -88
- package/dist/components/rel-cardmedia/rel-cardmedia.ts +0 -88
- package/dist/components/rel-carousel/index.ts +0 -1
- package/dist/components/rel-carousel/rel-carousel.ts +0 -723
- package/dist/components/rel-chart/README.md +0 -286
- package/dist/components/rel-chart/index.ts +0 -1
- package/dist/components/rel-chart/rel-chart.ts +0 -754
- package/dist/components/rel-checkbox/rel-checkbox.ts +0 -382
- package/dist/components/rel-chip/rel-chip.ts +0 -483
- package/dist/components/rel-container/rel-container.ts +0 -95
- package/dist/components/rel-date-picker/date-format.test.ts +0 -43
- package/dist/components/rel-date-picker/date-format.ts +0 -47
- package/dist/components/rel-date-picker/date-parse.test.ts +0 -116
- package/dist/components/rel-date-picker/date-parse.ts +0 -178
- package/dist/components/rel-date-picker/index.ts +0 -1
- package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1676
- package/dist/components/rel-divider/rel-divider.ts +0 -54
- package/dist/components/rel-drawer/index.ts +0 -1
- package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -27
- package/dist/components/rel-drawer/rel-drawer.ts +0 -607
- package/dist/components/rel-kbd/rel-kbd.ts +0 -188
- package/dist/components/rel-layout/rel-layout.ts +0 -49
- package/dist/components/rel-menu/rel-menu.ts +0 -541
- package/dist/components/rel-menubar/index.ts +0 -2
- package/dist/components/rel-menubar/rel-menubar-menu.css +0 -3
- package/dist/components/rel-menubar/rel-menubar-menu.ts +0 -17
- package/dist/components/rel-menubar/rel-menubar.ts +0 -777
- package/dist/components/rel-nav-menu/README.md +0 -289
- package/dist/components/rel-nav-menu/index.ts +0 -3
- package/dist/components/rel-nav-menu/rel-nav-menu-item.ts +0 -243
- package/dist/components/rel-nav-menu/rel-nav-menu-panel.ts +0 -72
- package/dist/components/rel-nav-menu/rel-nav-menu.ts +0 -270
- package/dist/components/rel-navbar/README.md +0 -126
- package/dist/components/rel-navbar/rel-navbar.ts +0 -105
- package/dist/components/rel-otp/index.ts +0 -1
- package/dist/components/rel-otp/rel-otp.ts +0 -527
- package/dist/components/rel-pagination/index.ts +0 -1
- package/dist/components/rel-pagination/rel-pagination.ts +0 -522
- package/dist/components/rel-popover/index.ts +0 -2
- package/dist/components/rel-popover/rel-popover-content.ts +0 -81
- package/dist/components/rel-popover/rel-popover.ts +0 -475
- package/dist/components/rel-progress/rel-progress.ts +0 -234
- package/dist/components/rel-radio/rel-radio.ts +0 -481
- package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1688
- package/dist/components/rel-resizable/index.ts +0 -3
- package/dist/components/rel-resizable/rel-resizable-group.ts +0 -405
- package/dist/components/rel-resizable/rel-resizable-handle.ts +0 -150
- package/dist/components/rel-resizable/rel-resizable-panel.ts +0 -58
- package/dist/components/rel-segmented-button/rel-segmented-button.ts +0 -217
- package/dist/components/rel-select/rel-select.ts +0 -1416
- package/dist/components/rel-sheet/rel-sheet.ts +0 -610
- package/dist/components/rel-sidebar/README.md +0 -209
- package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1191
- package/dist/components/rel-skeleton/rel-skeleton.ts +0 -143
- package/dist/components/rel-slider/rel-slider.ts +0 -673
- package/dist/components/rel-snackbar/rel-snackbar.ts +0 -329
- package/dist/components/rel-stepper/rel-stepper.ts +0 -567
- package/dist/components/rel-switch/rel-switch.ts +0 -199
- package/dist/components/rel-tab/rel-tab.ts +0 -264
- package/dist/components/rel-table/README.md +0 -178
- package/dist/components/rel-table/rel-table-body.ts +0 -22
- package/dist/components/rel-table/rel-table-caption.ts +0 -30
- package/dist/components/rel-table/rel-table-cell.ts +0 -43
- package/dist/components/rel-table/rel-table-footer.ts +0 -24
- package/dist/components/rel-table/rel-table-head.ts +0 -47
- package/dist/components/rel-table/rel-table-header.ts +0 -22
- package/dist/components/rel-table/rel-table-row.ts +0 -37
- package/dist/components/rel-table/rel-table.ts +0 -62
- package/dist/components/rel-textfield/rel-textfield.ts +0 -1054
- package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1482
- package/dist/components/rel-time-picker/time-parse.test.ts +0 -67
- package/dist/components/rel-time-picker/time-parse.ts +0 -85
- package/dist/components/rel-toast/rel-toast.ts +0 -206
- package/dist/components/rel-tooltip/rel-tooltip.ts +0 -193
- package/dist/components/rel-topbar/rel-topbar-actions.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-brand.ts +0 -54
- package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +0 -69
- package/dist/components/rel-topbar/rel-topbar-dropdown.ts +0 -31
- package/dist/components/rel-topbar/rel-topbar-item.ts +0 -324
- package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-profile.ts +0 -243
- package/dist/components/rel-topbar/rel-topbar-utilities.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar.ts +0 -446
- package/dist/components/rel-upload/UPLOAD-DESIGN-CHANGES.md +0 -134
- package/dist/components/rel-upload/rel-upload-actions.ts +0 -163
- package/dist/components/rel-upload/rel-upload.ts +0 -968
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
import { LitElement, html, css, nothing } from "lit";
|
|
2
|
-
import { customElement, property, state, query } from "lit/decorators.js";
|
|
3
|
-
import { announce } from "../../utils/announce";
|
|
4
|
-
|
|
5
|
-
export type OtpType = "numeric" | "alphanumeric";
|
|
6
|
-
|
|
7
|
-
@customElement("rel-otp")
|
|
8
|
-
export class RelOtp extends LitElement {
|
|
9
|
-
@property({ type: String, reflect: true }) value = "";
|
|
10
|
-
@property({ type: Number }) length = 6;
|
|
11
|
-
@property({ type: Number, attribute: "group-size" }) groupSize = 3;
|
|
12
|
-
@property({ type: String }) placeholder = "";
|
|
13
|
-
@property({ type: String }) type: OtpType = "numeric";
|
|
14
|
-
@property({ type: Boolean }) mask = false;
|
|
15
|
-
@property({ type: Boolean, reflect: true }) disabled = false;
|
|
16
|
-
@property({ type: Boolean, reflect: true }) readonly = false;
|
|
17
|
-
@property({ type: Boolean }) required = false;
|
|
18
|
-
@property({ type: String }) name: string | null = null;
|
|
19
|
-
@property({ type: String }) autocomplete = "one-time-code";
|
|
20
|
-
@property({ type: String }) inputmode: "numeric" | "text" | null = null;
|
|
21
|
-
@property({ type: String }) pattern: string | null = null;
|
|
22
|
-
@property({ type: String, attribute: "aria-label" }) ariaLabel: string | null = null;
|
|
23
|
-
@property({ type: Boolean, reflect: true }) invalid = false;
|
|
24
|
-
@property({ type: Boolean, attribute: "show-separator" }) showSeparator = true;
|
|
25
|
-
// reflect: CSS targets :host([size="sm"|"lg"]) — without reflection,
|
|
26
|
-
// setting `el.size = "lg"` as a property silently applies no styles.
|
|
27
|
-
@property({ type: String, reflect: true }) size: "sm" | "md" | "lg" = "md";
|
|
28
|
-
|
|
29
|
-
@state() private cells: string[] = [];
|
|
30
|
-
@query(".hidden-input") private hiddenInput?: HTMLInputElement;
|
|
31
|
-
|
|
32
|
-
private isUpdatingFromValue = false;
|
|
33
|
-
|
|
34
|
-
static styles = css`
|
|
35
|
-
:host {
|
|
36
|
-
color: var(--rel-text-default);
|
|
37
|
-
display: inline-block;
|
|
38
|
-
font-family: var(--rel-fonts-font-family);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
:host([disabled]) {
|
|
42
|
-
opacity: 0.6;
|
|
43
|
-
cursor: not-allowed;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.otp-root {
|
|
47
|
-
display: inline-flex;
|
|
48
|
-
align-items: center;
|
|
49
|
-
gap: var(--rel-spacing-xs);
|
|
50
|
-
position: relative;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.otp-group {
|
|
54
|
-
display: flex;
|
|
55
|
-
gap: var(--rel-spacing-2xs);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.otp-separator {
|
|
59
|
-
display: flex;
|
|
60
|
-
align-items: center;
|
|
61
|
-
justify-content: center;
|
|
62
|
-
color: var(--rel-border-default);
|
|
63
|
-
user-select: none;
|
|
64
|
-
padding: 0 var(--rel-spacing-3xs);
|
|
65
|
-
font-family: var(--rel-action-xl-font-family);
|
|
66
|
-
font-weight: var(--rel-action-xl-font-weight);
|
|
67
|
-
font-size: var(--rel-action-xl-font-size);
|
|
68
|
-
line-height: var(--rel-action-xl-line-height);
|
|
69
|
-
letter-spacing: var(--rel-action-xl-letter-spacing);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.otp-separator.hidden {
|
|
73
|
-
display: none;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
.otp-cell {
|
|
77
|
-
width: 40px;
|
|
78
|
-
height: 48px;
|
|
79
|
-
border: var(--rel-stroke-sm) solid var(--rel-border-default);
|
|
80
|
-
border-radius: var(--rel-border-radius-sm);
|
|
81
|
-
background: var(--rel-bg-neutral);
|
|
82
|
-
text-align: center;
|
|
83
|
-
color: var(--rel-text-default);
|
|
84
|
-
outline: none;
|
|
85
|
-
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
86
|
-
caret-color: var(--rel-text-default);
|
|
87
|
-
font-family: var(--rel-body-lg-regular-font-family);
|
|
88
|
-
font-weight: var(--rel-body-lg-regular-font-weight);
|
|
89
|
-
font-size: var(--rel-body-lg-regular-font-size);
|
|
90
|
-
line-height: var(--rel-body-lg-regular-line-height);
|
|
91
|
-
letter-spacing: var(--rel-body-lg-regular-letter-spacing);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/* Size variants */
|
|
95
|
-
:host([size="sm"]) .otp-cell {
|
|
96
|
-
width: 36px;
|
|
97
|
-
height: 40px;
|
|
98
|
-
font-family: var(--rel-body-md-regular-font-family);
|
|
99
|
-
font-weight: var(--rel-body-md-regular-font-weight);
|
|
100
|
-
font-size: var(--rel-body-md-regular-font-size);
|
|
101
|
-
line-height: var(--rel-body-md-regular-line-height);
|
|
102
|
-
letter-spacing: var(--rel-body-md-regular-letter-spacing);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
:host([size="lg"]) .otp-cell {
|
|
106
|
-
width: 48px;
|
|
107
|
-
height: 56px;
|
|
108
|
-
font-family: var(--rel-body-xl-regular-font-family);
|
|
109
|
-
font-weight: var(--rel-body-xl-regular-font-weight);
|
|
110
|
-
font-size: var(--rel-body-xl-regular-font-size);
|
|
111
|
-
line-height: var(--rel-body-xl-regular-line-height);
|
|
112
|
-
letter-spacing: var(--rel-body-xl-regular-letter-spacing);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.otp-cell::placeholder {
|
|
116
|
-
color: var(--rel-text-body);
|
|
117
|
-
opacity: 0.6;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
.otp-cell:hover:not(:disabled):not(:read-only) {
|
|
121
|
-
border-color: var(--rel-border-strong);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.otp-cell:focus-visible {
|
|
125
|
-
border-color: var(--rel-border-accent);
|
|
126
|
-
box-shadow: 0 0 0 2px var(--rel-border-default);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.otp-cell:disabled {
|
|
130
|
-
background: var(--rel-bg-surface-elevated);
|
|
131
|
-
color: var(--rel-text-disabled);
|
|
132
|
-
cursor: not-allowed;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
:host([disabled]) .otp-cell {
|
|
136
|
-
cursor: not-allowed;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
.otp-cell:read-only {
|
|
140
|
-
background: var(--rel-bg-neutral-elevated-1);
|
|
141
|
-
cursor: default;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/* Invalid state */
|
|
145
|
-
:host([invalid]) .otp-cell {
|
|
146
|
-
border-color: var(--rel-border-danger);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
:host([invalid]) .otp-cell:focus {
|
|
150
|
-
border-color: var(--rel-border-danger);
|
|
151
|
-
box-shadow: 0 0 0 2px var(--rel-bg-danger-light);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
.hidden-input {
|
|
155
|
-
position: absolute;
|
|
156
|
-
opacity: 0;
|
|
157
|
-
pointer-events: none;
|
|
158
|
-
width: 1px;
|
|
159
|
-
height: 1px;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/* Reduce motion */
|
|
163
|
-
@media (prefers-reduced-motion: reduce) {
|
|
164
|
-
.otp-cell {
|
|
165
|
-
transition: none;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
`;
|
|
170
|
-
|
|
171
|
-
connectedCallback() {
|
|
172
|
-
super.connectedCallback();
|
|
173
|
-
this.initializeCells();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
updated(changedProperties: Map<string, any>) {
|
|
177
|
-
super.updated(changedProperties);
|
|
178
|
-
|
|
179
|
-
// Only sync from external value changes, not internal updates
|
|
180
|
-
if (changedProperties.has("value") && !this.isUpdatingFromValue) {
|
|
181
|
-
this.syncCellsFromValue();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (changedProperties.has("length")) {
|
|
185
|
-
this.initializeCells();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
private initializeCells() {
|
|
190
|
-
this.cells = new Array(this.length).fill("");
|
|
191
|
-
this.syncCellsFromValue();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private syncCellsFromValue() {
|
|
195
|
-
const chars = this.value.split("").slice(0, this.length);
|
|
196
|
-
this.cells = new Array(this.length).fill("").map((_, i) => chars[i] || "");
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
private updateValue() {
|
|
200
|
-
this.isUpdatingFromValue = true;
|
|
201
|
-
const newValue = this.cells.join("");
|
|
202
|
-
this.value = newValue;
|
|
203
|
-
|
|
204
|
-
// Update hidden input for forms
|
|
205
|
-
if (this.hiddenInput) {
|
|
206
|
-
this.hiddenInput.value = newValue;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.requestUpdate();
|
|
210
|
-
|
|
211
|
-
// Use setTimeout to ensure isUpdatingFromValue is reset after update cycle
|
|
212
|
-
setTimeout(() => {
|
|
213
|
-
this.isUpdatingFromValue = false;
|
|
214
|
-
}, 0);
|
|
215
|
-
|
|
216
|
-
const complete = newValue.length === this.length && this.isValidValue(newValue);
|
|
217
|
-
|
|
218
|
-
this.dispatchEvent(
|
|
219
|
-
new CustomEvent("rel-change", {
|
|
220
|
-
detail: { value: newValue, complete },
|
|
221
|
-
bubbles: true,
|
|
222
|
-
composed: true,
|
|
223
|
-
})
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
if (complete) {
|
|
227
|
-
this.dispatchEvent(
|
|
228
|
-
new CustomEvent("rel-complete", {
|
|
229
|
-
detail: { value: newValue },
|
|
230
|
-
bubbles: true,
|
|
231
|
-
composed: true,
|
|
232
|
-
})
|
|
233
|
-
);
|
|
234
|
-
announce("Code complete");
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private isValidChar(char: string): boolean {
|
|
239
|
-
if (this.type === "numeric") {
|
|
240
|
-
return /^\d$/.test(char);
|
|
241
|
-
} else {
|
|
242
|
-
return /^[0-9a-zA-Z]$/.test(char);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
private isValidValue(value: string): boolean {
|
|
247
|
-
if (this.type === "numeric") {
|
|
248
|
-
return /^\d+$/.test(value);
|
|
249
|
-
} else {
|
|
250
|
-
return /^[0-9a-zA-Z]+$/.test(value);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
private getNextEditableIndex(): number {
|
|
255
|
-
// Find first empty cell, or return last index if all filled
|
|
256
|
-
const emptyIndex = this.cells.findIndex((c) => !c);
|
|
257
|
-
return emptyIndex >= 0 ? emptyIndex : this.length - 1;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
private handlePointerDown(e: PointerEvent) {
|
|
261
|
-
if (this.disabled || this.readonly) return;
|
|
262
|
-
|
|
263
|
-
const input = e.currentTarget as HTMLInputElement;
|
|
264
|
-
const targetIndex = parseInt(input.dataset.index || "0", 10);
|
|
265
|
-
const nextEditableIndex = this.getNextEditableIndex();
|
|
266
|
-
|
|
267
|
-
// Prevent jumping ahead to empty cells
|
|
268
|
-
if (targetIndex > nextEditableIndex) {
|
|
269
|
-
e.preventDefault();
|
|
270
|
-
this.focusCell(nextEditableIndex);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
private handleInput(e: Event) {
|
|
275
|
-
if (this.disabled || this.readonly) return;
|
|
276
|
-
|
|
277
|
-
const input = e.currentTarget as HTMLInputElement;
|
|
278
|
-
const index = parseInt(input.dataset.index || "0", 10);
|
|
279
|
-
let inputValue = input.value;
|
|
280
|
-
|
|
281
|
-
// Handle autofill/paste on any cell (mobile OTP can inject full code)
|
|
282
|
-
if (inputValue.length > 1) {
|
|
283
|
-
this.handlePasteValue(inputValue, index);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Get only the last character typed (handles replace-on-type)
|
|
288
|
-
const char = inputValue.slice(-1);
|
|
289
|
-
|
|
290
|
-
if (char && !this.isValidChar(char)) {
|
|
291
|
-
// Invalid character, revert
|
|
292
|
-
input.value = this.cells[index] || "";
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Update cell (replace existing value)
|
|
297
|
-
this.cells[index] = char;
|
|
298
|
-
input.value = char;
|
|
299
|
-
|
|
300
|
-
this.updateValue();
|
|
301
|
-
|
|
302
|
-
// Auto-advance to next cell
|
|
303
|
-
if (char && index < this.length - 1) {
|
|
304
|
-
this.focusCell(index + 1);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
private handleKeyDown(e: KeyboardEvent) {
|
|
309
|
-
if (this.disabled || this.readonly) return;
|
|
310
|
-
|
|
311
|
-
const input = e.currentTarget as HTMLInputElement;
|
|
312
|
-
const index = parseInt(input.dataset.index || "0", 10);
|
|
313
|
-
|
|
314
|
-
switch (e.key) {
|
|
315
|
-
case "Backspace":
|
|
316
|
-
e.preventDefault();
|
|
317
|
-
if (this.cells[index]) {
|
|
318
|
-
// Clear current cell, keep focus
|
|
319
|
-
this.cells[index] = "";
|
|
320
|
-
input.value = "";
|
|
321
|
-
this.updateValue();
|
|
322
|
-
} else if (index > 0) {
|
|
323
|
-
// Move to previous cell and clear it
|
|
324
|
-
this.cells[index - 1] = "";
|
|
325
|
-
this.updateValue();
|
|
326
|
-
this.focusCell(index - 1);
|
|
327
|
-
}
|
|
328
|
-
break;
|
|
329
|
-
|
|
330
|
-
case "Delete":
|
|
331
|
-
e.preventDefault();
|
|
332
|
-
this.cells[index] = "";
|
|
333
|
-
input.value = "";
|
|
334
|
-
this.updateValue();
|
|
335
|
-
break;
|
|
336
|
-
|
|
337
|
-
case "ArrowLeft":
|
|
338
|
-
e.preventDefault();
|
|
339
|
-
if (index > 0) {
|
|
340
|
-
this.focusCell(index - 1);
|
|
341
|
-
}
|
|
342
|
-
break;
|
|
343
|
-
|
|
344
|
-
case "ArrowRight":
|
|
345
|
-
e.preventDefault();
|
|
346
|
-
if (index < this.length - 1) {
|
|
347
|
-
this.focusCell(index + 1);
|
|
348
|
-
}
|
|
349
|
-
break;
|
|
350
|
-
|
|
351
|
-
case "Home":
|
|
352
|
-
e.preventDefault();
|
|
353
|
-
this.focusCell(0);
|
|
354
|
-
break;
|
|
355
|
-
|
|
356
|
-
case "End":
|
|
357
|
-
e.preventDefault();
|
|
358
|
-
this.focusCell(this.length - 1);
|
|
359
|
-
break;
|
|
360
|
-
|
|
361
|
-
case "ArrowUp":
|
|
362
|
-
case "ArrowDown":
|
|
363
|
-
e.preventDefault();
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
private handlePaste(e: ClipboardEvent) {
|
|
369
|
-
if (this.disabled || this.readonly) return;
|
|
370
|
-
|
|
371
|
-
e.preventDefault();
|
|
372
|
-
|
|
373
|
-
const input = e.currentTarget as HTMLInputElement;
|
|
374
|
-
const index = parseInt(input.dataset.index || "0", 10);
|
|
375
|
-
const pastedText = e.clipboardData?.getData("text") || "";
|
|
376
|
-
|
|
377
|
-
this.handlePasteValue(pastedText, index);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
private handlePasteValue(text: string, startIndex: number) {
|
|
381
|
-
// Filter valid characters
|
|
382
|
-
const validChars = text.split("").filter((char) => this.isValidChar(char));
|
|
383
|
-
|
|
384
|
-
// Distribute characters starting from startIndex
|
|
385
|
-
let updateIndex = startIndex;
|
|
386
|
-
validChars.forEach((char) => {
|
|
387
|
-
if (updateIndex < this.length) {
|
|
388
|
-
this.cells[updateIndex] = char;
|
|
389
|
-
updateIndex++;
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
this.updateValue();
|
|
394
|
-
|
|
395
|
-
const filled = this.cells.filter((c) => c).length;
|
|
396
|
-
if (filled < this.length) {
|
|
397
|
-
announce(
|
|
398
|
-
`${filled} ${this.type === "alphanumeric" ? "characters" : "digits"} entered`
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// Focus next empty cell or last cell
|
|
403
|
-
const nextEmptyIndex = this.cells.findIndex((c, i) => i >= startIndex && !c);
|
|
404
|
-
if (nextEmptyIndex >= 0) {
|
|
405
|
-
this.focusCell(nextEmptyIndex);
|
|
406
|
-
} else {
|
|
407
|
-
this.focusCell(Math.min(updateIndex, this.length - 1));
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
private handleFocus(e: FocusEvent) {
|
|
412
|
-
const input = e.currentTarget as HTMLInputElement;
|
|
413
|
-
input.select();
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
private handleBlur() {
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
private focusCell(index: number) {
|
|
420
|
-
if (index < 0 || index >= this.length) return;
|
|
421
|
-
|
|
422
|
-
const input = this.renderRoot.querySelector(
|
|
423
|
-
`input[data-index="${index}"]`
|
|
424
|
-
) as HTMLInputElement | null;
|
|
425
|
-
|
|
426
|
-
if (input) {
|
|
427
|
-
input.focus();
|
|
428
|
-
input.select();
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
private getInputMode(): string {
|
|
433
|
-
if (this.inputmode) return this.inputmode;
|
|
434
|
-
return this.type === "numeric" ? "numeric" : "text";
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
private getAriaLabel(index: number): string {
|
|
438
|
-
const total = this.length;
|
|
439
|
-
const position = index + 1;
|
|
440
|
-
const label = this.type === "numeric" ? "Digit" : "Character";
|
|
441
|
-
return `${label} ${position} of ${total}`;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
private getGroups(): number[][] {
|
|
445
|
-
const groups: number[][] = [];
|
|
446
|
-
if (this.groupSize <= 0 || !this.showSeparator) {
|
|
447
|
-
// Single group with all cells
|
|
448
|
-
groups.push(Array.from({ length: this.length }, (_, i) => i));
|
|
449
|
-
} else {
|
|
450
|
-
// Multiple groups
|
|
451
|
-
for (let i = 0; i < this.length; i += this.groupSize) {
|
|
452
|
-
groups.push(
|
|
453
|
-
Array.from(
|
|
454
|
-
{ length: Math.min(this.groupSize, this.length - i) },
|
|
455
|
-
(_, j) => i + j
|
|
456
|
-
)
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return groups;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
render() {
|
|
464
|
-
const groups = this.getGroups();
|
|
465
|
-
|
|
466
|
-
return html`
|
|
467
|
-
<div
|
|
468
|
-
part="base root"
|
|
469
|
-
class="otp-root"
|
|
470
|
-
role="group"
|
|
471
|
-
aria-label="${this.ariaLabel || "One-time password input"}">
|
|
472
|
-
${groups.map(
|
|
473
|
-
(group, groupIndex) => html`
|
|
474
|
-
<div class="otp-group">
|
|
475
|
-
${group.map(
|
|
476
|
-
(index) => html`
|
|
477
|
-
<input
|
|
478
|
-
part="input cell"
|
|
479
|
-
class="otp-cell"
|
|
480
|
-
data-index="${index}"
|
|
481
|
-
type="${this.mask ? "password" : "text"}"
|
|
482
|
-
inputmode="${this.getInputMode()}"
|
|
483
|
-
autocomplete="one-time-code"
|
|
484
|
-
pattern="${this.pattern || ""}"
|
|
485
|
-
placeholder="${this.placeholder}"
|
|
486
|
-
maxlength="1"
|
|
487
|
-
.value="${this.cells[index] || ""}"
|
|
488
|
-
?disabled="${this.disabled}"
|
|
489
|
-
?readonly="${this.readonly}"
|
|
490
|
-
?required="${this.required && index === 0}"
|
|
491
|
-
aria-label="${this.getAriaLabel(index)}"
|
|
492
|
-
aria-invalid="${this.invalid ? "true" : nothing}"
|
|
493
|
-
@pointerdown="${this.handlePointerDown}"
|
|
494
|
-
@input="${this.handleInput}"
|
|
495
|
-
@keydown="${this.handleKeyDown}"
|
|
496
|
-
@paste="${this.handlePaste}"
|
|
497
|
-
@focus="${this.handleFocus}"
|
|
498
|
-
@blur="${this.handleBlur}"
|
|
499
|
-
/>
|
|
500
|
-
`
|
|
501
|
-
)}
|
|
502
|
-
</div>
|
|
503
|
-
${groupIndex < groups.length - 1
|
|
504
|
-
? html`<div part="separator" class="otp-separator">-</div>`
|
|
505
|
-
: ""}
|
|
506
|
-
`
|
|
507
|
-
)}
|
|
508
|
-
|
|
509
|
-
${this.name
|
|
510
|
-
? html`<input
|
|
511
|
-
part="hidden-input"
|
|
512
|
-
class="hidden-input"
|
|
513
|
-
type="hidden"
|
|
514
|
-
name="${this.name}"
|
|
515
|
-
.value="${this.value}"
|
|
516
|
-
/>`
|
|
517
|
-
: ""}
|
|
518
|
-
</div>
|
|
519
|
-
`;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
declare global {
|
|
524
|
-
interface HTMLElementTagNameMap {
|
|
525
|
-
"rel-otp": RelOtp;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./rel-pagination";
|