mirror of
https://github.com/Theaninova/TheaninovOS.git
synced 2025-12-12 19:46:20 +00:00
refactor: make the whole thing more generic
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import Widget from "resource:///com/github/Aylur/ags/widget.js";
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
|
||||
/**
|
||||
* @typedef {import('types/widgets/eventbox').EventBoxProps & {
|
||||
* indicator?: import('types/widgets/box').BoxProps['child']
|
||||
* direction?: 'left' | 'right' | 'down' | 'up'
|
||||
* duration?: number
|
||||
* setupRevealer?: (rev: ReturnType<typeof Widget.Revealer>) => void
|
||||
* setupEventBox?: (rev: ReturnType<typeof Widget.EventBox>) => void
|
||||
* }} HoverRevealProps
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {HoverRevealProps} props
|
||||
*/
|
||||
export default ({
|
||||
indicator,
|
||||
child,
|
||||
direction = "left",
|
||||
duration = 300,
|
||||
setupEventBox,
|
||||
setupRevealer,
|
||||
...rest
|
||||
}) => {
|
||||
let open = false;
|
||||
const vertical = direction === "down" || direction === "up";
|
||||
const posStart = direction === "down" || direction === "right";
|
||||
const posEnd = direction === "up" || direction === "left";
|
||||
|
||||
const revealer = Widget.Revealer({
|
||||
transition: `slide_${direction}`,
|
||||
setup: setupRevealer,
|
||||
transition_duration: duration,
|
||||
child,
|
||||
});
|
||||
|
||||
const eventbox = Widget.EventBox({
|
||||
...rest,
|
||||
setup: setupEventBox,
|
||||
on_hover: () => {
|
||||
if (open) return;
|
||||
|
||||
revealer.reveal_child = true;
|
||||
Utils.timeout(duration, () => (open = true));
|
||||
},
|
||||
on_hover_lost: () => {
|
||||
if (!open) return;
|
||||
|
||||
revealer.reveal_child = false;
|
||||
open = false;
|
||||
},
|
||||
child: Widget.Box({
|
||||
vertical,
|
||||
children: [posStart && indicator, revealer, posEnd && indicator],
|
||||
}),
|
||||
});
|
||||
|
||||
return Widget.Box({
|
||||
children: [eventbox],
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user