Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add showConsole prop to conditionally display the Console tab #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ https://www.agney.dev/blog/introducing-playground
| transformJs | Transform the JavaScript using Babel. This is required if you want bare module imports | false | false |
| presets | Array of presets you want Babel to transform. This works only if transformJs is true. Eg. `["react", "es2015"]` | | false |
| theme | Pass in the theme variables to customise the appearance | [Our Theme](https://github.com/agneym/playground/blob/master/playground/src/utils/theme.ts) | false |
| showConsole | Controls the visibility of the console tab. Possible values: `true`, `false` | `true` | false |

### Format for initial snippet

Expand Down
2 changes: 2 additions & 0 deletions example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const app = html\`
render(app, document.getElementById('app'));
`,
};

return (
<div style={{ width: "80%", margin: "0 auto" }}>
<Playground
Expand All @@ -30,6 +31,7 @@ render(app, document.getElementById('app'));
defaultResultTab="result"
mode="dark"
transformJs
showConsole={true}
/>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions playground/src/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface IProps {
id?: string;
theme?: DefaultTheme;
mode: ColorMode;
showConsole?: boolean;
}

const Playground: FC<IProps> = ({
Expand All @@ -42,6 +43,7 @@ const Playground: FC<IProps> = ({
presets = [],
theme,
mode = "light",
showConsole = true,
}) => {
const [snippet, setSnippet] = useState<ISnippet>(initialSnippet);
const id = useId(userId) as string;
Expand Down Expand Up @@ -73,6 +75,7 @@ const Playground: FC<IProps> = ({
defaultTab={defaultResultTab}
transformJs={transformJs}
presets={presets}
showConsole={showConsole}
/>
)}
/>
Expand Down
8 changes: 6 additions & 2 deletions playground/src/Result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IProps {
transformJs: boolean;
presets: string[];
width: number;
showConsole?: boolean;
}

const Result: FC<IProps> = ({
Expand All @@ -27,14 +28,17 @@ const Result: FC<IProps> = ({
defaultTab,
transformJs,
width,
showConsole = true,
}) => {
const [logs, setLogs] = useState<unknown[]>([]);
const tabs: Readonly<ITabConfig<IResultTabs>[]> = useMemo(
() => [
{ name: "Result", value: "result" as IResultTabs },
{ name: "Console", value: "console" as IResultTabs },
...(showConsole
? [{ name: "Console", value: "console" as IResultTabs }]
: []),
],
[]
[showConsole]
);
useEffect(() => {
function waitForMessage() {
Expand Down