Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Create Edit and CodeSnippet components - #197

Merged
katydecorah merged 21 commits into
masterfrom
edit-in-buttons
Jan 7, 2020
Merged

katydecorah merged 21 commits into
masterfrom
edit-in-buttons

Conversation

@katydecorah

@katydecorah katydecorah commented Dec 4, 2019 •

Copy link
Copy Markdown
Contributor

This PR adds a new component that you can send code and metadata to and these buttons will bring it into your favorite editor:

image

This PR also adds CodeSnippet that include:

  • option to add Edit in buttons
  • option add CodeSnippetTitle
  • automatically pulls in prism.css

To do:

  • more tests, especially to catch errors with prettier attempting to parse bad html
  • break code into smaller functions, add tests
  • rework props to simplify (html, css, js, resources, frontmatter) we are currently doing a lot of massaging and pieces together of data to get it how we want, instead we should provide helper functions to help extract data so that this component can stay simple

How to test /mapbox-gl-js-docs:

  1. from this branch, npm run build (build it locally)
  2. in mapbox-gl-js-docs, pull down the dr-ui-edit-buttons branch
  3. in mapbox-gl-js-docs, install dr-ui locally: "@mapbox/dr-ui": "file:/Users/katydecorah/Documents/GitHub/dr-ui/pkg", (update this with your path to your local dr-ui)
  4. in mapbox-gl-js-docs, yarn install then yarn start
  5. navigate to an examples page and test any of the edit buttons

How to test in /help:

  1. from this branch, npm run build (build it locally)
  2. in help, pull down the dr-ui-code-snippet branch
  3. in help, install dr-ui locally: "@mapbox/dr-ui": "file:/Users/katydecorah/Documents/GitHub/dr-ui/pkg", (update this with your path to your local dr-ui)
  4. in help, npm install then npm start
  5. navigate to http://localhost:8080/help/tutorials/use-mapbox-gl-js-with-react/ and see the CodeSnippet in action

@katydecorah katydecorah changed the title 🚧Edit in CodePen/JSFiddle buttons Edit in CodePen/JSFiddle buttons Dec 16, 2019
@katydecorah

Copy link
Copy Markdown
Contributor Author

This is ready for review, but can wait until the new year.

@katydecorah
katydecorah requested a review from a team January 2, 2020 18:22
@colleenmcginnis
colleenmcginnis requested review from colleenmcginnis and removed request for a team January 2, 2020 21:24
@katydecorah

Copy link
Copy Markdown
Contributor Author

Per chat, we're going to work in mr-ui code-snippet to this PR

Katy DeCorah added 2 commits January 2, 2020 20:07
* master:
  Update CHANGELOG.md
  Update CHANGELOG.md
  Collapse grayed lines in code block (#206)
  Add a tag component with themes (#216)
  Add new related page component (#213)
  Rework Notes themes (#202)
  Add "tag" option to second and third level headings (#212)
  Update style of BetaFlag (#207)
  allow `feedbackSentryDsn` to accept string (url) or boolean (false)
  Add IE11 compatibility for the `Search` component (#203)
  conditionally set `section` and `preferredLanguage`; send along `environment`
  Prepare 0.24.0
  Add groovy highlight option (#201)
  Push text feedback to Sentry (#198)
  Prepare 0.23.0
  Allow for a configurable connector on search component (#200)
  Update budo
* master:
  Create themes component to house shared themes for Tag and Note (#217)
@katydecorah

katydecorah commented Jan 3, 2020 •

Copy link
Copy Markdown
Contributor Author

Need to test locally in:

  • mapbox-gl-js-docs
  • help

@katydecorah katydecorah changed the title Edit in CodePen/JSFiddle buttons Create Edit and CodeSnippet components Jan 3, 2020

import React from 'react';
import PropTypes from 'prop-types';
import MrCodeSnippet from '@mapbox/mr-ui/code-snippet';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MrCodeSnippet 😂

@katydecorah

katydecorah commented Jan 6, 2020 •

Copy link
Copy Markdown
Contributor Author

@colleenmcginnis this is ready for review again! I updated the original comment with some testing suggestions

edit: {
html: '<h1>gurd murn!</h1>',
css: 'h1 {color: red}',
js: "console.log('hurn')",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Trying to wrap my head around a real world example here. So if we were to use this with a tutorial code block, we could import the code and then use the extractor helper function to get the edit contents? Like:

<CodeSnippet
  code={rawCode}
  highlighter={() => highlightHtml}
  edit={extractor(code)}
  ...
/>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll add a test case!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@colleenmcginnis colleenmcginnis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great @katydecorah and all works as expected!

@katydecorah
katydecorah merged commit 5a11103 into master Jan 7, 2020
@katydecorah
katydecorah deleted the edit-in-buttons branch January 7, 2020 01:23
katydecorah pushed a commit that referenced this pull request Jan 7, 2020
* master: (32 commits)
  add missing indices (#219)
  Create `Edit` and `CodeSnippet` components (#197)
  Update CHANGELOG.md
  Update CHANGELOG.md
  create highlight/theme-css
  Create themes component to house shared themes for Tag and Note (#217)
  Update CHANGELOG.md
  Update CHANGELOG.md
  Collapse grayed lines in code block (#206)
  Add a tag component with themes (#216)
  Add new related page component (#213)
  Rework Notes themes (#202)
  Add "tag" option to second and third level headings (#212)
  Update style of BetaFlag (#207)
  allow `feedbackSentryDsn` to accept string (url) or boolean (false)
  Add IE11 compatibility for the `Search` component (#203)
  conditionally set `section` and `preferredLanguage`; send along `environment`
  Prepare 0.24.0
  Add groovy highlight option (#201)
  Push text feedback to Sentry (#198)
  ...
katydecorah pushed a commit that referenced this pull request Jan 7, 2020
* master:
  add missing indices (#219)
  Create `Edit` and `CodeSnippet` components (#197)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants