-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Migrate addon links to TS #6246
Merged
ndelangen
merged 6 commits into
storybookjs:next
from
sairus2k:ts-migration/addon-links
Mar 25, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a03f7eb
chore: add tsconfig in addons/links
c81f561
chore: migrate src of addons/a11y to Typescript
21d466d
Merge branch 'next' into pr/sairus2k/6246
ndelangen 1cc8945
chore: fix linkTo type in addons/links
d2d8d39
FIX linting & tests
ndelangen 17fa318
Merge branch 'ts-migration/addon-links' of github.com:sairus2k/storyb…
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { navigate, hrefTo } from '../../preview'; | ||
|
||
|
@@ -9,48 +8,58 @@ import { navigate, hrefTo } from '../../preview'; | |
// Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks | ||
const LEFT_BUTTON = 0; | ||
|
||
const isPlainLeftClick = e => | ||
const isPlainLeftClick = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => | ||
e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey; | ||
|
||
const cancelled = (e, cb = () => {}) => { | ||
const cancelled = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>, cb = (_e: any) => {}) => { | ||
if (isPlainLeftClick(e)) { | ||
e.preventDefault(); | ||
cb(e); | ||
} | ||
}; | ||
|
||
export default class LinkTo extends PureComponent { | ||
constructor(...args) { | ||
super(...args); | ||
interface Props { | ||
kind: string; | ||
story: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
this.state = { | ||
href: '/', | ||
}; | ||
interface State { | ||
href: string; | ||
} | ||
|
||
this.handleClick = this.handleClick.bind(this); | ||
} | ||
export default class LinkTo extends PureComponent<Props, State> { | ||
defaultProps: Props = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. forgot |
||
kind: null, | ||
story: null, | ||
children: undefined, | ||
}; | ||
|
||
state: State = { | ||
href: '/', | ||
}; | ||
|
||
componentDidMount() { | ||
this.updateHref(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
componentDidUpdate(prevProps: Props) { | ||
const { kind, story } = this.props; | ||
|
||
if (prevProps.kind !== kind || prevProps.story !== story) { | ||
this.updateHref(); | ||
} | ||
} | ||
|
||
async updateHref() { | ||
updateHref = async () => { | ||
const { kind, story } = this.props; | ||
const href = await hrefTo(kind, story); | ||
this.setState({ href }); | ||
} | ||
}; | ||
|
||
handleClick() { | ||
handleClick = () => { | ||
navigate(this.props); | ||
} | ||
}; | ||
|
||
render() { | ||
const { kind, story, children, ...rest } = this.props; | ||
|
@@ -63,15 +72,3 @@ export default class LinkTo extends PureComponent { | |
); | ||
} | ||
} | ||
|
||
LinkTo.defaultProps = { | ||
kind: null, | ||
story: null, | ||
children: undefined, | ||
}; | ||
|
||
LinkTo.propTypes = { | ||
kind: PropTypes.string, | ||
story: PropTypes.string, | ||
children: PropTypes.node, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import LinkTo from './components/link'; | ||
export default LinkTo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'global'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": ["webpack-env"] | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"src/__tests__/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentTarget
is alwaysdocument
which makes it throw on each click, see e.g.https://next--storybooks-html.netlify.com/?path=/story/welcome--welcome