Skip to content
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

fix(theme): CodeBlock should accept title of ReactNode type #10999

Merged
merged 2 commits into from
Mar 17, 2025

Conversation

lebalz
Copy link
Contributor

@lebalz lebalz commented Mar 17, 2025

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

The CodeBlock component is a nice component that can be reused consistently through all the docs. To allow more customization, it would be nice to pass ReactNodes instead of plain strings to the title container. This is already possible and works by passing in ReactNodes and casting them as any:

<CodeBlock
  language="yaml"
  title={
    (<div
      style={{
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center',
      }}>
      <span>
        <code>ReactNode</code> title
      </span>{' '}
      <span className="badge badge--primary">YAML</span>
    </div>) as any
  }>
  {`link:
  title: front page
  path: /docs/`}
</CodeBlock>

This PR fixes the types and adds a dogfood example.

<CodeBlock
  language="yaml"
  title={
    <div
      style={{
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center',
      }}>
      <span>
        <code>ReactNode</code> title
      </span>{' '}
      <span className="badge badge--primary">YAML</span>
    </div>
  }>
  {`link:
  title: front page
  path: /docs/`}
</CodeBlock>
image

Test Plan

Dogfooding example

Test links

Deploy preview: https://deploy-preview-10999--docusaurus-2.netlify.app/tests/pages/code-block-tests/#code-blocks-with-reactnode-in-title

Related issues/PRs

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 17, 2025
@lebalz lebalz changed the title allow ReactNode for CodeBlock title fix(ts-types): allow ReactNode for CodeBlock title Mar 17, 2025
Copy link

netlify bot commented Mar 17, 2025

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 156e542
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/67d7e3989af8a900081f341d
😎 Deploy Preview https://deploy-preview-10999--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Mar 17, 2025

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO Report
/ 🟠 71 🟢 98 🟢 100 🟢 100 Report
/docs/installation 🟠 50 🟢 97 🟢 100 🟢 100 Report
/docs/category/getting-started 🟠 73 🟢 100 🟢 100 🟠 86 Report
/blog 🟠 63 🟢 96 🟢 100 🟠 86 Report
/blog/preparing-your-site-for-docusaurus-v3 🔴 46 🟢 92 🟢 100 🟢 100 Report
/blog/tags/release 🟠 63 🟢 96 🟢 100 🟠 86 Report
/blog/tags 🟠 73 🟢 100 🟢 100 🟠 86 Report

@lebalz lebalz marked this pull request as draft March 17, 2025 08:37
@lebalz lebalz marked this pull request as ready for review March 17, 2025 08:58
@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Mar 17, 2025
@slorber slorber changed the title fix(ts-types): allow ReactNode for CodeBlock title fix(theme): CodeBlock should accept title of ReactNode type Mar 17, 2025
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, agree it's ok to accept ReactNode 👍

@slorber slorber merged commit 579bb5a into facebook:main Mar 17, 2025
39 checks passed
@lebalz lebalz deleted the fix/allow-reactnode-in-codeblock-title branch March 17, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants