Equicord/src/components/FormSwitch.tsx

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-10-03 00:18:39 +02:00
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./FormSwitch.css";
import { classes } from "@utils/misc";
import type { PropsWithChildren, ReactNode } from "react";
import { Divider } from "./Divider";
import { Span } from "./Span";
2025-10-03 00:18:39 +02:00
import { Switch } from "./Switch";
export interface FormSwitchProps {
title: ReactNode;
description?: ReactNode;
value: boolean;
onChange(value: boolean): void;
className?: string;
disabled?: boolean;
hideBorder?: boolean;
}
export function FormSwitch({ onChange, title, value, description, disabled, className, hideBorder }: FormSwitchProps) {
return (
<label className="vc-form-switch-wrapper">
2025-10-03 00:52:01 +02:00
<div className={classes("vc-form-switch", className, disabled && "vc-form-switch-disabled")}>
2025-10-03 00:18:39 +02:00
<div className={"vc-form-switch-text"}>
<Span size="md" weight="medium">{title}</Span>
2026-08-18 02:08:43 +02:00
{description && <Span size="sm" weight="normal" className="vc-form-switch-description">{description}</Span>}
2025-10-03 00:18:39 +02:00
</div>
<Switch checked={value} onChange={onChange} disabled={disabled} />
</div>
{!hideBorder && <Divider className="vc-form-switch-border" />}
</label>
2025-10-03 00:18:39 +02:00
);
}
// #region Old compatibility
export function FormSwitchCompat({ note, children, ...restProps }: PropsWithChildren<any>) {
return <FormSwitch title={children ?? ""} description={note} {...restProps} />;
2025-10-03 00:18:39 +02:00
}
// #endregion