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

docs(Examples): allow to use TS in examples #617

Merged
merged 13 commits into from
Dec 19, 2018
Merged

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Dec 14, 2018

Refs #495. This PR is a first part.


This PR:

  • adds ability use TypeScript in our examples via:
    • Babel plugin that transforms imports to JS-like in our examples
    • Gulp plugin that transforms our TS code to plain JS
  • drops raw-loader

Known issues

1. JS examples lose some formatting.

Babel is the transpiler so some formatting things are lost.

Input: TS code

  state = { isMounted: false }

  createdRef = React.createRef<HTMLButtonElement>()
  functionalRef = null

  handleRef = (node: HTMLButtonElement) => (this.functionalRef = node)

  componentDidMount() {
    this.setState({ isMounted: true })
  }

Babel: JS output

  state = {
    isMounted: false,
  }
  createdRef = React.createRef()
  functionalRef = null
  handleRef = node => (this.functionalRef = node)

  componentDidMount() {
    this.setState({
      isMounted: true,
    })
  }

I don't have a better idea how we can it be saved. I tried to use TS compiler there, but it gives more confusing result:

    constructor() {
        super(...arguments);
        this.state = { isMounted: false };
        this.createdRef = React.createRef();
        this.functionalRef = null;
        this.handleRef = (node) => (this.functionalRef = node);
    }
    componentDidMount() {
        this.setState({ isMounted: true });
    }

2. There are no toggle for Typescript

It will be done in a separate PR with a new SourceManager.

@DustyTheBot
Copy link
Collaborator

Warnings
⚠️ There are no updates provided to CHANGELOG. Ensure there are no publicly visible changes introduced by this PR.

Generated by 🚫 dangerJS

@layershifter layershifter changed the title [WIP] docs(Examples): allow to use TS in examples docs(Examples): allow to use TS in examples Dec 17, 2018
@layershifter
Copy link
Member Author

After #600 will be merged we can also apply ESLint's fixes and get more accurate output.

@layershifter
Copy link
Member Author

