@consumidor-positivo/aurora 3.0.1 → 3.2.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 (74) hide show
  1. package/assets/section-app/default-score-desktop.png +0 -0
  2. package/assets/section-app/default-score-mobile.png +0 -0
  3. package/assets/section-app/re-score-desktop.png +0 -0
  4. package/assets/section-app/re-score-mobile.png +0 -0
  5. package/astro/BadgeState/index.astro +4 -0
  6. package/astro/DropdownItem/index.astro +121 -0
  7. package/astro/EmptyState/index.astro +134 -0
  8. package/astro/FeedbackPage/index.astro +112 -0
  9. package/astro/FileUpload/Preview/index.astro +102 -0
  10. package/astro/FileUpload/Root/index.astro +205 -0
  11. package/astro/ListRow/index.astro +237 -0
  12. package/astro/Logo/ac/BadgeWhiteStroke.astro +1 -0
  13. package/astro/Logo/cp/BadgeWhiteStroke.astro +1 -1
  14. package/astro/SearchBar/index.astro +480 -0
  15. package/astro/SectionApp/index.astro +202 -0
  16. package/astro/form/Checkbox/Field/index.astro +1 -1
  17. package/astro/form/Field/ErrorMessage/index.astro +1 -1
  18. package/astro/form/Field/Input/index.astro +1 -1
  19. package/astro/form/Field/InputHolder/index.astro +1 -1
  20. package/astro/form/Field/Label/index.astro +1 -1
  21. package/astro/form/Field/Message/index.astro +1 -1
  22. package/astro/form/Field/Root/index.astro +1 -1
  23. package/astro/form/Field/TextArea/index.astro +1 -1
  24. package/dist/{BadgeWhite-CkZPPGmT.js → BadgeWhite-BjdKCzB3.js} +3 -2
  25. package/dist/{BadgeWhite-CkZPPGmT.js.map → BadgeWhite-BjdKCzB3.js.map} +1 -1
  26. package/dist/components/DropdownItem/index.d.ts +25 -0
  27. package/dist/components/DropdownItem/index.es.js +89 -0
  28. package/dist/components/DropdownItem/index.es.js.map +1 -0
  29. package/dist/components/DropdownItem/styles.css +1 -0
  30. package/dist/components/EmptyState/index.d.ts +37 -0
  31. package/dist/components/EmptyState/index.es.js +67 -0
  32. package/dist/components/EmptyState/index.es.js.map +1 -0
  33. package/dist/components/EmptyState/styles.css +1 -0
  34. package/dist/components/FeedbackPage/index.d.ts +26 -0
  35. package/dist/components/FeedbackPage/index.es.js +64 -0
  36. package/dist/components/FeedbackPage/index.es.js.map +1 -0
  37. package/dist/components/FeedbackPage/styles.css +1 -0
  38. package/dist/components/Field/styles.css +1 -1
  39. package/dist/components/Field/styles2.css +1 -1
  40. package/dist/components/FileUpload/Preview/index.d.ts +30 -0
  41. package/dist/components/FileUpload/Preview/index.es.js +48 -0
  42. package/dist/components/FileUpload/Preview/index.es.js.map +1 -0
  43. package/dist/components/FileUpload/Root/index.d.ts +40 -0
  44. package/dist/components/FileUpload/Root/index.es.js +132 -0
  45. package/dist/components/FileUpload/Root/index.es.js.map +1 -0
  46. package/dist/components/FileUpload/index.d.ts +10 -0
  47. package/dist/components/FileUpload/index.es.js +15 -0
  48. package/dist/components/FileUpload/index.es.js.map +1 -0
  49. package/dist/components/Footer/index.es.js +2 -74
  50. package/dist/components/Footer/index.es.js.map +1 -1
  51. package/dist/components/ListRow/index.d.ts +65 -0
  52. package/dist/components/ListRow/index.es.js +134 -0
  53. package/dist/components/ListRow/index.es.js.map +1 -0
  54. package/dist/components/ListRow/styles.css +1 -0
  55. package/dist/components/Logo/index.es.js +1 -1
  56. package/dist/components/SearchBar/hooks.d.ts +42 -0
  57. package/dist/components/SearchBar/index.d.ts +3 -0
  58. package/dist/components/SearchBar/index.es.js +336 -0
  59. package/dist/components/SearchBar/index.es.js.map +1 -0
  60. package/dist/components/SearchBar/styles.css +1 -0
  61. package/dist/components/SearchBar/types.d.ts +47 -0
  62. package/dist/components/SectionApp/index.d.ts +39 -0
  63. package/dist/components/SectionApp/index.es.js +95 -0
  64. package/dist/components/SectionApp/index.es.js.map +1 -0
  65. package/dist/components/SectionApp/styles.css +1 -0
  66. package/dist/components/form/Checkbox/Field/index.es.js +1 -1
  67. package/dist/components/form/Field/index.es.js +1 -1
  68. package/dist/components/styles/styles.css +1 -0
  69. package/dist/data-CpVzbjKR.js +81 -0
  70. package/dist/data-CpVzbjKR.js.map +1 -0
  71. package/dist/main.d.ts +7 -0
  72. package/dist/main.es.js +15 -1
  73. package/dist/main.es.js.map +1 -1
  74. package/package.json +5 -3
