-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ statistics/ | |
.scene_cache | ||
*.mp4 | ||
demo/storybook | ||
demo/storybook2 | ||
dist/ |
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
29 changes: 29 additions & 0 deletions
29
packages/react-moveable/stories/6-CustomAble/4-MouseEnterLeave.stories.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,29 @@ | ||
import { DEFAULT_REACT_CODESANDBOX } from "storybook-addon-preview"; | ||
import "../templates/default.css"; | ||
import App from "./apps/MouseEnterLeaveApp"; | ||
import RawApp from "!!raw-loader!./apps/MouseEnterLeaveApp"; | ||
import { DEFAULT_CSS_TEMPLATE } from "@/stories/templates/default"; | ||
import { convertReactTemplate, convertPath } from "../utils"; | ||
|
||
|
||
export const MouseEnterLeave = App as any; | ||
|
||
MouseEnterLeave.storyName = "Mouse Enter & Leave"; | ||
MouseEnterLeave.argTypes = {}; | ||
MouseEnterLeave.args = {}; | ||
|
||
MouseEnterLeave.parameters = { | ||
preview: [ | ||
{ | ||
tab: "React", | ||
template: convertReactTemplate(convertPath(RawApp)), | ||
codesandbox: DEFAULT_REACT_CODESANDBOX(["react-moveable", "moveable-helper"]), | ||
language: "tsx", | ||
}, | ||
{ | ||
tab: "CSS", | ||
template: DEFAULT_CSS_TEMPLATE, | ||
language: "css", | ||
}, | ||
], | ||
}; |
62 changes: 62 additions & 0 deletions
62
packages/react-moveable/stories/6-CustomAble/apps/MouseEnterLeaveApp.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,62 @@ | ||
import * as React from "react"; | ||
import Moveable, { makeAble, MoveableManagerInterface } from "@/react-moveable"; | ||
|
||
const MouseEnterLeaveAble = makeAble("enterLeave", { | ||
mouseEnter(moveable: MoveableManagerInterface) { | ||
if (moveable.moveables) { | ||
// group | ||
moveable.moveables.forEach(child => { | ||
child.state.target!.style.backgroundColor = "#e55"; | ||
}); | ||
} else { | ||
// single | ||
moveable.state.target!.style.backgroundColor = "#e55"; | ||
} | ||
}, | ||
mouseLeave(moveable: MoveableManagerInterface) { | ||
if (moveable.moveables) { | ||
// group | ||
moveable.moveables.forEach(child => { | ||
child.state.target!.style.backgroundColor = ""; | ||
}); | ||
} else { | ||
// single | ||
moveable.state.target!.style.backgroundColor = ""; | ||
} | ||
}, | ||
}); | ||
|
||
export default function App() { | ||
const targetRef = React.useRef<HTMLDivElement>(null); | ||
return <div className="container"> | ||
<div className="target target1">Target1</div> | ||
<div className="target target2">Target2</div> | ||
<div className="target target3" ref={targetRef}>Target3</div> | ||
<Moveable | ||
target={targetRef} | ||
ables={[MouseEnterLeaveAble]} | ||
origin={false} | ||
props={{ | ||
enterLeave: true, | ||
}} | ||
draggable={true} | ||
onDrag={e => { | ||
e.target.style.transform = e.transform; | ||
}} | ||
/> | ||
<Moveable | ||
target={[".target1", ".target2"]} | ||
ables={[MouseEnterLeaveAble]} | ||
origin={false} | ||
props={{ | ||
enterLeave: true, | ||
}} | ||
draggable={true} | ||
onDragGroup={e => { | ||
e.events.forEach(ev => { | ||
ev.target.style.transform = ev.transform; | ||
}); | ||
}} | ||
/> | ||
</div>; | ||
} |