diff --git a/packages/www/src/web-components/play-ground.tsx b/packages/www/src/web-components/play-ground.tsx index 6c6d2a216..066f827ae 100644 --- a/packages/www/src/web-components/play-ground.tsx +++ b/packages/www/src/web-components/play-ground.tsx @@ -8,6 +8,7 @@ export default async function PlayGround( const code = state(''); const preview: HTMLIFrameElement = self.querySelector('#preview-iframe')!; const activeTab = state('tab-wc'); + const activePanel = state('panel-code'); const isMobileLayout = state(false); function updateSplitViewOrientation() { @@ -26,6 +27,12 @@ export default async function PlayGround( preview.contentWindow?.postMessage({ code: defaultValue }); } + function updateActivePanel(e: MouseEvent) { + const button = e.target as HTMLButtonElement; + const panelId = button.getAttribute('aria-label') as string; + activePanel.value = panelId; + } + onMount(() => { // Set initial layout based on screen size updateSplitViewOrientation(); @@ -74,9 +81,11 @@ export default async function PlayGround( cursor: pointer; border-bottom: 2px solid transparent; } + button[role="tab"]:hover { background-color: var(--color-light-gray); } + button[role="tab"][aria-selected="true"] { border-bottom: 2px solid var(--color-dark); } @@ -84,6 +93,7 @@ export default async function PlayGround( .tab-content { display: none; } + .tab-content.active { display: flex; flex-grow: 1; @@ -93,6 +103,7 @@ export default async function PlayGround( #tab-compiled { padding: 0.5rem; } + #tab-compiled textarea { display: flex; flex-grow: 1; @@ -100,76 +111,108 @@ export default async function PlayGround( field-sizing: content; font-size: 1rem; border-radius: 0.5rem; + padding: 0.5rem; } @media (max-width: 968px) { .playground { flex-direction: column; + gap: 0; } - .original-code { + .active-panel { + flex: 1 1 0%; width: 100%; - height: 100%; + + div { + width: 100%; + height: 100%; + padding: 0.5rem; + } + + textarea { + width: 100%; + height: 100%; + resize: none; + field-sizing: content; + font-size: 1rem; + border-radius: 0.5rem; + padding: 0.5rem; + } } - .output { + .panel-toggle { + margin: auto; + height: 40px; + display: flex; + justify-content: center; + align-items: center; width: 100%; + + button[role="tab"] { + flex: 1; + height: 100%; + border: none; + background: none; + padding: 0.25rem 0.5rem; + cursor: pointer; + border-top: 2px solid transparent; + } + + button[role="tab"]:hover { + background-color: var(--color-light-gray); + } + + button[role="tab"][aria-selected="true"] { + border-top: 2px solid var(--color-dark); + } } } `; if (isMobileLayout.value) { return ( - -
- +
+
+ {activePanel.value === 'panel-code' ? ( + + ) : null} + {activePanel.value === 'panel-wc' ? ( + + ) : null} + {activePanel.value === 'panel-compiled' ? ( +
+ +
+ ) : null}
-
-
- - -
- -
+
- -
+
+ Web Component + +
- +
); } @@ -207,7 +250,6 @@ export default async function PlayGround( Compiled Code
-