Skip to content

Commit 0e1b797

Browse files
authored
feat(cta): pass slotted CTA data to lightbox (#12587)
### Description This PR introduces a new feature that enhances the CTA component by enabling slotted CTA data to be passed to the lightbox component. The implementation modifies the core CTA and video mixins to properly handle and forward slotted content data, ensuring that when users interact with video CTAs, the lightbox receives all necessary information from the slotted elements. ### Changelog **New** - The CTA (video mode) passes slotted CTA data to be passed lightbox component which renders it on the cta slot
1 parent 8e72754 commit 0e1b797

4 files changed

Lines changed: 96 additions & 9 deletions

File tree

packages/web-components/src/component-mixins/cta/cta.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ const CTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
8989
* @param event The event.
9090
*/
9191
_handleClick(event: MouseEvent) {
92-
const { ctaType, disabled, href, videoDescription, videoName } = this;
92+
const {
93+
ctaType,
94+
disabled,
95+
href,
96+
videoDescription,
97+
videoName,
98+
ctaContents,
99+
} = this;
93100

94101
if (ctaType === CTA_TYPE.VIDEO) {
95102
event.preventDefault(); // Stop following the link
@@ -107,6 +114,7 @@ const CTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
107114
ctaType,
108115
videoName,
109116
videoDescription,
117+
ctaContents,
110118
},
111119
})
112120
);
@@ -172,6 +180,12 @@ const CTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
172180
@property({ attribute: 'video-name', reflect: true })
173181
videoName?: string;
174182

183+
/**
184+
*The CTA slotted content
185+
*/
186+
@property()
187+
ctaContents?: HTMLElement;
188+
175189
/**
176190
* The video description.
177191
*/
@@ -214,6 +228,8 @@ const CTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
214228
// Check for the URL trigger meant to fire eventRunAction.
215229
if (ctaType === CTA_TYPE.VIDEO && href) {
216230
this._checkUrlVideoTrigger();
231+
this.ctaContents =
232+
(this.querySelector('[slot="cta"]') as HTMLElement) || undefined;
217233
}
218234
}
219235

@@ -369,7 +385,14 @@ const CTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
369385
* clicks on the CTA.
370386
*/
371387
_checkUrlVideoTrigger() {
372-
const { ctaType, disabled, href, videoDescription, videoName } = this;
388+
const {
389+
ctaType,
390+
disabled,
391+
href,
392+
videoDescription,
393+
videoName,
394+
ctaContents,
395+
} = this;
373396
// Without a video id, or if the button is disabled, there is nothing to
374397
// do here.
375398
if (ctaType !== CTA_TYPE.VIDEO || !href || disabled) {
@@ -394,6 +417,7 @@ const CTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
394417
ctaType,
395418
videoName,
396419
videoDescription,
420+
ctaContents,
397421
},
398422
})
399423
);

packages/web-components/src/component-mixins/cta/video.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2020, 2024
4+
* Copyright IBM Corp. 2020, 2026
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -43,7 +43,14 @@ const VideoCTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
4343
*/
4444
_handleClick(event: MouseEvent) {
4545
this.focus();
46-
const { ctaType, disabled, href, videoName, videoDescription } = this;
46+
const {
47+
ctaType,
48+
disabled,
49+
href,
50+
videoName,
51+
videoDescription,
52+
ctaContents,
53+
} = this;
4754
if (ctaType === CTA_TYPE.VIDEO) {
4855
event.preventDefault(); // Stop following the link
4956
}
@@ -59,6 +66,7 @@ const VideoCTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
5966
ctaType,
6067
videoName,
6168
videoDescription,
69+
ctaContents,
6270
},
6371
})
6472
);
@@ -116,15 +124,26 @@ const VideoCTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
116124
*/
117125
abstract videoThumbnailUrl?: never | string;
118126

127+
/**
128+
* The HTML element of the cta slotted content container
129+
*/
130+
abstract ctaContents?: never | HTMLElement;
131+
119132
/**
120133
* Handles `.updated()` method of `lit-element`.
121134
*/
122135
updated(changedProperties) {
123136
// Declaring this mixin as it extends `LitElement` seems to cause a TS error
124137
// @ts-ignore
125138
super.updated(changedProperties);
126-
const { ctaType, videoName, videoDescription, href, videoDuration } =
127-
this;
139+
const {
140+
ctaType,
141+
videoName,
142+
videoDescription,
143+
href,
144+
videoDuration,
145+
ctaContents,
146+
} = this;
128147
const { eventRequestVideoData } = this
129148
.constructor as typeof VideoCTAMixinImpl;
130149
if (changedProperties.has('ctaType') && ctaType === CTA_TYPE.VIDEO) {
@@ -138,6 +157,7 @@ const VideoCTAMixin = <T extends Constructor<HTMLElement>>(Base: T) => {
138157
href,
139158
videoName,
140159
videoDescription,
160+
ctaContents,
141161
},
142162
})
143163
);

