-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
feat: add CodeBox component and code tabs plugin #6038
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 theTabs
component to match theCodeBox
style.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.
CodeTabs
for dealing with the tabs structure? I couldn't manage to make it work with a single component;Tabs
implementation to accept anaddons
prop so that we can render it correctly without harming the responsive layout;CodeBox
component I'm using alanguageMap
variable for mapping the display language with the language that is used in the markdown. Where should this go? Should this have internationalization support?;codeTabsResolver
I'm using thenormalizeLanguage
function to handle JavaScript file extensions likemjs
. Is it ok? It seemed fragile to me, but I couldn't think of anything else;ArrowUpRightIcon
looks different from the one used in Figma;Tabs
component is different from the one used in Figma, so I had to overwrite it, but it seems wrong to do it. Should we update theTabs
green color or remove the style overriding it in theCodeTabs
?Related Issues
Addresses #5819.
Check List
npx turbo lint
to ensure the code follows the style guide. And runnpx turbo lint:fix
to fix the style errors if necessary.npx turbo format
to ensure the code follows the style guide.npx turbo test
to check if all tests are passing.