* Implemented strict linting standards and prettier formatting config. * More linter fixes and type updates. * More linter updates and type fixes * Remove noisy comments * Linter and type updates * Linter, formatting and type updates. * Linter updates * Type updates * Type updates * fixed all linter errors * Fixed all linting, formatting and type issues. * Resolve merge conflicts.
30 lines
1.0 KiB
TypeScript
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;
|
|
}));
|
|
};
|