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(editlink): add to default template, style updates, associated docs #239

Merged
merged 16 commits into from
Jul 17, 2019
Merged

Conversation

tay1orjones
Copy link
Member

Just took a quick shot here, let me know your feedback and I can revise as necessary

  • Migrated the previous emotion styles to the scss module
  • Added the component to the default template
  • Updated config to accept params for baseUrl and subDirectory
  • Added documentation to the example site

@vercel
Copy link

vercel bot commented Jul 11, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://gatsby-theme-carbon-git-fork-tay1orjones-edit-link.carbon-design-system.now.sh

@vercel vercel bot temporarily deployed to staging July 11, 2019 17:00 Inactive
@tay1orjones
Copy link
Member Author

Closes #162

@vpicone
Copy link
Collaborator

vpicone commented Jul 16, 2019

Awesome!!! I'll dive more into this tomorrow, but looks solid at first glance.

@vercel vercel bot temporarily deployed to staging July 16, 2019 16:30 Inactive
@tay1orjones
Copy link
Member Author

@vpicone updated with requested changes

@vpicone
Copy link
Collaborator

vpicone commented Jul 16, 2019

@tay1orjones Great work. You nailed it!

One last thing: you're correctly using the theme options object in the implementation, but in the docs you have them put the repository info into site metadata.

It's fine if you want to throw it in the site metadata object now to make querying easier. I'd just switch the docs to pass the repository as a theme option:

module.exports = {
  __experimentalThemes: [
    {
      resolve: 'gatsby-theme-carbon',
      options: {
        repository: {
          baseUrl:
            'https://github.com/carbon-design-system/gatsby-theme-carbon',
          subDirectory: '/packages/example',
        },
      },
    },
  ],
};

@tay1orjones
Copy link
Member Author

@vpicone great point, thanks for the catch. I just pushed an update with that change.

@vpicone
Copy link
Collaborator

vpicone commented Jul 17, 2019

@tay1orjones aw dang just realized this doesn't work if the site is an index.mdx inside of a directory (like the demo page). I think the solution is a page query that shares the file name. Unfortunately page queries are kind of a PITA for gatsby-mdx. We might need to do this in gatsby-node.

EDIT: I'm working on this, I'll just push to your branch.

@vpicone
Copy link
Collaborator

vpicone commented Jul 17, 2019

For the index.mdx fix, I added a hook to gatsby-node so we can provide templates with additional page context (like like the page's file path).

// We need to provide the actual file that created a specific page to append links for EditLink.
// We can't do page queries from MDX templates, so we'll add the page's relative path to context after it's created.
// The context object **is** supplied to MDX templates through the pageContext prop.
exports.onCreatePage = ({ page, actions }) => {
  const { createPage, deletePage } = actions;
  const [relativePagePath] = page.componentPath.split('src/pages').splice('-1');
  deletePage(page);
  createPage({
    ...page,
    context: {
      ...page.context,
      relativePagePath,
    },
  });
};


const repository = 'https://github.com/temporary/master/tree';
const EditLink = ({ relativePagePath, repository: repositoryProp }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Moved this to it's own query. Ideally data fetching would be separate from the component itself but we definitely don't want them sharing queries in case one gets shadowed.

@tay1orjones
Copy link
Member Author

Looks good to me, thanks!

Copy link
Member

@alisonjoseph alisonjoseph left a comment

Choose a reason for hiding this comment

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

This LGTM!

Just wanted to confirm this wouldn't add this link automatically to anyone upgrading correct? They would have to add the repository object to their config file first?

@vpicone
Copy link
Collaborator

vpicone commented Jul 17, 2019

@alisonjoseph yeah it doesn't render unless a url is provided as a theme option.

@vpicone vpicone merged commit 0448d3b into carbon-design-system:master Jul 17, 2019
@tay1orjones tay1orjones deleted the edit-link branch July 18, 2019 14:04
@vpicone vpicone mentioned this pull request Jul 30, 2019
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.

3 participants