-
Notifications
You must be signed in to change notification settings - Fork 3
Clarify global language synchronization for tabs and code blocks (Docs) #472
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
Merged
+167
−23
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
16b75b5
clarify language sync for tabs and code blocks
devalog f979951
add example without sync
devalog f47c3b8
change order of examples
devalog ae9a914
add in markdown examples
devalog 687504f
Merge branch 'main' into global-lang-sync
devalog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 154 additions & 21 deletions
175
fern/products/docs/pages/component-library/default-components/tabs.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,188 @@ | ||
| --- | ||
| title: 'Tabs' | ||
| description: 'The Tabs component allows you to display related content in a tabbed view.' | ||
| title: Tabs | ||
| description: The Tabs component allows you to display related content in a tabbed view with support for language synchronization. | ||
| --- | ||
|
|
||
| The Tabs component organizes content into separate tabs that users can switch between. Each tab can contain different types of content like examples or code snippets. | ||
| The Tabs component organizes content into separate tabs that users can switch between. Each tab can contain different types of content like examples, code snippets, or documentation sections. | ||
|
|
||
| <Tabs> | ||
| <Tab title="First Tab"> | ||
| ☝️ Welcome to the content that you can only see inside the first Tab. | ||
| </Tab> | ||
| <Tab title="Second Tab"> | ||
| ✌️ Here's content that's only inside the second Tab. | ||
| </Tab> | ||
| <Tab title="Third Tab"> | ||
| 💪 Here's content that's only inside the third Tab. | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| <CodeBlock title="Markdown"> | ||
| ```jsx | ||
| <Tabs> | ||
| <Tab title="First Tab"> | ||
| ☝️ Welcome to the content that you can only see inside the first Tab. | ||
| </Tab> | ||
| <Tab title="Second Tab"> | ||
| ✌️ Here's content that's only inside the second Tab. | ||
| </Tab> | ||
| <Tab title="Third Tab"> | ||
| 💪 Here's content that's only inside the third Tab. | ||
| </Tab> | ||
| </Tabs> | ||
| ``` | ||
| </CodeBlock> | ||
|
|
||
| ## Properties | ||
|
|
||
| <ParamField path="title" type="string" required={true}> | ||
| The title displayed in the tab header | ||
| </ParamField> | ||
|
|
||
| <ParamField path="language" type="string" required={false}> | ||
| The language associated with the code block. Any arbitrary string may be used. | ||
|
|
||
| When a user selects a tab with a specific language, all other tabs assigned to the same language will automatically sync and switch to match. Syncs with the [`for` property of `<CodeBlocks />`](/learn/docs/writing-content/components/code-blocks#override-synchronization). | ||
| When specified, enables global language synchronization across all tabs and code blocks with the same language value. | ||
| </ParamField> | ||
|
|
||
| <ParamField path="children" type="string | JSX" required={true}> | ||
| The content to be displayed when the tab is selected. Can include text, markdown, and components. | ||
| </ParamField> | ||
|
|
||
| <br /> | ||
| ## Language synchronization | ||
|
|
||
| Multiple `Tabs` with a `language` property automatically synchronize. This means | ||
| when a user selects a tab with a specific language, all other tabs across your | ||
| documentation site with the same language will automatically sync and switch to | ||
| match. Language preferences are stored in client-side local storage and persist | ||
| across browser sessions. | ||
|
|
||
| In the example below, choosing a language in either set of tabs will automatically update both sets to match: | ||
|
|
||
| <Tabs> | ||
| <Tab title="First Tab"> | ||
| ☝️ Welcome to the content that you can only see inside the first Tab. | ||
| <Tab title="TypeScript" language="typescript"> | ||
| ```typescript | ||
| console.log("First code block!"); | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Second Tab"> | ||
| ✌️ Here's content that's only inside the second Tab. | ||
| <Tab title="Python" language="python"> | ||
| ```python | ||
| print("First code block!") | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Third Tab"> | ||
| 💪 Here's content that's only inside the third Tab. | ||
| <Tab title="Java" language="java"> | ||
| ```java | ||
| System.out.println("First code block!"); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| <Aside> | ||
| <Tabs> | ||
| <Tab title="TypeScript" language="typescript"> | ||
| ```typescript | ||
| console.log("Second code block – language syncs with the one above!"); | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Python" language="python"> | ||
| ```python | ||
| print("Second code block – language syncs with the one above!") | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Java" language="java"> | ||
| ```java | ||
| System.out.println("Second code block – language syncs with the one above!"); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| <CodeBlock title="Markdown"> | ||
| ```jsx | ||
| ````jsx | ||
| <Tabs> | ||
| <Tab title="First Tab"> | ||
| ☝️ Welcome to the content that you can only see inside the first Tab. | ||
| <Tab title="TypeScript" language="typescript"> | ||
| ```typescript | ||
| console.log("Content inside the TypeScript tab"); | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Second Tab"> | ||
| ✌️ Here's content that's only inside the second Tab. | ||
| <Tab title="Python" language="python"> | ||
| ```python | ||
| print("Content inside the Python tab") | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Third Tab"> | ||
| 💪 Here's content that's only inside the third Tab. | ||
| <Tab title="Java" language="java"> | ||
| ```java | ||
| System.out.println("Content inside the Java tab"); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
| ``` | ||
| ```` | ||
| </CodeBlock> | ||
|
|
||
| </Aside> | ||
| <Note title="Tabs and CodeBlocks integration"> | ||
| Language-enabled `Tabs` automatically synchronize with [`CodeBlocks` in that same language](/docs/writing-content/components/code-blocks#language-synchronization). | ||
| </Note> | ||
|
|
||
| <Accordion title="Tabs without the language property" toc={true}> | ||
|
|
||
| Tabs **without** the `language` property don't stay in sync with other tabs on your site. In the below example, choosing a language in | ||
| either set of tabs doesn't affect the other set of tabs: | ||
|
|
||
| <Tabs> | ||
| <Tab title="TypeScript"> | ||
| ```typescript | ||
| console.log("First code block!"); | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Python"> | ||
| ```python | ||
| print("First code block!") | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Java"> | ||
| ```java | ||
| System.out.println("First code block!"); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| <Tabs> | ||
| <Tab title="TypeScript"> | ||
| ```typescript | ||
| console.log("Second code block – this won't sync with the one above!"); | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Python"> | ||
| ```python | ||
| print("Second code block – this won't sync with the one above!") | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Java"> | ||
| ```java | ||
| System.out.println("Second code block – this won't sync with the one above!"); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| <CodeBlock title="Markdown"> | ||
| ````jsx | ||
| <Tabs> | ||
| <Tab title="TypeScript"> | ||
| ```typescript | ||
| console.log("Content inside the TypeScript tab, with no language property"); | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Python"> | ||
| ```python | ||
| print("Content inside the Python tab, with no language property") | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Java"> | ||
| ```java | ||
| System.out.println("Content inside the Java tab, with no language property"); | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
| ```` | ||
| </CodeBlock> | ||
|
|
||
| </Accordion> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devalog I think we should add the markdown for both of these examples.
Also i think we should lead with the sync'd lanugage example and then the non-sync'd language example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I swapped the order. I agree about having markdown examples, but I keep getting mdx parsing errors when I try to do this. I don't think the parser is liking the nested code fences. Any ideas?