* fix: tooltip overflow * Adds more responsive Css * StartHidden has tooltip bottom * in debug setting too --------- Co-authored-by: CJ Pais <cj@cjpais.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import React from "react";
|
|
import { SettingContainer } from "./SettingContainer";
|
|
|
|
interface ToggleSwitchProps {
|
|
checked: boolean;
|
|
onChange: (checked: boolean) => void;
|
|
disabled?: boolean;
|
|
isUpdating?: boolean;
|
|
label: string;
|
|
description: string;
|
|
descriptionMode?: "inline" | "tooltip";
|
|
grouped?: boolean;
|
|
tooltipPosition?: "top" | "bottom";
|
|
}
|
|
|
|
export const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
|
|
checked,
|
|
onChange,
|
|
disabled = false,
|
|
isUpdating = false,
|
|
label,
|
|
description,
|
|
descriptionMode = "tooltip",
|
|
grouped = false,
|
|
tooltipPosition = "top",
|
|
}) => {
|
|
return (
|
|
<SettingContainer
|
|
title={label}
|
|
description={description}
|
|
descriptionMode={descriptionMode}
|
|
grouped={grouped}
|
|
disabled={disabled}
|
|
tooltipPosition={tooltipPosition}
|
|
>
|
|
<label
|
|
className={`inline-flex items-center ${disabled || isUpdating ? "cursor-not-allowed" : "cursor-pointer"}`}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
value=""
|
|
className="sr-only peer"
|
|
checked={checked}
|
|
disabled={disabled || isUpdating}
|
|
onChange={(e) => onChange(e.target.checked)}
|
|
/>
|
|
<div className="relative w-11 h-6 bg-mid-gray/20 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-logo-primary rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-background-ui peer-disabled:opacity-50"></div>
|
|
</label>
|
|
{isUpdating && (
|
|
<div className="absolute inset-0 flex items-center justify-center">
|
|
<div className="w-4 h-4 border-2 border-logo-primary border-t-transparent rounded-full animate-spin"></div>
|
|
</div>
|
|
)}
|
|
</SettingContainer>
|
|
);
|
|
};
|