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

feat(v2): add @theme-original alias to give access to pre-swizzled components #2455

Merged
merged 1 commit into from
Mar 24, 2020

Conversation

yangshun
Copy link
Contributor

Motivation

Provide an alias for theme components so that they can be semi-swizzled. Meaning you swizzle a component but only to wrap things around it, possibly to call new lifecycle logic or have components above/below it.

For example, I can now do this

import React from 'react';

import DocItemOriginal from '@theme-original/DocItem';

function DocItem(props) {
  return (
    <div>
      <p>Wrapper</p>
      <DocItemOriginal {...props} />
      <p>Wrapper</p>
    </div>
  );
}

export default DocItem;

and get this

Screen Shot 2020-03-24 at 12 19 30 PM

This is partially inspired by VuePress (although Endi and I already had this idea long ago when we were building themes). Libra docs is moving to v2 and wants this level of customization.

This @theme-original alias will also allow us to specify slot props (components as props) which serve to inject components somewhere into a component. We could do this for the various doc and blog items.

Follow Up

  • Add docs
  • Add slot props to doc and blog

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Modified unit tests and added example.

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@yangshun yangshun added the pr: new feature This PR adds a new API or behavior. label Mar 24, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 24, 2020
@@ -8,12 +8,25 @@
import {ThemeAlias} from '@docusaurus/types';
import {themeAlias} from './alias';

export function loadThemeAlias(themePaths: string[]): ThemeAlias {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote this part to make it slightly easier to read (IMO).

@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit c92e715

https://deploy-preview-2455--docusaurus-2.netlify.com

@yangshun yangshun requested a review from lex111 March 24, 2020 04:37
@yangshun yangshun merged commit 27e7fa6 into master Mar 24, 2020
@yangshun yangshun deleted the yangshun/theme-original branch March 28, 2020 16:15
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: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants