fix(react): fix types for new stencil

This commit is contained in:
Ely Lucas
2019-09-25 17:05:11 -06:00
committed by GitHub
parent cf223e40c1
commit c79e74b91f
9 changed files with 47 additions and 23 deletions

View File

@ -2,10 +2,10 @@ import { JSX as LocalJSX } from '@ionic/core';
import React from 'react';
import { NavContext } from '../../contexts/NavContext';
import { ReactProps } from '../ReactProps';
import { IonicReactProps } from '../IonicReactProps';
import { IonBackButtonInner } from '../inner-proxies';
type Props = LocalJSX.IonBackButton & ReactProps & {
type Props = LocalJSX.IonBackButton & IonicReactProps & {
ref?: React.RefObject<HTMLIonBackButtonElement>;
};

View File

@ -6,10 +6,9 @@ import { IonTabBarInner } from '../inner-proxies';
import { IonTabButton } from '../proxies';
type Props = LocalJSX.IonTabBar & {
ref?: React.RefObject<HTMLIonTabBarElement>;
navigate: (path: string, direction: 'back' | 'none') => void;
currentPath: string;
children?: React.ReactNode;
navigate?: (path: string, direction: 'back' | 'none') => void;
currentPath?: string;
slot?: 'bottom' | 'top';
};
interface Tab {
@ -48,7 +47,7 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
const activeTab = Object.keys(state.tabs)
.find(key => {
const href = state.tabs[key].originalHref;
return props.currentPath.startsWith(href);
return props.currentPath!.startsWith(href);
});
if (activeTab === undefined || (activeTab === state.activeTab && state.tabs[activeTab].currentHref === props.currentPath)) {
@ -68,10 +67,13 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
}
private onTabButtonClick = (e: CustomEvent<{ href: string, selected: boolean, tab: string }>) => {
if (this.state.activeTab === e.detail.tab) {
this.props.navigate(this.state.tabs[e.detail.tab].originalHref, 'back');
} else {
this.props.navigate(this.state.tabs[e.detail.tab].currentHref, 'none');
const { navigate } = this.props;
if (navigate) {
if (this.state.activeTab === e.detail.tab) {
navigate(this.state.tabs[e.detail.tab].originalHref, 'back');
} else {
navigate(this.state.tabs[e.detail.tab].currentHref, 'none');
}
}
}
@ -96,7 +98,7 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
}
})();
export const IonTabBar: React.FC<LocalJSX.IonTabBar & { currentPath?: string, navigate?: (path: string) => void; }> = props => {
export const IonTabBar: React.FC<Props> = props => {
const context = useContext(NavContext);
return (
<IonTabBarUnwrapped