@firstprateek/vastu 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +52 -2
  3. package/custom-elements.json +3737 -0
  4. package/dist/dev/all.d.ts +12 -0
  5. package/dist/dev/all.d.ts.map +1 -0
  6. package/dist/dev/all.js +13 -0
  7. package/dist/dev/all.js.map +1 -0
  8. package/dist/dev/bar-chart/bar-chart.d.ts +63 -0
  9. package/dist/dev/bar-chart/bar-chart.d.ts.map +1 -0
  10. package/dist/dev/bar-chart/bar-chart.js +316 -0
  11. package/dist/dev/bar-chart/bar-chart.js.map +1 -0
  12. package/dist/dev/bar-chart/index.d.ts +3 -0
  13. package/dist/dev/bar-chart/index.d.ts.map +1 -0
  14. package/dist/dev/bar-chart/index.js +5 -0
  15. package/dist/dev/bar-chart/index.js.map +1 -0
  16. package/dist/dev/button/button.d.ts +98 -0
  17. package/dist/dev/button/button.d.ts.map +1 -0
  18. package/dist/dev/button/button.js +292 -0
  19. package/dist/dev/button/button.js.map +1 -0
  20. package/dist/dev/button/index.d.ts +4 -0
  21. package/dist/dev/button/index.d.ts.map +1 -0
  22. package/dist/dev/button/index.js +5 -0
  23. package/dist/dev/button/index.js.map +1 -0
  24. package/dist/dev/checkbox/checkbox.d.ts +71 -0
  25. package/dist/dev/checkbox/checkbox.d.ts.map +1 -0
  26. package/dist/dev/checkbox/checkbox.js +232 -0
  27. package/dist/dev/checkbox/checkbox.js.map +1 -0
  28. package/dist/dev/checkbox/index.d.ts +3 -0
  29. package/dist/dev/checkbox/index.d.ts.map +1 -0
  30. package/dist/dev/checkbox/index.js +5 -0
  31. package/dist/dev/checkbox/index.js.map +1 -0
  32. package/dist/dev/core/cssom.d.ts +15 -0
  33. package/dist/dev/core/cssom.d.ts.map +1 -0
  34. package/dist/dev/core/cssom.js +30 -0
  35. package/dist/dev/core/cssom.js.map +1 -0
  36. package/dist/dev/core/define.d.ts +3 -0
  37. package/dist/dev/core/define.d.ts.map +1 -0
  38. package/dist/dev/core/define.js +6 -0
  39. package/dist/dev/core/define.js.map +1 -0
  40. package/dist/dev/core/dev-mode.d.ts +6 -0
  41. package/dist/dev/core/dev-mode.d.ts.map +1 -0
  42. package/dist/dev/core/dev-mode.js +6 -0
  43. package/dist/dev/core/dev-mode.js.map +1 -0
  44. package/dist/dev/core/focus-ring.d.ts +3 -0
  45. package/dist/dev/core/focus-ring.d.ts.map +1 -0
  46. package/dist/dev/core/focus-ring.js +14 -0
  47. package/dist/dev/core/focus-ring.js.map +1 -0
  48. package/dist/dev/core/form-control.d.ts +47 -0
  49. package/dist/dev/core/form-control.d.ts.map +1 -0
  50. package/dist/dev/core/form-control.js +75 -0
  51. package/dist/dev/core/form-control.js.map +1 -0
  52. package/dist/dev/core/warn.d.ts +12 -0
  53. package/dist/dev/core/warn.d.ts.map +1 -0
  54. package/dist/dev/core/warn.js +35 -0
  55. package/dist/dev/core/warn.js.map +1 -0
  56. package/dist/dev/dialog/dialog.d.ts +77 -0
  57. package/dist/dev/dialog/dialog.d.ts.map +1 -0
  58. package/dist/dev/dialog/dialog.js +253 -0
  59. package/dist/dev/dialog/dialog.js.map +1 -0
  60. package/dist/dev/dialog/index.d.ts +4 -0
  61. package/dist/dev/dialog/index.d.ts.map +1 -0
  62. package/dist/dev/dialog/index.js +5 -0
  63. package/dist/dev/dialog/index.js.map +1 -0
  64. package/dist/dev/menu/index.d.ts +3 -0
  65. package/dist/dev/menu/index.d.ts.map +1 -0
  66. package/dist/dev/menu/index.js +5 -0
  67. package/dist/dev/menu/index.js.map +1 -0
  68. package/dist/dev/menu/menu.d.ts +71 -0
  69. package/dist/dev/menu/menu.d.ts.map +1 -0
  70. package/dist/dev/menu/menu.js +330 -0
  71. package/dist/dev/menu/menu.js.map +1 -0
  72. package/dist/dev/navbar/index.d.ts +3 -0
  73. package/dist/dev/navbar/index.d.ts.map +1 -0
  74. package/dist/dev/navbar/index.js +5 -0
  75. package/dist/dev/navbar/index.js.map +1 -0
  76. package/dist/dev/navbar/navbar.d.ts +69 -0
  77. package/dist/dev/navbar/navbar.d.ts.map +1 -0
  78. package/dist/dev/navbar/navbar.js +353 -0
  79. package/dist/dev/navbar/navbar.js.map +1 -0
  80. package/dist/dev/poll/index.d.ts +3 -0
  81. package/dist/dev/poll/index.d.ts.map +1 -0
  82. package/dist/dev/poll/index.js +5 -0
  83. package/dist/dev/poll/index.js.map +1 -0
  84. package/dist/dev/poll/poll.d.ts +67 -0
  85. package/dist/dev/poll/poll.d.ts.map +1 -0
  86. package/dist/dev/poll/poll.js +301 -0
  87. package/dist/dev/poll/poll.js.map +1 -0
  88. package/dist/dev/switch/index.d.ts +3 -0
  89. package/dist/dev/switch/index.d.ts.map +1 -0
  90. package/dist/dev/switch/index.js +5 -0
  91. package/dist/dev/switch/index.js.map +1 -0
  92. package/dist/dev/switch/switch.d.ts +69 -0
  93. package/dist/dev/switch/switch.d.ts.map +1 -0
  94. package/dist/dev/switch/switch.js +213 -0
  95. package/dist/dev/switch/switch.js.map +1 -0
  96. package/dist/dev/tabs/index.d.ts +3 -0
  97. package/dist/dev/tabs/index.d.ts.map +1 -0
  98. package/dist/dev/tabs/index.js +5 -0
  99. package/dist/dev/tabs/index.js.map +1 -0
  100. package/dist/dev/tabs/tabs.d.ts +64 -0
  101. package/dist/dev/tabs/tabs.d.ts.map +1 -0
  102. package/dist/dev/tabs/tabs.js +212 -0
  103. package/dist/dev/tabs/tabs.js.map +1 -0
  104. package/dist/dev/text-field/index.d.ts +3 -0
  105. package/dist/dev/text-field/index.d.ts.map +1 -0
  106. package/dist/dev/text-field/index.js +5 -0
  107. package/dist/dev/text-field/index.js.map +1 -0
  108. package/dist/dev/text-field/text-field.d.ts +91 -0
  109. package/dist/dev/text-field/text-field.d.ts.map +1 -0
  110. package/dist/dev/text-field/text-field.js +267 -0
  111. package/dist/dev/text-field/text-field.js.map +1 -0
  112. package/dist/dev/toast/index.d.ts +4 -0
  113. package/dist/dev/toast/index.d.ts.map +1 -0
  114. package/dist/dev/toast/index.js +5 -0
  115. package/dist/dev/toast/index.js.map +1 -0
  116. package/dist/dev/toast/toast.d.ts +71 -0
  117. package/dist/dev/toast/toast.d.ts.map +1 -0
  118. package/dist/dev/toast/toast.js +258 -0
  119. package/dist/dev/toast/toast.js.map +1 -0
  120. package/dist/prod/all.js +13 -0
  121. package/dist/prod/bar-chart/bar-chart.js +316 -0
  122. package/dist/prod/bar-chart/index.js +5 -0
  123. package/dist/prod/button/button.js +292 -0
  124. package/dist/prod/button/index.js +5 -0
  125. package/dist/prod/checkbox/checkbox.js +232 -0
  126. package/dist/prod/checkbox/index.js +5 -0
  127. package/dist/prod/core/cssom.js +30 -0
  128. package/dist/prod/core/define.js +6 -0
  129. package/dist/prod/core/dev-mode.js +1 -0
  130. package/dist/prod/core/focus-ring.js +14 -0
  131. package/dist/prod/core/form-control.js +75 -0
  132. package/dist/prod/core/warn.js +2 -0
  133. package/dist/prod/dialog/dialog.js +253 -0
  134. package/dist/prod/dialog/index.js +5 -0
  135. package/dist/prod/menu/index.js +5 -0
  136. package/dist/prod/menu/menu.js +330 -0
  137. package/dist/prod/navbar/index.js +5 -0
  138. package/dist/prod/navbar/navbar.js +353 -0
  139. package/dist/prod/poll/index.js +5 -0
  140. package/dist/prod/poll/poll.js +301 -0
  141. package/dist/prod/switch/index.js +5 -0
  142. package/dist/prod/switch/switch.js +213 -0
  143. package/dist/prod/tabs/index.js +5 -0
  144. package/dist/prod/tabs/tabs.js +212 -0
  145. package/dist/prod/text-field/index.js +5 -0
  146. package/dist/prod/text-field/text-field.js +267 -0
  147. package/dist/prod/toast/index.js +5 -0
  148. package/dist/prod/toast/toast.js +258 -0
  149. package/package.json +110 -3
