Skip to content

Commit 551cfe4

Browse files
committed
ads: show two ads on a client height higher or equal to 950px
1 parent 162fa67 commit 551cfe4

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

docs/src/components/AdsContainerElement/index.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import './styles.css'
33

44
const AdsContainerElement = () => {
55
const containerRef = useRef<any>()
6+
const containerRef2 = useRef<any>()
67

78
useEffect(() => {
89
if (typeof window !== 'undefined') {
@@ -18,7 +19,26 @@ const AdsContainerElement = () => {
1819
}
1920
}, [])
2021

21-
return <div className="carbon-ads" ref={containerRef} />
22+
useEffect(() => {
23+
if (typeof window !== 'undefined' && window?.document?.body?.clientHeight >= 950) {
24+
const scriptElement = document.createElement('script')
25+
scriptElement.src = '//cdn.carbonads.com/carbon.js?serve=CWYD553L&placement=react-tooltipcom'
26+
scriptElement.id = '_carbonads_js'
27+
scriptElement.async = true
28+
29+
if (containerRef2?.current) {
30+
containerRef2.current.innerHTML = ''
31+
containerRef2.current.appendChild(scriptElement)
32+
}
33+
}
34+
}, [])
35+
36+
return (
37+
<>
38+
<div className="carbon-ads" ref={containerRef} />
39+
<div className="carbon-ads" ref={containerRef2} />
40+
</>
41+
)
2242
}
2343

2444
export default AdsContainerElement

docs/src/components/AdsContainerElement/styles.css

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
.carbon-ads {
22
position: fixed;
3+
display: grid;
4+
row-gap: 16px;
35
}
46

5-
#carbonads * {
7+
.carbon-ads > div * {
68
margin: initial;
79
padding: initial;
810
line-height: initial;
911
}
1012

11-
#carbonads {
13+
.carbon-ads > div {
1214
--carbon-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu,
1315
Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
1416
--carbon-font-size: 14px;
@@ -22,7 +24,7 @@
2224
font-family: var(--carbon-font-family);
2325
}
2426

25-
#carbonads > span {
27+
.carbon-ads > div > span {
2628
display: flex;
2729
flex-direction: column;
2830
min-inline-size: 130px;
@@ -34,37 +36,37 @@
3436
0 0 4px hsl(0deg 0% 0% / 0.085), 0 0 8px hsl(0deg 0% 0% / 0.085);
3537
}
3638

37-
#carbonads a {
39+
.carbon-ads > div a {
3840
color: var(--carbon-text-color);
3941
text-decoration: none;
4042
}
4143

42-
#carbonads a:hover {
44+
.carbon-ads > div a:hover {
4345
color: var(--carbon-text-color);
4446
}
4547

46-
#carbonads .carbon-wrap {
48+
.carbon-ads > div .carbon-wrap {
4749
display: flex;
4850
flex-wrap: wrap;
4951
gap: 1.5ex;
5052
}
5153

52-
#carbonads .carbon-img {
54+
.carbon-ads > div .carbon-img {
5355
flex: 0 0 130px;
5456
}
5557

56-
#carbonads .carbon-img img {
58+
.carbon-ads > div .carbon-img img {
5759
display: block;
5860
}
5961

60-
#carbonads .carbon-text {
62+
.carbon-ads > div .carbon-text {
6163
flex-grow: 1;
6264
flex-basis: var(--carbon-max-char);
6365
line-height: 1.4;
6466
text-align: left;
6567
}
6668

67-
#carbonads .carbon-poweredby {
69+
.carbon-ads > div .carbon-poweredby {
6870
padding: 6px 8px;
6971
background: var(--carbon-bg-secondary);
7072
color: var(--carbon-text-color);
@@ -77,7 +79,7 @@
7779
}
7880

7981
@media (prefers-color-scheme: dark) {
80-
#carbonads {
82+
.carbon-ads > div {
8183
--carbon-bg-primary: hsl(0, 0%, 12%);
8284
--carbon-bg-secondary: hsl(0, 0%, 15%);
8385
--carbon-text-color: hsl(0, 0%, 90%);

0 commit comments

Comments
 (0)