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: improve code preview #798

Merged
merged 31 commits into from
Jun 9, 2023
Merged

docs: improve code preview #798

merged 31 commits into from
Jun 9, 2023

Conversation

tulup-conner
Copy link
Collaborator

@tulup-conner tulup-conner commented Jun 7, 2023

Description

Improves code previews found on most of the pages at https://flowbite-react.com. Generally speaking, "improves" means more accurately mirroring the code previews found on https://flowbite.com.

We have the following specific targets:

  • Change code preview format from snippets to in-context React examples
    • Include required import statements
    • Include required "use client" directives
    • Include export default function like a Next.js page
    • Include external import statements where applicable (icons)
    • Include useState context where applicable (modal, pagination, tabs)
  • Add Github button that links to the component's source code
  • Add button to copy code to clipboard
  • Add button to toggle dark mode for component preview (not code)
  • Add max-height by default, and a button to expand/collapse
  • Fix remaining bugs with code preview
    • Always dark mode in production
    • Function bodies and FC display names are deleted in production mode
    • <Modal show> attribute doesn't show up, because its value is resolved
    • <Tabs ref> attribute is a mess, because ref.current is resolved

Fixes #785

Type of change

  • This change contains documentation update

Breaking changes

None.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Visual confirmation locally
  • Visual confirmation of Vercel preview deployment

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

@tulup-conner tulup-conner added this to the 1.0.0 milestone Jun 7, 2023
@tulup-conner tulup-conner self-assigned this Jun 7, 2023
@vercel
Copy link

vercel bot commented Jun 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 9, 2023 8:24am

We use a variety of custom CSS hooks in traditional CSS file (not Tailwind CSS) to override the
third-party plugin we use to render code previews. The `docs.css` file was not "cascading" as
intended in production, and all of the styles we wrote there suddenly disappeared in production
mode.
…copy to clipboard

This is rather easy to do without a third-party package!
…e preview

This will only toggle the preview box itself - not the code. That reflects the behavior found on
flowbite.com.
…h preview

Provide full React context in the style of a `Next.js` page for each code preview, to make it more
immediately obviously how components should actually be used in the real world.
Specifically, we're just doing the imports from `flowbite-react` - we
still need to add functionality to display an extra `import` line for
icons.
We are SSR and have access to the full HTML of the page via React 18, so we don't need something to
help us inject the script into the DOM.
This should refer specifically to the subset `CustomFlowbiteTheme["button"]`.
We need to have access to the development-mode-only `displayName` of each imported FC, as well as to
the contents (bodies) of anonymous functions used inside component props in code examples. The only
way to do that is to disable Webpack minification.
@tulup-conner tulup-conner marked this pull request as draft June 8, 2023 18:58
With these settings we reduce the bundle size back to where it was when we were minifying with
default settings, but still retain thedisplay names of FCs and the bodies of anonymous functions.
Provide a link to the Github.com page to view code of the primary component in each code preview.
We need to input the code for Modal code previews manually, because our syntax highlighter resolves
the value of `<Modal show>`  instead of displaying the computation itself, and I can't see a way
around this behavior.
…nteraction

For components that you can interact with, like Pagination, doing so caused the code preview to stop
highlighting/coloring code.
@zoltanszogyenyi
Copy link
Member

zoltanszogyenyi commented Jun 9, 2023

Hey @tulup-conner,

First of all, thanks for the contributions - there's awesome progress and we're almost ready to merge.

We're good to go!

Copy link
Collaborator

@rluders rluders left a comment

Choose a reason for hiding this comment

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

Didn't check all the code, PR is too big... But I tested and it seems to be working as expected.

@rluders rluders merged commit f806ada into main Jun 9, 2023
@rluders rluders deleted the docs/improve-code-preview branch June 9, 2023 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Component and code preview feature (copy paste, expand button, new design)
4 participants