-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs-infra] Move Ads component to TS (#42842)
- Loading branch information
1 parent
6482a29
commit 42d4aad
Showing
14 changed files
with
130 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
docs/src/modules/components/AdInHouse.js → docs/src/modules/components/AdInHouse.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/material/utils'; | ||
|
||
type AdPortal = { | ||
placement: 'body-top'; | ||
element: Element | null; | ||
}; | ||
|
||
interface AdManagerProps { | ||
/** | ||
* The querySelector use to target the element which will include the ad. | ||
*/ | ||
classSelector?: string; | ||
children?: React.ReactNode | undefined; | ||
} | ||
|
||
export const AdContext = React.createContext<AdPortal>({ placement: 'body-top', element: null }); | ||
|
||
// Persisted for the whole session. | ||
// The state is used to use different ad placements. | ||
const randomSession = Math.random(); | ||
|
||
// Distribution profile: | ||
// 20% body-inline | ||
// 80% body-image | ||
export const adShape = randomSession < 0.2 ? 'inline' : 'image'; | ||
|
||
export default function AdManager({ classSelector = '.description', children }: AdManagerProps) { | ||
const [portal, setPortal] = React.useState<AdPortal>({ placement: 'body-top', element: null }); | ||
|
||
useEnhancedEffect(() => { | ||
const container = document.querySelector(classSelector); | ||
setPortal({ placement: 'body-top', element: container }); | ||
}, [classSelector]); | ||
|
||
return <AdContext.Provider value={portal}>{children}</AdContext.Provider>; | ||
} | ||
|
||
AdManager.propTypes = { | ||
children: PropTypes.node, | ||
classSelector: PropTypes.string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Gtag from '@types/gtag.js'; | ||
|
||
declare global { | ||
interface Window { | ||
gtag: Gtag.Gtag; | ||
} | ||
} |
Oops, something went wrong.