refactor(admin): replace raw form elements with shared Input, Textarea, and Switch components in RoleEditPage
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
'use client';
|
||||
|
||||
const Switch = ({
|
||||
checked = false,
|
||||
onChange,
|
||||
label,
|
||||
description,
|
||||
disabled = false,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center justify-between gap-4 py-3 ${disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`}
|
||||
onClick={() => !disabled && onChange?.(!checked)}
|
||||
>
|
||||
<div className="flex flex-col gap-0.5 min-w-0">
|
||||
{label && (
|
||||
<span className="text-sm text-neutral-900 dark:text-white select-none">{label}</span>
|
||||
)}
|
||||
{description && (
|
||||
<span className="text-xs text-neutral-500 dark:text-neutral-400 select-none">{description}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={checked}
|
||||
disabled={disabled}
|
||||
onClick={(e) => { e.stopPropagation(); !disabled && onChange?.(!checked); }}
|
||||
className={`relative flex-shrink-0 w-11 h-6 rounded-full transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-white dark:focus:ring-offset-neutral-900 ${
|
||||
checked
|
||||
? 'bg-blue-600'
|
||||
: 'bg-neutral-300 dark:bg-neutral-600'
|
||||
} ${disabled ? 'cursor-not-allowed' : 'cursor-pointer'}`}
|
||||
>
|
||||
<span
|
||||
className={`absolute top-0.5 left-0.5 w-5 h-5 rounded-full bg-white shadow-sm transition-transform duration-200 ${
|
||||
checked ? 'translate-x-5' : 'translate-x-0'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Switch;
|
||||
@@ -25,3 +25,4 @@ export { default as MarkdownEditor } from './MarkdownEditor';
|
||||
export { default as PasswordStrengthIndicator } from './PasswordStrengthIndicator';
|
||||
export { default as FilterTabs } from './FilterTabs';
|
||||
export { default as Breadcrumb } from './Breadcrumb';
|
||||
export { default as Switch } from './Switch';
|
||||
|
||||
Reference in New Issue
Block a user