feat: add CodeBox component and code tabs plugin#6038
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ovflowd
left a comment
There was a problem hiding this comment.
Just wanted to say that I truly appreciate the effort you're putting in here, because this component is definitely a truly complex case.
Awesome work so far.
There was a problem hiding this comment.
@canerakdas your commit broke a few things:
- The code lines are not aligned anymore with the line numbers of the CodeBox
- There's a horizontal scrollbar on CodeBoxes... The line break was intentional as it's cleaner... Could you add it back? Thanks!
There was a problem hiding this comment.
I agree with @canerakdas , the CodeTabs story looks awkward on a mobile resolution. If the code was formatted with prettier, we could set the printWidth to something that would be a better fit for a smaller screen?
|
Im not sure applying prettier on the code snippets during runtime would be a good idea. Prettier is extremely costly. We might be able to fix tabulation for mobile with pure CSS. But also, to be honest, this website is not something that I see people accessing from mobile. Node.js website is mostly accessed for downloading Node.js; and sure we have blog and learn content but I'd discourage people actually reading these from mobile anyways |
|
For me it's not a blocker to this PR, I'm in favour of seeing it land and overall it looks good. We can always tweak the styling in the future. I agree that many people probably visit the site on a desktop to download Node, but I'm sure we have some users on mobile too |

Description
This PR introduces two new components related to the code block:
CodeBox: The main component for rendering the code block;CodeTabs: The component that customizes theTabscomponent to match theCodeBoxstyle.And introduces a plugin for resolving the desired format in markdown files into the code tabs structure:
codeTabsResolver: The plugin transforms the format below into the code tabs structure.Validation
Single file
Multiple files
Multiple files with link
Considerations
Some things were not clear to me about how the implementation should go.
CodeTabsfor dealing with the tabs structure? I couldn't manage to make it work with a single component;Tabsimplementation to accept anaddonsprop so that we can render it correctly without harming the responsive layout;CodeBoxcomponent I'm using alanguageMapvariable for mapping the display language with the language that is used in the markdown. Where should this go? Should this have internationalization support?;codeTabsResolverI'm using thenormalizeLanguagefunction to handle JavaScript file extensions likemjs. Is it ok? It seemed fragile to me, but I couldn't think of anything else;ArrowUpRightIconlooks different from the one used in Figma;Tabscomponent is different from the one used in Figma, so I had to overwrite it, but it seems wrong to do it. Should we update theTabsgreen color or remove the style overriding it in theCodeTabs?Related Issues
Addresses #5819.
Check List
npx turbo lintto ensure the code follows the style guide. And runnpx turbo lint:fixto fix the style errors if necessary.npx turbo formatto ensure the code follows the style guide.npx turbo testto check if all tests are passing.