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

[docs] Support demo previews with comments #3577

Merged
merged 5 commits into from
May 22, 2024
Merged

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented May 21, 2024

Allow for custom preview blocks in demos. The current solution focuses heavily on a single jsx element, not configurable. For Toolpad we're in need of more flexibility. This PR proposes the extraction of previews using // preview-start and // preview-end comment blocks. This allows for marking custom ranges as preview for demos, e.g.

import { useMyHook } from '@lib'

export default function () {
  // preview-start
  const result = useMyHook()
  // preview-end

  return <div>{result}</div>
}

Will result in a preview of

const result = useMyHook()

instead of

<div>{result}</div>

We can clean up the full demo in the markdownloader and remove the lines containing // preview-start and // preview-end. Additionally {/* preview-start */} and {/* preview-end */} are also supported to allow previewing specific JSX.

It's also possible to delineate multiple preview blocks. They will get joined in the preview by a // ...

Examples can be seen here: https://deploy-preview-3558--mui-toolpad-docs.netlify.app/toolpad/core/components/notifications/

tagging @mui/docs-infra wdyt?

Notes:

  • For now I implemented the solution in the babel plugin, but it probably can be done in the formattedTsDemos script.
  • We should probably move the script to core repo and not duplicate it in every project
  • edit: looks like multiple preview blocks breaks editing the preview

Also in this PR: run check in CI for formatted demos

@Janpot Janpot added the scope: docs-infra Specific to the docs-infra product label May 21, 2024
@Janpot Janpot marked this pull request as ready for review May 22, 2024 08:02
@Janpot Janpot merged commit 0ce6017 into mui:master May 22, 2024
12 checks passed
@Janpot Janpot deleted the preview branch May 22, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: docs-infra Specific to the docs-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant