mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 09:34:19 +08:00
fix(react): resolve errors with JSX and types
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import type { JSX as LocalJSX } from '@ionic/core/components';
|
import type { JSX as LocalJSX } from '@ionic/core/components';
|
||||||
import React from 'react';
|
import React, { type PropsWithChildren } from 'react';
|
||||||
|
|
||||||
import type { IonContextInterface } from '../contexts/IonContext';
|
import type { IonContextInterface } from '../contexts/IonContext';
|
||||||
import { IonContext } from '../contexts/IonContext';
|
import { IonContext } from '../contexts/IonContext';
|
||||||
@ -9,13 +9,11 @@ import { IonOverlayManager } from './IonOverlayManager';
|
|||||||
import type { IonicReactProps } from './IonicReactProps';
|
import type { IonicReactProps } from './IonicReactProps';
|
||||||
import { IonAppInner } from './inner-proxies';
|
import { IonAppInner } from './inner-proxies';
|
||||||
|
|
||||||
type Props = LocalJSX.IonApp &
|
type Props = PropsWithChildren<LocalJSX.IonApp & IonicReactProps & {
|
||||||
IonicReactProps & {
|
|
||||||
ref?: React.Ref<HTMLIonAppElement>;
|
ref?: React.Ref<HTMLIonAppElement>;
|
||||||
};
|
}>;
|
||||||
|
|
||||||
export const IonApp = /*@__PURE__*/ (() =>
|
export class IonApp extends React.Component<Props> {
|
||||||
class extends React.Component<Props> {
|
|
||||||
addOverlayCallback?: (id: string, overlay: ReactComponentOrElement, containerElement: HTMLDivElement) => void;
|
addOverlayCallback?: (id: string, overlay: ReactComponentOrElement, containerElement: HTMLDivElement) => void;
|
||||||
removeOverlayCallback?: (id: string) => void;
|
removeOverlayCallback?: (id: string) => void;
|
||||||
|
|
||||||
@ -23,9 +21,6 @@ export const IonApp = /*@__PURE__*/ (() =>
|
|||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Wire up methods to call into IonOverlayManager
|
|
||||||
*/
|
|
||||||
ionContext: IonContextInterface = {
|
ionContext: IonContextInterface = {
|
||||||
addOverlay: (id: string, overlay: ReactComponentOrElement, containerElement: HTMLDivElement) => {
|
addOverlay: (id: string, overlay: ReactComponentOrElement, containerElement: HTMLDivElement) => {
|
||||||
if (this.addOverlayCallback) {
|
if (this.addOverlayCallback) {
|
||||||
@ -55,7 +50,5 @@ export const IonApp = /*@__PURE__*/ (() =>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get displayName() {
|
static displayName = 'IonApp';
|
||||||
return 'IonApp';
|
}
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
import type { JSX as LocalJSX } from '@ionic/core/components';
|
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 { NavContext } from '../../contexts/NavContext';
|
||||||
import type { IonicReactProps } from '../IonicReactProps';
|
import type { IonicReactProps } from '../IonicReactProps';
|
||||||
import { IonBackButtonInner } from '../inner-proxies';
|
import { IonBackButtonInner } from '../inner-proxies';
|
||||||
|
|
||||||
type Props = Omit<LocalJSX.IonBackButton, 'icon'> &
|
type Props = PropsWithChildren<LocalJSX.IonBackButton & IonicReactProps & {
|
||||||
IonicReactProps & {
|
|
||||||
icon?:
|
|
||||||
| {
|
|
||||||
ios: string;
|
|
||||||
md: string;
|
|
||||||
}
|
|
||||||
| string;
|
|
||||||
ref?: React.Ref<HTMLIonBackButtonElement>;
|
ref?: React.Ref<HTMLIonBackButtonElement>;
|
||||||
};
|
}>;
|
||||||
|
|
||||||
export const IonBackButton = /*@__PURE__*/ (() =>
|
export class IonBackButton extends React.Component<Props> {
|
||||||
class extends React.Component<Props> {
|
|
||||||
context!: React.ContextType<typeof NavContext>;
|
context!: React.ContextType<typeof NavContext>;
|
||||||
|
|
||||||
clickButton = (e: React.MouseEvent) => {
|
clickButton = (e: React.MouseEvent) => {
|
||||||
@ -51,4 +43,8 @@ export const IonBackButton = /*@__PURE__*/ (() =>
|
|||||||
static get contextType() {
|
static get contextType() {
|
||||||
return NavContext;
|
return NavContext;
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
|
shouldComponentUpdate(_nextProps: Readonly<Props>): boolean {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,10 +13,14 @@ type Props = LocalJSX.IonTabButton &
|
|||||||
onPointerDown?: React.PointerEventHandler<HTMLIonTabButtonElement>;
|
onPointerDown?: React.PointerEventHandler<HTMLIonTabButtonElement>;
|
||||||
onTouchEnd?: React.TouchEventHandler<HTMLIonTabButtonElement>;
|
onTouchEnd?: React.TouchEventHandler<HTMLIonTabButtonElement>;
|
||||||
onTouchMove?: React.TouchEventHandler<HTMLIonTabButtonElement>;
|
onTouchMove?: React.TouchEventHandler<HTMLIonTabButtonElement>;
|
||||||
|
children?: React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const IonTabButton = /*@__PURE__*/ (() =>
|
export class IonTabButton extends React.Component<Props> {
|
||||||
class extends React.Component<Props> {
|
shouldComponentUpdate(_nextProps: Readonly<Props>, _nextState: Readonly<{}>): boolean {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.handleIonTabButtonClick = this.handleIonTabButtonClick.bind(this);
|
this.handleIonTabButtonClick = this.handleIonTabButtonClick.bind(this);
|
||||||
@ -50,4 +54,4 @@ export const IonTabButton = /*@__PURE__*/ (() =>
|
|||||||
static get displayName() {
|
static get displayName() {
|
||||||
return 'IonTabButton';
|
return 'IonTabButton';
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { Components } from '@ionic/core';
|
||||||
import type { JSX as LocalJSX } from '@ionic/core/components';
|
import type { JSX as LocalJSX } from '@ionic/core/components';
|
||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
|
|
||||||
@ -26,12 +27,14 @@ if (typeof (window as any) !== 'undefined' && window.customElements) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
export interface IonTabsProps extends React.HTMLAttributes<Components.IonTabs> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
onIonTabsWillChange?: (event: CustomEvent<{ tab: string }>) => void;
|
||||||
namespace JSX {
|
onIonTabsDidChange?: (event: CustomEvent<{ tab: string }>) => void;
|
||||||
interface IntrinsicElements {
|
}
|
||||||
'ion-tabs': any;
|
|
||||||
}
|
declare module 'react' {
|
||||||
|
interface HTMLElements {
|
||||||
|
'ion-tabs': IonTabsProps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +43,15 @@ type ChildFunction = (ionTabContext: IonTabsContextState) => React.ReactNode;
|
|||||||
interface Props extends LocalJSX.IonTabs {
|
interface Props extends LocalJSX.IonTabs {
|
||||||
className?: string;
|
className?: string;
|
||||||
children: ChildFunction | React.ReactNode;
|
children: ChildFunction | React.ReactNode;
|
||||||
|
onIonTabsWillChange?: (event: CustomEvent<{ tab: string }>) => void;
|
||||||
|
onIonTabsDidChange?: (event: CustomEvent<{ tab: string }>) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const IonTabs = /*@__PURE__*/ (() =>
|
export class IonTabs extends React.Component<Props> {
|
||||||
class extends React.Component<Props> {
|
shouldComponentUpdate(_nextProps: Readonly<Props>, _nextState: Readonly<{}>): boolean {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
context!: React.ContextType<typeof NavContext>;
|
context!: React.ContextType<typeof NavContext>;
|
||||||
/**
|
/**
|
||||||
* `routerOutletRef` allows users to add a `ref` to `IonRouterOutlet`.
|
* `routerOutletRef` allows users to add a `ref` to `IonRouterOutlet`.
|
||||||
@ -51,7 +59,7 @@ export const IonTabs = /*@__PURE__*/ (() =>
|
|||||||
* breaking their ability to access the `IonRouterOutlet` instance.
|
* breaking their ability to access the `IonRouterOutlet` instance.
|
||||||
* Do not remove this ref.
|
* Do not remove this ref.
|
||||||
*/
|
*/
|
||||||
routerOutletRef: React.Ref<HTMLIonRouterOutletElement> = React.createRef();
|
routerOutletRef: React.Ref<Components.IonRouterOutlet> = React.createRef();
|
||||||
selectTabHandler?: (tag: string) => boolean;
|
selectTabHandler?: (tag: string) => boolean;
|
||||||
tabBarRef = React.createRef<any>();
|
tabBarRef = React.createRef<any>();
|
||||||
|
|
||||||
@ -205,4 +213,4 @@ export const IonTabs = /*@__PURE__*/ (() =>
|
|||||||
static get contextType() {
|
static get contextType() {
|
||||||
return NavContext;
|
return NavContext;
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react';
|
import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react';
|
||||||
import { IonReactRouter } from '@ionic/react-router';
|
import { IonReactRouter } from '@ionic/react-router';
|
||||||
|
import React from 'react';
|
||||||
|
import { Route } from 'react-router-dom';
|
||||||
|
|
||||||
/* Core CSS required for Ionic components to work properly */
|
/* Core CSS required for Ionic components to work properly */
|
||||||
import '@ionic/react/css/core.css';
|
import '@ionic/react/css/core.css';
|
||||||
@ -21,19 +21,19 @@ import '@ionic/react/css/display.css';
|
|||||||
|
|
||||||
/* Theme variables */
|
/* Theme variables */
|
||||||
import './theme/variables.css';
|
import './theme/variables.css';
|
||||||
|
import Icons from './pages/Icons';
|
||||||
import Main from './pages/Main';
|
import Main from './pages/Main';
|
||||||
import OverlayHooks from './pages/overlay-hooks/OverlayHooks';
|
|
||||||
import OverlayComponents from './pages/overlay-components/OverlayComponents';
|
|
||||||
import KeepContentsMounted from './pages/overlay-components/KeepContentsMounted';
|
|
||||||
import Tabs from './pages/Tabs';
|
import Tabs from './pages/Tabs';
|
||||||
import TabsBasic from './pages/TabsBasic';
|
import TabsBasic from './pages/TabsBasic';
|
||||||
import Icons from './pages/Icons';
|
|
||||||
import NavComponent from './pages/navigation/NavComponent';
|
import NavComponent from './pages/navigation/NavComponent';
|
||||||
import IonModalConditionalSibling from './pages/overlay-components/IonModalConditionalSibling';
|
|
||||||
import IonModalConditional from './pages/overlay-components/IonModalConditional';
|
import IonModalConditional from './pages/overlay-components/IonModalConditional';
|
||||||
|
import IonModalConditionalSibling from './pages/overlay-components/IonModalConditionalSibling';
|
||||||
import IonModalDatetimeButton from './pages/overlay-components/IonModalDatetimeButton';
|
import IonModalDatetimeButton from './pages/overlay-components/IonModalDatetimeButton';
|
||||||
import IonPopoverNested from './pages/overlay-components/IonPopoverNested';
|
|
||||||
import IonModalMultipleChildren from './pages/overlay-components/IonModalMultipleChildren';
|
import IonModalMultipleChildren from './pages/overlay-components/IonModalMultipleChildren';
|
||||||
|
import IonPopoverNested from './pages/overlay-components/IonPopoverNested';
|
||||||
|
import KeepContentsMounted from './pages/overlay-components/KeepContentsMounted';
|
||||||
|
import OverlayComponents from './pages/overlay-components/OverlayComponents';
|
||||||
|
import OverlayHooks from './pages/overlay-hooks/OverlayHooks';
|
||||||
|
|
||||||
setupIonicReact();
|
setupIonicReact();
|
||||||
|
|
||||||
|
@ -7,12 +7,14 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"importHelpers": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
"es2017"
|
"es2020",
|
||||||
|
"dom.iterable"
|
||||||
],
|
],
|
||||||
"module": "es2015",
|
"module": "esnext",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "bundler",
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
@ -20,7 +22,8 @@
|
|||||||
"pretty": true,
|
"pretty": true,
|
||||||
"removeComments": false,
|
"removeComments": false,
|
||||||
"strictPropertyInitialization": false,
|
"strictPropertyInitialization": false,
|
||||||
"target": "es2017",
|
"target": "es2020",
|
||||||
|
"jsx": "react-jsx",
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@ionic/core/hydrate": [
|
"@ionic/core/hydrate": [
|
||||||
|
Reference in New Issue
Block a user