TODO for next PR

  1. Remove examples from exampleContext, we should require only index.tsx files
  2. Create a new context for *.source.json files and use it in ExternalExampleLayout with SourceRender (Docs example can be broken and merge into master without any check #554) and in ContributionPrompt.

@@ -62,7 +69,8 @@ task(

const componentsSrc = [`${paths.posix.src()}/components/*/[A-Z]*.tsx`, '!**/Slot.tsx']
const behaviorSrc = [`${paths.posix.src()}/lib/accessibility/Behaviors/*/[a-z]*.ts`]
const examplesSrc = `${paths.posix.docsSrc()}/examples/*/*/*/index.tsx`
const examplesIndexSrc = `${paths.posix.docsSrc()}/examples/*/*/*/index.tsx`
const examplesSrc = `${paths.posix.docsSrc()}/examples/*/*/*/!(*index|.knobs).tsx`
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for filtering out index files

@layershifter layershifter merged commit 03c0bd2 into master Dec 19, 2018
@layershifter layershifter deleted the docs/use-ts branch December 19, 2018 12:53
mnajdova pushed a commit that referenced this pull request Dec 19, 2018
* docs(Examples): allow to use TS in examples

* add jsdoc

* fix typo

* rename file

* add comment

* `createExample` to `createExampleSourceCode`

* rework with `path.relative()`

* remove JSON files on remove tsx

* create getRelativePathToSource function
mnajdova pushed a commit that referenced this pull request Dec 19, 2018
* feat(menuItem: add menu prop)

* Only one submenu open at a time

* Fix bug: submenu noe closes on clicking a menuItem with no submenu

* Code cleanup

* Remove the activeIndex prop passed to the menuItem

* Remove Popup and implement submenu without it

* initial keyboard support

* left/right arrow handling

* simplify keyboard handlers

* -fixed import in the MenuItem

* -added submenuIndicator
-small fixes in the styles and the way the submenu is generated

* -clicking on leaf element should close the submenus (the same should be done for enter/space)
-applied consistent (left-right) navigation for horizontal menu and (up-down) navigation for vertical menu

* -implemented outside click to close all menus
-implemented enter key on leaf menu item to close the menu

* -fixed import

* -refactored MenuItem handlers - fixed issues
-removed onClick handler for the Menu (not necessary for now)
-added onKeyDown in the creation of the MenuItem in the Menu component for handling the action prop

* -added setActiveIndex callback and removed onKeyDown in the creation of MenuItems in the Menu component

* -right arrow key is closing the submenus and goes to the next element if the menu is horizontal, or is focusing the first MenuItem if it is vertical

* -handled left arrow key

* -changed ref
-focus trap wip

* -added Ref component instead of using the itemRef on the ElementType
-removed subscription for focus

* -fixes

* -moved ref //TODO: figure out tests failing

* -close menu on outside focus

* -improved comments

* -fixed escape key not focusing the active element
-changed parentRef to inSubmenu boolean

* -fixing key problems
-added dependency for generating id

* -refactored submenuRef element

* fix broken tests

* -added comments in the tests
-changed the submenuDomElement so submenuRef

* -renamed inSubmenu to submenu prop in the Menu

* -fixed with the auto-controlled prop in the Menu

* -added state interface in the Menu
-improved menu variables' names

* -fixed variables in examples

* -remove state initialization in the MenuItem component

* -added new handler for escape
-changed submenu examples titles

* -refactored conditions using doesNodeContainClick

* -renamed submenu* props to menu in the MenuItem component
-changed setActiveIndex with onActiveChanged
-introduced different styles for the hovering vs active elements

* -improved example
-fixed issue with the condition for the active prop

* -exported MenuState
-added correct typings to the menuStyles

* -fixed underlined active + hovered style

* -fixed border corner clipped by adding custom styles for the first child menu items and the last child menu items in vertical menu

* -addressed comments on PR

* chore: prepare release 0.15.0 [ci skip]

* 0.15.0

* fix(Prototype): Fix Popover prototype after breaking changes (#623)

* chore: cache results of vulnerability scans (#621)

* implement caching strategy

* adjust file name of scan marker

* add yarn lock hash to marker file name

* add change to build config

* fix dir name in build config

* improve caching strategy

* just restore cache

* temporary remove lint and tests

* try

* fix caching strategy

* try

* try

* try

* try epoch

* create file on scan

* return lint and test steps

* introduce comment for the caching approach taken

* remove unnecessary function

* simplify expression for marker file name

* feat(text): color prop (#597)

* feat(text): color prop

* addressed comments

* changelog

* amended changelog

* made text color override other props that change color

* feat(header): header and header description color prop (#628)

* feat(header): header and header description color prop

* changelog

* fixed examples

* addressed PR comments

* fix(Popup): allow to 'detach' from trigger and RTL adjustments (#612)

* introduce offset prop

* correct description of supported values

* update changelog

* introduce fix

* ensure RTL is properly applied to complex offset expressions

* rename method to make logic more expressive

* add unit tests

* remove unnecessary grid props from offset example

* update changelog

* fix(SelectableList): Items in list should be selectable (#566)

* Reflect which item is selected in list

* Make list derived from autocontrolled component

* small fix

* Update ListExampleSelection.tsx

* Update ListExampleSelection.shorthand.tsx

* Small improvement

* Rename *ItemIndex -> *Index

* Names refactoring

* Minor improvements

* update changelog

* Add onSelectedIndexChange

* Add some tests

* Small improvements afer CR

* Small improvements afer CR

* Small improvements afer CR

* create focus handler when List is constructed

* fix changelog

* changelog

* docs(Examples): allow to use TS in examples (#617)

* docs(Examples): allow to use TS in examples

* add jsdoc

* fix typo

* rename file

* add comment

* `createExample` to `createExampleSourceCode`

* rework with `path.relative()`

* remove JSON files on remove tsx

* create getRelativePathToSource function

* -updated changelog

* -updated changelog

* -updated changelog with breaking changes
-removed TODO comment

* -fixed imports in examples
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.

4 participants