Skip to content

Commit 5e5235f

Browse files
authored
Merge pull request #109 from js-tool-pack/transition-group-remove-transition
TransitionGroup v3
2 parents f3c4f39 + 351c54a commit 5e5235f

18 files changed

+280
-208
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ coverage
1919
pnpm-lock.yaml
2020
.output
2121

22-
*.d.ts
22+
*.d.ts
23+
temp

commitlint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
2-
extends: ['@commitlint/config-conventional'],
32
// 以下是我们自定义的规则
43
rules: {
54
'type-enum': [
@@ -21,4 +20,5 @@ module.exports = {
2120
],
2221
],
2322
},
23+
extends: ['@commitlint/config-conventional'],
2424
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build:css-single": "pnpm -C packages/react-ui build:scss-single",
1515
"test": "pnpm -C packages/shared test && pnpm -C packages/components test",
1616
"eject": "react-scripts eject",
17-
"check:lint": "eslint \"**/*.{ts,tsx}\"",
17+
"check:lint": "eslint \"**/*.{ts,tsx}\" . --quiet",
1818
"check:ts": "tsc -p tsconfig.noEmit.json --noEmit",
1919
"check:ts-all": "pnpm check:ts & pnpm -r check:ts",
2020
"check:ts:lint": "npm run check:ts && npm run check:lint",

packages/components/src/transition-group/TransitionGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import type { FC } from 'react';
1010
* v2版参考了 {@link https://github.com/peoplesing1832/react-transition/blob/npm/src/v4/TransitionGroup.tsx} 该实现。
1111
*
1212
* 相比 v1 版, v2 需要元素外部套 Transition 组件,可随机插入(v1不行),动画更流畅。
13+
* v3版已移除在外部套 Transition 组件的方式
1314
*
14-
* 目前还是不够完美,以后需要再次优化。。。
15+
* 目前 v3 还是跟 vue 的有差距,还是不够完美,以后需要再次优化。。。
1516
*/
1617

1718
const defaultProps = {

packages/components/src/transition-group/__tests__/TransitionGroup.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ describe('TransitionGroup', () => {
77
testAttrs(TransitionGroup);
88

99
test('snap', () => {
10+
const { container } = render(
11+
<TransitionGroup>
12+
<div>foo bar</div>
13+
<div>foo-bar</div>
14+
</TransitionGroup>,
15+
);
16+
expect(container.firstChild).toMatchSnapshot();
17+
});
18+
test('transition snap', () => {
1019
const { container } = render(
1120
<TransitionGroup>
1221
<Transition appear>

packages/components/src/transition-group/__tests__/__snapshots__/TransitionGroup.test.tsx.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`TransitionGroup snap 1`] = `
4+
<div
5+
class="t-transition-group"
6+
>
7+
<div
8+
class=""
9+
>
10+
foo bar
11+
</div>
12+
<div
13+
class=""
14+
>
15+
foo-bar
16+
</div>
17+
</div>
18+
`;
19+
20+
exports[`TransitionGroup transition snap 1`] = `
421
<div
522
class="t-transition-group"
623
>

packages/components/src/transition-group/demo/all.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
* description: 点击列表内的按钮移除元素。
55
*/
66

7-
import {
8-
TransitionGroup,
9-
Transition,
10-
Button,
11-
Space,
12-
} from '@tool-pack/react-ui';
7+
import { TransitionGroup, Button, Space } from '@tool-pack/react-ui';
138
import React, { useCallback, useState, useRef } from 'react';
149
import styles from './all.module.scss';
1510

@@ -61,9 +56,9 @@ const App: React.FC = () => {
6156
<TransitionGroup className="group-container" tag="section" name="group">
6257
{children.current.map((item) => {
6358
return (
64-
<Transition key={item}>
65-
<button onClick={() => removeChild(item)}>{item}</button>
66-
</Transition>
59+
<button onClick={() => removeChild(item)} key={item}>
60+
{item}
61+
</button>
6762
);
6863
})}
6964
</TransitionGroup>

packages/components/src/transition-group/demo/flip.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
* title: 多维表格排序过渡
33
*/
44

5-
import {
6-
TransitionGroup,
7-
Transition,
8-
Button,
9-
Space,
10-
} from '@tool-pack/react-ui';
5+
import { TransitionGroup, Button, Space } from '@tool-pack/react-ui';
116
import React, { useCallback, useState, useRef } from 'react';
127
import styles from './flip.module.scss';
138

@@ -37,11 +32,7 @@ const App: React.FC = () => {
3732
<br />
3833
<TransitionGroup className="group-container" tag="section" name="group">
3934
{children.current.map((item) => {
40-
return (
41-
<Transition key={item}>
42-
<button>{item}</button>
43-
</Transition>
44-
);
35+
return <button key={item}>{item}</button>;
4536
})}
4637
</TransitionGroup>
4738
</div>

packages/components/src/transition-group/demo/list.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
* title: 列表过渡
33
*/
44

5-
import {
6-
TransitionGroup,
7-
Transition,
8-
Button,
9-
Space,
10-
} from '@tool-pack/react-ui';
5+
import { TransitionGroup, Button, Space } from '@tool-pack/react-ui';
116
import React, { useCallback, useState, useRef } from 'react';
127
import styles from './list.module.scss';
138

@@ -49,11 +44,7 @@ const App: React.FC = () => {
4944
<br />
5045
<TransitionGroup className="group-container" tag="section" name="group">
5146
{children.current.map((item) => {
52-
return (
53-
<Transition key={item}>
54-
<div>{item}</div>
55-
</Transition>
56-
);
47+
return <div key={item}>{item}</div>;
5748
})}
5849
</TransitionGroup>
5950
</div>

packages/components/src/transition-group/demo/mixed.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
* title: 排序过渡加列表过渡
33
*/
44

5-
import {
6-
TransitionGroup,
7-
Transition,
8-
Button,
9-
Space,
10-
} from '@tool-pack/react-ui';
5+
import { TransitionGroup, Button, Space } from '@tool-pack/react-ui';
116
import React, { useCallback, useState, useRef } from 'react';
127
import styles from './mixed.module.scss';
138

@@ -73,10 +68,10 @@ const App: React.FC = () => {
7368
<TransitionGroup className="group-container" tag="section" name="group">
7469
{children.current.map((item) => {
7570
return (
76-
<Transition key={item}>
77-
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
78-
<div onClick={() => removeChild(item)}>{item}</div>
79-
</Transition>
71+
/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */
72+
<div onClick={() => removeChild(item)} key={item}>
73+
{item}
74+
</div>
8075
);
8176
})}
8277
</TransitionGroup>

0 commit comments

Comments
 (0)