mirror of
https://github.com/stashapp/stash.git
synced 2025-12-09 18:04:33 +01:00
* Add identify task * Change type naming * Debounce folder select text input * Add generic slice comparison function
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import React from "react";
|
|
import { Button } from "react-bootstrap";
|
|
import { Icon } from ".";
|
|
|
|
interface IThreeStateCheckbox {
|
|
value: boolean | undefined;
|
|
setValue: (v: boolean | undefined) => void;
|
|
allowUndefined?: boolean;
|
|
label?: React.ReactNode;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
export const ThreeStateCheckbox: React.FC<IThreeStateCheckbox> = ({
|
|
value,
|
|
setValue,
|
|
allowUndefined,
|
|
label,
|
|
disabled = false,
|
|
}) => {
|
|
function cycleState() {
|
|
const undefAllowed = allowUndefined ?? true;
|
|
if (undefAllowed && value) {
|
|
return undefined;
|
|
}
|
|
if ((!undefAllowed && value) || value === undefined) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
const icon = value === undefined ? "minus" : value ? "check" : "times";
|
|
const labelClassName =
|
|
value === undefined ? "unset" : value ? "checked" : "not-checked";
|
|
|
|
return (
|
|
<span className={`three-state-checkbox ${labelClassName}`}>
|
|
<Button
|
|
onClick={() => setValue(cycleState())}
|
|
className="minimal"
|
|
disabled={disabled}
|
|
>
|
|
<Icon icon={icon} className="fa-fw" />
|
|
</Button>
|
|
<span className="label">{label}</span>
|
|
</span>
|
|
);
|
|
};
|