mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 00:53:14 +00:00
(feat:toggle) greener colors, flexible
This commit is contained in:
@@ -6,9 +6,8 @@ type ToggleSwitchProps = {
|
||||
className?: string;
|
||||
label?: string;
|
||||
disabled?: boolean;
|
||||
activeColor?: string;
|
||||
inactiveColor?: string;
|
||||
id?: string;
|
||||
size?: 'small' | 'medium' | 'large';
|
||||
labelPosition?: 'left' | 'right';
|
||||
};
|
||||
|
||||
const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
|
||||
@@ -17,17 +16,44 @@ const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
|
||||
className = '',
|
||||
label,
|
||||
disabled = false,
|
||||
activeColor = 'bg-purple-30',
|
||||
inactiveColor = 'bg-transparent',
|
||||
id,
|
||||
size = 'medium',
|
||||
labelPosition = 'left',
|
||||
}) => {
|
||||
// Size configurations
|
||||
const sizeConfig = {
|
||||
small: {
|
||||
box: 'h-6 w-10',
|
||||
toggle: 'h-4 w-4 left-1 top-1',
|
||||
translate: 'translate-x-4',
|
||||
},
|
||||
medium: {
|
||||
box: 'h-8 w-14',
|
||||
toggle: 'h-6 w-6 left-1 top-1',
|
||||
translate: 'translate-x-full',
|
||||
},
|
||||
large: {
|
||||
box: 'h-10 w-16',
|
||||
toggle: 'h-8 w-8 left-1 top-1',
|
||||
translate: 'translate-x-full',
|
||||
},
|
||||
};
|
||||
|
||||
const { box, toggle, translate } = sizeConfig[size];
|
||||
|
||||
return (
|
||||
<label
|
||||
className={`cursor-pointer select-none justify-between flex flex-row items-center ${disabled ? 'opacity-50 cursor-not-allowed' : ''} ${className}`}
|
||||
htmlFor={id}
|
||||
className={`cursor-pointer select-none flex flex-row items-center ${
|
||||
labelPosition === 'right' ? 'flex-row-reverse' : ''
|
||||
} ${disabled ? 'opacity-50 cursor-not-allowed' : ''} ${className}`}
|
||||
>
|
||||
{label && (
|
||||
<span className="mr-2 text-eerie-black dark:text-white">{label}</span>
|
||||
<span
|
||||
className={`text-eerie-black dark:text-white ${
|
||||
labelPosition === 'left' ? 'mr-1' : 'ml-1'
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
)}
|
||||
<div className="relative">
|
||||
<input
|
||||
@@ -36,18 +62,15 @@ const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
|
||||
onChange={(e) => onChange(e.target.checked)}
|
||||
className="sr-only"
|
||||
disabled={disabled}
|
||||
id={id}
|
||||
/>
|
||||
<div
|
||||
className={`box block h-8 w-14 rounded-full border border-purple-30 ${
|
||||
checked
|
||||
? `${activeColor} dark:${activeColor}`
|
||||
: `${inactiveColor} dark:${inactiveColor}`
|
||||
className={`box block ${box} rounded-full ${
|
||||
checked ? 'bg-apple-green' : 'bg-silver dark:bg-charcoal-grey'
|
||||
}`}
|
||||
></div>
|
||||
<div
|
||||
className={`absolute left-1 top-1 flex h-6 w-6 items-center justify-center rounded-full transition ${
|
||||
checked ? 'translate-x-full bg-silver' : 'bg-purple-30'
|
||||
className={`absolute ${toggle} flex items-center justify-center rounded-full transition bg-white ${
|
||||
checked ? `${translate} bg-silver` : ''
|
||||
}`}
|
||||
></div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user