@@ -0,0 +1,480 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types'
3
+ import FieldRoot from '../form/Field/Root/index.astro'
4
+ import FieldLabel from '../form/Field/Label/index.astro'
5
+ import DropdownItem from '../DropdownItem/index.astro'
6
+ import Spinner from '../Spinner/index.astro'
7
+ import IconSearch from '../icons/default/IconSearch.astro'
8
+ import IconX from '../icons/default/IconX.astro'
9
+ import '../../dist/components/SearchBar/styles.css'
10
+
11
+ export type SearchBarOption = {
12
+ value: string
13
+ label: string
14
+ /** Segunda linha abaixo do label (Dropdown Instance, Description=True). */
15
+ description?: string
16
+ disabled?: boolean
17
+ /** Marca a opção como a escolhida (Dropdown Instance, State=Selected). */
18
+ selected?: boolean
19
+ }
20
+
21
+ /** Grupo de resultados com título (Dropdown Instance, Type=Category), como "Buscas recentes". */
22
+ export type SearchBarGroup = {
23
+ category: string
24
+ options: SearchBarOption[]
25
+ }
26
+
27
+ /**
28
+ * Same props and markup as the React `SearchBar`. The inline controller
29
+ * follows the React hook step by step: the list opens with the field focused
30
+ * and closes on blur or Escape, the search icon turns into the clear button
31
+ * as soon as there is text, ArrowUp/ArrowDown walk the enabled options with
32
+ * a virtual focus (`aria-activedescendant`), Enter picks the highlighted
33
+ * option or searches, a click on a row picks it without blurring the field.
34
+ *
35
+ * Differences from React: `value` is the initial text; `filter` filters the
36
+ * rows of the markup (the controller keeps every row it found and shows the
37
+ * ones whose label matches the text, dropping categories left empty, so the
38
+ * rows come back as the text shrinks); `onChange` becomes
39
+ * `au:searchchange` (`detail.value`), `onSearch` becomes `au:search`
40
+ * (`detail.value`), `onSelect` becomes `au:searchselect` (`detail.value`,
41
+ * `detail.label`) and `onClear` becomes `au:searchclear`, all bubbling from
42
+ * the `au-field` root. The results come from the markup: the page can replace
43
+ * the children of the `au-search-bar__results` list with `DropdownItem`
44
+ * markup at any time (the controller picks them up), and toggles the loading
45
+ * state with `document.dispatchEvent(new CustomEvent('au:searchcontrol',
46
+ * { detail: { id, loading }, bubbles: true }))`, `id` being the input id
47
+ * (the listener sits on `window`, so the event has to bubble). `class` and
48
+ * `style` go on the `au-field` root, `data-testid` on the input; other HTML
49
+ * attributes land on the root.
50
+ */
51
+ export type Props = Omit<HTMLAttributes<'div'>, 'style' | 'placeholder'> & {
52
+ label?: string
53
+ placeholder?: string
54
+ /** Initial text of the field. */
55
+ value?: string
56
+ /** Resultados da busca, soltos ou em grupos com título. A lista abre com o campo em foco. */
57
+ options?: Array<SearchBarOption | SearchBarGroup>
58
+ /**
59
+ * Filtra as linhas pelo texto digitado no próprio componente, a cada letra, sem acento e sem
60
+ * diferenciar maiúsculas (Figma: Sync). Grupo que fica sem opção some. Com o campo vazio a lista
61
+ * sai inteira. Desligado, quem filtra é a página (busca assíncrona, com `au:searchcontrol`).
62
+ */
63
+ filter?: boolean
64
+ /** Spinner no lugar do ícone e lista de skeletons enquanto os resultados chegam (Figma: Loading). */
65
+ loading?: boolean
66
+ /** Linha mostrada quando há texto e nenhum resultado (Figma: No Results). Vazio desliga. */
67
+ emptyText?: string
68
+ disabled?: boolean
69
+ /** Id do `<input>`; sem ele, um id gerado. */
70
+ id?: string
71
+ name?: string
72
+ style?: HTMLAttributes<'div'>['style']
73
+ }
74
+
75
+ const {
76
+ label,
77
+ placeholder = 'Buscar',
78
+ value = '',
79
+ options = [],
80
+ filter = false,
81
+ loading = false,
82
+ emptyText = 'Nenhum resultado',
83
+ disabled = false,
84
+ id,
85
+ name,
86
+ class: className,
87
+ style,
88
+ 'data-testid': dataTestId,
89
+ ...rest
90
+ } = Astro.props
91
+
92
+ // Stand in for the React `useId()`.
93
+ const inputId = id ?? `au-search-bar-${crypto.randomUUID().slice(0, 8)}`
94
+ const labelId = `${inputId}-label`
95
+ const listId = `${inputId}-listbox`
96
+
97
+ // Same flattening as `getSearchBarRows` (lib/components/SearchBar/hooks.ts):
98
+ // `index` counts only the options, which is what the keyboard walks.
99
+ type Row =
100
+ | { kind: 'category'; label: string }
101
+ | { kind: 'option'; option: SearchBarOption; index: number }
102
+ const rows: Row[] = []
103
+ let optionIndex = 0
104
+ for (const entry of options) {
105
+ if ('category' in entry) {
106
+ rows.push({ kind: 'category', label: entry.category })
107
+ for (const option of entry.options) {
108
+ rows.push({ kind: 'option', option, index: optionIndex })
109
+ optionIndex += 1
110
+ }
111
+ } else {
112
+ rows.push({ kind: 'option', option: entry, index: optionIndex })
113
+ optionIndex += 1
114
+ }
115
+ }
116
+
117
+ const showEmpty = !loading && rows.length === 0 && value !== '' && !!emptyText
118
+ ---
119
+
120
+ <FieldRoot
121
+ style={style}
122
+ class:list={['au-search-bar', value !== '' && !disabled && 'au-search-bar--filled', loading && 'au-search-bar--loading', className]}
123
+ disabled={disabled}
124
+ data-element="au-search-bar"
125
+ data-au-search-empty-text={emptyText}
126
+ data-au-search-filter={filter ? '' : undefined}
127
+ {...rest}>
128
+ <FieldLabel text={label} id={inputId} labelId={labelId} disabled={disabled} showOptionalLabel={false} />
129
+ <div class="au-search-bar__control">
130
+ <input
131
+ class="au-field__input au-search-bar__input"
132
+ type="search"
133
+ role="combobox"
134
+ id={inputId}
135
+ name={name}
136
+ value={value}
137
+ placeholder={placeholder}
138
+ disabled={disabled}
139
+ autocomplete="off"
140
+ enterkeyhint="search"
141
+ aria-autocomplete="list"
142
+ aria-expanded="false"
143
+ aria-controls={listId}
144
+ aria-label={label ? undefined : placeholder}
145
+ data-testid={dataTestId}
146
+ />
147
+ {
148
+ loading ? (
149
+ <div class="au-search-bar__action au-search-bar__action--loading">
150
+ <Spinner />
151
+ </div>
152
+ ) : value !== '' && !disabled ? (
153
+ <button type="button" class="au-search-bar__action au-search-bar__action--clear" aria-label="Limpar busca">
154
+ <IconX />
155
+ </button>
156
+ ) : (
157
+ <button type="button" class="au-search-bar__action au-search-bar__action--search" aria-label="Buscar" disabled={disabled}>
158
+ <IconSearch />
159
+ </button>
160
+ )
161
+ }
162
+ </div>
163
+ <ul
164
+ id={listId}
165
+ class="au-search-bar__results"
166
+ role="listbox"
167
+ aria-labelledby={label ? labelId : undefined}
168
+ aria-label={label ? undefined : 'Resultados da busca'}
169
+ aria-busy={loading ? 'true' : undefined}
170
+ tabindex="-1">
171
+ {
172
+ loading ? (
173
+ [0, 1, 2].map(() => <DropdownItem label="" state="skeleton" />)
174
+ ) : showEmpty ? (
175
+ <DropdownItem label={emptyText} state="empty" />
176
+ ) : (
177
+ rows.map((row) =>
178
+ row.kind === 'category' ? (
179
+ <DropdownItem type="category" label={row.label} />
180
+ ) : (
181
+ <DropdownItem
182
+ id={`${inputId}-option-${row.index}`}
183
+ label={row.option.label}
184
+ description={row.option.description}
185
+ disabled={row.option.disabled}
186
+ selected={row.option.selected}
187
+ data-value={row.option.value}
188
+ />
189
+ ),
190
+ )
191
+ )
192
+ }
193
+ </ul>
194
+ <!-- What React renders only in some states, taken out of the page by the controller. -->
195
+ <template data-au-search-templates>
196
+ <div class="au-search-bar__action au-search-bar__action--loading">
197
+ <Spinner />
198
+ </div>
199
+ <button type="button" class="au-search-bar__action au-search-bar__action--clear" aria-label="Limpar busca">
200
+ <IconX />
201
+ </button>
202
+ <button type="button" class="au-search-bar__action au-search-bar__action--search" aria-label="Buscar" disabled={disabled}>
203
+ <IconSearch />
204
+ </button>
205
+ <DropdownItem label="" state="skeleton" />
206
+ <DropdownItem label="" state="skeleton" />
207
+ <DropdownItem label="" state="skeleton" />
208
+ <DropdownItem label={emptyText} state="empty" />
209
+ </template>
210
+ </FieldRoot>
211
+
212
+ <script>
213
+ import { elementController } from '@consumidor-positivo/aurora/astro/runtime'
214
+
215
+ const ITEM_CLASS = 'au-dropdown-item'
216
+ const FOCUSED_CLASS = 'au-dropdown-item--focused'
217
+ const CATEGORY_CLASS = 'au-dropdown-item--type-category'
218
+
219
+ // Copy of `matchesSearch` in `lib/components/SearchBar/hooks.ts`.
220
+ const normalize = (text: string) => text.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
221
+ const matchesSearch = (label: string, value: string) => normalize(label).includes(normalize(value))
222
+
223
+ elementController('au-search-bar', ({ root, query, on, emit }) => {
224
+ const inputEl = query<HTMLInputElement>('.au-search-bar__input')
225
+ const controlEl = query<HTMLDivElement>('.au-search-bar__control')
226
+ const listEl = query<HTMLUListElement>('.au-search-bar__results')
227
+ const templateEl = query<HTMLTemplateElement>('template[data-au-search-templates]')
228
+ if (!inputEl || !controlEl || !listEl || !templateEl) return
229
+ const input = inputEl as HTMLInputElement
230
+ const control = controlEl as HTMLDivElement
231
+ const list = listEl as HTMLUListElement
232
+ const template = templateEl as HTMLTemplateElement
233
+
234
+ const [loadingAction, clearAction, searchAction, ...listNodes] = Array.from(template.content.children) as HTMLElement[]
235
+ const skeletonNodes = listNodes.slice(0, 3)
236
+ const emptyNode = listNodes[3]
237
+ template.remove()
238
+
239
+ // Controller settings only; React's root carries no such attribute.
240
+ const emptyText = root.dataset.auSearchEmptyText ?? ''
241
+ root.removeAttribute('data-au-search-empty-text')
242
+ const filter = root.hasAttribute('data-au-search-filter')
243
+ root.removeAttribute('data-au-search-filter')
244
+
245
+ const inputId = input.id
246
+ const disabled = input.disabled
247
+ const optionId = (index: number) => `${inputId}-option-${index}`
248
+
249
+ // Nodes the controller itself puts in the list (skeletons, empty row), as
250
+ // opposed to the options that come from the markup or from the page.
251
+ const owned = new Set<HTMLElement>([...skeletonNodes, emptyNode])
252
+ for (const child of Array.from(list.children) as HTMLElement[]) {
253
+ // Rendered with `loading` or the empty row: state, not options.
254
+ if (child.classList.contains('au-dropdown-item--state-skeleton') || child.classList.contains('au-dropdown-item--state-empty')) owned.add(child)
255
+ }
256
+ const actions = new Set<HTMLElement>([loadingAction, clearAction, searchAction])
257
+ for (const action of Array.from(control.children) as HTMLElement[]) {
258
+ if (action !== input) actions.add(action)
259
+ }
260
+
261
+ // React state.
262
+ let loading = root.classList.contains('au-search-bar--loading')
263
+ let focused = document.activeElement === input
264
+ let dismissed = false
265
+ let activeIndex: number | null = null
266
+ let optionNodes: HTMLElement[] = []
267
+ // What the controller itself last put in the list: the same children
268
+ // again means the page did not touch the rows.
269
+ let lastRendered: HTMLElement[] | null = null
270
+ // Rows the page swaps in while the list is static.
271
+ const observer = new MutationObserver(() => render())
272
+
273
+ // The rows the page put in the list. Children equal to the last render
274
+ // (the filtered subset, the skeletons, the empty row) mean the options
275
+ // are the stored ones; anything else is the page's new rows, or the page
276
+ // clearing them.
277
+ function readOptions() {
278
+ const children = Array.from(list.children) as HTMLElement[]
279
+ if (lastRendered && children.length === lastRendered.length && children.every((child, index) => child === lastRendered![index])) return
280
+ const next = children.filter((child) => !owned.has(child))
281
+ const changed = next.length !== optionNodes.length || next.some((node, index) => node !== optionNodes[index])
282
+ optionNodes = next
283
+ // New rows, like new React `options`: the keyboard highlight restarts.
284
+ if (changed) activeIndex = null
285
+ }
286
+
287
+ const isOption = (node: HTMLElement) => node.getAttribute('role') === 'option' && !node.classList.contains('au-dropdown-item--state-empty')
288
+ const labelOf = (node: HTMLElement) => node.querySelector('.au-dropdown-item__label')?.textContent ?? ''
289
+
290
+ // The rows to show: with `filter` and text, the options whose label
291
+ // matches and the categories that still have one below them, as
292
+ // `filterSearchBarOptions` in the React hook.
293
+ const visible = () => {
294
+ if (!filter || input.value === '') return optionNodes
295
+ const kept: HTMLElement[] = []
296
+ let category: HTMLElement | null = null
297
+ for (const node of optionNodes) {
298
+ if (node.classList.contains(CATEGORY_CLASS)) {
299
+ category = node
300
+ continue
301
+ }
302
+ if (isOption(node) && !matchesSearch(labelOf(node), input.value)) continue
303
+ if (category) {
304
+ kept.push(category)
305
+ category = null
306
+ }
307
+ kept.push(node)
308
+ }
309
+ return kept
310
+ }
311
+
312
+ // The option rows, in order: the `index` React keys them by.
313
+ const options = () => visible().filter(isOption)
314
+ const selectable = () => options().filter((node) => node.getAttribute('aria-disabled') !== 'true')
315
+
316
+ const showEmpty = () => !loading && visible().length === 0 && input.value !== '' && !!emptyText
317
+ const isOpen = () => focused && !dismissed && !disabled && (loading || visible().length > 0 || showEmpty())
318
+
319
+ function render() {
320
+ readOptions()
321
+ const open = isOpen()
322
+
323
+ root.classList.toggle('au-search-bar--open', open)
324
+ root.classList.toggle('au-search-bar--filled', input.value !== '' && !disabled)
325
+ root.classList.toggle('au-search-bar--loading', loading)
326
+ list.classList.toggle('au-search-bar__results--open', open)
327
+ if (loading) list.setAttribute('aria-busy', 'true')
328
+ else list.removeAttribute('aria-busy')
329
+ input.setAttribute('aria-expanded', String(open))
330
+ if (activeIndex === null) input.removeAttribute('aria-activedescendant')
331
+ else input.setAttribute('aria-activedescendant', optionId(activeIndex))
332
+
333
+ // The action at the right: spinner, clear or search.
334
+ // Disabled keeps the search icon: the spec has no Filled state with the X there.
335
+ const action = loading ? loadingAction : input.value !== '' && !disabled ? clearAction : searchAction
336
+ const current = (Array.from(control.children) as HTMLElement[]).find((child) => actions.has(child))
337
+ if (current !== action) {
338
+ if (current) current.replaceWith(action)
339
+ else control.appendChild(action)
340
+ }
341
+
342
+ // The rows: skeletons, the empty row, or the (filtered) options.
343
+ const desired = loading ? skeletonNodes : showEmpty() ? [emptyNode] : visible()
344
+ options().forEach((node, index) => {
345
+ node.id = optionId(index)
346
+ node.classList.toggle(FOCUSED_CLASS, activeIndex === index)
347
+ })
348
+ const children = Array.from(list.children)
349
+ if (children.length !== desired.length || desired.some((node, index) => node !== children[index])) {
350
+ list.replaceChildren(...desired)
351
+ // The controller's own swap is not a change made by the page.
352
+ observer.takeRecords()
353
+ }
354
+ lastRendered = desired
355
+
356
+ // The `[activeIndex]` effect: scroll the highlighted row into view.
357
+ if (activeIndex !== null) list.querySelector<HTMLElement>(`.${FOCUSED_CLASS}`)?.scrollIntoView({ block: 'nearest' })
358
+ }
359
+
360
+ function setValue(next: string) {
361
+ if (input.value !== next) input.value = next
362
+ emit('au:searchchange', { value: next })
363
+ }
364
+
365
+ function moveActive(direction: 'down' | 'up') {
366
+ const rows = selectable()
367
+ if (loading || rows.length === 0) return
368
+ const positions = rows.map((node) => options().indexOf(node))
369
+ const current = activeIndex === null ? -1 : positions.indexOf(activeIndex)
370
+ const step = direction === 'down' ? 1 : -1
371
+ const start = current === -1 && direction === 'up' ? positions.length : current
372
+ activeIndex = positions[(start + step + positions.length) % positions.length]
373
+ }
374
+
375
+ function selectOption(node: HTMLElement) {
376
+ if (node.getAttribute('aria-disabled') === 'true') return
377
+ const label = labelOf(node)
378
+ setValue(label)
379
+ emit('au:searchselect', { value: node.dataset.value ?? label, label })
380
+ activeIndex = null
381
+ dismissed = true
382
+ render()
383
+ }
384
+
385
+ function clear() {
386
+ setValue('')
387
+ emit('au:searchclear')
388
+ activeIndex = null
389
+ dismissed = false
390
+ render()
391
+ input.focus()
392
+ }
393
+
394
+ function search() {
395
+ emit('au:search', { value: input.value })
396
+ input.focus()
397
+ }
398
+
399
+ input.addEventListener('input', () => {
400
+ emit('au:searchchange', { value: input.value })
401
+ activeIndex = null
402
+ dismissed = false
403
+ render()
404
+ })
405
+ input.addEventListener('focus', () => {
406
+ focused = true
407
+ render()
408
+ })
409
+ input.addEventListener('blur', () => {
410
+ focused = false
411
+ activeIndex = null
412
+ render()
413
+ })
414
+ input.addEventListener('keydown', (event) => {
415
+ if (disabled) return
416
+ const handlers: Record<string, () => void> = {
417
+ ArrowDown: () => {
418
+ event.preventDefault()
419
+ dismissed = false
420
+ moveActive('down')
421
+ render()
422
+ },
423
+ ArrowUp: () => {
424
+ event.preventDefault()
425
+ dismissed = false
426
+ moveActive('up')
427
+ render()
428
+ },
429
+ Enter: () => {
430
+ const active = activeIndex === null ? undefined : selectable().find((node) => options().indexOf(node) === activeIndex)
431
+ if (isOpen() && active) {
432
+ event.preventDefault()
433
+ selectOption(active)
434
+ return
435
+ }
436
+ emit('au:search', { value: input.value })
437
+ },
438
+ Escape: () => {
439
+ // Always prevented: Chrome clears a `type="search"` field on Escape.
440
+ event.preventDefault()
441
+ if (!isOpen()) return
442
+ dismissed = true
443
+ activeIndex = null
444
+ render()
445
+ },
446
+ }
447
+ // Own keys only: `event.key` could otherwise reach a prototype member.
448
+ if (Object.prototype.hasOwnProperty.call(handlers, event.key)) handlers[event.key]()
449
+ })
450
+
451
+ // The list and the action never take the focus from the field.
452
+ const keepFocus = (event: MouseEvent) => event.preventDefault()
453
+ list.addEventListener('mousedown', keepFocus)
454
+ for (const action of actions) action.addEventListener('mousedown', keepFocus)
455
+ clearAction.addEventListener('click', clear)
456
+ searchAction.addEventListener('click', search)
457
+ list.addEventListener('mousemove', () => {
458
+ if (activeIndex === null) return
459
+ activeIndex = null
460
+ render()
461
+ })
462
+ list.addEventListener('click', (event) => {
463
+ const row = (event.target as Element | null)?.closest<HTMLElement>(`.${ITEM_CLASS}`)
464
+ if (row && options().includes(row)) selectOption(row)
465
+ })
466
+
467
+ observer.observe(list, { childList: true })
468
+
469
+ // `loading` after the render, like the React prop changing.
470
+ on('global:au:searchcontrol', (event) => {
471
+ const detail = (event as CustomEvent<{ id?: string; loading?: boolean }>).detail
472
+ if (detail?.id !== inputId || typeof detail.loading !== 'boolean') return
473
+ loading = detail.loading
474
+ if (loading) activeIndex = null
475
+ render()
476
+ })
477
+
478
+ render()
479
+ })
480
+ </script>
@@ -0,0 +1,202 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types'
3
+ import type { ImageMetadata } from 'astro'
4
+ import Divider from '../Divider/index.astro'
5
+ import Text from '../Text/index.astro'
6
+ import IconCheck from '../icons/default/IconCheck.astro'
7
+ import defaultScoreDesktop from '@consumidor-positivo/aurora/assets/section-app/default-score-desktop.png'
8
+ import defaultScoreMobile from '@consumidor-positivo/aurora/assets/section-app/default-score-mobile.png'
9
+ import reScoreDesktop from '@consumidor-positivo/aurora/assets/section-app/re-score-desktop.png'
10
+ import reScoreMobile from '@consumidor-positivo/aurora/assets/section-app/re-score-mobile.png'
11
+ import '../../dist/components/SectionApp/styles.css'
12
+
13
+ export type SectionAppType = 'default' | 'about-us' | 'step-by-step'
14
+ export type SectionAppSize = 'mobile' | 'desktop'
15
+ export type SectionAppCampaign = 'default-score' | 're-score'
16
+
17
+ // The Section App Image of the Figma, one per campaign and size. Astro hands
18
+ // a PNG import back as metadata (`.src` is the URL) while plain Vite hands
19
+ // back the URL; `vite/client` types it as the string, so both are handled.
20
+ type ImportedImage = string | ImageMetadata
21
+ function imageUrl(asset: ImportedImage): string {
22
+ return typeof asset === 'string' ? asset : asset.src
23
+ }
24
+ const CAMPAIGN_IMAGES: Record<SectionAppCampaign, Record<SectionAppSize, string>> = {
25
+ 'default-score': { desktop: imageUrl(defaultScoreDesktop), mobile: imageUrl(defaultScoreMobile) },
26
+ 're-score': { desktop: imageUrl(reScoreDesktop), mobile: imageUrl(reScoreMobile) },
27
+ }
28
+
29
+ export type SectionAppStores = {
30
+ googleplay?: string
31
+ appstore?: string
32
+ }
33
+
34
+ export type SectionAppQrCode = {
35
+ src: string
36
+ alt?: string
37
+ text?: string
38
+ }
39
+
40
+ // Copy of `storesMap` in `lib/components/Footer/data.tsx` (a `.tsx` is not
41
+ // published with the Astro files); the Footer's `index.astro` has the same
42
+ // copy. Changed a badge there, change it here.
43
+ const STORES = {
44
+ googleplay: {
45
+ name: 'Google Play',
46
+ icon: 'https://assets.acordocerto.com.br/f/114280/117x36/e0e7eda65d/google-play.png',
47
+ },
48
+ appstore: {
49
+ name: 'App Store',
50
+ icon: 'https://assets.acordocerto.com.br/f/114280/117x36/38b0d1ecc9/app-store.png',
51
+ },
52
+ }
53
+
54
+ const DEFAULT_QR_TEXT = 'Ou escaneie o código para baixar nosso aplicativo.'
55
+
56
+ /**
57
+ * Same props and markup as the React `SectionApp`. Differences: `logo` and
58
+ * `image` are the `logo` and `image` named slots (the `image` slot wins over
59
+ * `campaign`). Every HTML attribute is forwarded to the `<section>`.
60
+ */
61
+ export type Props = HTMLAttributes<'section'> & {
62
+ /** Default (ações antes da lista, checks), About us (ações depois da lista) ou Step-by-step (números, até 6 itens). Figma: Section App, Type. */
63
+ type?: SectionAppType
64
+ title: string
65
+ description?: string
66
+ /** Benefícios (Default e About us) ou passos (Step-by-step), um por linha. */
67
+ items: string[]
68
+ /** Links das lojas; os badges vêm da lib (os mesmos do Footer). Sem nenhum, a seção sai sem botões. */
69
+ stores?: SectionAppStores
70
+ /** QR code ao lado dos botões. Só aparece no Desktop (a partir de 1024px). */
71
+ qrCode?: SectionAppQrCode
72
+ /** Uma das artes do Section App Image que vêm com a lib (Default Score ou Rê Score), na versão Mobile ou Desktop conforme o breakpoint ou `size`. */
73
+ campaign?: SectionAppCampaign
74
+ /** Força o layout Mobile (empilhado, sem QR code) ou Desktop (lado a lado, com QR code). Sem ela, segue o breakpoint de 1024px. Figma: Size. */
75
+ size?: SectionAppSize
76
+ /** Tag do título. */
77
+ titleAs?: 'h1' | 'h2' | 'h3'
78
+ }
79
+
80
+ const {
81
+ type = 'default',
82
+ title,
83
+ description,
84
+ items,
85
+ stores = {},
86
+ qrCode,
87
+ campaign,
88
+ size,
89
+ titleAs = 'h2',
90
+ class: className,
91
+ ...rest
92
+ } = Astro.props
93
+
94
+ const usedStores = (Object.keys(stores) as Array<keyof SectionAppStores>)
95
+ .filter((store) => !!stores[store])
96
+ .map((store) => ({ ...STORES[store], url: stores[store]! }))
97
+ const hasActions = usedStores.length > 0 || !!qrCode
98
+ const numbered = type === 'step-by-step'
99
+ const hasLogo = Astro.slots.has('logo')
100
+ const hasImageSlot = Astro.slots.has('image')
101
+ const campaignImages = campaign ? CAMPAIGN_IMAGES[campaign] : undefined
102
+ const hasImage = hasImageSlot || !!campaignImages
103
+ const actionsFirst = type === 'default'
104
+ ---
105
+
106
+ <section
107
+ class:list={[
108
+ 'au-section-app',
109
+ `au-section-app--type-${type}`,
110
+ size && `au-section-app--size-${size}`,
111
+ hasLogo && 'au-section-app--with-logo',
112
+ hasImage && 'au-section-app--with-image',
113
+ className,
114
+ ]}
115
+ {...rest}>
116
+ <div class="au-section-app__content">
117
+ {
118
+ hasLogo && (
119
+ <div class="au-section-app__logo" aria-hidden="true">
120
+ <slot name="logo" />
121
+ </div>
122
+ )
123
+ }
124
+ <div class="au-section-app__text">
125
+ <Text as={titleAs} variant="heading-medium" weight="bold" class="au-section-app__title">
126
+ {title}
127
+ </Text>
128
+ {
129
+ description && (
130
+ <Text as="p" variant="body-medium" color="secondary" class="au-section-app__description">
131
+ {description}
132
+ </Text>
133
+ )
134
+ }
135
+ </div>
136
+ {
137
+ [actionsFirst ? 'actions' : 'list', actionsFirst ? 'list' : 'actions'].map((block, index) => (
138
+ <Fragment>
139
+ {index === 1 && hasActions && <Divider width="small" />}
140
+ {block === 'actions' && hasActions && (
141
+ <div class="au-section-app__actions">
142
+ {usedStores.length > 0 && (
143
+ <div class="au-section-app__stores">
144
+ {usedStores.map(({ icon, url, name }) => (
145
+ <a class="au-section-app__store" href={url} target="_blank" rel="noopener noreferrer">
146
+ <img src={icon} alt={name} width="133" height="42" loading="lazy" draggable="false" />
147
+ </a>
148
+ ))}
149
+ </div>
150
+ )}
151
+ {usedStores.length > 0 && qrCode && <span class="au-section-app__actions-divider" aria-hidden="true" />}
152
+ {qrCode && (
153
+ <div class="au-section-app__qr">
154
+ <img
155
+ class="au-section-app__qr-image"
156
+ src={qrCode.src}
157
+ alt={qrCode.alt ?? 'QR code para baixar o aplicativo'}
158
+ width="74"
159
+ height="74"
160
+ loading="lazy"
161
+ draggable="false"
162
+ />
163
+ <Text as="p" variant="body-medium" color="secondary" class="au-section-app__qr-text">
164
+ {qrCode.text ?? DEFAULT_QR_TEXT}
165
+ </Text>
166
+ </div>
167
+ )}
168
+ </div>
169
+ )}
170
+ {block === 'list' && (
171
+ <ol class="au-section-app__list">
172
+ {items.map((item, itemIndex) => (
173
+ <li class="au-section-app__item">
174
+ <span class:list={['au-section-app__marker', numbered && 'au-section-app__marker--number']} aria-hidden="true">
175
+ {numbered ? itemIndex + 1 : <IconCheck size="small" />}
176
+ </span>
177
+ <span class="au-section-app__item-text">{item}</span>
178
+ </li>
179
+ ))}
180
+ </ol>
181
+ )}
182
+ </Fragment>
183
+ ))
184
+ }
185
+ </div>
186
+ <div class="au-section-app__image-area">
187
+ <div class:list={['au-section-app__image', hasImage && 'au-section-app__image--filled']}>
188
+ {
189
+ hasImageSlot ? (
190
+ <slot name="image" />
191
+ ) : campaignImages && size ? (
192
+ <img class="au-section-app__campaign" src={campaignImages[size]} alt="" loading="lazy" draggable="false" />
193
+ ) : campaignImages ? (
194
+ <picture>
195
+ <source media="(min-width: 1024px)" srcset={campaignImages.desktop} />
196
+ <img class="au-section-app__campaign" src={campaignImages.mobile} alt="" loading="lazy" draggable="false" />
197
+ </picture>
198
+ ) : null
199
+ }
200
+ </div>
201
+ </div>
202
+ </section>
@@ -3,7 +3,7 @@ import type { HTMLAttributes } from 'astro/types'
3
3
  import { COLOR_NEUTRAL_00 } from '@consumidor-positivo/aurora/astro/tokens'
4
4
  import IconCheck from '../../../icons/default/IconCheck.astro'
5
5
  import FieldErrorMessage from '../../Field/ErrorMessage/index.astro'
6
- import '../../../../dist/components/Field/styles.css'
6
+ import '../../../../dist/components/Field/styles2.css'
7
7
 
8
8
  /**
9
9
  * Same as React: every attribute except `style` and `class` goes to the