@@ -0,0 +1,212 @@
1
+ import { LitElement, css, html, nothing } from 'lit';
2
+ import { checkTokensLoaded, devWarn } from '../core/warn.js';
3
+ let nextId = 0;
4
+ /**
5
+ * Tabs that switch between panels of related content, following the WAI-ARIA tabs pattern.
6
+ *
7
+ * @tag va-tabs
8
+ * @summary Switches between panels of related content in the same place on the page.
9
+ *
10
+ * @slot tab - The tabs, as `<button slot="tab">` elements, in order.
11
+ * @slot panel - The panels, as elements with `slot="panel"`, in the same order as the tabs.
12
+ *
13
+ * @csspart tablist - The row of tabs.
14
+ * @csspart panels - The wrapper around the panels.
15
+ *
16
+ * @cssprop {<color>} --va-tabs-border - Colour of the line under the row of tabs.
17
+ * @cssprop {<color>} --va-tabs-indicator-border - Colour of the selected tab's underline.
18
+ * @cssprop {<color>} --va-tabs-fg - Text colour of tabs that aren't selected.
19
+ *
20
+ * @cssprop-applies --va-tabs-border tablist border-bottom-color
21
+ * @cssprop-applies --va-tabs-indicator-border light([aria-selected="true"]) border-bottom-color
22
+ * @cssprop-applies --va-tabs-fg light([aria-selected="false"]) color
23
+ *
24
+ * @keyboard-items [slot="tab"]
25
+ * @keyboard items: ArrowRight | next | Moves to the next tab, wrapping round. Selects it unless `activation="manual"`.
26
+ * @keyboard items: ArrowLeft | previous | Moves to the previous tab, wrapping round.
27
+ * @keyboard items: Home | first | Moves to the first tab.
28
+ * @keyboard items: End | last | Moves to the last tab.
29
+ * @keyboard items: Enter | activates | Selects the focused tab (needed when `activation="manual"`).
30
+ * @keyboard items: Tab | focus-next | Moves focus from the tabs into the selected panel.
31
+ *
32
+ * @a11y-role tablist
33
+ * @a11y-name-from accessible-label
34
+ * @replaces [role="tablist"]
35
+ * @a11y-name The `accessible-label` attribute, such as "Account settings" (not shown).
36
+ * @a11y-note Each tab gets `role="tab"`, `aria-selected` and `aria-controls`; each panel gets `role="tabpanel"` and `aria-labelledby`.
37
+ * @a11y-note Only the selected tab is in the Tab order (roving tabindex); arrow keys move between tabs.
38
+ *
39
+ * @guidance-use To switch between a few views of related content in one place, such as sections of a settings page.
40
+ * @guidance-avoid For navigation between pages, for steps in a sequence, or for more than about 6 tabs.
41
+ * @guidance-instead Links for navigation; a stepper for sequences; a list or menu for many options.
42
+ *
43
+ * @fires {CustomEvent<{ index: number, tab: HTMLElement }>} va-select - When the user selects a different tab. `event.detail.index` is its index; `event.detail.tab` is the tab.
44
+ * @event-trigger va-select | click-item 2
45
+ */
46
+ export class VaTabs extends LitElement {
47
+ static { this.properties = {
48
+ selectedIndex: { type: Number, reflect: true, attribute: 'selected-index' },
49
+ activation: { reflect: true },
50
+ accessibleLabel: { attribute: 'accessible-label' },
51
+ }; }
52
+ #id = `va-tabs-${nextId++}`;
53
+ constructor() {
54
+ super();
55
+ this.selectedIndex = 0;
56
+ this.activation = 'automatic';
57
+ this.accessibleLabel = '';
58
+ }
59
+ connectedCallback() {
60
+ super.connectedCallback();
61
+ checkTokensLoaded(this);
62
+ }
63
+ get #tabs() {
64
+ return [...this.querySelectorAll(':scope > [slot="tab"]')];
65
+ }
66
+ get #panels() {
67
+ return [...this.querySelectorAll(':scope > [slot="panel"]')];
68
+ }
69
+ updated(changed) {
70
+ if (changed.has('selectedIndex') || changed.has('accessibleLabel'))
71
+ this.#sync();
72
+ }
73
+ #sync = () => {
74
+ const tabs = this.#tabs;
75
+ const panels = this.#panels;
76
+ if (tabs.length && tabs.length !== panels.length) {
77
+ devWarn('va-tabs', `It has ${tabs.length} tabs but ${panels.length} panels.`, 'Give every <button slot="tab"> a matching element with slot="panel", in the same order.');
78
+ }
79
+ if (tabs.some((t) => t.localName !== 'button')) {
80
+ devWarn('va-tabs', 'A tab is not a <button>, so it may not be keyboard accessible.', 'Use <button slot="tab">Label</button> for each tab.');
81
+ }
82
+ if (tabs.length && !this.accessibleLabel) {
83
+ devWarn('va-tabs', 'The tabs have no accessible name.', 'Add accessible-label="…" that names the group (e.g. accessible-label="Account settings").');
84
+ }
85
+ const selected = Math.min(Math.max(this.selectedIndex, 0), Math.max(tabs.length - 1, 0));
86
+ // Keep the property honest: selected-index="5" with three tabs selects, and reads, 2.
87
+ if (tabs.length && selected !== this.selectedIndex)
88
+ this.selectedIndex = selected;
89
+ tabs.forEach((tab, i) => {
90
+ tab.id ||= `${this.#id}-tab-${i}`;
91
+ tab.setAttribute('role', 'tab');
92
+ tab.setAttribute('aria-selected', String(i === selected));
93
+ tab.tabIndex = i === selected ? 0 : -1;
94
+ if (tab.localName === 'button')
95
+ tab.type = 'button';
96
+ });
97
+ panels.forEach((panel, i) => {
98
+ panel.id ||= `${this.#id}-panel-${i}`;
99
+ panel.setAttribute('role', 'tabpanel');
100
+ panel.hidden = i !== selected;
101
+ if (!panel.hasAttribute('tabindex'))
102
+ panel.tabIndex = 0;
103
+ if (tabs[i]) {
104
+ panel.setAttribute('aria-labelledby', tabs[i].id);
105
+ tabs[i].setAttribute('aria-controls', panel.id);
106
+ }
107
+ });
108
+ };
109
+ #select(index, focus) {
110
+ const tabs = this.#tabs;
111
+ if (!tabs.length)
112
+ return;
113
+ const next = (index + tabs.length) % tabs.length;
114
+ if (focus)
115
+ tabs[next].focus();
116
+ if (next !== this.selectedIndex) {
117
+ this.selectedIndex = next;
118
+ this.dispatchEvent(new CustomEvent('va-select', { detail: { index: next, tab: tabs[next] }, bubbles: true, composed: true }));
119
+ }
120
+ }
121
+ #focusTab(index) {
122
+ const tabs = this.#tabs;
123
+ const next = (index + tabs.length) % tabs.length;
124
+ if (this.activation === 'automatic') {
125
+ this.#select(next, true);
126
+ }
127
+ else {
128
+ tabs.forEach((t, i) => (t.tabIndex = i === next ? 0 : -1));
129
+ tabs[next].focus();
130
+ }
131
+ }
132
+ #onKeydown(event) {
133
+ const tabs = this.#tabs;
134
+ const current = tabs.indexOf(event.target);
135
+ if (current < 0)
136
+ return;
137
+ const moves = { ArrowRight: current + 1, ArrowLeft: current - 1, Home: 0, End: tabs.length - 1 };
138
+ if (event.key in moves) {
139
+ event.preventDefault();
140
+ this.#focusTab(moves[event.key]);
141
+ }
142
+ }
143
+ #onClick(event) {
144
+ const tab = this.#tabs.find((t) => event.composedPath().includes(t));
145
+ if (tab)
146
+ this.#select(this.#tabs.indexOf(tab), true);
147
+ }
148
+ render() {
149
+ return html `
150
+ <div part="tablist" class="tablist" role="tablist" aria-label=${this.accessibleLabel || nothing} @keydown=${this.#onKeydown} @click=${this.#onClick}>
151
+ <slot name="tab" @slotchange=${this.#sync}></slot>
152
+ </div>
153
+ <div part="panels" class="panels">
154
+ <slot name="panel" @slotchange=${this.#sync}></slot>
155
+ </div>
156
+ `;
157
+ }
158
+ static { this.styles = css `
159
+ :host {
160
+ display: block;
161
+ font-family: var(--va-font-family-ui);
162
+ color: var(--va-color-text-default);
163
+ }
164
+ :host([hidden]) {
165
+ display: none;
166
+ }
167
+ .tablist {
168
+ display: flex;
169
+ gap: var(--va-space-gap-md);
170
+ overflow-x: auto;
171
+ border-bottom: 1px solid var(--va-tabs-border, var(--va-color-border-subtle));
172
+ }
173
+ ::slotted([slot='tab']) {
174
+ flex: none;
175
+ min-height: var(--va-size-control-md);
176
+ margin: 0 0 -1px;
177
+ padding: 0 var(--va-space-inline-md);
178
+ border: none;
179
+ border-bottom: 2px solid transparent;
180
+ background: none;
181
+ color: var(--va-tabs-fg, var(--va-color-text-muted));
182
+ font: inherit;
183
+ font-size: var(--va-font-size-md);
184
+ cursor: pointer;
185
+ }
186
+ ::slotted([slot='tab']:hover) {
187
+ color: var(--va-color-text-default);
188
+ }
189
+ ::slotted([aria-selected='true']) {
190
+ border-bottom-color: var(--va-tabs-indicator-border, var(--va-color-accent-default));
191
+ color: var(--va-color-text-default);
192
+ font-weight: var(--va-font-weight-medium);
193
+ }
194
+ ::slotted([slot='tab']:focus-visible) {
195
+ outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
196
+ outline-offset: -2px;
197
+ }
198
+ .panels {
199
+ padding-top: var(--va-space-inline-lg);
200
+ }
201
+ ::slotted([slot='panel']:focus-visible) {
202
+ outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
203
+ outline-offset: 4px;
204
+ }
205
+ @media (forced-colors: active) {
206
+ ::slotted([aria-selected='true']) {
207
+ border-bottom-color: Highlight;
208
+ }
209
+ }
210
+ `; }
211
+ }
212
+ //# sourceMappingURL=tabs.js.map
@@ -0,0 +1,5 @@
1
+ import { define } from '../core/define.js';
2
+ import { VaTextField } from './text-field.js';
3
+ export { VaTextField };
4
+ define('va-text-field', VaTextField);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,267 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { FormControl } from '../core/form-control.js';
3
+ import { checkTokensLoaded, devWarn } from '../core/warn.js';
4
+ // Whether a pointer button is down anywhere on the page. Used to delay error messages that
5
+ // would otherwise appear mid-click and move the layout under the pointer (see #onBlur).
6
+ let pointerDown = false;
7
+ if (typeof document !== 'undefined') {
8
+ document.addEventListener('pointerdown', () => (pointerDown = true), true);
9
+ document.addEventListener('pointerup', () => (pointerDown = false), true);
10
+ document.addEventListener('pointercancel', () => (pointerDown = false), true);
11
+ }
12
+ /**
13
+ * A single-line text input with a visible label, help text and error message.
14
+ *
15
+ * @tag va-text-field
16
+ * @summary Collects a short piece of text, such as a name, an email address or a search term.
17
+ *
18
+ * @slot start - An icon or prefix inside the field, before the text.
19
+ * @slot end - An icon or suffix inside the field, after the text.
20
+ *
21
+ * @csspart label - The visible label.
22
+ * @csspart field - The box around the input and its icons.
23
+ * @csspart input - The native input.
24
+ * @csspart help-text - The help text.
25
+ * @csspart error - The error message.
26
+ *
27
+ * @cssprop {<color>} --va-text-field-bg - Background colour of the field.
28
+ * @cssprop {<color>} --va-text-field-border - Border colour of the field.
29
+ * @cssprop {<color>} --va-text-field-border-invalid - Border colour while the field shows an error.
30
+ * @cssprop {<length>} --va-text-field-radius - Corner radius of the field.
31
+ * @cssprop {<length>} --va-text-field-height - Minimum height of the field.
32
+ *
33
+ * @cssprop-applies --va-text-field-bg field background-color
34
+ * @cssprop-applies --va-text-field-border field border-top-color
35
+ * @cssprop-applies --va-text-field-border-invalid field:invalid border-top-color
36
+ * @cssprop-applies --va-text-field-radius field border-top-left-radius
37
+ * @cssprop-applies --va-text-field-height field min-height
38
+ *
39
+ * @keyboard Tab | focus-next | Moves focus to the next control.
40
+ *
41
+ * @a11y-role textbox
42
+ * @a11y-name-from label
43
+ * @replaces input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="tel"], input[type="url"]
44
+ * @a11y-name The `label` attribute, shown above the field. Every text field needs one.
45
+ * @a11y-note Help text and the error message are linked with `aria-describedby`; the error also sets `aria-invalid`.
46
+ * @a11y-note Errors appear after the user leaves the field or submits the form, not while they type.
47
+ *
48
+ * @guidance-use For short, free-form text: names, email addresses, search terms, codes.
49
+ * @guidance-avoid For long text, or for picking from a fixed set of options.
50
+ * @guidance-instead A textarea for long text; a select or radio group for fixed options.
51
+ *
52
+ * @fires input - The native input event, on every keystroke. Read `event.target.value`.
53
+ * @fires change - When the user commits a change, by leaving the field or pressing Enter.
54
+ * @event-trigger input | press a
55
+ * @event-trigger change | commit
56
+ */
57
+ export class VaTextField extends FormControl {
58
+ static { this.shadowRootOptions = { ...FormControl.shadowRootOptions, delegatesFocus: true }; }
59
+ static { this.properties = {
60
+ label: {},
61
+ type: {},
62
+ value: {},
63
+ placeholder: {},
64
+ helpText: { attribute: 'help-text' },
65
+ error: {},
66
+ readOnly: { type: Boolean, reflect: true, attribute: 'readonly' },
67
+ minLength: { type: Number, attribute: 'minlength' },
68
+ maxLength: { type: Number, attribute: 'maxlength' },
69
+ pattern: {},
70
+ autocomplete: {},
71
+ _showError: { state: true },
72
+ }; }
73
+ #defaultValue = '';
74
+ constructor() {
75
+ super();
76
+ this.label = '';
77
+ this.type = 'text';
78
+ this.value = '';
79
+ this.placeholder = '';
80
+ this.helpText = '';
81
+ this.error = '';
82
+ this.readOnly = false;
83
+ this.pattern = '';
84
+ this.autocomplete = '';
85
+ this._showError = false;
86
+ // Fired on the host when the form's submit is blocked: show the error from then on.
87
+ this.addEventListener('invalid', () => (this._showError = true));
88
+ }
89
+ connectedCallback() {
90
+ super.connectedCallback();
91
+ this.#defaultValue = this.getAttribute('value') ?? '';
92
+ checkTokensLoaded(this);
93
+ }
94
+ firstUpdated() {
95
+ if (!this.label) {
96
+ devWarn('va-text-field', 'This text field has no label.', 'Add label="…" that says what to type (e.g. label="Email address"). A placeholder is not a label.');
97
+ }
98
+ }
99
+ get #input() {
100
+ return this.shadowRoot?.querySelector('input') ?? null;
101
+ }
102
+ updated(changed) {
103
+ const input = this.#input;
104
+ if (!input)
105
+ return;
106
+ if (changed.has('error') && this.error)
107
+ this._showError = true;
108
+ this._internals.setFormValue(this.value);
109
+ input.setCustomValidity(this.error);
110
+ this._internals.setValidity(input.validity, input.validationMessage, input);
111
+ }
112
+ /** @internal */
113
+ formResetCallback() {
114
+ this.value = this.#defaultValue;
115
+ this._showError = false;
116
+ }
117
+ /** Selects all the text in the field. */
118
+ select() {
119
+ this.#input?.select();
120
+ }
121
+ #onInput(event) {
122
+ this.value = event.target.value;
123
+ }
124
+ #onChange() {
125
+ this._emit('change');
126
+ }
127
+ #onBlur() {
128
+ const show = () => {
129
+ this._showError = true;
130
+ this.requestUpdate();
131
+ };
132
+ // Focus left because the user is clicking something else. Showing the error now would push
133
+ // the content below down between mousedown and mouseup, and the click would be lost.
134
+ if (pointerDown)
135
+ window.addEventListener('pointerup', () => setTimeout(show), { once: true, capture: true });
136
+ else
137
+ show();
138
+ }
139
+ render() {
140
+ const input = this.#input;
141
+ const invalid = this._showError && !!(this.error || (input && !input.validity.valid));
142
+ const message = this.error || (invalid ? input?.validationMessage : '');
143
+ const describedBy = [this.helpText ? 'help-text' : '', invalid ? 'error' : ''].filter(Boolean).join(' ');
144
+ return html `
145
+ <label part="label" class="label ${this._isDisabled ? 'disabled' : ''}" for="input">${this.label}${this.required ? html `<span class="required" aria-hidden="true"> *</span>` : nothing}</label>
146
+ <div part="field" class="field ${invalid ? 'invalid' : ''} ${this._isDisabled ? 'disabled' : ''}">
147
+ <slot name="start"></slot>
148
+ <input
149
+ part="input"
150
+ id="input"
151
+ .value=${this.value}
152
+ type=${this.type}
153
+ placeholder=${this.placeholder || nothing}
154
+ ?disabled=${this._isDisabled}
155
+ ?readonly=${this.readOnly}
156
+ ?required=${this.required}
157
+ minlength=${this.minLength ?? nothing}
158
+ maxlength=${this.maxLength ?? nothing}
159
+ pattern=${this.pattern || nothing}
160
+ autocomplete=${(this.autocomplete || nothing)}
161
+ aria-invalid=${invalid ? 'true' : nothing}
162
+ aria-describedby=${describedBy || nothing}
163
+ @input=${this.#onInput}
164
+ @change=${this.#onChange}
165
+ @blur=${this.#onBlur}
166
+ />
167
+ <slot name="end"></slot>
168
+ </div>
169
+ <div part="help-text" id="help-text" class="help-text" ?hidden=${!this.helpText}>${this.helpText}</div>
170
+ <div part="error" id="error" class="error" ?hidden=${!invalid}>${message}</div>
171
+ `;
172
+ }
173
+ static { this.styles = css `
174
+ :host {
175
+ --_border: var(--va-text-field-border, var(--va-color-border-control));
176
+ display: inline-flex;
177
+ flex-direction: column;
178
+ gap: var(--va-space-gap-sm);
179
+ min-width: 12rem;
180
+ font-family: var(--va-font-family-ui);
181
+ font-size: var(--va-font-size-md);
182
+ color: var(--va-color-text-default);
183
+ vertical-align: top;
184
+ }
185
+ :host([hidden]) {
186
+ display: none;
187
+ }
188
+ .label {
189
+ font-weight: var(--va-font-weight-medium);
190
+ font-size: var(--va-font-size-sm);
191
+ }
192
+ .required {
193
+ color: var(--va-color-danger-default);
194
+ }
195
+ .field {
196
+ box-sizing: border-box;
197
+ display: flex;
198
+ align-items: center;
199
+ gap: var(--va-space-gap-md);
200
+ min-height: var(--va-text-field-height, var(--va-size-control-md));
201
+ padding: 0 var(--va-space-inline-md);
202
+ border: 1px solid var(--_border);
203
+ border-radius: var(--va-text-field-radius, var(--va-radius-control));
204
+ background-color: var(--va-text-field-bg, var(--va-color-surface-default));
205
+ }
206
+ .field:focus-within {
207
+ outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
208
+ outline-offset: 1px;
209
+ }
210
+ .field.invalid {
211
+ border-color: var(--va-text-field-border-invalid, var(--va-color-danger-default));
212
+ }
213
+ input {
214
+ flex: 1;
215
+ min-width: 0;
216
+ margin: 0;
217
+ padding: 0.5rem 0;
218
+ border: none;
219
+ outline: none;
220
+ background: transparent;
221
+ color: inherit;
222
+ font: inherit;
223
+ }
224
+ input::placeholder {
225
+ color: var(--va-color-text-muted);
226
+ }
227
+ ::slotted([slot='start']),
228
+ ::slotted([slot='end']) {
229
+ flex: none;
230
+ color: var(--va-color-text-muted);
231
+ }
232
+ /* Only the box fades: the label and help text (often saying why it's disabled) stay readable. */
233
+ .field.disabled {
234
+ opacity: 0.5;
235
+ }
236
+ .label.disabled {
237
+ color: var(--va-color-text-muted);
238
+ }
239
+ :host([readonly]) .field {
240
+ background-color: var(--va-color-surface-subtle);
241
+ }
242
+ .help-text {
243
+ color: var(--va-color-text-muted);
244
+ font-size: var(--va-font-size-sm);
245
+ }
246
+ .error {
247
+ color: var(--va-color-danger-default);
248
+ font-size: var(--va-font-size-sm);
249
+ }
250
+ .help-text[hidden],
251
+ .error[hidden] {
252
+ display: none;
253
+ }
254
+ @media (forced-colors: active) {
255
+ .field {
256
+ border-color: FieldText;
257
+ }
258
+ .field.invalid {
259
+ border-width: 2px;
260
+ }
261
+ .field:focus-within {
262
+ outline-color: Highlight;
263
+ }
264
+ }
265
+ `; }
266
+ }
267
+ //# sourceMappingURL=text-field.js.map
@@ -0,0 +1,5 @@
1
+ import { define } from '../core/define.js';
2
+ import { VaToast } from './toast.js';
3
+ export { VaToast };
4
+ define('va-toast', VaToast);
5
+ //# sourceMappingURL=index.js.map