@consumidor-positivo/aurora 3.0.1 → 3.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 (69) 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 +241 -0
  12. package/astro/SearchBar/index.astro +432 -0
  13. package/astro/SectionApp/index.astro +202 -0
  14. package/astro/form/Checkbox/Field/index.astro +1 -1
  15. package/astro/form/Field/ErrorMessage/index.astro +1 -1
  16. package/astro/form/Field/Input/index.astro +1 -1
  17. package/astro/form/Field/InputHolder/index.astro +1 -1
  18. package/astro/form/Field/Label/index.astro +1 -1
  19. package/astro/form/Field/Message/index.astro +1 -1
  20. package/astro/form/Field/Root/index.astro +1 -1
  21. package/astro/form/Field/TextArea/index.astro +1 -1
  22. package/dist/components/DropdownItem/index.d.ts +25 -0
  23. package/dist/components/DropdownItem/index.es.js +89 -0
  24. package/dist/components/DropdownItem/index.es.js.map +1 -0
  25. package/dist/components/DropdownItem/styles.css +1 -0
  26. package/dist/components/EmptyState/index.d.ts +37 -0
  27. package/dist/components/EmptyState/index.es.js +67 -0
  28. package/dist/components/EmptyState/index.es.js.map +1 -0
  29. package/dist/components/EmptyState/styles.css +1 -0
  30. package/dist/components/FeedbackPage/index.d.ts +26 -0
  31. package/dist/components/FeedbackPage/index.es.js +64 -0
  32. package/dist/components/FeedbackPage/index.es.js.map +1 -0
  33. package/dist/components/FeedbackPage/styles.css +1 -0
  34. package/dist/components/Field/styles.css +1 -1
  35. package/dist/components/Field/styles2.css +1 -1
  36. package/dist/components/FileUpload/Preview/index.d.ts +30 -0
  37. package/dist/components/FileUpload/Preview/index.es.js +48 -0
  38. package/dist/components/FileUpload/Preview/index.es.js.map +1 -0
  39. package/dist/components/FileUpload/Root/index.d.ts +40 -0
  40. package/dist/components/FileUpload/Root/index.es.js +132 -0
  41. package/dist/components/FileUpload/Root/index.es.js.map +1 -0
  42. package/dist/components/FileUpload/index.d.ts +10 -0
  43. package/dist/components/FileUpload/index.es.js +15 -0
  44. package/dist/components/FileUpload/index.es.js.map +1 -0
  45. package/dist/components/Footer/index.es.js +2 -74
  46. package/dist/components/Footer/index.es.js.map +1 -1
  47. package/dist/components/ListRow/index.d.ts +65 -0
  48. package/dist/components/ListRow/index.es.js +137 -0
  49. package/dist/components/ListRow/index.es.js.map +1 -0
  50. package/dist/components/ListRow/styles.css +1 -0
  51. package/dist/components/SearchBar/hooks.d.ts +36 -0
  52. package/dist/components/SearchBar/index.d.ts +3 -0
  53. package/dist/components/SearchBar/index.es.js +319 -0
  54. package/dist/components/SearchBar/index.es.js.map +1 -0
  55. package/dist/components/SearchBar/styles.css +1 -0
  56. package/dist/components/SearchBar/types.d.ts +41 -0
  57. package/dist/components/SectionApp/index.d.ts +39 -0
  58. package/dist/components/SectionApp/index.es.js +95 -0
  59. package/dist/components/SectionApp/index.es.js.map +1 -0
  60. package/dist/components/SectionApp/styles.css +1 -0
  61. package/dist/components/form/Checkbox/Field/index.es.js +1 -1
  62. package/dist/components/form/Field/index.es.js +1 -1
  63. package/dist/components/styles/styles.css +1 -0
  64. package/dist/data-CpVzbjKR.js +81 -0
  65. package/dist/data-CpVzbjKR.js.map +1 -0
  66. package/dist/main.d.ts +7 -0
  67. package/dist/main.es.js +14 -0
  68. package/dist/main.es.js.map +1 -1
  69. package/package.json +5 -3
