signal buttons with tooltips works

This commit is contained in:
wil committed 2024-09-10 16:07:45 -04:00
1 parent 406cb237aa
commit 98b76398a5
2 files changed
+32 -17

No files matched your search

+18 -8
View File
@@ -17,17 +17,27 @@ const events = Object.values(ToolbarImageButtonNames).reduce(
},
);
const effectsCleanups = Object.values(ToolbarImageButtonNames).reduce(
(acc, buttonName) => {
acc[buttonName] = undefined;
return acc;
},
{} as {
[key in ToolbarImageButtonNames]: (() => void) | undefined;
},
);
export const eventsHandlers = Object.values(ToolbarImageButtonNames).reduce(
(acc, buttonName) => {
acc[buttonName] = {
onClick: (callback: () => void) => {
effect(() => {
onClick: (callback: MouseEventHandler<HTMLButtonElement>) => {
if (effectsCleanups[buttonName]) {
effectsCleanups[buttonName]();
}
effectsCleanups[buttonName] = effect(() => {
if (events[buttonName].value) {
callback();
return () => {
//console.log("Toolbar Image effect event handler cleanup");
events[buttonName].value = undefined;
};
callback(events[buttonName].value);
events[buttonName].value = undefined;
}
});
},
@@ -36,7 +46,7 @@ export const eventsHandlers = Object.values(ToolbarImageButtonNames).reduce(
},
{} as {
[key in ToolbarImageButtonNames]: {
onClick: (callback: () => void) => void;
onClick: (callback: MouseEventHandler<HTMLButtonElement>) => void;
};
},
);
+14 -9
View File
@@ -16,22 +16,27 @@ const events = Object.values(ToolbarMainButtonNames).reduce(
>;
},
);
const effectsCleanups = Object.values(ToolbarMainButtonNames).reduce(
(acc, buttonName) => {
acc[buttonName] = undefined;
return acc;
},
{} as {
[key in ToolbarMainButtonNames]: (() => void) | undefined;
},
);
export const eventsHandlers = Object.values(ToolbarMainButtonNames).reduce(
(acc, buttonName) => {
acc[buttonName] = {
onClick: (callback: MouseEventHandler<HTMLButtonElement>) => {
effect(() => {
if (effectsCleanups[buttonName]) {
effectsCleanups[buttonName]();
}
effectsCleanups[buttonName] = effect(() => {
if (events[buttonName].value) {
callback(events[buttonName].value);
return () => {
//console.log("Toolbar Main effect event handler cleanup");
events[buttonName].value = undefined;
};
return () => {
//console.log("Toolbar Image effect event handler cleanup");
events[buttonName].value = undefined;
};
events[buttonName].value = undefined;
}
});
},