Skip to content

Commit 6f891d9

Browse files
authored
feat(placement): new gradient (#12197)
* feat(placement): new gradien * fix colors * support strings and numbers
1 parent a5cb491 commit 6f891d9

File tree

5 files changed

+90
-74
lines changed

5 files changed

+90
-74
lines changed

Diff for: client/src/playground/index.scss

-61
Original file line numberDiff line numberDiff line change
@@ -217,67 +217,6 @@ main.play {
217217
align-items: center;
218218
display: flex;
219219
flex-direction: column;
220-
@media (min-width: 25rem) {
221-
.place {
222-
align-self: flex-end;
223-
max-width: 20rem;
224-
min-height: 10rem;
225-
226-
.pong-box2,
227-
.pong-box {
228-
width: 100%;
229-
230-
.pong {
231-
flex-direction: row;
232-
}
233-
234-
.pong-note {
235-
margin-top: 0;
236-
}
237-
}
238-
239-
&.new-side {
240-
height: 12rem;
241-
max-width: 30rem;
242-
min-height: 12rem;
243-
244-
.pong-box2 {
245-
height: 21rem;
246-
min-height: 0;
247-
width: 25rem;
248-
249-
.pong-cta {
250-
margin: 0.5rem auto 1rem 1rem;
251-
}
252-
253-
.pong-note {
254-
margin: 0.5rem 0.5rem auto auto;
255-
}
256-
257-
.pong {
258-
> img {
259-
height: 100%;
260-
width: auto;
261-
}
262-
263-
> div.content {
264-
align-items: end;
265-
background: linear-gradient(
266-
to left,
267-
var(--place-new-side-background) 16rem,
268-
transparent
269-
);
270-
flex-direction: column;
271-
height: 100%;
272-
justify-content: end;
273-
padding-left: 8rem;
274-
width: 100%;
275-
}
276-
}
277-
}
278-
}
279-
}
280-
}
281220

282221
button.flag-example {
283222
align-self: flex-end;

Diff for: client/src/playground/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export default function Playground() {
414414
sandbox="allow-scripts allow-same-origin allow-forms"
415415
></iframe>
416416
<Console vConsole={vConsole} />
417-
<SidePlacement />
417+
<SidePlacement extraClasses={["horizontal"]} />
418418
</section>
419419
</main>
420420
</>

Diff for: client/src/ui/organisms/placement/index.scss

+61
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ section.place {
7171
background: linear-gradient(
7272
to top,
7373
var(--place-new-side-background) 9rem,
74+
transparent 12rem,
7475
transparent
7576
);
7677
border-radius: var(--border-radius);
@@ -435,3 +436,63 @@ div.empty-place {
435436
}
436437
}
437438
}
439+
440+
@media (min-width: 25rem) {
441+
.place.horizontal {
442+
align-self: flex-end;
443+
max-width: 20rem;
444+
min-height: 10rem;
445+
446+
.pong-box2,
447+
.pong-box {
448+
width: 100%;
449+
450+
.pong {
451+
flex-direction: row;
452+
}
453+
454+
.pong-note {
455+
margin-top: 0;
456+
}
457+
}
458+
459+
&.new-side {
460+
height: 12rem;
461+
max-width: 30rem;
462+
min-height: 12rem;
463+
464+
.pong-box2 {
465+
height: 21rem;
466+
min-height: 0;
467+
width: 25rem;
468+
469+
.pong-cta {
470+
margin: 0.5rem auto 1rem 1rem;
471+
}
472+
473+
.pong-note {
474+
margin: 0.5rem 0.5rem auto auto;
475+
}
476+
477+
.pong {
478+
> img {
479+
height: 100%;
480+
position: absolute;
481+
width: auto;
482+
z-index: 1;
483+
}
484+
485+
> div.content {
486+
align-items: end;
487+
background: var(--place-new-side-background);
488+
flex-direction: column;
489+
height: 100%;
490+
justify-content: end;
491+
padding-left: 10rem;
492+
width: 100%;
493+
}
494+
}
495+
}
496+
}
497+
}
498+
}

Diff for: client/src/ui/organisms/placement/index.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ function viewed(pong?: PlacementData) {
3737
);
3838
}
3939

40-
export function SidePlacement() {
40+
export function SidePlacement({
41+
extraClasses = [],
42+
}: {
43+
extraClasses?: string[];
44+
} = {}) {
4145
const placementData = usePlacement();
4246
const { textColor, backgroundColor, textColorDark, backgroundColorDark } =
4347
placementData?.side?.colors || {};
@@ -54,11 +58,11 @@ export function SidePlacement() {
5458
);
5559

5660
return !placementData?.side ? (
57-
<section className="place side"></section>
61+
<section className={["place", "side", ...extraClasses].join(" ")}></section>
5862
) : placementData.side.cta && placementData.side.heading ? (
5963
<PlacementInner
6064
pong={placementData.side}
61-
extraClassNames={["side", "new-side"]}
65+
extraClassNames={["side", "new-side", ...extraClasses]}
6266
imageWidth={125}
6367
imageHeight={125}
6468
cta={placementData.side.cta}
@@ -69,7 +73,7 @@ export function SidePlacement() {
6973
) : (
7074
<PlacementInner
7175
pong={placementData.side}
72-
extraClassNames={["side"]}
76+
extraClassNames={["side", ...extraClasses]}
7377
imageWidth={130}
7478
imageHeight={100}
7579
renderer={RenderSideOrTopBanner}

Diff for: libs/pong/pong2.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
import he from "he";
33
import anonymousIpByCC from "./cc2ip.js";
44

5+
function fixupColor(hash) {
6+
if (typeof hash !== "string" && typeof hash !== "number") {
7+
return undefined;
8+
} else if (hash?.startsWith?.("rgb") || hash?.startsWith?.("#")) {
9+
return hash;
10+
} else {
11+
return `#${hash}`;
12+
}
13+
}
14+
515
export function createPong2GetHandler(zoneKeys, coder) {
616
return async (body, countryCode, userAgent) => {
717
let { pongs = null } = body;
@@ -71,14 +81,16 @@ export function createPong2GetHandler(zoneKeys, coder) {
7181
cta: CallToAction && he.decode(CallToAction),
7282
heading: Heading && he.decode(Heading),
7383
colors: {
74-
textColor: TextColor || TextColorLight,
75-
backgroundColor: BackgroundColor || BackgroundColorLight,
76-
ctaTextColor: CtaTextColorLight,
77-
ctaBackgroundColor: CtaBackgroundColorLight,
78-
textColorDark: TextColorDark,
79-
backgroundColorDark: BackgroundColorDark,
80-
ctaTextColorDark: CtaTextColorDark,
81-
ctaBackgroundColorDark: CtaBackgroundColorDark,
84+
textColor: fixupColor(TextColor || TextColorLight),
85+
backgroundColor: fixupColor(
86+
BackgroundColor || BackgroundColorLight
87+
),
88+
ctaTextColor: fixupColor(CtaTextColorLight),
89+
ctaBackgroundColor: fixupColor(CtaBackgroundColorLight),
90+
textColorDark: fixupColor(TextColorDark),
91+
backgroundColorDark: fixupColor(BackgroundColorDark),
92+
ctaTextColorDark: fixupColor(CtaTextColorDark),
93+
ctaBackgroundColorDark: fixupColor(CtaBackgroundColorDark),
8294
},
8395
},
8496
};

0 commit comments

Comments
 (0)