@@ -17,7 +17,10 @@ import cn from 'classnames'
1717import type { ComponentProps } from 'react'
1818
1919// input type is fixed to "radio"
20- export type RadioProps = Omit < React . ComponentProps < 'input' > , 'type' >
20+ export type RadioProps = Omit < React . ComponentProps < 'input' > , 'type' > & {
21+ /** Align radio button with top of content instead of center (useful for multi-line content) */
22+ alignTop ?: boolean
23+ }
2124
2225const fieldStyles = `
2326 peer appearance-none absolute outline-hidden
@@ -26,15 +29,13 @@ const fieldStyles = `
2629 disabled:hover:bg-transparent
2730`
2831
29- export const Radio = ( { children, className, ...inputProps } : RadioProps ) => (
30- < label className = "text-sans-md flex" >
31- < div className = "inline-flex h-lh shrink-0 grow-0 items-center" >
32- < span className = "relative h-4 w-4 shrink-0" >
33- < input className = { cn ( fieldStyles , className ) } type = "radio" { ...inputProps } />
34- { /* the dot in the middle. hide by default, use peer-checked to show if checked */ }
35- < div className = "bg-accent pointer-events-none absolute top-1 left-1 hidden h-2 w-2 rounded-full peer-checked:block" />
36- </ span >
37- </ div >
32+ export const Radio = ( { children, className, alignTop, ...inputProps } : RadioProps ) => (
33+ < label className = { cn ( 'inline-flex' , alignTop ? 'items-start' : 'items-center' ) } >
34+ < span className = "relative h-4 w-4 shrink-0" >
35+ < input className = { cn ( fieldStyles , className ) } type = "radio" { ...inputProps } />
36+ { /* the dot in the middle. hide by default, use peer-checked to show if checked */ }
37+ < div className = "bg-accent pointer-events-none absolute top-1 left-1 hidden h-2 w-2 rounded-full peer-checked:block" />
38+ </ span >
3839
3940 { children && < span className = "text-default ml-2.5" > { children } </ span > }
4041 </ label >
0 commit comments