Skip to content

Commit d9ad265

Browse files
feat: add CTA to HeroBloc (#882)
- Require opendatateam/udata#3630 --------- Co-authored-by: Nicolas KEMPF <[email protected]>
1 parent e73e4e7 commit d9ad265

File tree

8 files changed

+34
-20
lines changed

8 files changed

+34
-20
lines changed

components/Pages/BrandedButtonEditor.vue

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@
2323
role="textbox"
2424
class="outline-none min-w-[10ch] focus:ring-2 focus:ring-blue-300 rounded-sm"
2525
:aria-label="$t('Titre du bouton')"
26-
@blur="$emit('update:title', ($event.target as HTMLElement).textContent || '')"
26+
@blur="title = ($event.target as HTMLElement).textContent || ''"
2727
>{{ title || $t('Titre du bouton') }}</span>
2828
</div>
2929
<input
30-
:value="href"
30+
v-model="href"
3131
type="text"
3232
class="block text-sm text-gray-500 border rounded px-2 py-1 w-full max-w-xs"
3333
:placeholder="$t('URL du bouton')"
3434
:aria-label="$t('URL du bouton')"
35-
@input="$emit('update:href', ($event.target as HTMLInputElement).value)"
3635
>
3736
</div>
3837

@@ -54,15 +53,20 @@ import { RiDeleteBinLine } from '@remixicon/vue'
5453
5554
const props = withDefaults(defineProps<{
5655
edit: boolean
57-
title?: string | null
58-
href?: string | null
5956
color?: ComponentProps<typeof BrandedButton>['color']
6057
class?: string
6158
}>(), {
6259
color: 'primary',
6360
class: '',
6461
})
6562
63+
const title = defineModel<string | null>('title')
64+
const href = defineModel<string | null>('href')
65+
66+
defineEmits<{
67+
clear: []
68+
}>()
69+
6670
const buttonColors = computed(() => {
6771
const colors: Record<string, string> = {
6872
'primary': 'text-white bg-new-primary !border-new-primary',
@@ -75,10 +79,4 @@ const buttonColors = computed(() => {
7579
}
7680
return colors[props.color] || colors.primary
7781
})
78-
79-
defineEmits<{
80-
'update:title': [value: string]
81-
'update:href': [value: string]
82-
'clear': []
83-
}>()
8482
</script>

components/Pages/HeroBloc.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636
+ {{ $t('Ajouter une description') }}
3737
</button>
3838

39+
<BrandedButtonEditor
40+
v-model:title="bloc.main_link_title"
41+
v-model:href="bloc.main_link_url"
42+
:edit
43+
color="secondary"
44+
class="mt-4"
45+
@clear="bloc.main_link_title = null; bloc.main_link_url = null"
46+
/>
47+
3948
<div
4049
v-if="edit"
4150
class="flex items-center gap-2 pt-4"
@@ -60,6 +69,7 @@
6069

6170
<script setup lang="ts">
6271
import EditableText from './EditableText.vue'
72+
import BrandedButtonEditor from './BrandedButtonEditor.vue'
6373
import type { HeroBloc } from '~/types/pages'
6474
6575
defineProps<{

components/Pages/LinksListBloc.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@
3737

3838
<!-- Main link (in the left column when paragraph is present) -->
3939
<BrandedButtonEditor
40+
v-model:title="bloc.main_link_title"
41+
v-model:href="bloc.main_link_url"
4042
:edit
41-
:title="bloc.main_link_title"
42-
:href="bloc.main_link_url"
4343
:color="mainColor"
4444
class="mt-12"
45-
@update:title="bloc.main_link_title = $event"
46-
@update:href="bloc.main_link_url = $event"
4745
@clear="bloc.main_link_title = ''; bloc.main_link_url = ''"
4846
/>
4947
</div>
@@ -137,13 +135,11 @@
137135
<!-- Main button (in the right column when no paragraph) -->
138136
<BrandedButtonEditor
139137
v-if="!bloc.paragraph"
138+
v-model:title="bloc.main_link_title"
139+
v-model:href="bloc.main_link_url"
140140
:edit
141-
:title="bloc.main_link_title"
142-
:href="bloc.main_link_url"
143141
:color="mainColor"
144142
class="mt-4"
145-
@update:title="bloc.main_link_title = $event"
146-
@update:href="bloc.main_link_url = $event"
147143
@clear="bloc.main_link_title = ''; bloc.main_link_url = ''"
148144
/>
149145
</div>

tests/edito/pages-editor.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ test('can edit edito page with all bloc types', async ({ page }) => {
6161
await page.locator('.bg-new-green-illustration.size-8').click()
6262
await page.waitForTimeout(200)
6363

64+
// Add a CTA button
65+
const heroCTATitle = page.locator('.bg-new-green-illustration [aria-label="Titre du bouton"]')
66+
await heroCTATitle.click()
67+
await heroCTATitle.fill('Découvrir les données')
68+
await page.mouse.click(1, 1)
69+
const heroCTAUrl = page.locator('.bg-new-green-illustration [aria-label="URL du bouton"]')
70+
await heroCTAUrl.fill('https://www.data.gouv.fr/fr/datasets/')
71+
6472
// Debug screenshot: after adding hero bloc
6573
await page.screenshot({ path: 'tests/edito/screenshots/01c-hero-bloc.png', fullPage: true })
6674

50.5 KB
Loading
92.6 KB
Loading

types/pages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export type HeroBloc = {
6161
title: string
6262
description: string | null
6363
color: 'primary' | 'green' | 'purple'
64+
main_link_title: string | null
65+
main_link_url: string | null
6466
} & { id: string }
6567

6668
export type PageBloc = ContentBloc | AccordionListBloc | HeroBloc

utils/pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function useBlocsTypes() {
6969
description: t('Bandeau d\'en-tête avec titre et description'),
7070
component: HeroBlocComponent,
7171
fullWidth: true,
72-
default: (): Omit<HeroBloc, 'id'> => ({ class: 'HeroBloc', title: 'Titre', description: null, color: 'primary' }),
72+
default: (): Omit<HeroBloc, 'id'> => ({ class: 'HeroBloc', title: 'Titre', description: null, color: 'primary', main_link_title: null, main_link_url: null }),
7373
},
7474
}
7575
}

0 commit comments

Comments
 (0)