From 22ee8cfd920efb8017ae08b6f61290bb7e868eaf Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 8 Aug 2019 06:29:17 +0900 Subject: [PATCH] [react-transition-group] Unify to standard module syntax (#37405) Use `import` and `export` syntax instead of `namespace`. `Transition.d.ts` has already used the standard syntax. --- .../react-transition-group/CSSTransition.d.ts | 82 +++++++++---------- .../SwitchTransition.d.ts | 28 +++---- types/react-transition-group/Transition.d.ts | 4 +- .../TransitionGroup.d.ts | 34 ++++---- types/react-transition-group/index.d.ts | 15 +--- .../react-transition-group-tests.tsx | 40 +++++---- 6 files changed, 95 insertions(+), 108 deletions(-) diff --git a/types/react-transition-group/CSSTransition.d.ts b/types/react-transition-group/CSSTransition.d.ts index cb540659b0..2ae620aded 100644 --- a/types/react-transition-group/CSSTransition.d.ts +++ b/types/react-transition-group/CSSTransition.d.ts @@ -1,47 +1,45 @@ -import { Component } from "react"; +import { Component } from 'react'; import { TransitionProps } from "./Transition"; -declare namespace CSSTransition { - interface CSSTransitionClassNames { - appear?: string; - appearActive?: string; - appearDone?: string; - enter?: string; - enterActive?: string; - enterDone?: string; - exit?: string; - exitActive?: string; - exitDone?: string; - } - - interface CSSTransitionProps extends TransitionProps { - /** - * The animation `classNames` applied to the component as it enters or exits. - * A single name can be provided and it will be suffixed for each stage: e.g. - * - * `classNames="fade"` applies `fade-enter`, `fade-enter-active`, - * `fade-exit`, `fade-exit-active`, `fade-appear`, and `fade-appear-active`. - * - * Each individual classNames can also be specified independently like: - * - * ```js - * classNames={{ - * appear: 'my-appear', - * appearActive: 'my-appear-active', - * appearDone: 'my-appear-done', - * enter: 'my-enter', - * enterActive: 'my-enter-active', - * enterDone: 'my-enter-done', - * exit: 'my-exit', - * exitActive: 'my-exit-active', - * exitDone: 'my-exit-done' - * }} - * ``` - */ - classNames?: string | CSSTransitionClassNames; - } +export interface CSSTransitionClassNames { + appear?: string; + appearActive?: string; + appearDone?: string; + enter?: string; + enterActive?: string; + enterDone?: string; + exit?: string; + exitActive?: string; + exitDone?: string; } -declare class CSSTransition extends Component {} +export interface CSSTransitionProps extends TransitionProps { + /** + * The animation `classNames` applied to the component as it enters or exits. + * A single name can be provided and it will be suffixed for each stage: e.g. + * + * `classNames="fade"` applies `fade-enter`, `fade-enter-active`, + * `fade-exit`, `fade-exit-active`, `fade-appear`, and `fade-appear-active`. + * + * Each individual classNames can also be specified independently like: + * + * ```js + * classNames={{ + * appear: 'my-appear', + * appearActive: 'my-appear-active', + * appearDone: 'my-appear-done', + * enter: 'my-enter', + * enterActive: 'my-enter-active', + * enterDone: 'my-enter-done', + * exit: 'my-exit', + * exitActive: 'my-exit-active', + * exitDone: 'my-exit-done' + * }} + * ``` + */ + classNames?: string | CSSTransitionClassNames; +} -export = CSSTransition; +declare class CSSTransition extends Component {} + +export default CSSTransition; diff --git a/types/react-transition-group/SwitchTransition.d.ts b/types/react-transition-group/SwitchTransition.d.ts index 030c1bdcd5..2368257c70 100644 --- a/types/react-transition-group/SwitchTransition.d.ts +++ b/types/react-transition-group/SwitchTransition.d.ts @@ -1,24 +1,22 @@ -import { Component } from "react"; +import { Component, ReactElement } from "react"; export enum modes { out = 'out-in', in = 'in-out' } -declare namespace SwitchTransition { - interface SwitchTransitionProps { - /** - * Transition modes. - * `out-in`: Current element transitions out first, then when complete, the new element transitions in. - * `in-out`: New element transitions in first, then when complete, the current element transitions out. - */ - mode?: 'out-in' | 'in-out'; +export interface SwitchTransitionProps { + /** + * Transition modes. + * `out-in`: Current element transitions out first, then when complete, the new element transitions in. + * `in-out`: New element transitions in first, then when complete, the current element transitions out. + */ + mode?: 'out-in' | 'in-out'; - /** - * Any `Transition` or `CSSTransition` component - */ - children: React.ReactElement; - } + /** + * Any `Transition` or `CSSTransition` component + */ + children: ReactElement; } /** @@ -46,6 +44,6 @@ declare namespace SwitchTransition { * } * ``` */ -declare class SwitchTransition extends Component {} +declare class SwitchTransition extends Component {} export default SwitchTransition; diff --git a/types/react-transition-group/Transition.d.ts b/types/react-transition-group/Transition.d.ts index 179f63c38e..7b14a368f4 100644 --- a/types/react-transition-group/Transition.d.ts +++ b/types/react-transition-group/Transition.d.ts @@ -1,4 +1,4 @@ -import { Component } from "react"; +import { Component, ReactNode } from "react"; export type EndHandler = (node: HTMLElement, done: () => void) => void; export type EnterHandler = (node: HTMLElement, isAppearing: boolean) => void; @@ -37,7 +37,7 @@ export type TransitionStatus = typeof EXITING | typeof EXITED | typeof UNMOUNTED; -export type TransitionChildren = React.ReactNode | ((status: TransitionStatus) => React.ReactNode); +export type TransitionChildren = ReactNode | ((status: TransitionStatus) => ReactNode); export interface TransitionProps extends TransitionActions { /** * Show the component; triggers the enter or exit states diff --git a/types/react-transition-group/TransitionGroup.d.ts b/types/react-transition-group/TransitionGroup.d.ts index 48bc9bbe6d..316e9f80ec 100644 --- a/types/react-transition-group/TransitionGroup.d.ts +++ b/types/react-transition-group/TransitionGroup.d.ts @@ -1,23 +1,23 @@ import { Component, ReactType, HTMLProps, ReactElement } from "react"; import { TransitionActions, TransitionProps } from "./Transition"; -declare namespace TransitionGroup { - interface IntrinsicTransitionGroupProps extends TransitionActions { - component?: T|null; - } - - interface ComponentTransitionGroupProps extends TransitionActions { - component: T; - } - - type TransitionGroupProps = - (IntrinsicTransitionGroupProps & JSX.IntrinsicElements[T]) | (ComponentTransitionGroupProps) & { - children?: ReactElement | Array>; - childFactory?(child: ReactElement): ReactElement; - [prop: string]: any; - }; +export interface IntrinsicTransitionGroupProps + extends TransitionActions { + component?: T | null; } +export interface ComponentTransitionGroupProps extends TransitionActions { + component: T; +} + +export type TransitionGroupProps = + | (IntrinsicTransitionGroupProps & JSX.IntrinsicElements[T]) + | (ComponentTransitionGroupProps) & { + children?: ReactElement | Array>; + childFactory?(child: ReactElement): ReactElement; + [prop: string]: any; + }; + /** * The `` component manages a set of `` components * in a list. Like with the `` component, ``, is a @@ -75,6 +75,6 @@ declare namespace TransitionGroup { * components. This means you can mix and match animations across different * list items. */ -declare class TransitionGroup extends Component {} +declare class TransitionGroup extends Component {} -export = TransitionGroup; +export default TransitionGroup; diff --git a/types/react-transition-group/index.d.ts b/types/react-transition-group/index.d.ts index ee0bc14514..9b187024d1 100644 --- a/types/react-transition-group/index.d.ts +++ b/types/react-transition-group/index.d.ts @@ -6,14 +6,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -import CSSTransition = require("./CSSTransition"); -import Transition from "./Transition"; -import TransitionGroup = require("./TransitionGroup"); -import SwitchTransition from "./SwitchTransition"; - -export { - CSSTransition, - Transition, - TransitionGroup, - SwitchTransition -}; +export { default as Transition } from './Transition'; +export { default as CSSTransition } from './CSSTransition'; +export { default as TransitionGroup } from './TransitionGroup'; +export { default as SwitchTransition } from './SwitchTransition'; diff --git a/types/react-transition-group/react-transition-group-tests.tsx b/types/react-transition-group/react-transition-group-tests.tsx index 927028ba7b..4902defd0a 100644 --- a/types/react-transition-group/react-transition-group-tests.tsx +++ b/types/react-transition-group/react-transition-group-tests.tsx @@ -1,9 +1,7 @@ import * as React from "react"; -import CSSTransition = require("react-transition-group/CSSTransition"); -import Transition, { UNMOUNTED, EXITED, ENTERING, ENTERED, EXITING, TransitionStatus } from "react-transition-group/Transition"; -import TransitionGroup = require("react-transition-group/TransitionGroup"); -import SwitchTransition, { modes } from "react-transition-group/SwitchTransition"; -import Components = require("react-transition-group"); +import { UNMOUNTED, EXITED, ENTERING, ENTERED, EXITING, TransitionStatus } from "react-transition-group/Transition"; +import { modes } from "react-transition-group/SwitchTransition"; +import { Transition, CSSTransition, TransitionGroup, SwitchTransition } from "react-transition-group"; interface ContainerProps { theme: string; @@ -41,7 +39,7 @@ const Test: React.StatelessComponent = () => { return ( <> - { onExited={ handleExit } >
{ "test" }
-
+
- { onExited={ handleExit } >
{ "test" }
-
+
- { onExited={ handleExit } >
{ "test" }
-
+
- { onExited={ handleExit } >
{ "test" }
-
+
{ className="animated-list" childFactory={ (child: React.ReactElement) => child } > - { onExited={ handleExit } >
{ "test" }
-
- + + {(status) => { switch (status) { case ENTERING: @@ -159,11 +157,11 @@ const Test: React.StatelessComponent = () => { return
{status}
; } }} -
+ - + {statusAsArgument} - + {
{ "test" }
- { classNames="fade" >
{ "test" }
-
+