Skip to content

Commit 8348f68

Browse files
authored
fix: inject preview modal on applyVariants (#209)
1 parent 539882c commit 8348f68

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

packages/experiment-tag/src/experiment.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ export class DefaultWebExperimentClient implements WebExperimentClient {
187187
),
188188
);
189189
}
190-
showPreviewModeModal({
191-
flags: this.previewFlags,
192-
});
193190
}
194191

195192
const initialFlagsString = JSON.stringify(this.initialFlags);
@@ -372,6 +369,11 @@ export class DefaultWebExperimentClient implements WebExperimentClient {
372369
* @param options
373370
*/
374371
public applyVariants(options?: ApplyVariantsOptions) {
372+
if (Object.keys(this.previewFlags).length > 0) {
373+
showPreviewModeModal({
374+
flags: this.previewFlags,
375+
});
376+
}
375377
const { flagKeys } = options || {};
376378
const variants = this.getVariants();
377379
if (Object.keys(variants).length === 0) {

packages/experiment-tag/src/preview/preview.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class PreviewModeModal {
1616
}
1717

1818
show(): void {
19-
if (this.modal) {
19+
if (this.modal || document.getElementById('amp-preview-modal')) {
2020
return;
2121
}
2222

@@ -46,6 +46,7 @@ export class PreviewModeModal {
4646
}
4747

4848
this.modal = document.createElement('div');
49+
this.modal.id = 'amp-preview-modal';
4950
this.modal.className = 'amp-preview-modal';
5051

5152
const container = document.createElement('div');
@@ -144,7 +145,7 @@ export class PreviewModeModal {
144145
padding: 12px 16px;
145146
max-width: 600px;
146147
}
147-
148+
148149
@keyframes amp-preview-modal-slide-in {
149150
from {
150151
transform: translateX(100%);
@@ -155,40 +156,40 @@ export class PreviewModeModal {
155156
opacity: 1;
156157
}
157158
}
158-
159+
159160
.amp-preview-modal-container {
160161
flex: 1;
161162
display: flex;
162163
flex-direction: column;
163164
gap: 8px;
164165
}
165-
166+
166167
.amp-preview-modal-row {
167168
display: flex;
168169
align-items: center;
169170
gap: 8px;
170171
}
171-
172+
172173
.amp-preview-modal-icon {
173174
flex-shrink: 0;
174175
display: flex;
175176
align-items: center;
176177
justify-content: center;
177178
}
178-
179+
179180
.amp-preview-modal-icon-img {
180181
width: 16px;
181182
height: 16px;
182183
color: #718096;
183184
}
184-
185+
185186
.amp-preview-modal-title {
186187
font-weight: 600;
187188
color: #1a202c;
188189
font-size: 14px;
189190
white-space: nowrap;
190191
}
191-
192+
192193
/* Base badge styles */
193194
.amp-preview-modal-badge {
194195
background-color: #ffffff;
@@ -203,37 +204,37 @@ export class PreviewModeModal {
203204
gap: 6px;
204205
border: 1px solid #e2e8f0;
205206
}
206-
207+
207208
.amp-preview-modal-preview-badge {
208209
color: #718096;
209210
}
210-
211+
211212
.amp-preview-modal-preview-icon {
212213
width: 14px;
213214
height: 14px;
214215
color: currentColor;
215216
}
216-
217+
217218
.amp-preview-modal-variant-dot {
218219
width: 8px;
219220
height: 8px;
220221
border-radius: 50%;
221222
background-color: #68d391;
222223
flex-shrink: 0;
223224
}
224-
225+
225226
.amp-preview-modal-variant-badge.amp-preview-modal-variant-a .amp-preview-modal-variant-dot {
226227
background-color: #68d391;
227228
}
228-
229+
229230
.amp-preview-modal-variant-badge.amp-preview-modal-variant-b .amp-preview-modal-variant-dot {
230231
background-color: #fc8181;
231232
}
232-
233+
233234
.amp-preview-modal-variant-badge.amp-preview-modal-variant-testing .amp-preview-modal-variant-dot {
234235
background-color: #63b3ed;
235236
}
236-
237+
237238
.amp-preview-modal-close {
238239
background: none;
239240
border: none;
@@ -252,59 +253,59 @@ export class PreviewModeModal {
252253
transition: all 0.2s ease;
253254
align-self: flex-start;
254255
}
255-
256+
256257
.amp-preview-modal-close:hover {
257258
background-color: #f7fafc;
258259
color: #718096;
259260
}
260-
261+
261262
.amp-preview-modal-close:focus {
262263
outline: 2px solid #3182ce;
263264
outline-offset: 1px;
264265
}
265-
266+
266267
/* Dark mode support */
267268
@media (prefers-color-scheme: dark) {
268269
.amp-preview-modal {
269270
background-color: #2d3748;
270271
border-color: #4a5568;
271272
color: #e2e8f0;
272273
}
273-
274+
274275
.amp-preview-modal-title {
275276
color: #f7fafc;
276277
}
277-
278+
278279
.amp-preview-modal-badge {
279280
background-color: #2d3748;
280281
color: #e2e8f0;
281282
border-color: #4a5568;
282283
}
283-
284+
284285
.amp-preview-modal-preview-badge {
285286
color: #a0aec0;
286287
}
287-
288+
288289
.amp-preview-modal-variant-dot {
289290
background-color: #68d391;
290291
}
291-
292+
292293
.amp-preview-modal-variant-badge.amp-preview-modal-variant-a .amp-preview-modal-variant-dot {
293294
background-color: #68d391;
294295
}
295-
296+
296297
.amp-preview-modal-variant-badge.amp-preview-modal-variant-b .amp-preview-modal-variant-dot {
297298
background-color: #fc8181;
298299
}
299-
300+
300301
.amp-preview-modal-variant-badge.amp-preview-modal-variant-testing .amp-preview-modal-variant-dot {
301302
background-color: #63b3ed;
302303
}
303-
304+
304305
.amp-preview-modal-close {
305306
color: #718096;
306307
}
307-
308+
308309
.amp-preview-modal-close:hover {
309310
background-color: #4a5568;
310311
color: #e2e8f0;

0 commit comments

Comments
 (0)