Add platform status switch

This commit is contained in:
2026-05-12 21:49:08 +08:00
parent 682a491d27
commit a76ab941bc
10 changed files with 195 additions and 5 deletions
+1
View File
@@ -13,6 +13,7 @@ export * from './message';
export * from './popover';
export * from './select';
export * from './separator';
export * from './switch';
export * from './table';
export * from './tabs';
export * from './textarea';
+32
View File
@@ -0,0 +1,32 @@
import * as React from 'react';
import { cn } from '../../lib/utils';
export interface SwitchProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onChange'> {
checked: boolean;
onCheckedChange?: (checked: boolean) => void;
}
export const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
({ checked, className, disabled, onCheckedChange, ...props }, ref) => (
<button
aria-checked={checked}
className={cn('shSwitch', className)}
data-state={checked ? 'checked' : 'unchecked'}
disabled={disabled}
ref={ref}
role="switch"
{...props}
type="button"
onClick={(event) => {
props.onClick?.(event);
if (!event.defaultPrevented && !disabled) {
onCheckedChange?.(!checked);
}
}}
>
<span className="shSwitchThumb" />
</button>
),
);
Switch.displayName = 'Switch';