Skip to content

Commit c4d2631

Browse files
committed
Add hidden param to files
1 parent 80426f3 commit c4d2631

File tree

5 files changed

+149
-629
lines changed

5 files changed

+149
-629
lines changed

packages/scrollycoding/src/code.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export { Code }
77

88
function Code({ files, activeFile, ...props }: CodeProps) {
99
const file = files[activeFile]
10+
const tabs = Object.keys(files).filter(
11+
filename => !files[filename].hideTab
12+
)
1013
return (
1114
<MiniEditorWithState
1215
key={activeFile}
@@ -15,7 +18,7 @@ function Code({ files, activeFile, ...props }: CodeProps) {
1518
<CodeSandboxIcon url={useCodeSandboxLink()} />
1619
}
1720
file={activeFile}
18-
tabs={Object.keys(files)}
21+
tabs={tabs}
1922
lang={file.lang}
2023
code={file.code}
2124
{...props}

packages/scrollycoding/src/hike-context.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export interface PreviewProps extends MiniBrowserProps {
1818
}
1919

2020
export interface CodeFiles {
21-
[path: string]: { lang: string; code: string }
21+
[path: string]: {
22+
lang: string
23+
code: string
24+
hideTab?: boolean
25+
}
2226
}
2327

2428
export type CodeProps = {

packages/scrollycoding/src/mdx-steps.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ function getFiles(
7979
const codeElementProps =
8080
preElement?.props?.children?.props || {}
8181
const lang = codeElementProps.className?.slice(9)
82-
const filename =
82+
const { filename, hideTab } = parseMetastring(
8383
codeElementProps.metastring || defaultFilename
84+
)
8485
const code = codeElementProps.children
85-
files[filename] = { code, lang }
86+
files[filename] = { code, lang, hideTab }
8687
if (activeFile === "") {
8788
activeFile = filename
8889
}
@@ -94,6 +95,11 @@ function getFiles(
9495
return { files, activeFile }
9596
}
9697

98+
function parseMetastring(metastring: string) {
99+
const [filename, ...params] = metastring.split(" ")
100+
return { filename, hideTab: params.includes("hidden") }
101+
}
102+
97103
function getPreviewProps(
98104
stepHeadProps: StepHeadProps,
99105
hikePreviewProps: PreviewProps

packages/storybook/src/assets/scrollycoding.repeat.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function Button() {
1212
}
1313
```
1414

15-
```jsx App.js
15+
```jsx App.js hidden
1616
import Button from "./Button"
1717

1818
export default function App() {

0 commit comments

Comments
 (0)