/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see .
*/
/** @jsxRuntime automatic */
/** @jsxImportSource hono/jsx */
export type ToggleSwitchSize = 'small' | 'medium' | 'large';
export interface ToggleSwitchProps {
name: string;
label?: string;
checked: boolean;
disabled?: boolean;
size?: ToggleSwitchSize;
helperText?: string;
id?: string;
onChangeScript?: string;
}
const sizeClasses: Record = {
small: {
track: 'w-8 h-5',
thumb: 'w-3 h-3 translate-x-3',
},
medium: {
track: 'w-11 h-6',
thumb: 'w-4 h-4 translate-x-5',
},
large: {
track: 'w-14 h-7',
thumb: 'w-5 h-5 translate-x-7',
},
};
export function ToggleSwitch({
name,
label,
checked,
disabled = false,
size = 'medium',
helperText,
id,
onChangeScript,
}: ToggleSwitchProps) {
const switchId = id || name;
const {track, thumb} = sizeClasses[size];
const trackClass = checked ? `bg-neutral-900` : `bg-neutral-300`;
const thumbPosition = checked ? thumb : 'translate-x-0.5';
return (