Plugin Settings: Use Switches for booleans
This commit is contained in:
parent
2db0e71e5b
commit
7c7723bfb1
1 changed files with 12 additions and 17 deletions
|
@ -16,8 +16,9 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { wordsFromCamel, wordsToTitle } from "@utils/text";
|
||||||
import { PluginOptionBoolean } from "@utils/types";
|
import { PluginOptionBoolean } from "@utils/types";
|
||||||
import { Forms, React, Select } from "@webpack/common";
|
import { Forms, React, Switch } from "@webpack/common";
|
||||||
|
|
||||||
import { ISettingElementProps } from ".";
|
import { ISettingElementProps } from ".";
|
||||||
|
|
||||||
|
@ -31,11 +32,6 @@ export function SettingBooleanComponent({ option, pluginSettings, definedSetting
|
||||||
onError(error !== null);
|
onError(error !== null);
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
const options = [
|
|
||||||
{ label: "Enabled", value: true, default: def === true },
|
|
||||||
{ label: "Disabled", value: false, default: typeof def === "undefined" || def === false },
|
|
||||||
];
|
|
||||||
|
|
||||||
function handleChange(newValue: boolean): void {
|
function handleChange(newValue: boolean): void {
|
||||||
const isValid = option.isValid?.call(definedSettings, newValue) ?? true;
|
const isValid = option.isValid?.call(definedSettings, newValue) ?? true;
|
||||||
if (typeof isValid === "string") setError(isValid);
|
if (typeof isValid === "string") setError(isValid);
|
||||||
|
@ -49,18 +45,17 @@ export function SettingBooleanComponent({ option, pluginSettings, definedSetting
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Forms.FormSection>
|
<Forms.FormSection>
|
||||||
<Forms.FormTitle>{option.description}</Forms.FormTitle>
|
<Switch
|
||||||
<Select
|
value={state}
|
||||||
isDisabled={option.disabled?.call(definedSettings) ?? false}
|
onChange={handleChange}
|
||||||
options={options}
|
note={option.description}
|
||||||
placeholder={option.placeholder ?? "Select an option"}
|
disabled={option.disabled?.call(definedSettings) ?? false}
|
||||||
maxVisibleItems={5}
|
|
||||||
closeOnSelect={true}
|
|
||||||
select={handleChange}
|
|
||||||
isSelected={v => v === state}
|
|
||||||
serialize={v => String(v)}
|
|
||||||
{...option.componentProps}
|
{...option.componentProps}
|
||||||
/>
|
hideBorder
|
||||||
|
style={{ marginBottom: "0.5em" }}
|
||||||
|
>
|
||||||
|
{wordsToTitle(wordsFromCamel(id))}
|
||||||
|
</Switch>
|
||||||
{error && <Forms.FormText style={{ color: "var(--text-danger)" }}>{error}</Forms.FormText>}
|
{error && <Forms.FormText style={{ color: "var(--text-danger)" }}>{error}</Forms.FormText>}
|
||||||
</Forms.FormSection>
|
</Forms.FormSection>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue