snapshot of https://github.com/shadcn-ui/ui.git (main, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
42
apps/v4/registry/bases/aria/ui/switch.tsx
Normal file
42
apps/v4/registry/bases/aria/ui/switch.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
"use client"
|
||||
|
||||
import { cn } from "cn"
|
||||
import {
|
||||
composeRenderProps,
|
||||
Switch as SwitchPrimitive,
|
||||
type SwitchProps as SwitchPrimitiveProps,
|
||||
} from "react-aria-components"
|
||||
|
||||
function Switch({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: SwitchPrimitiveProps & {
|
||||
size?: "sm" | "default"
|
||||
}) {
|
||||
return (
|
||||
<SwitchPrimitive
|
||||
data-slot="switch"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"cn-switch cn-switch-aria peer group/switch relative inline-flex items-center transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 data-disabled:cursor-not-allowed data-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{composeRenderProps(children, (children, { isSelected }) => (
|
||||
<>
|
||||
<span
|
||||
data-slot="switch-thumb"
|
||||
data-selected={isSelected || undefined}
|
||||
className="cn-switch-thumb cn-switch-thumb-aria pointer-events-none block ring-0 transition-transform"
|
||||
/>
|
||||
{children}
|
||||
</>
|
||||
))}
|
||||
</SwitchPrimitive>
|
||||
)
|
||||
}
|
||||
|
||||
export { Switch }
|
||||
Reference in New Issue
Block a user