Skip to content

Commit

Permalink
feat(docs): document synced codeblocks that's easily usable (#5921)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysheridan authored Feb 7, 2025
1 parent 3943f17 commit 4515358
Showing 1 changed file with 73 additions and 39 deletions.
112 changes: 73 additions & 39 deletions fern/pages/docs/components/code-blocks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ By default, long lines that exceed the width of the code block become scrollable
<Tabs>
<Tab title="Example">
```txt title="Without Word Wrap"
A very very very long line of text that may cause the codeblock to overflow and scroll as a result.
A very very very long line of text that may cause the code block to overflow and scroll as a result.
```
</Tab>
<Tab title="Markdown">
````markdown
```txt title="Without Word Wrap"
A very very very long line of text that may cause the codeblock to overflow and scroll as a result.
A very very very long line of text that may cause the code block to overflow and scroll as a result.
```
````
</Tab>
Expand All @@ -206,7 +206,7 @@ To disable scrolling and wrap overflow onto the next line, use the `wordWrap` pr
<Tabs>
<Tab title="Example">
```txt title="With Word Wrap" wordWrap
A very very very long line of text that may cause the codeblock to overflow and scroll as a result.
A very very very long line of text that may cause the code block to overflow and scroll as a result.
```
</Tab>
<Tab title="Markdown">
Expand Down Expand Up @@ -259,71 +259,105 @@ and a maximum height.
</Tabs>


## Tabbed CodeBlocks
## Code Blocks with Tabs

The `CodeBlocks` component is used to display multiple code snippets in a tabbed view. It does not take any props. When a `CodeBlock` with a specific language is selected, all other `CodeBlocks` will sync to show that language, if present.
The `CodeBlocks` component allows you to display multiple code blocks in a tabbed interface.

<Tabs>
<Tab title="Example">
<CodeBlocks>
```javascript title="helloWorld.js"
console.log("Hello World");
```ruby title="hello_world.rb"
puts "Hello World"
```

```python title="hello_world.py"
print('Hello World!')
```php title="hello_world.php"
<?php
echo "Hello World";
?>
```

```java title="HelloWorld.java"
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
```rust title="hello_world.rs"
fn main() {
println!("Hello World");
}
```
</CodeBlocks>
</Tab>
<Tab title = "Markdown">
<Tab title="Markdown">
````jsx maxLines=0
<CodeBlocks>
```javascript title="helloWorld.js"
console.log("Hello World");
```ruby title="hello_world.rb"
puts "Hello World"
```

```python title="hello_world.py"
print('Hello World!')
```php title="hello_world.php"
<?php
echo "Hello World";
?>
```

```java title="HelloWorld.java"
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```rust title="hello_world.rs"
fn main() {
println!("Hello World");
}
```
</CodeBlocks>
````
</Tab>
</Tabs>

**Syncing CodeBlocks**
### Example of Synchronized Blocks

Multiple `CodeBlocks` on a page automatically synchronize, showing the same language across all blocks.

<CodeBlocks>
```python title="Python"
print("First code block!")
```

```typescript title="TypeScript"
console.log("First code block!");
```

```go title="Go"
fmt.Println("First code block!")
```

```csharp title="C#"
Console.WriteLine("First code block!");
```

```java title="Java"
System.out.println("First code block!");
```

```ruby title="Ruby"
puts "First code block!"
```
</CodeBlocks>

<CodeBlocks>
```javascript title="helper.js"
function helper() {
console.log("Helping out!");
}
```python title="Python"
print("Second code block - syncs with the one above!")
```

```typescript title="TypeScript"
console.log("Second code block - syncs with the one above!");
```

```go title="Go"
fmt.Println("Second code block - syncs with the one above!")
```

```csharp title="C#"
Console.WriteLine("Second code block - syncs with the one above!");
```

```python title="helper.py"
def helper():
print("Helping out!")
```java title="Java"
System.out.println("Second code block - syncs with the one above!");
```

```java title="Helper.java"
class Helper {
public static void main(String[] args) {
System.out.println("Helping out!");
}
}
```ruby title="Ruby"
puts "Second code block - syncs with the one above!"
```
</CodeBlocks>

0 comments on commit 4515358

Please sign in to comment.