packages/web-components/src/components/cta/__stories__/cta.stories.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2020, 2024
4+
* Copyright IBM Corp. 2020, 2026
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -221,6 +221,28 @@ export const Default = (args) => {
221221
`;
222222
};
223223

224+
export const VideoWithSlottedCTA = () => {
225+
return html`
226+
<c4d-cta
227+
cta-style="text"
228+
cta-type="video"
229+
href="0_ibuqxqbe"
230+
video-name="Meet Mombo"
231+
video-description="This is a custom video description with CTA buttons that will be forwarded to the lightbox.">
232+
Video Link
233+
<div slot="cta">
234+
<c4d-button href="https://example.com" cta-type="local">
235+
Follow Link
236+
</c4d-button>
237+
</div>
238+
</c4d-cta>
239+
`;
240+
};
241+
242+
VideoWithSlottedCTA.story = {
243+
parameters: {},
244+
};
245+
224246
Default.story = {
225247
parameters: {
226248
gridContentClasses: 'cds--col-sm-4 cds--col-lg-8',

packages/web-components/src/components/cta/video-cta-composite.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2020, 2024
4+
* Copyright IBM Corp. 2020, 2026
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -126,11 +126,23 @@ class C4DVideoCTAComposite extends ModalRenderMixin(
126126
@HostListener('eventRunAction')
127127
// @ts-ignore: The decorator refers to this method but TS thinks this method is not referred to
128128
private _handleRunAction(event: CustomEvent) {
129-
const { ctaType, href, videoName, videoDescription } = event.detail;
129+
const { ctaType, href, videoName, videoDescription, ctaContents } =
130+
event.detail;
131+
const { selectorLightboxVideoPlayerComposite } = this
132+
.constructor as typeof C4DVideoCTAComposite;
130133
if (ctaType === CTA_TYPE.VIDEO) {
131134
this._activeVideoId = href;
132135
this._videoName = videoName;
133136
this._videoDescription = videoDescription;
137+
this._ctaContents = ctaContents;
138+
if (ctaContents) {
139+
const videoPlayerComposite = (
140+
this.modalRenderRoot as Element
141+
).querySelector(
142+
selectorLightboxVideoPlayerComposite
143+
) as C4DLightboxVideoPlayerComposite;
144+
videoPlayerComposite.ctaElement = this._ctaContents;
145+
}
134146
}
135147
}
136148

@@ -160,6 +172,12 @@ class C4DVideoCTAComposite extends ModalRenderMixin(
160172
@property({ attribute: false })
161173
mediaData?: { [videoId: string]: MediaData };
162174

175+
/**
176+
*The CTA slotted content
177+
*/
178+
@property()
179+
_ctaContents?: HTMLElement;
180+
163181
disconnectedCallback() {
164182
if (this._hCloseModal) {
165183
this._hCloseModal = this._hCloseModal.release();
@@ -178,6 +196,7 @@ class C4DVideoCTAComposite extends ModalRenderMixin(
178196
selectorLightboxVideoPlayerComposite
179197
) as C4DLightboxVideoPlayerComposite;
180198
// Manually hooks the event listeners on the modal render root to make the event names configurable
199+
videoPlayerComposite.ctaElement = this._ctaContents;
181200
this._hCloseModal = on(
182201
videoPlayerComposite.modalRenderRoot,
183202
(this.constructor as typeof C4DVideoCTAComposite).eventCloseLightbox,
@@ -197,6 +216,7 @@ class C4DVideoCTAComposite extends ModalRenderMixin(
197216
_activeVideoId: activeVideoId,
198217
_embedMedia: embedMedia,
199218
_videoDescription: videoDescription,
219+
_ctaContents: ctaContents,
200220
} = this;
201221
return html`
202222
<c4d-lightbox-video-player-composite
@@ -208,6 +228,7 @@ class C4DVideoCTAComposite extends ModalRenderMixin(
208228
.embeddedVideos="${ifDefined(embeddedVideos)}"
209229
.mediaData="${ifDefined(mediaData)}"
210230
._embedMedia="${ifDefined(embedMedia)}">
231+
${ctaContents}
211232
</c4d-lightbox-video-player-composite>
212233
`;
213234
}

0 commit comments

Comments
 (0)