Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename AnimationGroup to TransitionGroup #26

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,13 @@ Same as [useAnimation](#useanimation), but it drives function not React element.
### useTransitionAnimation

A hook to compose multiple [useAnimation](#useanimation) and plays them when element enter/update/exits.
This hook must be used under [AnimationGroup component](#animationgroup).
This hook must be used under [TransitionGroup component](#TransitionGroup).

[Examples](./stories/hooks/useTransitionAnimation.stories.tsx)

### AnimationGroup
### TransitionGroup

A component to provide some behavior to its children.
Currently it only detects enter/update/exit of children by key, that works similar to [TransitionGroup of react-transition-group](https://reactcommunity.org/react-transition-group/transition-group).
A component to manage enter/update/exit of its children by key, that works similar to [TransitionGroup of react-transition-group](https://reactcommunity.org/react-transition-group/transition-group).

## Use polyfill

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ const Provider = ({
);
};

export type AnimationGroupProps = {
export type TransitionGroupProps = {
children: ReactElement | ReactElement[];
};

export const AnimationGroup = ({
export const TransitionGroup = ({
children,
}: AnimationGroupProps): ReactElement => {
}: TransitionGroupProps): ReactElement => {
const elemsRef = useRef<ReactElement[]>(null!);
const prevElems = elemsRef.current || [];
const elems = Children.map(children, (c) => c);
Expand Down
4 changes: 2 additions & 2 deletions src/react/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { AnimationGroup } from "./AnimationGroup";
export type { AnimationGroupProps } from "./AnimationGroup";
export { TransitionGroup } from "./TransitionGroup";
export type { TransitionGroupProps } from "./TransitionGroup";
2 changes: 1 addition & 1 deletion src/react/hooks/useTransitionAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
TransitionNotifierContext,
TransitionState,
TransitionStateContext,
} from "../components/AnimationGroup";
} from "../components/TransitionGroup";
import type { AnimationHandle } from "./useAnimation";
import {
AnimationController,
Expand Down
14 changes: 7 additions & 7 deletions stories/hooks/useTransitionAnimation.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StoryObj } from "@storybook/react";
import React, { useEffect, useRef, useState } from "react";
import {
AnimationGroup,
TransitionGroup,
AnimationOptions,
useAnimation,
useTransitionAnimation,
Expand Down Expand Up @@ -61,11 +61,11 @@ export const Input: StoryObj = {
<input value={value} onChange={(e) => setValue(e.target.value)} />
</div>
<div>
<AnimationGroup>
<TransitionGroup>
{value.split("").map((t, i) => (
<Text key={i}>{t}</Text>
))}
</AnimationGroup>
</TransitionGroup>
</div>
</div>
);
Expand Down Expand Up @@ -133,13 +133,13 @@ export const Alphabet: StoryObj = {
<>
<svg width={600} height={400}>
<g transform={`translate(${25},${50})`}>
<AnimationGroup>
<TransitionGroup>
{texts.map((t, i) => (
<SvgText key={t} i={i}>
{t}
</SvgText>
))}
</AnimationGroup>
</TransitionGroup>
</g>
</svg>
<style>{`text { font: bold 28px monospace; }`}</style>
Expand Down Expand Up @@ -230,11 +230,11 @@ export const Expand: StoryObj = {
alignContent: "flex-start",
}}
>
<AnimationGroup>
<TransitionGroup>
{expanded
? rects.map((i) => <ExpandRect key={i} i={i} length={length} />)
: []}
</AnimationGroup>
</TransitionGroup>
</div>
</>
);
Expand Down