Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

docs(Examples): refactor SourceManager, add toggle for languages #650

Merged
merged 17 commits into from
Jan 9, 2019

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Dec 19, 2018

Fixes #495.
Fixes #615.


This PR:

  • refactors SourceManager to a React component to provide declarative controls
  • adds toggle for TypeScript examples
  • fixes issues with Children and Shorthand APIs switch

image

@layershifter layershifter changed the title [WIP] docs(Examples): refactor SourceManager, add toggle for languages docs(Examples): refactor SourceManager, add toggle for languages Dec 20, 2018
…om/stardust-ui/react into docs/add-code-togle

# Conflicts:
#	docs/src/components/ComponentDoc/ComponentExample/SourceCodeManager.ts
#	docs/src/components/ComponentDoc/ComponentExamples.tsx
#	docs/src/components/ExternalExampleLayout.tsx
#	docs/src/utils/exampleContexts.ts
#	docs/src/utils/exampleKebabNameToSourceFilename.ts
#	docs/src/utils/index.tsx
import getExampleSource from './getExampeSource'

export type ComponentSourceManagerRenderProps = ComponentSourceManagerState & {
handleCodeAPIChange: (newApi: keyof ComponentAPIs) => void
Copy link
Contributor

Choose a reason for hiding this comment

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

The Shorthand API should be the first selected option. This is the one we want to advertise. With the latest changes the Children API is first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, would recommend the Shorthand API to be the first option, as it was before.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, done with the latest commit :)

const currentCode = storedCode || originalCode
const currentCodePath = examplePath + componentAPIs[currentCodeAPI].fileSuffix

const codeParser = currentCodeLanguage === 'ts' ? 'typescript' : 'babylon'
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that this doesn't raise any error in the Typescript mode:

const notString: string = 3

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, we don't have TS checks there. And I'm not sure that we actually need them for now.

I renamed codeParser to prettierParser to avoid confusion

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it now, I thought it was actually a code parser. I know that the Monaco editor was configurable to parse and show ts errors, so I thought there is something similar here.

this.sourceCodeMgr.codeType = codeType
this.updateAndRenderSourceCode()
if (wasCodeChanged) {
if (confirm('Lose your changes?')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It was awkward to me to lose the changes between switching to Javascript and Typescript. Can't we store both source codes in state? Not sure if this will really be used by the users, but just wondering...

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to avoid implementation complications there.

If we will get claims about it, we can refactor ComponentSourceManager somehow to store both source codes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Valid point..

@mnajdova
Copy link
Contributor

mnajdova commented Jan 9, 2019

One more thought. Now that we are autogenerating the js code, maybe we should disable the edit on github option for those examples? It seems kind a strange that edit is navigating you to different file..
image

@layershifter
Copy link
Member Author

One more thought. Now that we are autogenerating the js code, maybe we should disable the edit on github option for those examples? It seems kind a strange that edit is navigating you to different file..
image

Agree, I pushed changes with this 👍

href={ghEditHref}
target="_blank"
/>
)}
</Menu>
)
}

renderJSX = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, let's rename this one too to renderSourceCode

@layershifter layershifter merged commit 0829c46 into master Jan 9, 2019
@layershifter layershifter deleted the docs/add-code-togle branch January 9, 2019 17:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: crash on click on "Shorthand API" Docs: use TypeScript and plain JS in examples
3 participants