-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding greybox to map * MWPW-160548: CTA Widget and Chat CTA style updates (#273) * Updated CSS to match current designs. Found a few issues that require discusssion * Small tweaks to height and display: * Adding new block, good way there * Styles mostly all there, just need to get the 'modal' screen on mobile * add curtain * widget button style updates * sync with figma styles * unit tests * fix mobile landscape * change selector - safari 16 bug * fix button color on safari * hide scrollbar when not needed --------- Co-authored-by: Jason Slavin <[email protected]> --------- Co-authored-by: Jason Slavin <[email protected]> Co-authored-by: Jason Slavin <[email protected]>
- Loading branch information
1 parent
015d301
commit 28ebd57
Showing
6 changed files
with
317 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
.cta-widget { | ||
position: fixed; | ||
width: fit-content; | ||
height: 56px; | ||
right: 10px; | ||
bottom: 10px; | ||
background-color: var(--color-white); | ||
border-radius: 6px; | ||
border: 1px solid #909090; | ||
box-shadow: 2px 4px 6px 0 #0003; | ||
z-index: 4; | ||
padding: 0; | ||
font-family: var(--body-font-family); | ||
color: var(--text-color); | ||
} | ||
|
||
.cta-widget div { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 16px; | ||
font-weight: 700; | ||
padding: 0 24px; | ||
} | ||
|
||
.cta-widget span.icon-chat { | ||
margin-inline-end: 13px; | ||
width: auto; | ||
} | ||
|
||
.cta-widget .icon-chat svg { | ||
width: 26px; | ||
height: auto; | ||
} | ||
|
||
.cta-widget-body { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
margin: auto auto 0; | ||
position: fixed; | ||
right: 0; | ||
bottom: 10px; | ||
left: 0; | ||
box-shadow: 2px 4px 6px 0 #0003; | ||
border-radius: 6px; | ||
border: 1px solid #909090; | ||
z-index: 12; | ||
background-color: var(--background-color); | ||
width: 340px; | ||
max-height: calc(100vh - 20px); | ||
padding: 40px 33px; | ||
box-sizing: border-box; | ||
overflow-y: auto; | ||
} | ||
|
||
.cta-widget-body.hidden, | ||
.cta-widget.hidden, | ||
.cta-curtain.hidden { | ||
display: none; | ||
} | ||
|
||
.cta-widget-body div { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
width: 100%; | ||
} | ||
|
||
.cta-widget-body div:first-of-type { | ||
padding-bottom: 32px; | ||
border-bottom: 1px solid rgb(112 112 112); | ||
} | ||
|
||
.cta-widget-body div:last-of-type { | ||
margin-top: 32px; | ||
} | ||
|
||
.cta-widget-body div img { | ||
max-width: 32px; | ||
} | ||
|
||
.cta-widget-body div :is(h1, h2, h3, h4, h5, h6) { | ||
font-size: var(--type-heading-s-size); | ||
margin: 0; | ||
line-height: var(--type-heading-s-lh); | ||
max-width: 200px; | ||
} | ||
|
||
.cta-widget-body div p { | ||
font-size: var(--type-body-xs-size); | ||
line-height: var(--type-body-xs-lh); | ||
margin-bottom: var(--spacing-xs); | ||
max-width: 200px; | ||
text-align: center; | ||
} | ||
|
||
.cta-widget-body div p:first-of-type { | ||
margin: 0 0 16px; | ||
} | ||
|
||
.cta-widget-body div p:nth-child(3) { | ||
margin: 5px 0 24px; | ||
} | ||
|
||
.cta-widget-body div p:last-of-type { | ||
margin: 0; | ||
} | ||
|
||
.widget-close { | ||
width: 18px; | ||
height: auto; | ||
position: absolute; | ||
top: 16.5px; | ||
right: 14px; | ||
padding: 0; | ||
background-color: transparent; | ||
border: none; | ||
color: var(--text-color); | ||
} | ||
|
||
.cta-curtain { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
background-color: rgb(0 0 0 / 50%); | ||
z-index: 11; | ||
} | ||
|
||
@media screen and (min-width: 900px), | ||
screen and (max-height: 499px) { | ||
.cta-widget-body { | ||
flex-direction: row; | ||
max-width: 482px; | ||
width: unset; | ||
height: unset; | ||
top: auto; | ||
right: 10px; | ||
bottom: 10px; | ||
left: auto; | ||
margin: 0; | ||
padding: 32px; | ||
align-items: stretch; | ||
} | ||
|
||
.cta-widget-body div { | ||
max-width: 241px; | ||
align-items: flex-start; | ||
justify-content: flex-start; | ||
} | ||
|
||
.cta-widget-body div p { | ||
max-width: 177px; | ||
text-align: left; | ||
} | ||
|
||
.cta-widget-body div p:nth-child(3) { | ||
flex-grow: 1; | ||
} | ||
|
||
.cta-widget-body div:first-of-type { | ||
padding-right: 32px; | ||
padding-bottom: 0; | ||
border-right: 1px solid rgb(112 112 112); | ||
border-bottom: none; | ||
} | ||
|
||
.cta-widget-body div:last-of-type { | ||
margin: 0; | ||
padding-left: 32px; | ||
} | ||
} | ||
|
||
@media screen and (min-width: 900px) { | ||
.cta-curtain { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { LIBS } from '../../scripts/scripts.js'; | ||
|
||
const CLOSE_ICON = `<svg id="close" viewBox="0 0 18 18"> | ||
<path fill="currentcolor" d="M13.2425,3.343,9,7.586,4.7575,3.343a.5.5,0,0,0-.707,0L3.343,4.05a.5.5,0,0,0,0,.707L7.586,9,3.343,13.2425a.5.5,0,0,0,0,.707l.707.7075a.5.5,0,0,0,.707,0L9,10.414l4.2425,4.243a.5.5,0,0,0,.707,0l.7075-.707a.5.5,0,0,0,0-.707L10.414,9l4.243-4.2425a.5.5,0,0,0,0-.707L13.95,3.343a.5.5,0,0,0-.70711-.00039Z"/> | ||
</svg>`; | ||
|
||
export default async function init(el) { | ||
const { createTag } = await import(`${LIBS}/utils/utils.js`); | ||
|
||
const [widgetDiv, cta1Div, cta2Div] = el.querySelectorAll(':scope > div'); | ||
const widgetSection = createTag('button', { class: 'cta-widget', tabindex: '0' }, widgetDiv.querySelector('div')); | ||
const ctaSections = [cta1Div.querySelector('div'), cta2Div.querySelector('div')]; | ||
const ctaSection = createTag('section', { class: 'cta-widget-body', tabindex: '0' }, ctaSections); | ||
const close = createTag('button', { | ||
class: 'widget-close', | ||
'aria-label': 'Close', | ||
}, CLOSE_ICON); | ||
const curtain = createTag('div', { class: 'cta-curtain' }); | ||
|
||
ctaSections.forEach((section) => section.querySelector('a')?.classList.add('con-button', 'outline')); | ||
|
||
ctaSection.classList.add('hidden'); | ||
ctaSection.prepend(close); | ||
curtain.classList.add('hidden'); | ||
|
||
widgetSection.addEventListener('click', () => { | ||
ctaSection.classList.remove('hidden'); | ||
curtain.classList.remove('hidden'); | ||
widgetSection.classList.add('hidden'); | ||
}); | ||
|
||
close.addEventListener('click', () => { | ||
widgetSection.classList.remove('hidden'); | ||
ctaSection.classList.add('hidden'); | ||
curtain.classList.add('hidden'); | ||
}); | ||
|
||
el.after(ctaSection, widgetSection, curtain); | ||
el.remove(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
|
||
const { default: init } = await import('../../../blocks/cta-widget/cta-widget.js'); | ||
|
||
describe('CTA Widget', () => { | ||
before(async () => { | ||
document.body.innerHTML = await readFile({ path: './mocks/body.html' }); | ||
await init(document.querySelector('.cta-widget')); | ||
}); | ||
|
||
it('Toggles body on click', () => { | ||
const cta = document.querySelector('.cta-widget'); | ||
const body = document.querySelector('.cta-widget-body'); | ||
const curtain = document.querySelector('.cta-curtain'); | ||
cta.click(); | ||
expect(body.classList.contains('hidden')).to.be.false; | ||
expect(curtain.classList.contains('hidden')).to.be.false; | ||
expect(cta.classList.contains('hidden')).to.be.true; | ||
|
||
const close = document.querySelector('.widget-close'); | ||
close.click(); | ||
expect(body.classList.contains('hidden')).to.be.true; | ||
expect(curtain.classList.contains('hidden')).to.be.true; | ||
expect(cta.classList.contains('hidden')).to.be.false; | ||
}); | ||
|
||
it('Decorates the button correctly for mobile', () => { | ||
const anchor = document.querySelector('a'); | ||
expect(anchor.classList.contains('con-button')).to.be.true; | ||
expect(anchor.classList.contains('outline')).to.be.true; | ||
}); | ||
}); |
Oops, something went wrong.