@api-client/ui 0.5.6 → 0.5.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/.cursor/rules/html-and-css-best-practices.mdc +63 -0
- package/.cursor/rules/lit-best-practices.mdc +78 -0
- package/.github/instructions/html-and-css-best-practices.instructions.md +70 -0
- package/.github/instructions/lit-best-practices.instructions.md +86 -0
- package/build/src/elements/currency/currency-picker.d.ts +10 -0
- package/build/src/elements/currency/currency-picker.d.ts.map +1 -0
- package/build/src/elements/currency/currency-picker.js +27 -0
- package/build/src/elements/currency/currency-picker.js.map +1 -0
- package/build/src/elements/currency/internals/Picker.d.ts +311 -0
- package/build/src/elements/currency/internals/Picker.d.ts.map +1 -0
- package/build/src/elements/currency/internals/Picker.js +857 -0
- package/build/src/elements/currency/internals/Picker.js.map +1 -0
- package/build/src/elements/currency/internals/Picker.styles.d.ts +3 -0
- package/build/src/elements/currency/internals/Picker.styles.d.ts.map +1 -0
- package/build/src/elements/currency/internals/Picker.styles.js +58 -0
- package/build/src/elements/currency/internals/Picker.styles.js.map +1 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.d.ts +216 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.d.ts.map +1 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.js +1037 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.js.map +1 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.styles.d.ts +3 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.styles.d.ts.map +1 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.styles.js +274 -0
- package/build/src/elements/mention-textarea/internals/MentionTextArea.styles.js.map +1 -0
- package/build/src/elements/mention-textarea/ui-mention-textarea.d.ts +13 -0
- package/build/src/elements/mention-textarea/ui-mention-textarea.d.ts.map +1 -0
- package/build/src/elements/mention-textarea/ui-mention-textarea.js +28 -0
- package/build/src/elements/mention-textarea/ui-mention-textarea.js.map +1 -0
- package/build/src/md/button/internals/base.d.ts +1 -0
- package/build/src/md/button/internals/base.d.ts.map +1 -1
- package/build/src/md/button/internals/base.js +7 -0
- package/build/src/md/button/internals/base.js.map +1 -1
- package/build/src/md/chip/internals/Chip.styles.d.ts.map +1 -1
- package/build/src/md/chip/internals/Chip.styles.js +2 -0
- package/build/src/md/chip/internals/Chip.styles.js.map +1 -1
- package/build/src/md/date-picker/internals/DatePicker.styles.d.ts.map +1 -1
- package/build/src/md/date-picker/internals/DatePicker.styles.js +73 -0
- package/build/src/md/date-picker/internals/DatePicker.styles.js.map +1 -1
- package/build/src/md/date-picker/internals/DatePickerCalendar.d.ts +164 -51
- package/build/src/md/date-picker/internals/DatePickerCalendar.d.ts.map +1 -1
- package/build/src/md/date-picker/internals/DatePickerCalendar.js +660 -368
- package/build/src/md/date-picker/internals/DatePickerCalendar.js.map +1 -1
- package/build/src/md/date-picker/ui-date-picker-input.d.ts +65 -13
- package/build/src/md/date-picker/ui-date-picker-input.d.ts.map +1 -1
- package/build/src/md/date-picker/ui-date-picker-input.js +143 -76
- package/build/src/md/date-picker/ui-date-picker-input.js.map +1 -1
- package/build/src/md/date-picker/ui-date-picker-modal-input.d.ts +76 -17
- package/build/src/md/date-picker/ui-date-picker-modal-input.d.ts.map +1 -1
- package/build/src/md/date-picker/ui-date-picker-modal-input.js +192 -127
- package/build/src/md/date-picker/ui-date-picker-modal-input.js.map +1 -1
- package/build/src/md/date-picker/ui-date-picker-modal.d.ts +63 -15
- package/build/src/md/date-picker/ui-date-picker-modal.d.ts.map +1 -1
- package/build/src/md/date-picker/ui-date-picker-modal.js +143 -64
- package/build/src/md/date-picker/ui-date-picker-modal.js.map +1 -1
- package/demo/elements/currency/index.html +91 -0
- package/demo/elements/currency/index.ts +272 -0
- package/demo/elements/index.html +6 -0
- package/demo/elements/mention-textarea/index.html +19 -0
- package/demo/elements/mention-textarea/index.ts +205 -0
- package/demo/md/date-picker/date-picker.ts +138 -103
- package/package.json +2 -2
- package/src/elements/currency/currency-picker.ts +14 -0
- package/src/elements/currency/internals/Picker.styles.ts +58 -0
- package/src/elements/currency/internals/Picker.ts +846 -0
- package/src/elements/mention-textarea/internals/MentionTextArea.styles.ts +274 -0
- package/src/elements/mention-textarea/internals/MentionTextArea.ts +1036 -0
- package/src/elements/mention-textarea/ui-mention-textarea.ts +18 -0
- package/src/md/button/internals/base.ts +7 -0
- package/src/md/chip/internals/Chip.styles.ts +2 -0
- package/src/md/date-picker/internals/DatePicker.styles.ts +73 -0
- package/src/md/date-picker/internals/DatePickerCalendar.ts +643 -309
- package/src/md/date-picker/ui-date-picker-input.ts +110 -49
- package/src/md/date-picker/ui-date-picker-modal-input.ts +168 -99
- package/src/md/date-picker/ui-date-picker-modal.ts +136 -53
- package/test/README.md +3 -2
- package/test/elements/currency/CurrencyPicker.accessibility.test.ts +328 -0
- package/test/elements/currency/CurrencyPicker.core.test.ts +318 -0
- package/test/elements/currency/CurrencyPicker.integration.test.ts +482 -0
- package/test/elements/currency/CurrencyPicker.test.ts +486 -0
- package/test/elements/mention-textarea/MentionTextArea.basic.test.ts +63 -0
- package/test/elements/mention-textarea/MentionTextArea.test.ts +321 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { html, TemplateResult } from 'lit'
|
|
2
|
+
import { DemoPage } from '../../../src/demo/DemoPage.js'
|
|
3
|
+
import reactive from '../../../src/decorators/reactive.js'
|
|
4
|
+
import type { Currency, CurrencyPickerError } from '../../../src/elements/currency/internals/Picker.js'
|
|
5
|
+
|
|
6
|
+
import '../../../src/elements/currency/currency-picker.js'
|
|
7
|
+
import '../../../src/md/button/ui-button.js'
|
|
8
|
+
import '../../../src/md/checkbox/ui-checkbox.js'
|
|
9
|
+
|
|
10
|
+
class CurrencyPickerDemoPage extends DemoPage {
|
|
11
|
+
override accessor componentName = 'Currency Picker'
|
|
12
|
+
|
|
13
|
+
@reactive() accessor singleSelected: string[] = []
|
|
14
|
+
@reactive() accessor multiSelected: string[] = ['USD', 'EUR']
|
|
15
|
+
@reactive() accessor limitedSelected: string[] = []
|
|
16
|
+
@reactive() accessor formSelected: string[] = []
|
|
17
|
+
@reactive() accessor disabledSelected: string[] = ['GBP']
|
|
18
|
+
|
|
19
|
+
@reactive() accessor lastChangeEvent = 'No changes yet'
|
|
20
|
+
@reactive() accessor lastErrorEvent = 'No errors yet'
|
|
21
|
+
|
|
22
|
+
private readonly allowedCurrencies = ['USD', 'EUR', 'GBP', 'JPY', 'CAD']
|
|
23
|
+
|
|
24
|
+
handleSingleChange(event: CustomEvent<{ currencies: Currency[]; codes: string[] }>): void {
|
|
25
|
+
this.singleSelected = event.detail.codes
|
|
26
|
+
this.lastChangeEvent = `Single Select: ${JSON.stringify(event.detail, null, 2)}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
handleMultiChange(event: CustomEvent<{ currencies: Currency[]; codes: string[] }>): void {
|
|
30
|
+
this.multiSelected = event.detail.codes
|
|
31
|
+
this.lastChangeEvent = `Multi Select: ${JSON.stringify(event.detail, null, 2)}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
handleLimitedChange(event: CustomEvent<{ currencies: Currency[]; codes: string[] }>): void {
|
|
35
|
+
this.limitedSelected = event.detail.codes
|
|
36
|
+
this.lastChangeEvent = `Limited Currencies: ${JSON.stringify(event.detail, null, 2)}`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
handleFormChange(event: CustomEvent<{ currencies: Currency[]; codes: string[] }>): void {
|
|
40
|
+
this.formSelected = event.detail.codes
|
|
41
|
+
this.lastChangeEvent = `Form Element: ${JSON.stringify(event.detail, null, 2)}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
handleError(event: CustomEvent<{ error: CurrencyPickerError }>): void {
|
|
45
|
+
this.lastErrorEvent = `Error: ${JSON.stringify(event.detail, null, 2)}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
handleClearSingle(): void {
|
|
49
|
+
const picker = document.querySelector('#single-picker') as HTMLElement & { clearSelection(): void }
|
|
50
|
+
picker?.clearSelection()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
handleClearMulti(): void {
|
|
54
|
+
const picker = document.querySelector('#multi-picker') as HTMLElement & { clearSelection(): void }
|
|
55
|
+
picker?.clearSelection()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
handleClearLimited(): void {
|
|
59
|
+
const picker = document.querySelector('#limited-picker') as HTMLElement & { clearSelection(): void }
|
|
60
|
+
picker?.clearSelection()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
handleTriggerValidationError(): void {
|
|
64
|
+
const picker = document.querySelector('#error-demo-picker') as HTMLElement & { selected: string[] }
|
|
65
|
+
if (picker) {
|
|
66
|
+
// Try to set invalid currency codes
|
|
67
|
+
picker.selected = ['INVALID', 'FAKE', 'USD']
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
handleTriggerSelectionError(): void {
|
|
72
|
+
const picker = document.querySelector('#single-error-picker') as HTMLElement & { selected: string[] }
|
|
73
|
+
if (picker) {
|
|
74
|
+
// Try to set multiple currencies on single-select picker
|
|
75
|
+
picker.selected = ['USD', 'EUR', 'GBP']
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override contentTemplate(): TemplateResult {
|
|
80
|
+
return html`
|
|
81
|
+
<section class="demo-section">
|
|
82
|
+
<h3>Single Currency Selection</h3>
|
|
83
|
+
<p>Select one currency at a time. When a new currency is selected, it replaces the previous selection.</p>
|
|
84
|
+
|
|
85
|
+
<div class="demo-controls">
|
|
86
|
+
<currency-picker
|
|
87
|
+
id="single-picker"
|
|
88
|
+
label="Select Currency"
|
|
89
|
+
.selected="${this.singleSelected}"
|
|
90
|
+
@change="${this.handleSingleChange}"
|
|
91
|
+
@error="${this.handleError}"
|
|
92
|
+
></currency-picker>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<ui-button @click="${this.handleClearSingle}">Clear Selection</ui-button>
|
|
96
|
+
|
|
97
|
+
<div class="output-section">
|
|
98
|
+
<h4>Selected Currency</h4>
|
|
99
|
+
<div class="output-content">${this.singleSelected.join(', ') || 'None'}</div>
|
|
100
|
+
</div>
|
|
101
|
+
</section>
|
|
102
|
+
|
|
103
|
+
<section class="demo-section">
|
|
104
|
+
<h3>Multiple Currency Selection</h3>
|
|
105
|
+
<p>Select multiple currencies. Selected currencies appear as chips that can be removed individually.</p>
|
|
106
|
+
|
|
107
|
+
<div class="demo-controls">
|
|
108
|
+
<currency-picker
|
|
109
|
+
id="multi-picker"
|
|
110
|
+
label="Add Currency"
|
|
111
|
+
multi
|
|
112
|
+
.selected="${this.multiSelected}"
|
|
113
|
+
@change="${this.handleMultiChange}"
|
|
114
|
+
@error="${this.handleError}"
|
|
115
|
+
></currency-picker>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<ui-button @click="${this.handleClearMulti}">Clear All</ui-button>
|
|
119
|
+
|
|
120
|
+
<div class="output-section">
|
|
121
|
+
<h4>Selected Currencies</h4>
|
|
122
|
+
<div class="output-content">${this.multiSelected.join(', ') || 'None'}</div>
|
|
123
|
+
</div>
|
|
124
|
+
</section>
|
|
125
|
+
|
|
126
|
+
<section class="demo-section">
|
|
127
|
+
<h3>Limited Currency Options</h3>
|
|
128
|
+
<p>Restrict available currencies to a specific subset using the allowedCurrencies property.</p>
|
|
129
|
+
|
|
130
|
+
<div class="demo-controls">
|
|
131
|
+
<currency-picker
|
|
132
|
+
id="limited-picker"
|
|
133
|
+
label="Select from Limited Options"
|
|
134
|
+
multi
|
|
135
|
+
.selected="${this.limitedSelected}"
|
|
136
|
+
.allowedCurrencies="${this.allowedCurrencies}"
|
|
137
|
+
supportingText="Only major currencies available"
|
|
138
|
+
@change="${this.handleLimitedChange}"
|
|
139
|
+
@error="${this.handleError}"
|
|
140
|
+
></currency-picker>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<ui-button @click="${this.handleClearLimited}">Clear Selection</ui-button>
|
|
144
|
+
|
|
145
|
+
<div class="output-section">
|
|
146
|
+
<h4>Available Currencies</h4>
|
|
147
|
+
<div class="output-content">${this.allowedCurrencies.join(', ')}</div>
|
|
148
|
+
<h4>Selected Currencies</h4>
|
|
149
|
+
<div class="output-content">${this.limitedSelected.join(', ') || 'None'}</div>
|
|
150
|
+
</div>
|
|
151
|
+
</section>
|
|
152
|
+
|
|
153
|
+
<section class="demo-section">
|
|
154
|
+
<h3>Form Integration</h3>
|
|
155
|
+
<p>Use the currency picker in forms with proper name and required attributes.</p>
|
|
156
|
+
|
|
157
|
+
<form @submit="${this.handleFormSubmit}">
|
|
158
|
+
<div class="demo-controls">
|
|
159
|
+
<currency-picker
|
|
160
|
+
label="Required Currency"
|
|
161
|
+
name="currency"
|
|
162
|
+
required
|
|
163
|
+
.selected="${this.formSelected}"
|
|
164
|
+
supportingText="This field is required"
|
|
165
|
+
@change="${this.handleFormChange}"
|
|
166
|
+
@error="${this.handleError}"
|
|
167
|
+
></currency-picker>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<ui-button type="submit">Submit Form</ui-button>
|
|
171
|
+
<ui-button color="text" type="reset">Reset Form</ui-button>
|
|
172
|
+
</form>
|
|
173
|
+
|
|
174
|
+
<div class="output-section">
|
|
175
|
+
<h4>Form Value</h4>
|
|
176
|
+
<div class="output-content">${this.formSelected.join(', ') || 'None'}</div>
|
|
177
|
+
</div>
|
|
178
|
+
</section>
|
|
179
|
+
|
|
180
|
+
<section class="demo-section">
|
|
181
|
+
<h3>Disabled State</h3>
|
|
182
|
+
<p>Currency picker in disabled state with pre-selected currencies.</p>
|
|
183
|
+
|
|
184
|
+
<div class="demo-controls">
|
|
185
|
+
<currency-picker
|
|
186
|
+
label="Disabled Picker"
|
|
187
|
+
disabled
|
|
188
|
+
.selected="${this.disabledSelected}"
|
|
189
|
+
supportingText="This picker is disabled"
|
|
190
|
+
></currency-picker>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<div class="output-section">
|
|
194
|
+
<h4>Disabled Selection</h4>
|
|
195
|
+
<div class="output-content">${this.disabledSelected.join(', ')}</div>
|
|
196
|
+
</div>
|
|
197
|
+
</section>
|
|
198
|
+
|
|
199
|
+
<section class="demo-section">
|
|
200
|
+
<h3>Error Handling Demonstration</h3>
|
|
201
|
+
<p>Test various error scenarios to see how the component handles and displays errors.</p>
|
|
202
|
+
|
|
203
|
+
<h4>Validation Errors</h4>
|
|
204
|
+
<p>This picker demonstrates validation errors when invalid currency codes are set programmatically.</p>
|
|
205
|
+
|
|
206
|
+
<div class="demo-controls">
|
|
207
|
+
<currency-picker
|
|
208
|
+
id="error-demo-picker"
|
|
209
|
+
label="Validation Error Demo"
|
|
210
|
+
multi
|
|
211
|
+
@error="${this.handleError}"
|
|
212
|
+
></currency-picker>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<ui-button @click="${this.handleTriggerValidationError}">Trigger Validation Error</ui-button>
|
|
216
|
+
|
|
217
|
+
<h4>Selection Constraint Errors</h4>
|
|
218
|
+
<p>This single-select picker demonstrates selection constraint errors.</p>
|
|
219
|
+
|
|
220
|
+
<div class="demo-controls">
|
|
221
|
+
<currency-picker
|
|
222
|
+
id="single-error-picker"
|
|
223
|
+
label="Single Select Error Demo"
|
|
224
|
+
@error="${this.handleError}"
|
|
225
|
+
></currency-picker>
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
<ui-button @click="${this.handleTriggerSelectionError}">Trigger Selection Error</ui-button>
|
|
229
|
+
|
|
230
|
+
<div class="output-section">
|
|
231
|
+
<h4>Error Event Output</h4>
|
|
232
|
+
<div class="output-content">${this.lastErrorEvent}</div>
|
|
233
|
+
</div>
|
|
234
|
+
</section>
|
|
235
|
+
|
|
236
|
+
<section class="demo-section">
|
|
237
|
+
<h3>Event Output</h3>
|
|
238
|
+
<p>View the latest change event data in real-time.</p>
|
|
239
|
+
|
|
240
|
+
<div class="output-section">
|
|
241
|
+
<h4>Last Change Event</h4>
|
|
242
|
+
<div class="output-content">${this.lastChangeEvent}</div>
|
|
243
|
+
</div>
|
|
244
|
+
</section>
|
|
245
|
+
|
|
246
|
+
<section class="demo-section">
|
|
247
|
+
<h3>Error Handling</h3>
|
|
248
|
+
<p>View the latest error event data in real-time.</p>
|
|
249
|
+
|
|
250
|
+
<div class="output-section">
|
|
251
|
+
<h4>Last Error Event</h4>
|
|
252
|
+
<div class="output-content">${this.lastErrorEvent}</div>
|
|
253
|
+
</div>
|
|
254
|
+
</section>
|
|
255
|
+
`
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private handleFormSubmit(event: Event): void {
|
|
259
|
+
event.preventDefault()
|
|
260
|
+
const formData = new FormData(event.target as HTMLFormElement)
|
|
261
|
+
console.log('Form submitted:', Object.fromEntries(formData.entries()))
|
|
262
|
+
|
|
263
|
+
if (this.formSelected.length === 0) {
|
|
264
|
+
alert('Please select a currency before submitting the form.')
|
|
265
|
+
} else {
|
|
266
|
+
alert(`Form submitted with currency: ${this.formSelected.join(', ')}`)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const instance = new CurrencyPickerDemoPage()
|
|
272
|
+
instance.render()
|
package/demo/elements/index.html
CHANGED
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
|
|
28
28
|
<dt><a href="context-menu/index.html">Context menu</a></dt>
|
|
29
29
|
<dd>An element that render a context menu.</dd>
|
|
30
|
+
|
|
31
|
+
<dt><a href="currency/index.html">Currency picker</a></dt>
|
|
32
|
+
<dd>A component for selecting currencies with chips display.</dd>
|
|
30
33
|
|
|
31
34
|
<dt><a href="environment/index.html">Environment</a></dt>
|
|
32
35
|
<dd>The environment elements library.</dd>
|
|
@@ -43,6 +46,9 @@
|
|
|
43
46
|
<dt><a href="http-client/index.html">HTTP Client</a></dt>
|
|
44
47
|
<dd>The HTTP Client UI library.</dd>
|
|
45
48
|
|
|
49
|
+
<dt><a href="mention-textarea/index.html">Mention Textarea</a></dt>
|
|
50
|
+
<dd>The mention-textarea component.</dd>
|
|
51
|
+
|
|
46
52
|
<dt><a href="icons/index.html">Icons</a></dt>
|
|
47
53
|
<dd>The icons library.</dd>
|
|
48
54
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en-GB">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
|
|
6
|
+
<title>Mention Textarea</title>
|
|
7
|
+
<link
|
|
8
|
+
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
|
|
9
|
+
rel="stylesheet"
|
|
10
|
+
/>
|
|
11
|
+
<link href="../../../src/styles/m3/tokens.css" rel="stylesheet" type="text/css" />
|
|
12
|
+
<link href="../../../src/styles/m3/theme.css" rel="stylesheet" type="text/css" />
|
|
13
|
+
<link href="../../page.css" rel="stylesheet" type="text/css" />
|
|
14
|
+
<script type="module" src="/.tmp/demo/elements/mention-textarea/index.js"></script>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<div id="app"></div>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { html, TemplateResult } from 'lit'
|
|
2
|
+
import reactive from '../../../src/decorators/reactive.js'
|
|
3
|
+
import { DemoPage } from '../../../src/demo/DemoPage.js'
|
|
4
|
+
import type {
|
|
5
|
+
MentionTextAreaElement,
|
|
6
|
+
MentionSuggestion,
|
|
7
|
+
MentionInsertEvent,
|
|
8
|
+
MentionRemoveEvent,
|
|
9
|
+
} from '../../../src/elements/mention-textarea/ui-mention-textarea.js'
|
|
10
|
+
import '../../../src/elements/mention-textarea/ui-mention-textarea.js'
|
|
11
|
+
|
|
12
|
+
class ComponentDemoPage extends DemoPage {
|
|
13
|
+
override accessor componentName = 'Mention Textarea'
|
|
14
|
+
|
|
15
|
+
@reactive() accessor value = 'Hello @{john-doe}, please review the document with @{jane-smith}.'
|
|
16
|
+
|
|
17
|
+
@reactive() accessor suggestions: MentionSuggestion[] = [
|
|
18
|
+
{
|
|
19
|
+
id: 'john-doe',
|
|
20
|
+
label: 'John Doe',
|
|
21
|
+
description: 'Senior Developer',
|
|
22
|
+
suffix: 'Engineering',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'jane-smith',
|
|
26
|
+
label: 'Jane Smith',
|
|
27
|
+
description: 'Product Manager',
|
|
28
|
+
suffix: 'Product',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'bob-wilson',
|
|
32
|
+
label: 'Bob Wilson',
|
|
33
|
+
description: 'UI/UX Designer',
|
|
34
|
+
suffix: 'Design',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'alice-johnson',
|
|
38
|
+
label: 'Alice Johnson',
|
|
39
|
+
description: 'Quality Assurance Engineer',
|
|
40
|
+
suffix: 'QA',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'mike-brown',
|
|
44
|
+
label: 'Mike Brown',
|
|
45
|
+
description: 'DevOps Engineer',
|
|
46
|
+
suffix: 'Infrastructure',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'sarah-davis',
|
|
50
|
+
label: 'Sarah Davis',
|
|
51
|
+
description: 'Technical Writer',
|
|
52
|
+
suffix: 'Documentation',
|
|
53
|
+
},
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
handleMentionInsert(event: CustomEvent<MentionInsertEvent>): void {
|
|
57
|
+
console.log('Mention inserted:', event.detail)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handleMentionRemove(event: CustomEvent<MentionRemoveEvent>): void {
|
|
61
|
+
console.log('Mention removed:', event.detail)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
handleInput(event: Event): void {
|
|
65
|
+
const target = event.target as MentionTextAreaElement
|
|
66
|
+
this.value = target.value
|
|
67
|
+
console.log('Value changed:', this.value)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
contentTemplate(): TemplateResult {
|
|
71
|
+
return html`
|
|
72
|
+
<a href="../">Back</a>
|
|
73
|
+
|
|
74
|
+
<section class="demo-section">
|
|
75
|
+
<h2 class="display-large">Basic Usage</h2>
|
|
76
|
+
<p>
|
|
77
|
+
Type @ to trigger mentions. The component supports rich suggestions with headline, description, and suffix.
|
|
78
|
+
</p>
|
|
79
|
+
|
|
80
|
+
<mention-textarea
|
|
81
|
+
label="Message"
|
|
82
|
+
supporting-text="Type @ to mention someone"
|
|
83
|
+
.value="${this.value}"
|
|
84
|
+
.suggestions="${this.suggestions}"
|
|
85
|
+
@mention-insert="${this.handleMentionInsert}"
|
|
86
|
+
@mention-remove="${this.handleMentionRemove}"
|
|
87
|
+
@input="${this.handleInput}"
|
|
88
|
+
></mention-textarea>
|
|
89
|
+
|
|
90
|
+
<h3 class="title-large">Current Value:</h3>
|
|
91
|
+
<pre
|
|
92
|
+
style="background: var(--md-sys-color-surface-variant); padding: 16px; border-radius: 8px; overflow-x: auto;"
|
|
93
|
+
>
|
|
94
|
+
${this.value}
|
|
95
|
+
</pre
|
|
96
|
+
>
|
|
97
|
+
</section>
|
|
98
|
+
|
|
99
|
+
<section class="demo-section">
|
|
100
|
+
<h2 class="display-large">Different States</h2>
|
|
101
|
+
|
|
102
|
+
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
|
|
103
|
+
<mention-textarea label="Default" .suggestions="${this.suggestions}"></mention-textarea>
|
|
104
|
+
|
|
105
|
+
<mention-textarea
|
|
106
|
+
label="With placeholder"
|
|
107
|
+
placeholder="Start typing..."
|
|
108
|
+
.suggestions="${this.suggestions}"
|
|
109
|
+
></mention-textarea>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
|
|
113
|
+
<mention-textarea label="Required" required .suggestions="${this.suggestions}"></mention-textarea>
|
|
114
|
+
|
|
115
|
+
<mention-textarea
|
|
116
|
+
label="Invalid"
|
|
117
|
+
invalid
|
|
118
|
+
supporting-text="This field has an error"
|
|
119
|
+
.suggestions="${this.suggestions}"
|
|
120
|
+
></mention-textarea>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<mention-textarea
|
|
124
|
+
label="Disabled"
|
|
125
|
+
disabled
|
|
126
|
+
value="This is disabled"
|
|
127
|
+
.suggestions="${this.suggestions}"
|
|
128
|
+
></mention-textarea>
|
|
129
|
+
</section>
|
|
130
|
+
|
|
131
|
+
<section class="demo-section">
|
|
132
|
+
<h2 class="display-large">Custom Trigger</h2>
|
|
133
|
+
<p>This example uses '#' as the mention trigger instead of '@'.</p>
|
|
134
|
+
|
|
135
|
+
<mention-textarea
|
|
136
|
+
label="Tags"
|
|
137
|
+
supporting-text="Type # to add tags"
|
|
138
|
+
mention-trigger="#"
|
|
139
|
+
.suggestions="${this.suggestions.map((s) => ({ ...s, label: s.label.toLowerCase().replace(' ', '-') }))}"
|
|
140
|
+
></mention-textarea>
|
|
141
|
+
</section>
|
|
142
|
+
|
|
143
|
+
<section class="demo-section">
|
|
144
|
+
<h2 class="display-large">Minimum Query Length</h2>
|
|
145
|
+
<p>This example requires at least 2 characters after @ before showing suggestions.</p>
|
|
146
|
+
|
|
147
|
+
<mention-textarea
|
|
148
|
+
label="Message with min query"
|
|
149
|
+
supporting-text="Type @+ at least 2 characters"
|
|
150
|
+
min-query-length="2"
|
|
151
|
+
.suggestions="${this.suggestions}"
|
|
152
|
+
></mention-textarea>
|
|
153
|
+
</section>
|
|
154
|
+
|
|
155
|
+
<section class="demo-section">
|
|
156
|
+
<h2 class="display-large">Overflow: Hidden Test</h2>
|
|
157
|
+
<p>
|
|
158
|
+
This test ensures the popover works correctly even inside containers with overflow: hidden. The Popover API
|
|
159
|
+
should handle this properly.
|
|
160
|
+
</p>
|
|
161
|
+
|
|
162
|
+
<div
|
|
163
|
+
style="height: 150px; overflow: hidden; border: 2px solid var(--md-sys-color-outline); border-radius: 8px; padding: 16px;"
|
|
164
|
+
>
|
|
165
|
+
<p>Container with overflow: hidden (height: 150px)</p>
|
|
166
|
+
<mention-textarea
|
|
167
|
+
label="Test @mentions here"
|
|
168
|
+
supporting-text="Type @ - the suggestions should appear outside this container"
|
|
169
|
+
.suggestions="${this.suggestions}"
|
|
170
|
+
></mention-textarea>
|
|
171
|
+
</div>
|
|
172
|
+
|
|
173
|
+
<div
|
|
174
|
+
style="height: 100px; width: 300px; overflow: hidden; border: 2px solid var(--md-sys-color-outline); border-radius: 8px; padding: 16px; margin-top: 20px;"
|
|
175
|
+
>
|
|
176
|
+
<p>Small container with overflow: hidden</p>
|
|
177
|
+
<mention-textarea label="Constrained" .suggestions="${this.suggestions}"></mention-textarea>
|
|
178
|
+
</div>
|
|
179
|
+
</section>
|
|
180
|
+
|
|
181
|
+
<style>
|
|
182
|
+
.demo-section {
|
|
183
|
+
max-width: 900px;
|
|
184
|
+
margin: 40px auto;
|
|
185
|
+
padding: 0 20px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
mention-textarea {
|
|
189
|
+
width: 100%;
|
|
190
|
+
margin-bottom: 20px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
pre {
|
|
194
|
+
font-family: 'Courier New', monospace;
|
|
195
|
+
font-size: 14px;
|
|
196
|
+
white-space: pre-wrap;
|
|
197
|
+
word-break: break-all;
|
|
198
|
+
}
|
|
199
|
+
</style>
|
|
200
|
+
`
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const instance = new ComponentDemoPage()
|
|
205
|
+
instance.render()
|