@internetarchive/elements 0.2.1-webdev-8162.1 → 0.2.1-webdev-8777.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.
Files changed (43) hide show
  1. package/README.md +208 -30
  2. package/dist/src/elements/ia-button/ia-button.d.ts +41 -3
  3. package/dist/src/elements/ia-button/ia-button.d.ts.map +1 -1
  4. package/dist/src/elements/ia-button/ia-button.js +350 -11
  5. package/dist/src/elements/ia-button/ia-button.js.map +1 -1
  6. package/dist/src/elements/ia-combo-box/ia-combo-box.d.ts +1 -1
  7. package/dist/src/elements/ia-combo-box/ia-combo-box.d.ts.map +1 -1
  8. package/dist/src/elements/ia-combo-box/ia-combo-box.js +7 -3
  9. package/dist/src/elements/ia-combo-box/ia-combo-box.js.map +1 -1
  10. package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.d.ts +68 -0
  11. package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.d.ts.map +1 -0
  12. package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.js +328 -0
  13. package/dist/src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.js.map +1 -0
  14. package/dist/src/elements/ia-dropdown-search-bar/models.d.ts +17 -0
  15. package/dist/src/elements/ia-dropdown-search-bar/models.d.ts.map +1 -0
  16. package/dist/src/elements/ia-dropdown-search-bar/models.js +2 -0
  17. package/dist/src/elements/ia-dropdown-search-bar/models.js.map +1 -0
  18. package/dist/src/elements/ia-dropdown-search-bar/search.svg +10 -0
  19. package/dist/src/elements/ia-otp-form/ia-otp-form.d.ts +21 -0
  20. package/dist/src/elements/ia-otp-form/ia-otp-form.d.ts.map +1 -0
  21. package/dist/src/elements/ia-otp-form/ia-otp-form.js +157 -0
  22. package/dist/src/elements/ia-otp-form/ia-otp-form.js.map +1 -0
  23. package/dist/src/elements/ia-otp-input/ia-otp-input.d.ts +35 -0
  24. package/dist/src/elements/ia-otp-input/ia-otp-input.d.ts.map +1 -0
  25. package/dist/src/elements/ia-otp-input/ia-otp-input.js +217 -0
  26. package/dist/src/elements/ia-otp-input/ia-otp-input.js.map +1 -0
  27. package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.d.ts +10 -0
  28. package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.d.ts.map +1 -0
  29. package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.js +43 -0
  30. package/dist/src/elements/ia-sr-only-text/ia-sr-only-text.js.map +1 -0
  31. package/dist/src/elements/ia-status-indicator/ia-status-indicator.d.ts +4 -1
  32. package/dist/src/elements/ia-status-indicator/ia-status-indicator.d.ts.map +1 -1
  33. package/dist/src/elements/ia-status-indicator/ia-status-indicator.js +10 -1
  34. package/dist/src/elements/ia-status-indicator/ia-status-indicator.js.map +1 -1
  35. package/dist/src/elements/index.d.ts +3 -2
  36. package/dist/src/elements/index.d.ts.map +1 -1
  37. package/dist/src/elements/index.js +3 -2
  38. package/dist/src/elements/index.js.map +1 -1
  39. package/dist/src/labs/ia-snow/ia-snow.js +3 -3
  40. package/dist/src/themes/theme-styles.d.ts.map +1 -1
  41. package/dist/src/themes/theme-styles.js +94 -0
  42. package/dist/src/themes/theme-styles.js.map +1 -1
  43. package/package.json +5 -3
