Files
dotfiles/ags/HyprPanel/widget/settings/shared/components/boolean.ts
T
2024-10-23 21:12:15 +07:00

30 lines
1.0 KiB
TypeScript

import { Opt } from 'lib/option';
import { Attribute, BoxWidget } from 'lib/types/widget';
import { Variable } from 'types/variable';
import { dependencies as checkDependencies } from 'lib/utils';
export const booleanInputter = <T>(
self: BoxWidget,
opt: Opt<T>,
disabledBinding: Variable<boolean> | undefined,
dependencies: string[] | undefined,
): Attribute => {
return (self.child = Widget.Switch({
sensitive: disabledBinding !== undefined ? disabledBinding.bind('value').as((disabled) => !disabled) : true,
})
.on('notify::active', (self) => {
if (disabledBinding !== undefined && disabledBinding.value) {
return;
}
if (self.active && dependencies !== undefined && !dependencies.every((d) => checkDependencies(d))) {
self.active = false;
return;
}
opt.value = self.active as T;
})
.hook(opt, (self) => {
self.active = opt.value as boolean;
}));
};