@@ -0,0 +1,432 @@
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; `onChange` becomes
36
+ * `au:searchchange` (`detail.value`), `onSearch` becomes `au:search`
37
+ * (`detail.value`), `onSelect` becomes `au:searchselect` (`detail.value`,
38
+ * `detail.label`) and `onClear` becomes `au:searchclear`, all bubbling from
39
+ * the `au-field` root. The results come from the markup: the page can replace
40
+ * the children of the `au-search-bar__results` list with `DropdownItem`
41
+ * markup at any time (the controller picks them up), and toggles the loading
42
+ * state with `document.dispatchEvent(new CustomEvent('au:searchcontrol',
43
+ * { detail: { id, loading }, bubbles: true }))`, `id` being the input id
44
+ * (the listener sits on `window`, so the event has to bubble). `class` and
45
+ * `style` go on the `au-field` root, `data-testid` on the input; other HTML
46
+ * attributes land on the root.
47
+ */
48
+ export type Props = Omit<HTMLAttributes<'div'>, 'style' | 'placeholder'> & {
49
+ label?: string
50
+ placeholder?: string
51
+ /** Initial text of the field. */
52
+ value?: string
53
+ /** Resultados da busca, soltos ou em grupos com título. A lista abre com o campo em foco. */
54
+ options?: Array<SearchBarOption | SearchBarGroup>
55
+ /** Spinner no lugar do ícone e lista de skeletons enquanto os resultados chegam (Figma: Loading). */
56
+ loading?: boolean
57
+ /** Linha mostrada quando há texto e nenhum resultado (Figma: No Results). Vazio desliga. */
58
+ emptyText?: string
59
+ disabled?: boolean
60
+ /** Id do `<input>`; sem ele, um id gerado. */
61
+ id?: string
62
+ name?: string
63
+ style?: HTMLAttributes<'div'>['style']
64
+ }
65
+
66
+ const {
67
+ label,
68
+ placeholder = 'Buscar',
69
+ value = '',
70
+ options = [],
71
+ loading = false,
72
+ emptyText = 'Nenhum resultado',
73
+ disabled = false,
74
+ id,
75
+ name,
76
+ class: className,
77
+ style,
78
+ 'data-testid': dataTestId,
79
+ ...rest
80
+ } = Astro.props
81
+
82
+ // Stand in for the React `useId()`.
83
+ const inputId = id ?? `au-search-bar-${crypto.randomUUID().slice(0, 8)}`
84
+ const labelId = `${inputId}-label`
85
+ const listId = `${inputId}-listbox`
86
+
87
+ // Same flattening as `getSearchBarRows` (lib/components/SearchBar/hooks.ts):
88
+ // `index` counts only the options, which is what the keyboard walks.
89
+ type Row =
90
+ | { kind: 'category'; label: string }
91
+ | { kind: 'option'; option: SearchBarOption; index: number }
92
+ const rows: Row[] = []
93
+ let optionIndex = 0
94
+ for (const entry of options) {
95
+ if ('category' in entry) {
96
+ rows.push({ kind: 'category', label: entry.category })
97
+ for (const option of entry.options) {
98
+ rows.push({ kind: 'option', option, index: optionIndex })
99
+ optionIndex += 1
100
+ }
101
+ } else {
102
+ rows.push({ kind: 'option', option: entry, index: optionIndex })
103
+ optionIndex += 1
104
+ }
105
+ }
106
+
107
+ const showEmpty = !loading && rows.length === 0 && value !== '' && !!emptyText
108
+ ---
109
+
110
+ <FieldRoot
111
+ style={style}
112
+ class:list={['au-search-bar', value !== '' && 'au-search-bar--filled', loading && 'au-search-bar--loading', className]}
113
+ disabled={disabled}
114
+ data-element="au-search-bar"
115
+ data-au-search-empty-text={emptyText}
116
+ {...rest}>
117
+ <FieldLabel text={label} id={inputId} labelId={labelId} disabled={disabled} showOptionalLabel={false} />
118
+ <div class="au-search-bar__control">
119
+ <input
120
+ class="au-field__input au-search-bar__input"
121
+ type="search"
122
+ role="combobox"
123
+ id={inputId}
124
+ name={name}
125
+ value={value}
126
+ placeholder={placeholder}
127
+ disabled={disabled}
128
+ autocomplete="off"
129
+ enterkeyhint="search"
130
+ aria-autocomplete="list"
131
+ aria-expanded="false"
132
+ aria-controls={listId}
133
+ aria-label={label ? undefined : placeholder}
134
+ data-testid={dataTestId}
135
+ />
136
+ {
137
+ loading ? (
138
+ <div class="au-search-bar__action au-search-bar__action--loading">
139
+ <Spinner />
140
+ </div>
141
+ ) : value !== '' ? (
142
+ <button type="button" class="au-search-bar__action au-search-bar__action--clear" aria-label="Limpar busca" disabled={disabled}>
143
+ <IconX size="medium" />
144
+ </button>
145
+ ) : (
146
+ <button type="button" class="au-search-bar__action au-search-bar__action--search" aria-label="Buscar" disabled={disabled}>
147
+ <IconSearch />
148
+ </button>
149
+ )
150
+ }
151
+ </div>
152
+ <ul
153
+ id={listId}
154
+ class="au-search-bar__results"
155
+ role="listbox"
156
+ aria-labelledby={label ? labelId : undefined}
157
+ aria-label={label ? undefined : 'Resultados da busca'}
158
+ aria-busy={loading ? 'true' : undefined}
159
+ tabindex="-1">
160
+ {
161
+ loading ? (
162
+ [0, 1, 2].map(() => <DropdownItem label="" state="skeleton" />)
163
+ ) : showEmpty ? (
164
+ <DropdownItem label={emptyText} state="empty" />
165
+ ) : (
166
+ rows.map((row) =>
167
+ row.kind === 'category' ? (
168
+ <DropdownItem type="category" label={row.label} />
169
+ ) : (
170
+ <DropdownItem
171
+ id={`${inputId}-option-${row.index}`}
172
+ label={row.option.label}
173
+ description={row.option.description}
174
+ disabled={row.option.disabled}
175
+ selected={row.option.selected}
176
+ data-value={row.option.value}
177
+ />
178
+ ),
179
+ )
180
+ )
181
+ }
182
+ </ul>
183
+ <!-- What React renders only in some states, taken out of the page by the controller. -->
184
+ <template data-au-search-templates>
185
+ <div class="au-search-bar__action au-search-bar__action--loading">
186
+ <Spinner />
187
+ </div>
188
+ <button type="button" class="au-search-bar__action au-search-bar__action--clear" aria-label="Limpar busca" disabled={disabled}>
189
+ <IconX size="medium" />
190
+ </button>
191
+ <button type="button" class="au-search-bar__action au-search-bar__action--search" aria-label="Buscar" disabled={disabled}>
192
+ <IconSearch />
193
+ </button>
194
+ <DropdownItem label="" state="skeleton" />
195
+ <DropdownItem label="" state="skeleton" />
196
+ <DropdownItem label="" state="skeleton" />
197
+ <DropdownItem label={emptyText} state="empty" />
198
+ </template>
199
+ </FieldRoot>
200
+
201
+ <script>
202
+ import { elementController } from '@consumidor-positivo/aurora/astro/runtime'
203
+
204
+ const ITEM_CLASS = 'au-dropdown-item'
205
+ const FOCUSED_CLASS = 'au-dropdown-item--focused'
206
+
207
+ elementController('au-search-bar', ({ root, query, on, emit }) => {
208
+ const inputEl = query<HTMLInputElement>('.au-search-bar__input')
209
+ const controlEl = query<HTMLDivElement>('.au-search-bar__control')
210
+ const listEl = query<HTMLUListElement>('.au-search-bar__results')
211
+ const templateEl = query<HTMLTemplateElement>('template[data-au-search-templates]')
212
+ if (!inputEl || !controlEl || !listEl || !templateEl) return
213
+ const input = inputEl as HTMLInputElement
214
+ const control = controlEl as HTMLDivElement
215
+ const list = listEl as HTMLUListElement
216
+ const template = templateEl as HTMLTemplateElement
217
+
218
+ const [loadingAction, clearAction, searchAction, ...listNodes] = Array.from(template.content.children) as HTMLElement[]
219
+ const skeletonNodes = listNodes.slice(0, 3)
220
+ const emptyNode = listNodes[3]
221
+ template.remove()
222
+
223
+ // Controller settings only; React's root carries no such attribute.
224
+ const emptyText = root.dataset.auSearchEmptyText ?? ''
225
+ root.removeAttribute('data-au-search-empty-text')
226
+
227
+ const inputId = input.id
228
+ const disabled = input.disabled
229
+ const optionId = (index: number) => `${inputId}-option-${index}`
230
+
231
+ // Nodes the controller itself puts in the list (skeletons, empty row), as
232
+ // opposed to the options that come from the markup or from the page.
233
+ const owned = new Set<HTMLElement>([...skeletonNodes, emptyNode])
234
+ for (const child of Array.from(list.children) as HTMLElement[]) {
235
+ // Rendered with `loading` or the empty row: state, not options.
236
+ if (child.classList.contains('au-dropdown-item--state-skeleton') || child.classList.contains('au-dropdown-item--state-empty')) owned.add(child)
237
+ }
238
+ const actions = new Set<HTMLElement>([loadingAction, clearAction, searchAction])
239
+ for (const action of Array.from(control.children) as HTMLElement[]) {
240
+ if (action !== input) actions.add(action)
241
+ }
242
+
243
+ // React state.
244
+ let loading = root.classList.contains('au-search-bar--loading')
245
+ let focused = document.activeElement === input
246
+ let dismissed = false
247
+ let activeIndex: number | null = null
248
+ let optionNodes: HTMLElement[] = []
249
+ // Rows the page swaps in while the list is static.
250
+ const observer = new MutationObserver(() => render())
251
+
252
+ // The rows the page put in the list. Only controller-owned rows in the
253
+ // list (skeletons, the empty row) means the options are the stored ones;
254
+ // an empty list means the page cleared them.
255
+ function readOptions() {
256
+ const children = Array.from(list.children) as HTMLElement[]
257
+ if (children.length === 0 || children.some((child) => !owned.has(child))) {
258
+ const next = children.filter((child) => !owned.has(child))
259
+ const changed = next.length !== optionNodes.length || next.some((node, index) => node !== optionNodes[index])
260
+ optionNodes = next
261
+ // New rows, like new React `options`: the keyboard highlight restarts.
262
+ if (changed) activeIndex = null
263
+ }
264
+ }
265
+
266
+ // The option rows, in order: the `index` React keys them by.
267
+ const options = () => optionNodes.filter((node) => node.getAttribute('role') === 'option' && !node.classList.contains('au-dropdown-item--state-empty'))
268
+ const selectable = () => options().filter((node) => node.getAttribute('aria-disabled') !== 'true')
269
+
270
+ const showEmpty = () => !loading && optionNodes.length === 0 && input.value !== '' && !!emptyText
271
+ const isOpen = () => focused && !dismissed && !disabled && (loading || optionNodes.length > 0 || showEmpty())
272
+
273
+ function render() {
274
+ readOptions()
275
+ const open = isOpen()
276
+
277
+ root.classList.toggle('au-search-bar--open', open)
278
+ root.classList.toggle('au-search-bar--filled', input.value !== '')
279
+ root.classList.toggle('au-search-bar--loading', loading)
280
+ list.classList.toggle('au-search-bar__results--open', open)
281
+ if (loading) list.setAttribute('aria-busy', 'true')
282
+ else list.removeAttribute('aria-busy')
283
+ input.setAttribute('aria-expanded', String(open))
284
+ if (activeIndex === null) input.removeAttribute('aria-activedescendant')
285
+ else input.setAttribute('aria-activedescendant', optionId(activeIndex))
286
+
287
+ // The action at the right: spinner, clear or search.
288
+ const action = loading ? loadingAction : input.value !== '' ? clearAction : searchAction
289
+ const current = (Array.from(control.children) as HTMLElement[]).find((child) => actions.has(child))
290
+ if (current !== action) {
291
+ if (current) current.replaceWith(action)
292
+ else control.appendChild(action)
293
+ }
294
+
295
+ // The rows: skeletons, the empty row, or the options.
296
+ const desired = loading ? skeletonNodes : showEmpty() ? [emptyNode] : optionNodes
297
+ options().forEach((node, index) => {
298
+ node.id = optionId(index)
299
+ node.classList.toggle(FOCUSED_CLASS, activeIndex === index)
300
+ })
301
+ const children = Array.from(list.children)
302
+ if (children.length !== desired.length || desired.some((node, index) => node !== children[index])) {
303
+ list.replaceChildren(...desired)
304
+ // The controller's own swap is not a change made by the page.
305
+ observer.takeRecords()
306
+ }
307
+
308
+ // The `[activeIndex]` effect: scroll the highlighted row into view.
309
+ if (activeIndex !== null) list.querySelector<HTMLElement>(`.${FOCUSED_CLASS}`)?.scrollIntoView({ block: 'nearest' })
310
+ }
311
+
312
+ function setValue(next: string) {
313
+ if (input.value !== next) input.value = next
314
+ emit('au:searchchange', { value: next })
315
+ }
316
+
317
+ function moveActive(direction: 'down' | 'up') {
318
+ const rows = selectable()
319
+ if (loading || rows.length === 0) return
320
+ const positions = rows.map((node) => options().indexOf(node))
321
+ const current = activeIndex === null ? -1 : positions.indexOf(activeIndex)
322
+ const step = direction === 'down' ? 1 : -1
323
+ const start = current === -1 && direction === 'up' ? positions.length : current
324
+ activeIndex = positions[(start + step + positions.length) % positions.length]
325
+ }
326
+
327
+ function selectOption(node: HTMLElement) {
328
+ if (node.getAttribute('aria-disabled') === 'true') return
329
+ const label = node.querySelector('.au-dropdown-item__label')?.textContent ?? ''
330
+ setValue(label)
331
+ emit('au:searchselect', { value: node.dataset.value ?? label, label })
332
+ activeIndex = null
333
+ dismissed = true
334
+ render()
335
+ }
336
+
337
+ function clear() {
338
+ setValue('')
339
+ emit('au:searchclear')
340
+ activeIndex = null
341
+ dismissed = false
342
+ render()
343
+ input.focus()
344
+ }
345
+
346
+ function search() {
347
+ emit('au:search', { value: input.value })
348
+ input.focus()
349
+ }
350
+
351
+ input.addEventListener('input', () => {
352
+ emit('au:searchchange', { value: input.value })
353
+ activeIndex = null
354
+ dismissed = false
355
+ render()
356
+ })
357
+ input.addEventListener('focus', () => {
358
+ focused = true
359
+ render()
360
+ })
361
+ input.addEventListener('blur', () => {
362
+ focused = false
363
+ activeIndex = null
364
+ render()
365
+ })
366
+ input.addEventListener('keydown', (event) => {
367
+ if (disabled) return
368
+ const handlers: Record<string, () => void> = {
369
+ ArrowDown: () => {
370
+ event.preventDefault()
371
+ dismissed = false
372
+ moveActive('down')
373
+ render()
374
+ },
375
+ ArrowUp: () => {
376
+ event.preventDefault()
377
+ dismissed = false
378
+ moveActive('up')
379
+ render()
380
+ },
381
+ Enter: () => {
382
+ const active = activeIndex === null ? undefined : selectable().find((node) => options().indexOf(node) === activeIndex)
383
+ if (isOpen() && active) {
384
+ event.preventDefault()
385
+ selectOption(active)
386
+ return
387
+ }
388
+ emit('au:search', { value: input.value })
389
+ },
390
+ Escape: () => {
391
+ // Always prevented: Chrome clears a `type="search"` field on Escape.
392
+ event.preventDefault()
393
+ if (!isOpen()) return
394
+ dismissed = true
395
+ activeIndex = null
396
+ render()
397
+ },
398
+ }
399
+ // Own keys only: `event.key` could otherwise reach a prototype member.
400
+ if (Object.prototype.hasOwnProperty.call(handlers, event.key)) handlers[event.key]()
401
+ })
402
+
403
+ // The list and the action never take the focus from the field.
404
+ const keepFocus = (event: MouseEvent) => event.preventDefault()
405
+ list.addEventListener('mousedown', keepFocus)
406
+ for (const action of actions) action.addEventListener('mousedown', keepFocus)
407
+ clearAction.addEventListener('click', clear)
408
+ searchAction.addEventListener('click', search)
409
+ list.addEventListener('mousemove', () => {
410
+ if (activeIndex === null) return
411
+ activeIndex = null
412
+ render()
413
+ })
414
+ list.addEventListener('click', (event) => {
415
+ const row = (event.target as Element | null)?.closest<HTMLElement>(`.${ITEM_CLASS}`)
416
+ if (row && options().includes(row)) selectOption(row)
417
+ })
418
+
419
+ observer.observe(list, { childList: true })
420
+
421
+ // `loading` after the render, like the React prop changing.
422
+ on('global:au:searchcontrol', (event) => {
423
+ const detail = (event as CustomEvent<{ id?: string; loading?: boolean }>).detail
424
+ if (detail?.id !== inputId || typeof detail.loading !== 'boolean') return
425
+ loading = detail.loading
426
+ if (loading) activeIndex = null
427
+ render()
428
+ })
429
+
430
+ render()
431
+ })
432
+ </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
@@ -1,5 +1,5 @@
1
1
  ---
2
- import '../../../../dist/components/Field/styles2.css'
2
+ import '../../../../dist/components/Field/styles.css'
3
3
 
4
4
  /** Same props as the React `Field.ErrorMessage`. */
5
5
  export type Props = {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import type { HTMLAttributes } from 'astro/types'
3
- import '../../../../dist/components/Field/styles2.css'
3
+ import '../../../../dist/components/Field/styles.css'
4
4
 
5
5
  /**
6
6
  * The bare `au-field__input`. Every HTML attribute lands on the `<input>`;
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import type { HTMLAttributes } from 'astro/types'
3
- import '../../../../dist/components/Field/styles2.css'
3
+ import '../../../../dist/components/Field/styles.css'
4
4
 
5
5
  /**
6
6
  * The React `rightSideSlot` is the `right` named slot here. The
@@ -8,7 +8,7 @@ import {
8
8
  COLOR_NEUTRAL_40,
9
9
  COLOR_SUCCESS_50,
10
10
  } from '@consumidor-positivo/aurora/astro/tokens'
11
- import '../../../../dist/components/Field/styles2.css'
11
+ import '../../../../dist/components/Field/styles.css'
12
12
 
13
13
  /**
14
14
  * Same props as the React `Field.Label`. `id` is the id of the control the