Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/embed/src/css/popup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@include mobile {
.tf-v1-popup {
@include fullsize;
background: var(--tf-popup-background, rgba(0, 0, 0, 0.75));

.tf-v1-iframe-wrapper {
position: relative;
Expand Down
20 changes: 20 additions & 0 deletions packages/embed/src/factories/create-popup/create-popup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ describe('create-popup', () => {
expect(wrapper.style.width).toBe('200px')
expect(wrapper.style.height).toBe('100px')
})

it('should set the popup background from the form theme', () => {
const popupElement = container.querySelector('.tf-v1-popup') as HTMLElement
const iframe = popupElement.querySelector('iframe') as HTMLIFrameElement
const embedId = new URL(iframe.src).searchParams.get('typeform-embed-id')

window.dispatchEvent(
new MessageEvent('message', {
data: { type: 'form-theme', embedId: 'other-embed-id', theme: { backgroundColor: 'rgba(0, 0, 255, 0)' } },
})
)
expect(popupElement.style.getPropertyValue('--tf-popup-background')).toBe('')

window.dispatchEvent(
new MessageEvent('message', {
data: { type: 'form-theme', embedId, theme: { backgroundColor: 'rgba(255, 200, 0, 0)' } },
})
)
expect(popupElement.style.getPropertyValue('--tf-popup-background')).toBe('rgba(255, 200, 0, 255)')
})
})

describe('#close', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/embed/src/factories/create-popup/create-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
invokeWithoutDefault,
handlePreventReopenOnClose,
closeIconSvg,
changeColorOpacity,
} from '../../utils'
import type { RemoveHandler } from '../../utils'
import { getFormThemeHandler } from '../../utils/create-iframe/get-form-event-handler'
import { POPUP_SIZE } from '../../constants'
import { isInPage, isOpen } from '../../utils'
import { EmbedPopup } from '../../base'
Expand Down Expand Up @@ -84,6 +86,16 @@ export const createPopup = (formId: string, userOptions: PopupOptions = {}): Pop
popup.append(spinner)
popup.append(wrapper)

window.addEventListener(
'message',
getFormThemeHandler(embedId, (data) => {
const backgroundColor = data?.theme?.backgroundColor
if (backgroundColor) {
popup.style.setProperty('--tf-popup-background', changeColorOpacity(backgroundColor))
}
})
)

const container = options.container || document.body

iframe.onload = (event) => {
Expand Down
Loading