-
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 #110 from js-tool-pack/draggable-transition
Draggable 新增动画功能
- Loading branch information
Showing
8 changed files
with
219 additions
and
15 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
55 changes: 55 additions & 0 deletions
55
packages/components/src/draggable/demo/transition-debug.tsx
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,55 @@ | ||
/** | ||
* title: transition debug | ||
* debug: true | ||
* description: 开启 transition 动画。 | ||
*/ | ||
|
||
import { ButtonGroup, Draggable, Button } from '@tool-pack/react-ui'; | ||
import styles from './transition.module.scss'; | ||
import React from 'react'; | ||
|
||
const App: React.FC = () => { | ||
const [state, setState] = React.useState<{ name: string; id: number }[]>([ | ||
{ name: 'John', id: 1 }, | ||
{ name: 'Joao', id: 2 }, | ||
{ name: 'Jean', id: 3 }, | ||
{ name: 'Gerard', id: 4 }, | ||
]); | ||
return ( | ||
<div className={styles['root']}> | ||
<ButtonGroup> | ||
<Button | ||
onClick={() => { | ||
const id = state.length + 1; | ||
setState([...state, { name: 'anyone', id }]); | ||
}} | ||
type="primary" | ||
> | ||
添加 | ||
</Button> | ||
<Button onClick={() => setState(state.slice(0, -1))} type="success"> | ||
删减 | ||
</Button> | ||
</ButtonGroup> | ||
<div className="main"> | ||
<Draggable onChange={setState} list={state} tag={null} transition> | ||
{state.map((item, index) => ( | ||
<div className="draggable-item" key={item.id}> | ||
<span>{index + 1}.</span> <span>{item.name}</span>{' '} | ||
<span>{item.id}</span> | ||
</div> | ||
))} | ||
</Draggable> | ||
<div className="data"> | ||
[ | ||
{state.map((it) => ( | ||
<div key={it.id}>{JSON.stringify(it)}</div> | ||
))} | ||
] | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
37 changes: 37 additions & 0 deletions
37
packages/components/src/draggable/demo/transition.module.scss
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,37 @@ | ||
.root { | ||
:global { | ||
.main { | ||
display: flex; | ||
margin-top: 1rem; | ||
} | ||
.t-draggable { | ||
flex: 1; | ||
} | ||
.draggable-item { | ||
padding: 0 0.5rem; | ||
border: 1px solid #e6e6e6; | ||
background: #fff1d7; | ||
line-height: 32px; | ||
} | ||
.data { | ||
flex: 1; | ||
padding: 0 20px; | ||
white-space: pre-wrap; | ||
} | ||
.t-group { | ||
&-enter-active, | ||
&-leave-active, | ||
&-move-active { | ||
transition: all 0.3s ease; | ||
} | ||
&-enter-from { | ||
transform: translateY(-100%); | ||
opacity: 0; | ||
} | ||
&-leave-to { | ||
transform: translateY(100%); | ||
opacity: 0; | ||
} | ||
} | ||
} | ||
} |
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,54 @@ | ||
/** | ||
* title: transition | ||
* description: 开启 transition 动画。 | ||
*/ | ||
|
||
import { ButtonGroup, Draggable, Button } from '@tool-pack/react-ui'; | ||
import styles from './transition.module.scss'; | ||
import React from 'react'; | ||
|
||
const App: React.FC = () => { | ||
const [state, setState] = React.useState<{ name: string; id: number }[]>([ | ||
{ name: 'John', id: 1 }, | ||
{ name: 'Joao', id: 2 }, | ||
{ name: 'Jean', id: 3 }, | ||
{ name: 'Gerard', id: 4 }, | ||
]); | ||
return ( | ||
<div className={styles['root']}> | ||
<ButtonGroup> | ||
<Button | ||
onClick={() => { | ||
const id = state.length + 1; | ||
setState([...state, { name: 'anyone', id }]); | ||
}} | ||
type="primary" | ||
> | ||
添加 | ||
</Button> | ||
<Button onClick={() => setState(state.slice(0, -1))} type="success"> | ||
删减 | ||
</Button> | ||
</ButtonGroup> | ||
<div className="main"> | ||
<Draggable onChange={setState} list={state} transition> | ||
{state.map((item, index) => ( | ||
<div className="draggable-item" key={item.id}> | ||
<span>{index + 1}.</span> <span>{item.name}</span>{' '} | ||
<span>{item.id}</span> | ||
</div> | ||
))} | ||
</Draggable> | ||
<div className="data"> | ||
[ | ||
{state.map((it) => ( | ||
<div key={it.id}>{JSON.stringify(it)}</div> | ||
))} | ||
] | ||
</div> | ||
</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
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,34 @@ | ||
--- | ||
category: Components | ||
title: Draggable | ||
atomId: Draggable | ||
demo: | ||
cols: 2 | ||
group: | ||
title: Common | ||
--- | ||
|
||
Draggable 拖拽。 | ||
|
||
## 代码演示 | ||
|
||
<!-- prettier-ignore --> | ||
<code src="./demo/basic.tsx"></code> | ||
<code src="./demo/draggable.tsx"></code> | ||
<code src="./demo/tag.tsx"></code> | ||
<code src="./demo/transition.tsx"></code> | ||
<code src="./demo/transition-debug.tsx"></code> | ||
|
||
## API | ||
|
||
Draggable 的属性说明如下: | ||
|
||
| 属性 | 说明 | 类型 | 默认值 | 版本 | | ||
| ---------- | ---------------- | --------------------------------------------------------- | ------ | ---- | | ||
| list | 列表对应的数组 | any[] | -- | -- | | ||
| onChange | 列表改动回调 | (list: T[]) => void | -- | -- | | ||
| tag | 组件 html 根元素 | string \| null | 'div' | -- | | ||
| transition | 动画效果 | boolean \| [TransitionGroupProps](./transition-group#api) | 'div' | -- | | ||
| attrs | html 标签属性 | Partial\<React.HTMLAttributes\<HTMLDivElement>> | -- | -- | | ||
|
||
其他说明。 |
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