From 18b08e9682e19a40b0b5648aebb3fe52ba9210cd Mon Sep 17 00:00:00 2001 From: Yoki Yu Date: Thu, 23 Dec 2021 09:41:25 +0800 Subject: [PATCH] feat: add SwitchTransition, update docs --- README.md | 52 ++++++++++++++++++++++++++++++---- src/SwitchTransition/index.tsx | 20 +++++++++++++ src/Transition/index.tsx | 2 +- src/index.ts | 1 + 4 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 src/SwitchTransition/index.tsx diff --git a/README.md b/README.md index 52f79aa..8b6e9a0 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,12 @@ - [useTransition](#usetransition) - [useSwitchTransition](#useswitchtransition) - [Transition](#transition) + - [SwitchTransition](#switchtransition) - [API Reference](#api-reference) - [useTransition(state, timeout)](#usetransitionstate-timeout) - [useSwitchTransition(state, timeout, mode)](#useswitchtransitionstate-timeout-mode) - [Transition](#transition-1) + - [SwitchTransition](#switchtransition-1) - [License](#license) ## Installation @@ -137,6 +139,29 @@ return
``` +### SwitchTransition + +FaCC pattern version of useSwitchTransition + +```jsx + + {(state, stage) => ( +

+ {state} {stage} hello +

+ )} +
+``` + ## API Reference ### useTransition(state, timeout) @@ -163,17 +188,17 @@ return
const transition = useSwitchTransition(onOff, 300, 'default') ``` -| Parameters | Type | Description | -| :--------- | :--------------------------------- | :------------------------------------------------------------ | -| `state` | `any` | **Required**. Your state, which triggers animation | -| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | -| `mode` | `default` \| `out-in` \| `int-out` | **Optional**. Default to `default` mode | +| Parameters | Type | Description | +| :--------- | :-------------------------------- | :------------------------------------------------------------ | +| `state` | `any` | **Required**. Your state, which triggers animation | +| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | +| `mode` | `default` \| `out-in` \| `in-out` | **Optional**. Default to `default` mode | ### Transition ```jsx - {(stage, shouldMount) => shouldMount &&
hello
} + {(stage, shouldMount) => shouldMount &&
hello
}
``` @@ -183,6 +208,21 @@ return
| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | | `children` | `(stage: Stage, shouldMount: boolean)=>React.ReactNode` | **Required**. FaCC pattern. | +### SwitchTransition + +```jsx + + {(state, stage) =>
{state} hello
} +
+``` + +| Props | Type | Description | +| :--------- | :-------------------------------------------- | :-------------------------------------------------------------------- | +| `state` | `any` | **Required**. Your boolean state, which controls animation in and out | +| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | +| `mode` | `default` \| `out-in` \| `in-out` | **Optional**. Default to `default` mode | +| `children` | `(state: any, stage: Stage)=>React.ReactNode` | **Required**. FaCC pattern. | + ## License [MIT](https://choosealicense.com/licenses/mit/) diff --git a/src/SwitchTransition/index.tsx b/src/SwitchTransition/index.tsx new file mode 100644 index 0000000..e058121 --- /dev/null +++ b/src/SwitchTransition/index.tsx @@ -0,0 +1,20 @@ +import {Stage, useSwitchTransition} from '..'; +import {Mode} from '../useSwitchTransition/types'; + +type SwitchTransitionProps = { + state: S; + timeout: number; + mode: Mode; + children: (state: S, stage: Stage) => React.ReactNode; +}; + +export function SwitchTransition({ + state, + timeout, + mode, + children, +}: SwitchTransitionProps) { + const transition = useSwitchTransition(state, timeout, mode); + + return transition(children); +} diff --git a/src/Transition/index.tsx b/src/Transition/index.tsx index 615fbcc..976be77 100644 --- a/src/Transition/index.tsx +++ b/src/Transition/index.tsx @@ -1,4 +1,4 @@ -import {Stage, useTransition} from '../useTransition'; +import {Stage, useTransition} from '..'; type TransitionProps = { state: boolean; diff --git a/src/index.ts b/src/index.ts index ae038d2..60071bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ export * from './useTransition'; export * from './useSwitchTransition'; export * from './Transition'; +export * from './SwitchTransition';