-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): resolve errors with JSX and types
- Loading branch information
1 parent
30b1e7f
commit 22b852e
Showing
6 changed files
with
292 additions
and
288 deletions.
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
84 changes: 40 additions & 44 deletions
84
packages/react/src/components/navigation/IonBackButton.tsx
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,54 +1,50 @@ | ||
import type { JSX as LocalJSX } from '@ionic/core/components'; | ||
import React from 'react'; | ||
import React, { type PropsWithChildren } from 'react'; | ||
|
||
import { NavContext } from '../../contexts/NavContext'; | ||
import type { IonicReactProps } from '../IonicReactProps'; | ||
import { IonBackButtonInner } from '../inner-proxies'; | ||
|
||
type Props = Omit<LocalJSX.IonBackButton, 'icon'> & | ||
IonicReactProps & { | ||
icon?: | ||
| { | ||
ios: string; | ||
md: string; | ||
} | ||
| string; | ||
ref?: React.Ref<HTMLIonBackButtonElement>; | ||
}; | ||
|
||
export const IonBackButton = /*@__PURE__*/ (() => | ||
class extends React.Component<Props> { | ||
context!: React.ContextType<typeof NavContext>; | ||
|
||
clickButton = (e: React.MouseEvent) => { | ||
/** | ||
* If ion-back-button is being used inside | ||
* of ion-nav then we should not interact with | ||
* the router. | ||
*/ | ||
if (e.target && (e.target as HTMLElement).closest('ion-nav') !== null) { | ||
return; | ||
} | ||
|
||
const { defaultHref, routerAnimation } = this.props; | ||
|
||
if (this.context.hasIonicRouter()) { | ||
e.stopPropagation(); | ||
this.context.goBack(defaultHref, routerAnimation); | ||
} else if (defaultHref !== undefined) { | ||
window.location.href = defaultHref; | ||
} | ||
}; | ||
|
||
render() { | ||
return <IonBackButtonInner onClick={this.clickButton} {...this.props}></IonBackButtonInner>; | ||
type Props = PropsWithChildren<LocalJSX.IonBackButton & IonicReactProps & { | ||
ref?: React.Ref<HTMLIonBackButtonElement>; | ||
}>; | ||
|
||
export class IonBackButton extends React.Component<Props> { | ||
context!: React.ContextType<typeof NavContext>; | ||
|
||
clickButton = (e: React.MouseEvent) => { | ||
/** | ||
* If ion-back-button is being used inside | ||
* of ion-nav then we should not interact with | ||
* the router. | ||
*/ | ||
if (e.target && (e.target as HTMLElement).closest('ion-nav') !== null) { | ||
return; | ||
} | ||
|
||
static get displayName() { | ||
return 'IonBackButton'; | ||
} | ||
const { defaultHref, routerAnimation } = this.props; | ||
|
||
static get contextType() { | ||
return NavContext; | ||
if (this.context.hasIonicRouter()) { | ||
e.stopPropagation(); | ||
this.context.goBack(defaultHref, routerAnimation); | ||
} else if (defaultHref !== undefined) { | ||
window.location.href = defaultHref; | ||
} | ||
})(); | ||
}; | ||
|
||
render() { | ||
return <IonBackButtonInner onClick={this.clickButton} {...this.props}></IonBackButtonInner>; | ||
} | ||
|
||
static get displayName() { | ||
return 'IonBackButton'; | ||
} | ||
|
||
static get contextType() { | ||
return NavContext; | ||
} | ||
|
||
shouldComponentUpdate(_nextProps: Readonly<Props>): boolean { | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.