[2.0] RFC: docusaurus swizzle --wrap/copy
See original GitHub issueš Feature
We have a feature to wrap existing theme components: https://docusaurus.io/docs/using-themes#wrapping-theme-components
import OriginalFooter from "@theme-original/Footer";
import React from "react";
export default function Footer(props) {
return (
<>
<div>Before footer</div>
<OriginalFooter {...props} />
</>
);
}
Itās a very useful pattern to use to customize your Docusaurus site. It allows you to enhance a Docusaurus theme without having to copy (and maintain) theme code.
Unfortunately, this feature is not very visible and we donāt encourage its usage, as the code above is only found in our doc, and the swizzle CLI command does not produce such code.
Some use-cases:
- Add a custom comp before/after (above/under) any existing theme component (like add comments to blog posts)
- Slightly modify the layout/behavior of an existing theme component (like, add line numbers to code blocks)
- Add custom MDX components
I suggest to do some changes:
- Add a
docusaurus swizzle --wrapoption to produce such code. It wouldnāt require the usage of--dangerbecause itās way safer than copying. - For copying, require explicit usage of
--copyoption, keep--dangerfor unsafe components and suggest to prefer usage of--wrap - No option: suggest use either
--wrapor--copy, hint to prefer--wrap
Other changes to consider in the long term:
- Rename
docusaurus swizzleto something more intuitive likedocusaurus theme? - Create much smaller theme components, so that users naturally have more before/after wrapping possibilities to suit their use-cases.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Swizzling - Docusaurus
Ejecting: creates a copy of the original theme component, which you can fully customize; Wrapping: creates a wrapper around the original themeĀ ...
Read more >2.0.0-rc.1 - Docusaurus
#7776 fix(core): swizzle --eject js should not copy theme .d.ts files (@slorber) Ā· #7750 fix(deploy): revert "feat(deploy): copy local git configĀ ...
Read more >Announcing Docusaurus 2.0
Today we are extremely happy to finally announce Docusaurus 2.0! ... React component provided by our default theme: we call this swizzling.
Read more >CLI - Docusaurus
Docusaurus CLI commandsā Ā· docusaurus start [siteDir] ā Ā· docusaurus build [siteDir] ā Ā· docusaurus swizzle [themeName] [componentName] [siteDir] ā.
Read more >Styling and Layout - Docusaurus
refer to the swizzling guide. A Docusaurus site is a single-page React application. You can style it the way you style React apps....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Great, you can go ahead š I would be relaxing a little
swizzlebecause it sounds funky šswizzleis not intuitive enoughAgreed. I also think a more hierarchical component structure is better than crowding
src/themewith all kinds of components, since it makes navigation and understanding the componentsā usage easier.No strong feelings about extending the CLI. I think we can make it fully interactive (just like
docusaurus-init) so that runningdocusaurus swizzlewill prompt you for wrap/copy, the theme, and the component, step by step. Right now if the theme name / component name isnāt provided it throws anexit code: 1in my face which I donāt like. If user just wants to list the components/themes available but not to actually choose any of them, they can either provide an explicit--listargument or choose aquitoption in the interactive console.