Skip to content

🎥 Make videos programmatically with React

Elements: Hide docs chrome in Studio library iframe

Igor Samokhovets4cc3df5ea34b
diff --git a/packages/docs/src/css/custom.css b/packages/docs/src/css/custom.css
index 493b50d6c7..6a6b28d6df 100644
--- a/packages/docs/src/css/custom.css
+++ b/packages/docs/src/css/custom.css
@@ -76,6 +76,42 @@ h6 {
margin-bottom: 0.75rem;
}
+/* The Elements library is also browsed inside Studio's iframe. */
+.studio-elements-embed .theme-announcement-bar,
+.studio-elements-embed .theme-doc-footer,
+.studio-elements-embed .pagination-nav {
+ display: none;
+}
+
+.elements-embed-breadcrumbs {
+ display: flex;
+}
+
+.studio-elements-embed .elements-embed-breadcrumbs {
+ display: none;
+}
+
+@media (min-width: 997px) {
+ .studio-elements-embed {
+ --ifm-navbar-height: 0px;
+ }
+
+ html:has(.studio-elements-embed) {
+ scroll-padding-top: 0;
+ }
+
+ .studio-elements-embed .navbar {
+ display: none;
+ }
+}
+
+@media (max-width: 996px) {
+ /* Keep the mobile sidebar toggle so categories remain navigable. */
+ .studio-elements-embed .navbar__items--right {
+ display: none;
+ }
+}
+
.elements-sidebar-root > .menu__list {
padding-left: 0;
}
diff --git a/packages/docs/src/theme/DocBreadcrumbs/index.tsx b/packages/docs/src/theme/DocBreadcrumbs/index.tsx
index 5eb5de976c..840490b90e 100644
--- a/packages/docs/src/theme/DocBreadcrumbs/index.tsx
+++ b/packages/docs/src/theme/DocBreadcrumbs/index.tsx
@@ -179,8 +179,8 @@ export default function DocBreadcrumbsWrapper(props: Props): ReactNode {
return (
<div
+ className="elements-embed-breadcrumbs"
style={{
- display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: '1rem',
diff --git a/packages/docs/src/theme/Layout/index.tsx b/packages/docs/src/theme/Layout/index.tsx
index 4a53fec4de..7521652cac 100644
--- a/packages/docs/src/theme/Layout/index.tsx
+++ b/packages/docs/src/theme/Layout/index.tsx
@@ -1,10 +1,16 @@
-import {useHistory} from '@docusaurus/router';
+import {useHistory, useLocation} from '@docusaurus/router';
import type {WrapperProps} from '@docusaurus/types';
import '@remotion/promo-pages/dist/tailwind.css';
+import {isInsideStudio} from '@remotion/studio-protocol';
import Layout from '@theme-original/Layout';
import type LayoutType from '@theme/Layout';
import {useCrawlChatSidePanel} from 'crawlchat-client';
-import React, {useEffect, type ReactNode} from 'react';
+import React, {
+ useEffect,
+ useLayoutEffect,
+ useState,
+ type ReactNode,
+} from 'react';
type Props = WrapperProps<typeof LayoutType>;
@@ -17,7 +23,10 @@ const CRAWLCHAT_SCRIPT_ID = 'crawlchat-script';
// a second time ("Identifier 'CrawlChatEmbed' has already been declared").
const useCrawlChatScript = () => {
useEffect(() => {
- if (document.getElementById(CRAWLCHAT_SCRIPT_ID)) {
+ if (
+ document.body.classList.contains('studio-elements-embed') ||
+ document.getElementById(CRAWLCHAT_SCRIPT_ID)
+ ) {
return;
}
@@ -42,6 +51,26 @@ const LayoutWithCrawlChat = (props: Props): ReactNode => {
};
const LayoutWrapper = (props: Props): ReactNode => {
+ const {pathname} = useLocation();
+ const [isStudioElementsEmbed, setIsStudioElementsEmbed] = useState(false);
+
+ useLayoutEffect(() => {
+ // Client-side navigation drops the iframe's ?remotion-studio=true parameter.
+ const isEmbedded =
+ isInsideStudio() &&
+ (pathname === '/elements' || pathname.startsWith('/elements/'));
+ document.body.classList.toggle('studio-elements-embed', isEmbedded);
+ setIsStudioElementsEmbed(isEmbedded);
+
+ return () => {
+ document.body.classList.remove('studio-elements-embed');
+ };
+ }, [pathname]);
+
+ if (isStudioElementsEmbed) {
+ return <Layout {...props} noFooter />;
+ }
+
return <LayoutWithCrawlChat {...props} />;
};
diff --git a/packages/example/remotion.config.ts b/packages/example/remotion.config.ts
index 500c7eb36b..c85c0bc9d8 100644
--- a/packages/example/remotion.config.ts
+++ b/packages/example/remotion.config.ts
@@ -15,6 +15,6 @@ Config.addElementLibrary({
displayName: 'Remocn',
});
Config.addElementLibrary({
- url: 'http://localhost:3002/elements',
+ url: 'http://localhost:3318/elements',
displayName: 'Local Elements',
});