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

Create getting started docs page #495

Merged
merged 15 commits into from
Apr 20, 2020

Conversation

macintoshhelper
Copy link
Contributor

@macintoshhelper macintoshhelper commented Apr 16, 2020

Hopefully addresses #263 (there's overlap with the slow start PR, but decided to carry on the effort as a more general purpose getting started page, as it's been inactive).

Copy link
Collaborator

@mathieudutour mathieudutour left a comment

Choose a reason for hiding this comment

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

Thanks! Just a few suggestions

npm run render
```

If you forget to create a new document, you may get an error saying `null is not an object`. You can handle this case with the instructions below:
Copy link
Collaborator

Choose a reason for hiding this comment

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

not to be addressed in this PR but it'd be nice to throw a better error message

Copy link
Contributor Author

@macintoshhelper macintoshhelper Apr 17, 2020

Choose a reason for hiding this comment

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

👍 Is it not worth creating a new Sketch document by default in the render function? If no documents are found.

e.g.

export const getDocumentDataFromContext = (ctx: SketchContext): SketchDocumentData =>
(
ctx.document ||
(ctx.actionContext || {}).document ||
NSDocumentController.sharedDocumentController().currentDocument()
).documentData();

->

 export const getDocumentDataFromContext = (ctx: SketchContext): SketchDocumentData => {
  try {
    return ( 
     ctx.document || 
     (ctx.actionContext || {}).document || 
     NSDocumentController.sharedDocumentController().currentDocument() 
   ).documentData(); 
  } catch(err) {
    if (sketch.documents.length === 0) {
      return new sketch.Document().sketchObject.documentData();
    }
  }

Copy link
Collaborator

Choose a reason for hiding this comment

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

No I don't think it should do something that it wasn't explicitly told not to. If we have a nice error message with some suggestion to fix the issue, it will be a lot more actionable than if we sometimes create a new doc but not always

Copy link
Contributor Author

@macintoshhelper macintoshhelper Apr 18, 2020

Choose a reason for hiding this comment

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

Should I open up a PR for:

 export const getDocumentDataFromContext = (ctx: SketchContext): SketchDocumentData => {
  try {
    return ( 
     ctx.document || 
     (ctx.actionContext || {}).document || 
     NSDocumentController.sharedDocumentController().currentDocument() 
   ).documentData(); 
  } catch(err) {
    if (err.includes('null is not an object')) {
      throw new Error('No open document found. Please try opening/creating a document, or you could use \'render(<App />, sketch.getSelectedDocument() || new sketch.Document())\'');
    }
  }

I'd use if (sketch.getDocuments().length === 0) { throw ... }, but not sure if it's best to avoid the public Sketch API? Couldn't find any imports for it in the source.

Copy link
Collaborator

@mathieudutour mathieudutour Apr 19, 2020

Choose a reason for hiding this comment

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

Let's avoid the plugin sketch API for now (because it might be a pain on nodejs and not working on sketch <49).

But I think it can be just

export const getDocumentDataFromContext = (ctx: SketchContext): SketchDocumentData => {
  let document = ctx.document || 
     (ctx.actionContext || {}).document || 
     NSDocumentController.sharedDocumentController().currentDocument()
  if (!document || !document.documentData) {
    throw new Error('No open document found.\nTry opening/creating a document before calling `render`.\n\nFor more information, check out http://airbnb.io/react-sketchapp/docs/guides/rendering.html');
  }
  return document.documentData()
}

@@ -105,6 +105,7 @@ Some properties are Sketch specific and won't work cross-platform but give you a
| --- | --- | --- |
| `shadowSpread` | `number` | ✅ |
| `shadowInner` | `boolean` | ✅ |
| `textTransform` | `none` &#124; `uppercase` &#124; `lowercase` | ✅ |
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's put it in Type Style and open an issue for the support of capitalize


If you forget to create a new document, you may get an error saying `null is not an object`. You can handle this case with the instructions below:

### Rendering to Multiple Pages or New Documents
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that could be in a guide of their own - maybe called Rendering or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created rendering.md

Copy link
Collaborator

@mathieudutour mathieudutour left a comment

Choose a reason for hiding this comment

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

perfect, thanks!

@mathieudutour mathieudutour merged commit 30c6f58 into airbnb:master Apr 20, 2020
@macintoshhelper macintoshhelper deleted the docs/getting-started branch April 20, 2020 18:50
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.

Document textTransform support
2 participants