Skip to content

Commit

Permalink
add console header
Browse files Browse the repository at this point in the history
  • Loading branch information
amandaesmith333 committed Jul 27, 2023
1 parent 5262567 commit 93a36ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/components/global/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default function Playground({
const codeRef = useRef(null);
const frameiOS = useRef<HTMLIFrameElement | null>(null);
const frameMD = useRef<HTMLIFrameElement | null>(null);
const consoleRef = useRef<HTMLDivElement | null>(null);
const consoleBodyRef = useRef<HTMLDivElement | null>(null);

const defaultMode = typeof mode !== 'undefined' ? mode : Mode.iOS;

Expand Down Expand Up @@ -269,14 +269,14 @@ export default function Playground({
if (frameiOS.current) {
frameiOS.current.contentWindow.addEventListener('console', (ev: CustomEvent) => {
setiOSConsoleItems((oldConsoleItems) => [...oldConsoleItems, ev.detail]);
consoleRef.current.scrollTo(0, consoleRef.current.scrollHeight);
consoleBodyRef.current.scrollTo(0, consoleBodyRef.current.scrollHeight);
});
}

if (frameMD.current) {
frameMD.current.contentWindow.addEventListener('console', (ev: CustomEvent) => {
setMDConsoleItems((oldConsoleItems) => [...oldConsoleItems, ev.detail]);
consoleRef.current.scrollTo(0, consoleRef.current.scrollHeight);
consoleBodyRef.current.scrollTo(0, consoleBodyRef.current.scrollHeight);
});
}
}
Expand Down Expand Up @@ -470,15 +470,20 @@ export default function Playground({

function renderConsole() {
return (
<div className="playground__console" ref={consoleRef}>
{(ionicMode === Mode.iOS ? iosConsoleItems : mdConsoleItems).map((consoleItem, i) => (
<div key={i} className={`playground__console-item playground__console-item--${consoleItem.type}`}>
{consoleItem.type !== 'log' && (
<div className="playground__console-icon">{consoleItem.type === 'warning' ? '⚠' : '❌'}</div>
)}
<code>{consoleItem.message}</code>
</div>
))}
<div className="playground__console">
<div className="playground__console-header">
<code>Console</code>
</div>
<div className="playground__console-body" ref={consoleBodyRef}>
{(ionicMode === Mode.iOS ? iosConsoleItems : mdConsoleItems).map((consoleItem, i) => (
<div key={i} className={`playground__console-item playground__console-item--${consoleItem.type}`}>
{consoleItem.type !== 'log' && (
<div className="playground__console-icon">{consoleItem.type === 'warning' ? '⚠' : '❌'}</div>
)}
<code>{consoleItem.message}</code>
</div>
))}
</div>
</div>
);
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/global/Playground/playground.css
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@
border-top: 0;
border-bottom-left-radius: var(--ifm-code-border-radius);
border-bottom-right-radius: var(--ifm-code-border-radius);
}

.playground__console-header {
background-color: var(--playground-separator-color);
font-weight: bold;
padding: 3px 3px 3px 28px;
text-transform: uppercase;
}

.playground__console-body {
overflow-y: auto;

height: 120px;
Expand Down Expand Up @@ -297,7 +307,7 @@
left: 3px;
}

.playground__console-item code {
.playground__console code {
background-color: transparent;
padding: 0;
padding-block-start: 0; /* prevents text getting cut off vertically */
Expand Down

0 comments on commit 93a36ba

Please sign in to comment.