@@ -0,0 +1,328 @@
1
+ import { __decorate } from "tslib";
2
+ import { msg } from '@lit/localize';
3
+ import { css, html, LitElement, nothing, } from 'lit';
4
+ import { customElement, property, query } from 'lit/decorators.js';
5
+ import themeStyles from '../../themes/theme-styles.js';
6
+ import searchIcon from './search.svg';
7
+ import '@internetarchive/ia-clearable-text-input';
8
+ import '@internetarchive/ia-dropdown';
9
+ import '../../elements/ia-status-indicator/ia-status-indicator.js';
10
+ /**
11
+ * Event names emitted by this component
12
+ */
13
+ const Events = {
14
+ CategoryChanged: 'categoryChanged',
15
+ SearchRequested: 'searchRequested',
16
+ };
17
+ let IADropdownSearchBar = class IADropdownSearchBar extends LitElement {
18
+ constructor() {
19
+ super(...arguments);
20
+ /** Dropdown menu options (tab IDs + labels) */
21
+ this.categories = [];
22
+ /** Placeholder text for the search input */
23
+ this.placeholder = msg('Search');
24
+ /** Whether to use the mobile layout */
25
+ this.useMobileView = false;
26
+ /** Whether to hide the category dropdown to the left of the search bar */
27
+ this.hideDropdown = false;
28
+ /** Whether the search button should show its loading state */
29
+ this.loading = false;
30
+ }
31
+ /** The effective selected category, falling back to the first in the list. */
32
+ get resolvedCategory() {
33
+ return this.selectedCategory ?? this.categories?.[0]?.id ?? '';
34
+ }
35
+ render() {
36
+ return html `
37
+ <div id="container" part="container" role="search">
38
+ <div
39
+ id="main-bar"
40
+ part="main-bar"
41
+ class=${this.hideDropdown ? 'no-dropdown' : nothing}
42
+ >
43
+ ${this.hideDropdown ? nothing : this.dropdownTemplate}
44
+ ${this.textBoxTemplate} ${this.searchButtonTemplate}
45
+ </div>
46
+ </div>
47
+ `;
48
+ }
49
+ willUpdate(changed) {
50
+ // Push new categories down to the inner dropdown immediately, since ia-dropdown
51
+ // mutates its own selected option on interaction which can cause Lit's
52
+ // property-binding diff to miss the change in certain cases.
53
+ if (changed.has('selectedCategory') || changed.has('categories')) {
54
+ const resolved = this.resolvedCategory;
55
+ if (this.categoryDropdown &&
56
+ this.categoryDropdown.selectedOption !== resolved) {
57
+ this.categoryDropdown.selectedOption = resolved;
58
+ }
59
+ }
60
+ }
61
+ /**
62
+ * Template for the category dropdown on the left side of the search bar.
63
+ */
64
+ get dropdownTemplate() {
65
+ return html `
66
+ <ia-dropdown
67
+ id="category-dropdown"
68
+ part="category-dropdown"
69
+ displayCaret
70
+ includeSelectedOption
71
+ closeOnSelect
72
+ closeOnEscape
73
+ closeOnBackdropClick
74
+ openViaButton
75
+ .selectedOption=${this.resolvedCategory}
76
+ .options=${this.categories}
77
+ @optionSelected=${this.handleCategorySelected}
78
+ >
79
+ <span slot="dropdown-label" part="category-dropdown-label"
80
+ >${this.selectedCategoryLabel}</span
81
+ >
82
+ </ia-dropdown>
83
+ `;
84
+ }
85
+ /**
86
+ * Template for the main text entry box of the search bar.
87
+ */
88
+ get textBoxTemplate() {
89
+ return html `
90
+ <ia-clearable-text-input
91
+ id="search-input"
92
+ part="search-input"
93
+ .value=${this.spacedQuery}
94
+ placeholder=${this.placeholder}
95
+ clearButtonScreenReaderLabel=${msg('Clear search query')}
96
+ screenReaderLabel=${msg('Search the Archive. Filters and Advanced Search available below.')}
97
+ @clear=${this.searchFieldCleared}
98
+ @submit=${this.handleSubmit}
99
+ ></ia-clearable-text-input>
100
+ `;
101
+ }
102
+ /**
103
+ * Template for the "magnifying glass" search button to the right of the search bar.
104
+ */
105
+ get searchButtonTemplate() {
106
+ return html `
107
+ <button
108
+ id="search-button"
109
+ part="search-button"
110
+ class=${this.loading ? 'loading' : nothing}
111
+ type="button"
112
+ aria-label=${msg('Search')}
113
+ @click=${this.handleSubmit}
114
+ >
115
+ ${this.loading
116
+ ? html `<ia-status-indicator
117
+ mode="loading"
118
+ class="search-button-loading-icon"
119
+ ></ia-status-indicator>`
120
+ : html `<img src=${searchIcon} alt="" />`}
121
+ </button>
122
+ `;
123
+ }
124
+ /**
125
+ * The display label for the currently selected category.
126
+ */
127
+ get selectedCategoryLabel() {
128
+ const match = this.categories.find((c) => c.id === this.resolvedCategory);
129
+ return match?.label ?? this.resolvedCategory;
130
+ }
131
+ /**
132
+ * The current search query with +'s replaced by spaces.
133
+ */
134
+ get spacedQuery() {
135
+ return this.query?.replace(/\+/g, ' ') ?? '';
136
+ }
137
+ /**
138
+ * Handler for when the search bar's clear button is pressed.
139
+ */
140
+ searchFieldCleared() {
141
+ if (this.query) {
142
+ this.emitSearchRequested();
143
+ }
144
+ }
145
+ /**
146
+ * Handler for Enter key or search button click.
147
+ */
148
+ handleSubmit() {
149
+ this.emitSearchRequested();
150
+ }
151
+ /**
152
+ * Handler for when the user selects a category from the dropdown.
153
+ *
154
+ * Sets `selectedCategory` locally for immediate visual feedback (semi-controlled
155
+ * pattern). The parent also binds this property and may re-set it on re-render.
156
+ */
157
+ handleCategorySelected(e) {
158
+ const newCategoryId = e.detail.option.id;
159
+ if (newCategoryId === this.resolvedCategory)
160
+ return;
161
+ this.selectedCategory = newCategoryId;
162
+ // On next tick, focus the text input bar (seemingly fails in Safari without the delay)
163
+ setTimeout(() => this.searchInput.focus());
164
+ this.dispatchEvent(new CustomEvent(Events.CategoryChanged, {
165
+ detail: newCategoryId,
166
+ }));
167
+ }
168
+ /**
169
+ * Emits a `searchRequested` event with the current query and category.
170
+ */
171
+ emitSearchRequested() {
172
+ this.dispatchEvent(new CustomEvent(Events.SearchRequested, {
173
+ detail: {
174
+ query: this.searchInput.value,
175
+ category: this.resolvedCategory,
176
+ },
177
+ }));
178
+ }
179
+ static get styles() {
180
+ const ownStyles = css `
181
+ :host {
182
+ --search-bar-height--: var(--search-bar-height, 30px);
183
+ --search-bar-width--: var(--search-bar-width, 300px);
184
+ --search-bar-internal-padding--: var(--padding-sm, 5px);
185
+ --clear-button-offset--: var(--clear-button-offset, 0);
186
+ --dropdown-z-index--: var(--dropdown-z-index, initial);
187
+ }
188
+
189
+ #container {
190
+ display: inline-block;
191
+ width: var(--search-bar-width--);
192
+ }
193
+
194
+ #main-bar {
195
+ display: flex;
196
+ height: var(--search-bar-height--, 30px);
197
+ flex: 1;
198
+ }
199
+
200
+ #category-dropdown {
201
+ display: flex;
202
+ flex-shrink: 0;
203
+ height: 100%;
204
+ box-sizing: border-box;
205
+
206
+ background-color: #f5f5f7;
207
+ border: 1px solid #999;
208
+ border-radius: 5px 0 0 5px;
209
+
210
+ --dropdownMainButtonPadding: 0 var(--search-bar-internal-padding--, 5px);
211
+ --dropdownBgColor: #2c2c2c;
212
+ --dropdownTextColor: #fff;
213
+ --dropdownBorderColor: #ddd;
214
+ --dropdownCaretColor: var(--ia-theme-primary-text-color, #2c2c2c);
215
+ --dropdownHoverBgColor: rgba(255, 255, 255, 0.3);
216
+ --dropdownHoverTextColor: #fff;
217
+ --dropdownSelectedBgColor: rgba(255, 255, 255, 0.3);
218
+ --dropdownSelectedTextColor: #fff;
219
+ --dropdownWhiteSpace: nowrap;
220
+ --dropdownOffsetTop: 2px;
221
+ --caretHeight: 8px;
222
+ --caretWidth: 12px;
223
+ --caretPadding: 0 0 0 5px;
224
+ --dropdownFontSize: inherit;
225
+ --dropdownBorderRadius: 4px;
226
+ --buttonSlotPaddingRight: 0;
227
+ --dropdownTextAlign: left;
228
+ --dropdownListZIndex: var(--dropdown-z-index--);
229
+ }
230
+
231
+ #category-dropdown [slot='dropdown-label'] {
232
+ color: var(--ia-theme-primary-text-color, #2c2c2c);
233
+ font-size: 1.4rem;
234
+ font-family: inherit;
235
+ white-space: nowrap;
236
+ }
237
+
238
+ .no-dropdown #search-input {
239
+ border-left: 1px solid #999;
240
+ border-radius: 5px 0 0 5px;
241
+ overflow: hidden;
242
+ }
243
+
244
+ #search-input {
245
+ width: 100%;
246
+ height: 100%;
247
+ box-sizing: border-box;
248
+ border-top: 1px solid #999;
249
+ border-bottom: 1px solid #999;
250
+ font-size: inherit;
251
+
252
+ --input-height: calc(var(--search-bar-height--) - 2px);
253
+ --input-padding: 0 var(--search-bar-internal-padding--, 5px);
254
+ --input-background-color: var(
255
+ --ia-theme-secondary-background-color,
256
+ #fff
257
+ );
258
+ --input-border-radius: 0;
259
+ --input-border-width: 0;
260
+ --input-box-shadow: none;
261
+ --input-focused-box-shadow: none;
262
+ --input-font-size: auto;
263
+ --clear-button-top: var(--clear-button-offset--, 0);
264
+ --clear-button-right: 2px;
265
+ }
266
+
267
+ #search-button {
268
+ appearance: none;
269
+ box-sizing: border-box;
270
+ border-radius: 0 5px 5px 0;
271
+ background-color: var(--ia-theme-secondary-background-color, #fff);
272
+ border: 1px solid #999;
273
+ border-left: 0;
274
+ padding: 0 var(--search-bar-internal-padding--, 5px) 0 5px;
275
+ min-width: 30px;
276
+ height: 100%;
277
+ cursor: pointer;
278
+ display: flex;
279
+ align-items: center;
280
+ justify-content: center;
281
+ flex-shrink: 0;
282
+ }
283
+
284
+ #search-button img {
285
+ width: 18px;
286
+ height: 18px;
287
+ }
288
+
289
+ .search-button-loading-icon {
290
+ --icon-width: 20px;
291
+ margin-top: 2px;
292
+ }
293
+ `;
294
+ return [themeStyles, ownStyles];
295
+ }
296
+ };
297
+ __decorate([
298
+ property({ type: String })
299
+ ], IADropdownSearchBar.prototype, "query", void 0);
300
+ __decorate([
301
+ property({ type: Array })
302
+ ], IADropdownSearchBar.prototype, "categories", void 0);
303
+ __decorate([
304
+ property({ type: String })
305
+ ], IADropdownSearchBar.prototype, "selectedCategory", void 0);
306
+ __decorate([
307
+ property({ type: String })
308
+ ], IADropdownSearchBar.prototype, "placeholder", void 0);
309
+ __decorate([
310
+ property({ type: Boolean })
311
+ ], IADropdownSearchBar.prototype, "useMobileView", void 0);
312
+ __decorate([
313
+ property({ type: Boolean })
314
+ ], IADropdownSearchBar.prototype, "hideDropdown", void 0);
315
+ __decorate([
316
+ property({ type: Boolean })
317
+ ], IADropdownSearchBar.prototype, "loading", void 0);
318
+ __decorate([
319
+ query('#search-input')
320
+ ], IADropdownSearchBar.prototype, "searchInput", void 0);
321
+ __decorate([
322
+ query('#category-dropdown')
323
+ ], IADropdownSearchBar.prototype, "categoryDropdown", void 0);
324
+ IADropdownSearchBar = __decorate([
325
+ customElement('ia-dropdown-search-bar')
326
+ ], IADropdownSearchBar);
327
+ export { IADropdownSearchBar };
328
+ //# sourceMappingURL=ia-dropdown-search-bar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ia-dropdown-search-bar.js","sourceRoot":"","sources":["../../../../src/elements/ia-dropdown-search-bar/ia-dropdown-search-bar.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EACL,GAAG,EACH,IAAI,EACJ,UAAU,EACV,OAAO,GAGR,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAKnE,OAAO,WAAW,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;KAiHpB,CAAC;QAEF,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAClC,CAAC;CACF,CAAA;AA5T6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAgB;AAGhB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;uDAAmC;AAGjC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6DAA2B;AAG1B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAA6B;AAG3B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;0DAAuB;AAGtB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;yDAAsB;AAGrB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;oDAAiB;AAGrC;IADP,KAAK,CAAC,eAAe,CAAC;wDACoB;AAGnC;IADP,KAAK,CAAC,oBAAoB,CAAC;6DACU;AA1B3B,mBAAmB;IAD/B,aAAa,CAAC,wBAAwB,CAAC;GAC3B,mBAAmB,CA8T/B","sourcesContent":["import { msg } from '@lit/localize';\nimport {\n css,\n html,\n LitElement,\n nothing,\n PropertyValues,\n TemplateResult,\n} from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport type { IaClearableTextInput } from '@internetarchive/ia-clearable-text-input';\nimport type { IaDropdown, optionInterface } from '@internetarchive/ia-dropdown';\nimport type { SearchCategory, SearchRequestedDetail } from './models';\n\nimport themeStyles from '@src/themes/theme-styles';\nimport searchIcon from './search.svg';\n\nimport '@internetarchive/ia-clearable-text-input';\nimport '@internetarchive/ia-dropdown';\nimport '@src/elements/ia-status-indicator/ia-status-indicator';\n\n/**\n * Event names emitted by this component\n */\nconst Events = {\n CategoryChanged: 'categoryChanged',\n SearchRequested: 'searchRequested',\n};\n\n@customElement('ia-dropdown-search-bar')\nexport class IADropdownSearchBar extends LitElement {\n /** The query that appears in the search bar */\n @property({ type: String }) query?: string;\n\n /** Dropdown menu options (tab IDs + labels) */\n @property({ type: Array }) categories: SearchCategory[] = [];\n\n /** The currently selected dropdown category ID */\n @property({ type: String }) selectedCategory?: string;\n\n /** Placeholder text for the search input */\n @property({ type: String }) placeholder = msg('Search');\n\n /** Whether to use the mobile layout */\n @property({ type: Boolean }) useMobileView = false;\n\n /** Whether to hide the category dropdown to the left of the search bar */\n @property({ type: Boolean }) hideDropdown = false;\n\n /** Whether the search button should show its loading state */\n @property({ type: Boolean }) loading = false;\n\n @query('#search-input')\n private searchInput!: IaClearableTextInput;\n\n @query('#category-dropdown')\n private categoryDropdown?: IaDropdown;\n\n /** The effective selected category, falling back to the first in the list. */\n private get resolvedCategory(): string {\n return this.selectedCategory ?? this.categories?.[0]?.id ?? '';\n }\n\n render(): TemplateResult {\n return html`\n <div id=\"container\" part=\"container\" role=\"search\">\n <div\n id=\"main-bar\"\n part=\"main-bar\"\n class=${this.hideDropdown ? 'no-dropdown' : nothing}\n >\n ${this.hideDropdown ? nothing : this.dropdownTemplate}\n ${this.textBoxTemplate} ${this.searchButtonTemplate}\n </div>\n </div>\n `;\n }\n\n willUpdate(changed: PropertyValues) {\n // Push new categories down to the inner dropdown immediately, since ia-dropdown\n // mutates its own selected option on interaction which can cause Lit's\n // property-binding diff to miss the change in certain cases.\n if (changed.has('selectedCategory') || changed.has('categories')) {\n const resolved = this.resolvedCategory;\n if (\n this.categoryDropdown &&\n this.categoryDropdown.selectedOption !== resolved\n ) {\n this.categoryDropdown.selectedOption = resolved;\n }\n }\n }\n\n /**\n * Template for the category dropdown on the left side of the search bar.\n */\n private get dropdownTemplate(): TemplateResult {\n return html`\n <ia-dropdown\n id=\"category-dropdown\"\n part=\"category-dropdown\"\n displayCaret\n includeSelectedOption\n closeOnSelect\n closeOnEscape\n closeOnBackdropClick\n openViaButton\n .selectedOption=${this.resolvedCategory}\n .options=${this.categories}\n @optionSelected=${this.handleCategorySelected}\n >\n <span slot=\"dropdown-label\" part=\"category-dropdown-label\"\n >${this.selectedCategoryLabel}</span\n >\n </ia-dropdown>\n `;\n }\n\n /**\n * Template for the main text entry box of the search bar.\n */\n private get textBoxTemplate(): TemplateResult {\n return html`\n <ia-clearable-text-input\n id=\"search-input\"\n part=\"search-input\"\n .value=${this.spacedQuery}\n placeholder=${this.placeholder}\n clearButtonScreenReaderLabel=${msg('Clear search query')}\n screenReaderLabel=${msg(\n 'Search the Archive. Filters and Advanced Search available below.',\n )}\n @clear=${this.searchFieldCleared}\n @submit=${this.handleSubmit}\n ></ia-clearable-text-input>\n `;\n }\n\n /**\n * Template for the \"magnifying glass\" search button to the right of the search bar.\n */\n private get searchButtonTemplate(): TemplateResult {\n return html`\n <button\n id=\"search-button\"\n part=\"search-button\"\n class=${this.loading ? 'loading' : nothing}\n type=\"button\"\n aria-label=${msg('Search')}\n @click=${this.handleSubmit}\n >\n ${this.loading\n ? html`<ia-status-indicator\n mode=\"loading\"\n class=\"search-button-loading-icon\"\n ></ia-status-indicator>`\n : html`<img src=${searchIcon} alt=\"\" />`}\n </button>\n `;\n }\n\n /**\n * The display label for the currently selected category.\n */\n private get selectedCategoryLabel(): string | TemplateResult {\n const match = this.categories.find((c) => c.id === this.resolvedCategory);\n return match?.label ?? this.resolvedCategory;\n }\n\n /**\n * The current search query with +'s replaced by spaces.\n */\n private get spacedQuery(): string {\n return this.query?.replace(/\\+/g, ' ') ?? '';\n }\n\n /**\n * Handler for when the search bar's clear button is pressed.\n */\n private searchFieldCleared(): void {\n if (this.query) {\n this.emitSearchRequested();\n }\n }\n\n /**\n * Handler for Enter key or search button click.\n */\n private handleSubmit(): void {\n this.emitSearchRequested();\n }\n\n /**\n * Handler for when the user selects a category from the dropdown.\n *\n * Sets `selectedCategory` locally for immediate visual feedback (semi-controlled\n * pattern). The parent also binds this property and may re-set it on re-render.\n */\n private handleCategorySelected(\n e: CustomEvent<{ option: optionInterface }>,\n ): void {\n const newCategoryId = e.detail.option.id;\n if (newCategoryId === this.resolvedCategory) return;\n\n this.selectedCategory = newCategoryId;\n\n // On next tick, focus the text input bar (seemingly fails in Safari without the delay)\n setTimeout(() => this.searchInput.focus());\n\n this.dispatchEvent(\n new CustomEvent<string>(Events.CategoryChanged, {\n detail: newCategoryId,\n }),\n );\n }\n\n /**\n * Emits a `searchRequested` event with the current query and category.\n */\n private emitSearchRequested(): void {\n this.dispatchEvent(\n new CustomEvent<SearchRequestedDetail>(Events.SearchRequested, {\n detail: {\n query: this.searchInput.value,\n category: this.resolvedCategory,\n },\n }),\n );\n }\n\n static get styles() {\n const ownStyles = css`\n :host {\n --search-bar-height--: var(--search-bar-height, 30px);\n --search-bar-width--: var(--search-bar-width, 300px);\n --search-bar-internal-padding--: var(--padding-sm, 5px);\n --clear-button-offset--: var(--clear-button-offset, 0);\n --dropdown-z-index--: var(--dropdown-z-index, initial);\n }\n\n #container {\n display: inline-block;\n width: var(--search-bar-width--);\n }\n\n #main-bar {\n display: flex;\n height: var(--search-bar-height--, 30px);\n flex: 1;\n }\n\n #category-dropdown {\n display: flex;\n flex-shrink: 0;\n height: 100%;\n box-sizing: border-box;\n\n background-color: #f5f5f7;\n border: 1px solid #999;\n border-radius: 5px 0 0 5px;\n\n --dropdownMainButtonPadding: 0 var(--search-bar-internal-padding--, 5px);\n --dropdownBgColor: #2c2c2c;\n --dropdownTextColor: #fff;\n --dropdownBorderColor: #ddd;\n --dropdownCaretColor: var(--ia-theme-primary-text-color, #2c2c2c);\n --dropdownHoverBgColor: rgba(255, 255, 255, 0.3);\n --dropdownHoverTextColor: #fff;\n --dropdownSelectedBgColor: rgba(255, 255, 255, 0.3);\n --dropdownSelectedTextColor: #fff;\n --dropdownWhiteSpace: nowrap;\n --dropdownOffsetTop: 2px;\n --caretHeight: 8px;\n --caretWidth: 12px;\n --caretPadding: 0 0 0 5px;\n --dropdownFontSize: inherit;\n --dropdownBorderRadius: 4px;\n --buttonSlotPaddingRight: 0;\n --dropdownTextAlign: left;\n --dropdownListZIndex: var(--dropdown-z-index--);\n }\n\n #category-dropdown [slot='dropdown-label'] {\n color: var(--ia-theme-primary-text-color, #2c2c2c);\n font-size: 1.4rem;\n font-family: inherit;\n white-space: nowrap;\n }\n\n .no-dropdown #search-input {\n border-left: 1px solid #999;\n border-radius: 5px 0 0 5px;\n overflow: hidden;\n }\n\n #search-input {\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n border-top: 1px solid #999;\n border-bottom: 1px solid #999;\n font-size: inherit;\n\n --input-height: calc(var(--search-bar-height--) - 2px);\n --input-padding: 0 var(--search-bar-internal-padding--, 5px);\n --input-background-color: var(\n --ia-theme-secondary-background-color,\n #fff\n );\n --input-border-radius: 0;\n --input-border-width: 0;\n --input-box-shadow: none;\n --input-focused-box-shadow: none;\n --input-font-size: auto;\n --clear-button-top: var(--clear-button-offset--, 0);\n --clear-button-right: 2px;\n }\n\n #search-button {\n appearance: none;\n box-sizing: border-box;\n border-radius: 0 5px 5px 0;\n background-color: var(--ia-theme-secondary-background-color, #fff);\n border: 1px solid #999;\n border-left: 0;\n padding: 0 var(--search-bar-internal-padding--, 5px) 0 5px;\n min-width: 30px;\n height: 100%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n }\n\n #search-button img {\n width: 18px;\n height: 18px;\n }\n\n .search-button-loading-icon {\n --icon-width: 20px;\n margin-top: 2px;\n }\n `;\n\n return [themeStyles, ownStyles];\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { TemplateResult } from 'lit';
2
+ /**
3
+ * A category to include in the dropdown. Consists of an internal `id` string that is
4
+ * emitted on selection, and a human-readable `label` to display in the dropdown.
5
+ */
6
+ export type SearchCategory = {
7
+ id: string;
8
+ label: string | TemplateResult;
9
+ };
10
+ /**
11
+ * Detail object emitted with `searchRequested` events.
12
+ */
13
+ export type SearchRequestedDetail = {
14
+ query: string;
15
+ category: string;
16
+ };
17
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-dropdown-search-bar/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/elements/ia-dropdown-search-bar/models.ts"],"names":[],"mappings":"","sourcesContent":["import { TemplateResult } from 'lit';\n\n/**\n * A category to include in the dropdown. Consists of an internal `id` string that is\n * emitted on selection, and a human-readable `label` to display in the dropdown.\n */\nexport type SearchCategory = {\n id: string;\n label: string | TemplateResult;\n};\n\n/**\n * Detail object emitted with `searchRequested` events.\n */\nexport type SearchRequestedDetail = {\n query: string;\n category: string;\n};\n"]}
@@ -0,0 +1,10 @@
1
+ <svg
2
+ viewBox="0 0 100 100"
3
+ xmlns="http://www.w3.org/2000/svg">
4
+ <path
5
+ class="fill-color"
6
+ d="m17.0555551 41.3194459c0-12.7430552 10.3541664-23.1027772 23.0847216-23.1027772 12.7166664 0 23.0777773 10.359722 23.0777773 23.1027772 0 12.7361108-10.3611109 23.0986106-23.0777773 23.0986106-12.7305552 0-23.0847216-10.3624998-23.0847216-23.0986106zm-17.24305512 0c0 22.2916661 18.04583292 40.3472213 40.32777672 40.3472213 8.9208332 0 17.145833-2.9319449 23.8194439-7.8527776l24.1513883 24.0777771c1.2125 1.1402778 2.8430555 1.8430556 4.6374999 1.8430556 3.7444443 0 6.7805554-3.0361111 6.7805554-6.7791665 0-2.0652778-.9222222-3.9069444-2.3736111-5.1499999l-23.718055-23.7458328c4.4152777-6.4791665 7.0152776-14.3055552 7.0152776-22.7402772 0-22.2791661-18.0458328-40.34861006-40.312499-40.34861006-22.2819438 0-40.32777672 18.06944396-40.32777672 40.34861006z"
7
+ fill="#2c2c2c"
8
+ fill-rule="evenodd"
9
+ />
10
+ </svg>
@@ -0,0 +1,21 @@
1
+ import { LitElement, TemplateResult, CSSResultGroup, PropertyValues } from 'lit';
2
+ import type { LoadingStatus } from '../../elements/ia-status-indicator/ia-status-indicator.js';
3
+ import '../../elements/ia-status-indicator/ia-status-indicator.js';
4
+ import '../../elements/ia-otp-input/ia-otp-input.js';
5
+ import '../../elements/ia-button/ia-button.js';
6
+ /**
7
+ * Form for entering OTP codes, including success/loading/error states and a request new code button
8
+ */
9
+ export declare class IAOTPForm extends LitElement {
10
+ validationStatus: LoadingStatus;
11
+ newCodeSending: boolean;
12
+ numPasscodeChars: number;
13
+ numericOnly: boolean;
14
+ private OTPInput;
15
+ render(): TemplateResult;
16
+ protected willUpdate(changed: PropertyValues): void;
17
+ private get resendCodeButtonTemplate();
18
+ private handleNewCodeRequested;
19
+ static get styles(): CSSResultGroup;
20
+ }
21
+ //# sourceMappingURL=ia-otp-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ia-otp-form.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-otp-form/ia-otp-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,cAAc,EACd,cAAc,EAGd,cAAc,EACf,MAAM,KAAK,CAAC;AAOb,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uDAAuD,CAAC;AAE3F,OAAO,uDAAuD,CAAC;AAC/D,OAAO,yCAAyC,CAAC;AACjD,OAAO,mCAAmC,CAAC;AAU3C;;GAEG;AACH,qBACa,SAAU,SAAQ,UAAU;IAGvC,gBAAgB,EAAE,aAAa,CAAW;IAI1C,cAAc,EAAE,OAAO,CAAS;IAIhC,gBAAgB,EAAE,MAAM,CAAK;IAI7B,WAAW,EAAE,OAAO,CAAQ;IAG5B,OAAO,CAAC,QAAQ,CAAc;IAE9B,MAAM,IAAI,cAAc;IAuBxB,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAenD,OAAO,KAAK,wBAAwB,GAiBnC;YAGa,sBAAsB;IAUpC,MAAM,KAAK,MAAM,IAAI,cAAc,CA8ClC;CACF"}
@@ -0,0 +1,157 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement, css, nothing, } from 'lit';
3
+ import { msg } from '@lit/localize';
4
+ import { property, customElement, query } from 'lit/decorators.js';
5
+ import themeStyles from '../../themes/theme-styles.js';
6
+ import '../../elements/ia-status-indicator/ia-status-indicator.js';
7
+ import '../../elements/ia-otp-input/ia-otp-input.js';
8
+ import '../../elements/ia-button/ia-button.js';
9
+ /**
10
+ * Custom events fired by the component
11
+ */
12
+ const Events = {
13
+ NewCodeRequested: 'newCodeRequested',
14
+ CodeSubmitted: 'codeSubmitted', // Bubbles up from ia-otp-input
15
+ };
16
+ /**
17
+ * Form for entering OTP codes, including success/loading/error states and a request new code button
18
+ */
19
+ let IAOTPForm = class IAOTPForm extends LitElement {
20
+ constructor() {
21
+ super(...arguments);
22
+ /* The state of the validation process */
23
+ this.validationStatus = 'ready';
24
+ /* Whether to display a loading indicator instead of the button text */
25
+ this.newCodeSending = false;
26
+ /* Number of characters to expect for the passcode */
27
+ this.numPasscodeChars = 6;
28
+ /* Whether to restrict entry to numeric characters */
29
+ this.numericOnly = true;
30
+ }
31
+ render() {
32
+ return html `
33
+ <div class="input-section">
34
+ <ia-otp-input
35
+ .numChars=${this.numPasscodeChars}
36
+ ?numericOnly=${this.numericOnly}
37
+ ?disabled=${this.validationStatus === 'loading' ||
38
+ this.validationStatus === 'success'}
39
+ ></ia-otp-input>
40
+ <ia-status-indicator
41
+ part="status-indicator"
42
+ .mode=${this.validationStatus}
43
+ ></ia-status-indicator>
44
+ </div>
45
+ ${this.validationStatus === 'error'
46
+ ? html `<p class="error-msg">
47
+ ${msg('The code entered is invalid or expired')}
48
+ </p>`
49
+ : nothing}
50
+ ${this.resendCodeButtonTemplate}
51
+ `;
52
+ }
53
+ willUpdate(changed) {
54
+ if (changed.has('validationStatus') &&
55
+ this.OTPInput &&
56
+ this.validationStatus === 'error') {
57
+ this.OTPInput.prefillValue = '';
58
+ }
59
+ if (changed.has('newCodeSending') && this.newCodeSending && this.OTPInput) {
60
+ this.OTPInput.prefillValue = '';
61
+ }
62
+ }
63
+ /* The button to display to send a new code */
64
+ get resendCodeButtonTemplate() {
65
+ return this.newCodeSending
66
+ ? html `<span part="new-code-message" class="new-code-msg"
67
+ >${msg('Emailing...')}</span
68
+ >`
69
+ : html `
70
+ <ia-button
71
+ mode="link"
72
+ class="new-code-btn"
73
+ part="new-code-button"
74
+ .disabled=${this.validationStatus === 'loading' ||
75
+ this.validationStatus === 'success'}
76
+ @click=${this.handleNewCodeRequested}
77
+ >
78
+ ${msg('Email me another code')}
79
+ </ia-button>
80
+ `;
81
+ }
82
+ /* Emits an event to request the new code */
83
+ async handleNewCodeRequested() {
84
+ this.dispatchEvent(new CustomEvent(Events.NewCodeRequested, {
85
+ bubbles: true,
86
+ composed: true,
87
+ }));
88
+ this.OTPInput.prefillValue = '';
89
+ }
90
+ static get styles() {
91
+ return [
92
+ themeStyles,
93
+ css `
94
+ :host {
95
+ --font-size-standard--: var(--font-size-standard);
96
+ --font-size-lg--: var(--font-size-lg);
97
+ --color-success--: var(--color-success);
98
+ --color-danger--: var(--color-danger);
99
+ --link-color--: var(--link-color);
100
+
101
+ display: flex;
102
+ flex-direction: column;
103
+ align-items: center;
104
+ justify-content: center;
105
+ }
106
+
107
+ .input-section {
108
+ display: flex;
109
+ flex-direction: row;
110
+ align-items: center;
111
+ justify-content: center;
112
+ gap: 5px;
113
+ }
114
+
115
+ ia-status-indicator {
116
+ --icon-width: calc(var(--font-size-lg--) * 1.33);
117
+ }
118
+
119
+ .error-msg {
120
+ margin-top: 10px;
121
+ font-size: var(--font-size-standard--);
122
+ color: var(--color-danger--);
123
+ margin-bottom: -10px;
124
+ }
125
+
126
+ .new-code-msg {
127
+ margin-top: 10px;
128
+ font-size: var(--font-size-standard--);
129
+ color: var(--link-color--);
130
+ display: flex;
131
+ flex-direction: column;
132
+ justify-content: center;
133
+ }
134
+ `,
135
+ ];
136
+ }
137
+ };
138
+ __decorate([
139
+ property({ type: String })
140
+ ], IAOTPForm.prototype, "validationStatus", void 0);
141
+ __decorate([
142
+ property({ type: Boolean })
143
+ ], IAOTPForm.prototype, "newCodeSending", void 0);
144
+ __decorate([
145
+ property({ type: Number })
146
+ ], IAOTPForm.prototype, "numPasscodeChars", void 0);
147
+ __decorate([
148
+ property({ type: Boolean })
149
+ ], IAOTPForm.prototype, "numericOnly", void 0);
150
+ __decorate([
151
+ query('ia-otp-input')
152
+ ], IAOTPForm.prototype, "OTPInput", void 0);
153
+ IAOTPForm = __decorate([
154
+ customElement('ia-otp-form')
155
+ ], IAOTPForm);
156
+ export { IAOTPForm };
157
+ //# sourceMappingURL=ia-otp-form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ia-otp-form.js","sourceRoot":"","sources":["../../../../src/elements/ia-otp-form/ia-otp-form.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EAGV,GAAG,EACH,OAAO,GAER,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,WAAW,MAAM,0BAA0B,CAAC;AAKnD,OAAO,uDAAuD,CAAC;AAC/D,OAAO,yCAAyC,CAAC;AACjD,OAAO,mCAAmC,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,GAAG;IACb,gBAAgB,EAAE,kBA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CAAC,aAAa,CAAC;UACrB;YACJ,CAAC,CAAC,IAAI,CAAA;;;;;wBAKY,IAAI,CAAC,gBAAgB,KAAK,SAAS;gBAC/C,IAAI,CAAC,gBAAgB,KAAK,SAAS;qBAC1B,IAAI,CAAC,sBAAsB;;cAElC,GAAG,CAAC,uBAAuB,CAAC;;SAEjC,CAAC;IACR,CAAC;IAED,4CAA4C;IACpC,KAAK,CAAC,sBAAsB;QAClC,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE;YACvC,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CACH,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,YAAY,GAAG,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO;YACL,WAAW;YACX,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AApIC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mDACe;AAI1C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iDACI;AAIhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mDACE;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;8CACA;AAGpB;IADP,KAAK,CAAC,cAAc,CAAC;2CACQ;AAlBnB,SAAS;IADrB,aAAa,CAAC,aAAa,CAAC;GAChB,SAAS,CAuIrB","sourcesContent":["import {\n html,\n LitElement,\n TemplateResult,\n CSSResultGroup,\n css,\n nothing,\n PropertyValues,\n} from 'lit';\nimport { msg } from '@lit/localize';\nimport { property, customElement, query } from 'lit/decorators.js';\n\nimport themeStyles from '@src/themes/theme-styles';\n\nimport type { IAOTPInput } from '@src/elements/ia-otp-input/ia-otp-input';\nimport type { LoadingStatus } from '@src/elements/ia-status-indicator/ia-status-indicator';\n\nimport '@src/elements/ia-status-indicator/ia-status-indicator';\nimport '@src/elements/ia-otp-input/ia-otp-input';\nimport '@src/elements/ia-button/ia-button';\n\n/**\n * Custom events fired by the component\n */\nconst Events = {\n NewCodeRequested: 'newCodeRequested',\n CodeSubmitted: 'codeSubmitted', // Bubbles up from ia-otp-input\n};\n\n/**\n * Form for entering OTP codes, including success/loading/error states and a request new code button\n */\n@customElement('ia-otp-form')\nexport class IAOTPForm extends LitElement {\n /* The state of the validation process */\n @property({ type: String })\n validationStatus: LoadingStatus = 'ready';\n\n /* Whether to display a loading indicator instead of the button text */\n @property({ type: Boolean })\n newCodeSending: boolean = false;\n\n /* Number of characters to expect for the passcode */\n @property({ type: Number })\n numPasscodeChars: number = 6;\n\n /* Whether to restrict entry to numeric characters */\n @property({ type: Boolean })\n numericOnly: boolean = true;\n\n @query('ia-otp-input')\n private OTPInput!: IAOTPInput;\n\n render(): TemplateResult {\n return html`\n <div class=\"input-section\">\n <ia-otp-input\n .numChars=${this.numPasscodeChars}\n ?numericOnly=${this.numericOnly}\n ?disabled=${this.validationStatus === 'loading' ||\n this.validationStatus === 'success'}\n ></ia-otp-input>\n <ia-status-indicator\n part=\"status-indicator\"\n .mode=${this.validationStatus}\n ></ia-status-indicator>\n </div>\n ${this.validationStatus === 'error'\n ? html`<p class=\"error-msg\">\n ${msg('The code entered is invalid or expired')}\n </p>`\n : nothing}\n ${this.resendCodeButtonTemplate}\n `;\n }\n\n protected willUpdate(changed: PropertyValues): void {\n if (\n changed.has('validationStatus') &&\n this.OTPInput &&\n this.validationStatus === 'error'\n ) {\n this.OTPInput.prefillValue = '';\n }\n\n if (changed.has('newCodeSending') && this.newCodeSending && this.OTPInput) {\n this.OTPInput.prefillValue = '';\n }\n }\n\n /* The button to display to send a new code */\n private get resendCodeButtonTemplate(): TemplateResult {\n return this.newCodeSending\n ? html`<span part=\"new-code-message\" class=\"new-code-msg\"\n >${msg('Emailing...')}</span\n >`\n : html`\n <ia-button\n mode=\"link\"\n class=\"new-code-btn\"\n part=\"new-code-button\"\n .disabled=${this.validationStatus === 'loading' ||\n this.validationStatus === 'success'}\n @click=${this.handleNewCodeRequested}\n >\n ${msg('Email me another code')}\n </ia-button>\n `;\n }\n\n /* Emits an event to request the new code */\n private async handleNewCodeRequested(): Promise<void> {\n this.dispatchEvent(\n new CustomEvent(Events.NewCodeRequested, {\n bubbles: true,\n composed: true,\n }),\n );\n this.OTPInput.prefillValue = '';\n }\n\n static get styles(): CSSResultGroup {\n return [\n themeStyles,\n css`\n :host {\n --font-size-standard--: var(--font-size-standard);\n --font-size-lg--: var(--font-size-lg);\n --color-success--: var(--color-success);\n --color-danger--: var(--color-danger);\n --link-color--: var(--link-color);\n\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n\n .input-section {\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n gap: 5px;\n }\n\n ia-status-indicator {\n --icon-width: calc(var(--font-size-lg--) * 1.33);\n }\n\n .error-msg {\n margin-top: 10px;\n font-size: var(--font-size-standard--);\n color: var(--color-danger--);\n margin-bottom: -10px;\n }\n\n .new-code-msg {\n margin-top: 10px;\n font-size: var(--font-size-standard--);\n color: var(--link-color--);\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n `,\n ];\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { LitElement, TemplateResult, CSSResultGroup, PropertyValues } from 'lit';
2
+ /**
3
+ * Renders an input for OTP entry, which combines a series of separate
4
+ * inputs into one, shifting focus as needed and handling paste and backspace
5
+ * events.
6
+ */
7
+ export declare class IAOTPInput extends LitElement {
8
+ prefillValue?: string;
9
+ disabled: boolean;
10
+ numChars: number;
11
+ numericOnly: boolean;
12
+ private allowedChars;
13
+ private inputs;
14
+ render(): TemplateResult;
15
+ protected firstUpdated(): void;
16
+ protected willUpdate(changed: PropertyValues): void;
17
+ private handleInput;
18
+ private handleKeydown;
19
+ /**
20
+ * Transmits pasted data to the input-filling function
21
+ */
22
+ private handlePaste;
23
+ /**
24
+ * Fills as many inputs as possible with the specified value, starting from the beginning.
25
+ * Submits the result if enough characters are filled.
26
+ */
27
+ private fillInputs;
28
+ /** Clears all inputs and returns focus to first input */
29
+ private clearInputs;
30
+ /** Checks whether all inputs are filled and submits if so */
31
+ private submitIfInputsFilled;
32
+ private triggerSubmit;
33
+ static get styles(): CSSResultGroup;
34
+ }
35
+ //# sourceMappingURL=ia-otp-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ia-otp-input.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-otp-input/ia-otp-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,cAAc,EACd,cAAc,EAEd,cAAc,EACf,MAAM,KAAK,CAAC;AAcb;;;;GAIG;AACH,qBACa,UAAW,SAAQ,UAAU;IAGxC,YAAY,CAAC,EAAE,MAAM,CAAC;IAItB,QAAQ,EAAE,OAAO,CAAS;IAI1B,QAAQ,EAAE,MAAM,CAAK;IAIrB,WAAW,EAAE,OAAO,CAAQ;IAI5B,OAAO,CAAC,YAAY,CAAyB;IAI7C,OAAO,CAAC,MAAM,CAAgC;IAE9C,MAAM,IAAI,cAAc;IAmBxB,SAAS,CAAC,YAAY,IAAI,IAAI;IAI9B,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAYnD,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,aAAa;IAmCrB;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAuBlB,yDAAyD;IACzD,OAAO,CAAC,WAAW;IAKnB,6DAA6D;IAC7D,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,aAAa;IAUrB,MAAM,KAAK,MAAM,IAAI,cAAc,CA4BlC;CACF"}