-
Notifications
You must be signed in to change notification settings - Fork 340
refactor(common): convert nav-button to TypeScript #3966
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
Open
devin-ai-integration
wants to merge
9
commits into
master
Choose a base branch
from
devin-ai/convert-ts-nav-button-1740441688
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d055bcf
refactor(common): convert nav-button to TypeScript
devin-ai-integration[bot] 35c0654
fix(common): address PR comments on nav-button TypeScript conversion
devin-ai-integration[bot] 7ba08e8
fix(common): add index.js.flow for backward compatibility
devin-ai-integration[bot] 7de658a
fix(common): address PR comments on index.js.flow
devin-ai-integration[bot] 00099e4
fix(common): fix Flow errors in nav-button component
devin-ai-integration[bot] a507ce7
fix(common): update BackButton.tsx to accept string or Location
devin-ai-integration[bot] 07bdc33
revert(common): revert Flow fixes in nav-button component
devin-ai-integration[bot] 18c007c
fix(common): update Flow types in nav-button component
devin-ai-integration[bot] f81f743
Merge branch 'master' into devin-ai/convert-ts-nav-button-1740441688
tjuanitas 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
File renamed without changes.
This file contains hidden or 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,35 @@ | ||
| import * as React from 'react'; | ||
| import classNames from 'classnames'; | ||
| import { FormattedMessage } from 'react-intl'; | ||
| import { Route } from 'react-router-dom'; | ||
| import type { Location } from 'history'; | ||
| import IconNavigateLeft from '../../../icons/general/IconNavigateLeft'; | ||
| import PlainButton from '../../../components/plain-button'; | ||
| import messages from '../messages'; | ||
| import { ButtonType } from '../../../components/button'; | ||
| import './BackButton.scss'; | ||
|
|
||
| export interface BackButtonProps { | ||
| className?: string; | ||
| to?: Location; | ||
| } | ||
|
|
||
| const BackButton = ({ className, to, ...rest }: BackButtonProps) => ( | ||
| <Route> | ||
| {({ history }) => ( | ||
| <PlainButton | ||
| className={classNames('bdl-BackButton', className)} | ||
| onClick={() => (to ? history.push(to) : history.goBack())} | ||
| type={ButtonType.BUTTON} | ||
| {...rest} | ||
| > | ||
| <IconNavigateLeft height={24} width={24} /> | ||
| <span className="accessibility-hidden"> | ||
| <FormattedMessage {...messages.back} /> | ||
| </span> | ||
| </PlainButton> | ||
| )} | ||
| </Route> | ||
| ); | ||
|
|
||
| export default BackButton; | ||
File renamed without changes.
This file contains hidden or 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,77 @@ | ||
| import * as React from 'react'; | ||
| import classNames from 'classnames'; | ||
| import { Route } from 'react-router-dom'; | ||
| import type { match } from 'react-router'; | ||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import type { Location } from 'history'; | ||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import PlainButton, { PlainButtonProps } from '../../../components/plain-button'; | ||
| import { isLeftClick } from '../../../utils/dom'; | ||
|
|
||
| export interface NavButtonProps { | ||
| activeClassName?: string; | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| component?: React.ComponentType<PlainButtonProps & { ref?: React.Ref<HTMLButtonElement> }>; | ||
| exact?: boolean; | ||
| isActive?: (match: match, location: Location) => boolean; | ||
| isDisabled?: boolean; | ||
| onClick?: (event: React.SyntheticEvent) => void; | ||
| replace?: boolean; | ||
| strict?: boolean; | ||
| to: string | Location; | ||
| } | ||
|
|
||
| const NavButton = React.forwardRef<HTMLButtonElement, NavButtonProps>( | ||
| (props: NavButtonProps, ref: React.Ref<HTMLButtonElement>) => { | ||
| const { | ||
| activeClassName = 'bdl-is-active', | ||
| children, | ||
| className = 'bdl-NavButton', | ||
| component: Component = PlainButton, | ||
| exact, | ||
| isActive, | ||
| isDisabled, | ||
| onClick, | ||
| replace, | ||
| strict, | ||
| to, | ||
| ...rest | ||
| } = props; | ||
| const path = typeof to === 'object' ? to.pathname : to; | ||
|
|
||
| const disabledClassName = 'bdl-is-disabled'; | ||
|
|
||
| return ( | ||
| <Route exact={exact} path={path} strict={strict}> | ||
| {({ history, location, match }) => { | ||
| const isActiveValue = !!(isActive ? isActive(match, location) : match); | ||
|
|
||
| return ( | ||
| <Component | ||
| className={classNames(className, { | ||
| [activeClassName]: isActiveValue, | ||
| [disabledClassName]: isDisabled, | ||
| })} | ||
| isDisabled={isDisabled} | ||
| onClick={event => { | ||
| if (onClick) { | ||
| onClick(event); | ||
| } | ||
|
|
||
| if (!event.defaultPrevented && isLeftClick(event)) { | ||
| const method = replace ? history.replace : history.push; | ||
| method(to); | ||
| } | ||
| }} | ||
| ref={ref} | ||
| {...rest} | ||
| > | ||
| {children} | ||
| </Component> | ||
| ); | ||
| }} | ||
| </Route> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| export default NavButton; | ||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 @@ | ||
| export { default as BackButton } from './BackButton'; | ||
| export { default } from './NavButton'; |
This file contains hidden or 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,4 @@ | ||
| export { default as BackButton } from './BackButton'; | ||
| export { default } from './NavButton'; | ||
| export type { BackButtonProps } from './BackButton'; | ||
| export type { NavButtonProps } from './NavButton'; |
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.
Uh oh!
There was an error while loading. Please reload this page.