-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from js-tool-pack/transition-group-tag-null
TransitionGroup tag receive null
- Loading branch information
Showing
10 changed files
with
287 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* title: 标签 | ||
* description: 默认标签为 div,可设置 tag 为其它标签,当 tag 为 null 时,移除包裹元素 | ||
*/ | ||
|
||
import { | ||
TransitionGroup, | ||
Transition, | ||
Button, | ||
Space, | ||
} from '@tool-pack/react-ui'; | ||
import React, { useCallback, useState, useRef } from 'react'; | ||
import styles from './list.module.scss'; | ||
|
||
const App: React.FC = () => { | ||
const [, update] = useState({}); | ||
const forceUpdate = useCallback(() => update({}), []); | ||
|
||
const children = useRef<number[]>([...Array.from({ length: 10 }).keys()]); | ||
|
||
const index = useRef(children.current.length); | ||
function addChild() { | ||
const list = children.current; | ||
const splice = list.splice(~~(Math.random() * list.length), list.length); | ||
list.push(index.current); | ||
list.push(...splice); | ||
forceUpdate(); | ||
index.current++; | ||
} | ||
function removeChild(item: number) { | ||
const index = children.current.indexOf(item); | ||
if (index === -1) return; | ||
children.current.splice(index, 1); | ||
forceUpdate(); | ||
} | ||
function removeRandomChild() { | ||
removeChild(children.current[~~(Math.random() * children.current.length)]!); | ||
} | ||
|
||
return ( | ||
<div className={styles['root']}> | ||
<Space style={{ justifyContent: 'center' }}> | ||
<Button onClick={addChild} type="primary"> | ||
添加 | ||
</Button> | ||
<Button onClick={removeRandomChild} type="warning" plain> | ||
移除 | ||
</Button> | ||
</Space> | ||
<br /> | ||
<div className="group-container"> | ||
<TransitionGroup name="group" tag={null}> | ||
{children.current.map((item) => { | ||
return ( | ||
<Transition key={item}> | ||
<div>{item}</div> | ||
</Transition> | ||
); | ||
})} | ||
</TransitionGroup> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.