'use client' /** * RestrictedToggle 组件 * * 受限功能开关组件,集成 PRO 徽章和点击拦截逻辑 * 当功能受限时显示禁用状态,点击时触发授权提示弹窗 * * @created 2025-12-16 * @component */ import { useState } from 'react' import { useTheme, cn } from '@/lib/ui-styles' import ProBadge from './ProBadge' import UpgradeModal from './UpgradeModal' import type { FeatureKey } from '@/lib/license/types' interface RestrictedToggleProps { /** 开关标签 */ label: string /** 功能键,用于检查是否受限 */ featureKey: FeatureKey /** 当前值 */ value: boolean /** 值变化回调 */ onChange: (value: boolean) => void /** 功能描述(可选) */ description?: string /** 是否受限(由父组件传入,基于许可证状态) */ isRestricted: boolean /** 自定义类名 */ className?: string } export default function RestrictedToggle({ label, featureKey, value, onChange, description, isRestricted, className, }: RestrictedToggleProps) { const theme = useTheme() const [showUpgradeModal, setShowUpgradeModal] = useState(false) const handleClick = () => { if (isRestricted) { setShowUpgradeModal(true) } else { onChange(!value) } } return ( <>
{description}
)} {isRestricted && (当前许可证未包含此功能
)}