Skip to content

Commit

Permalink
fix: reactivity of animation
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 25, 2022
1 parent fcfcc96 commit c017f41
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 18 deletions.
37 changes: 32 additions & 5 deletions packages/solid-contextmenu/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
import { Component } from "solid-js";
import { Menu, useContextMenu, Item, Separator } from ".";
import { Component, createSignal, For } from "solid-js";
import { Menu, useContextMenu, Item, Separator, animation } from ".";

const App: Component = () => {
const [_animation, setAnimation] = createSignal(animation.scale);

const { show } = useContextMenu({ id: "1", props: "lala" });
return (
<div
style={{ height: "100vh" }}
style={{
height: "100vh",
display: "flex",
"flex-direction": "column",
"justify-content": "center",
"align-items": "center",
gap: "0.5rem",
}}
onContextMenu={(e) => {
show(e, { props: 1 });
}}
>
right click
<Menu id="1" animation="scale" theme="light">
<h4>right click</h4>
<select
onChange={(e) => {
setAnimation(e.currentTarget.value);
}}
>
<For
each={[
animation.scale,
animation.fade,
animation.flip,
animation.slide,
]}
>
{(item) => {
return <option value={item}>{item}</option>;
}}
</For>
</select>
<Menu id="1" animation={_animation()} theme="light">
<Item>⚡ Beautiful</Item>
<Item>😊 Easy use</Item>
<Item>💕 Built with heart</Item>
Expand Down
21 changes: 15 additions & 6 deletions packages/solid-contextmenu/src/components/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
createMemo,
createSignal,
mergeProps,
onCleanup,
Expand Down Expand Up @@ -70,16 +71,24 @@ export const Menu = (props: MenuProps) => {
bus.off("hideAll");
});

const animation = () => {
if (!local.animation) {
return "";
const animation = createMemo(() => {
let ans = "";
if (local.animation) {
ans = `solid-contextmenu-${local.animation}`;
}
return `solid-contextmenu-${local.animation}`;
};
console.log(ans);
return ans;
});
const animationClass = createMemo(() => {
return {
enterActiveClass: animation() + "-enter-active",
exitActiveClass: animation() + "-exit-active",
};
});
return (
<MenuContext.Provider value={contextValue}>
<Portal>
<Transition name={animation()}>
<Transition {...animationClass()}>
<Show when={shown()}>
<div
{...others}
Expand Down
2 changes: 1 addition & 1 deletion sites/site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<script src="/src/index.tsx" type="module"></script>
<script src="/src/main.tsx" type="module"></script>
</body>
</html>
39 changes: 33 additions & 6 deletions sites/site/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
import { Component } from "solid-js";
import { Menu, useContextMenu, Item } from "solid-contextmenu";
import "solid-contextmenu/dist/style.css";
import { Component, createSignal, For } from "solid-js";
import { Menu, useContextMenu, Item, Separator, animation } from ".";

const App: Component = () => {
const [_animation, setAnimation] = createSignal(animation.scale);

const { show } = useContextMenu({ id: "1", props: "lala" });
return (
<div
style={{ height: "100vh" }}
style={{
height: "100vh",
display: "flex",
"flex-direction": "column",
"justify-content": "center",
"align-items": "center",
gap: "0.5rem",
}}
onContextMenu={(e) => {
show(e, { props: 1 });
}}
>
right click
<Menu id="1" animation="scale" theme="dark">
<h4>right click</h4>
<select
onChange={(e) => {
setAnimation(e.currentTarget.value);
}}
>
<For
each={[
animation.scale,
animation.fade,
animation.flip,
animation.slide,
]}
>
{(item) => {
return <option value={item}>{item}</option>;
}}
</For>
</select>
<Menu id="1" animation={_animation()} theme="light">
<Item>⚡ Beautiful</Item>
<Item>😊 Easy use</Item>
<Item>💕 Built with heart</Item>
<Separator />
<Item disabled>❌ Disabled</Item>
</Menu>
</div>
Expand Down
2 changes: 2 additions & 0 deletions sites/site/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "solid-contextmenu/dist/style.css"
export * from "solid-contextmenu";
File renamed without changes.

0 comments on commit c017f41

Please sign in to comment.