Skip to content

Commit 9cd2759

Browse files
committed
fix: primary cta size on mobile
1 parent 9529230 commit 9cd2759

File tree

3 files changed

+84
-15
lines changed

3 files changed

+84
-15
lines changed

components/blocks/text-block.vue

+59-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
</div>
2626

2727
<div v-if="block.ctas" class="button-row">
28-
<template v-if="block.ctas && Array.isArray(block.ctas)">
28+
<template v-if="ctaData">
2929
<ButtonCta
3030
v-for="(cta, index) in ctaData"
3131
:key="index"
3232
:tag="cta.tag"
3333
:to="cta.to"
3434
:theme="cta.theme"
35+
:variant="ctaVariant || cta.variant"
3536
:disabled="cta.disabled">
3637
{{ cta.text }}
3738
<span
@@ -71,11 +72,43 @@ export default {
7172
}
7273
},
7374
75+
data () {
76+
return {
77+
resize: false,
78+
ctaVariant: false
79+
}
80+
},
81+
7482
computed: {
7583
ctaData () {
76-
return this.block.ctas.map((object) => {
77-
return { ...object, disabled: object.to === undefined || object.to === '' }
78-
})
84+
if (this.block.ctas && Array.isArray(this.block.ctas)) {
85+
return this.block.ctas.map((object) => {
86+
return { ...object, disabled: object.to === undefined || object.to === '' }
87+
})
88+
}
89+
return false
90+
}
91+
},
92+
93+
mounted () {
94+
if (this.ctaData && this.ctaData.some(cta => cta.theme === 'primary' && cta.variant !== 'large')) {
95+
this.resizeCta()
96+
this.resize = () => { this.resizeCta() }
97+
window.addEventListener('resize', this.resize )
98+
}
99+
},
100+
101+
beforeUnmount () {
102+
if (this.resize) { window.removeEventListener('resize', this.resize) }
103+
},
104+
105+
methods: {
106+
resizeCta () {
107+
if (window.matchMedia('(max-width: 40rem)').matches) {
108+
if (!this.ctaVariant) { this.ctaVariant = 'small' }
109+
} else if (this.ctaVariant) {
110+
this.ctaVariant = false
111+
}
79112
}
80113
}
81114
}
@@ -151,4 +184,26 @@ export default {
151184
}
152185
}
153186
}
187+
188+
.button-row {
189+
:deep(.button) {
190+
&.theme__primary {
191+
@include mini {
192+
height: toRem(33);
193+
}
194+
.inner-content {
195+
@include mini {
196+
height: toRem(33);
197+
padding: toRem(8) toRem(28) toRem(8) toRem(10);
198+
}
199+
}
200+
.detail-wrapper {
201+
@include mini {
202+
left: toRem(-19);
203+
width: calc(100% + toRem(19) - toRem(2));
204+
}
205+
}
206+
}
207+
}
208+
}
154209
</style>

components/button/cta.vue

+24-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<ZeroButton
33
v-slot="{ loading }"
44
v-bind="props"
5-
:class="['button-x', `theme__${props.theme}`, { large: variantLarge }]">
5+
:class="['button-x', `theme__${props.theme}`, variant]">
66
<div class="inner-content">
77

8-
<div :class="['detail-wrapper', { large: variantLarge }]">
8+
<div :class="['detail-wrapper', variant]">
99
<svg
1010
v-if="theme === 'primary'"
1111
width="400"
12-
:height="variantLarge ? 57 : 41"
13-
:viewBox="`0 0 400 ${ variantLarge ? 57 : 41 }`"
12+
:height="detailHeight"
13+
:viewBox="`0 0 400 ${detailHeight}`"
1414
fill="none"
1515
xmlns="http://www.w3.org/2000/svg"
1616
class="detail">
@@ -73,18 +73,32 @@ const props = defineProps({
7373
required: false,
7474
default: 'primary'
7575
},
76-
variantLarge: {
77-
type: Boolean,
76+
variant: { // 'large', 'small' or none
77+
type: String,
7878
required: false,
79-
default: false
79+
default: ''
8080
}
8181
})
8282
8383
// ==================================================================== Computed
8484
const path = computed(() => {
85-
return props.variantLarge ?
86-
'M 536 53.6 H 2.7391 C 1.871 53.6 1.232 52.7872 1.34 51.9436 L 9.5042 18.7416 C 12.06 8.04 21.44 1.34 32.16 1.34 H 536' :
87-
'M 400 40 H 2.0441 C 1.3963 40 0.9194 39.3934 1 38.7639 L 7.0927 13.9863 C 9 6 16 1 24 1 H 400'
85+
if (props.variant === 'large') {
86+
return 'M 536 53.6 H 2.7391 C 1.871 53.6 1.232 52.7872 1.34 51.9436 L 9.5042 18.7416 C 12.06 8.04 21.44 1.34 32.16 1.34 H 536'
87+
}
88+
if (props.variant === 'small') {
89+
return 'M 322 32 H 2.25 C 1 32 1 30.75 1 30.75 L 6 11 C 7 5 13 1 19 1 H 322'
90+
}
91+
return 'M 400 40 H 2.0441 C 1.3963 40 0.9194 39.3934 1 38.7639 L 7.0927 13.9863 C 9 6 16 1 24 1 H 400'
92+
})
93+
94+
const detailHeight = computed(() => {
95+
if (props.variant === 'large') {
96+
return 57
97+
}
98+
if (props.variant === 'small') {
99+
return 33
100+
}
101+
return 41
88102
})
89103
90104
</script>

components/site-header.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
tag="nuxt-link"
1616
to="/"
1717
theme="primary"
18-
:variant-large="true"
18+
variant="large"
1919
class="modal-sign-up-cta">
2020
Sign up
2121
</ButtonCta>

0 commit comments

Comments
 (0)