Search
πŸ’‘

Radio-group

Created
2026/02/07 05:58
Tags
2026/02/07 06:45

Context

ν•­λͺ©μ„ μ„ νƒν•˜κΈ° μœ„ν•΄ Radio μ»΄ν¬λ„ŒνŠΈλ₯Ό μ‚¬μš©ν•  λ•Œκ°€ μžˆλ‹€. 이 κΈ€μ—μ„œλŠ” shadcn의 radio-group μ»΄ν¬λ„ŒνŠΈλ₯Ό μ†Œκ°œν•œλ‹€.

Agenda

β€’
shadcn의 radio-group μ»΄ν¬λ„ŒνŠΈλ₯Ό λΆ„μ„ν•˜κ³  κ·Έ λ‚΄μš©μ„ μ΄ν•΄ν•˜λŠ” 것을 λͺ©ν‘œλ‘œ 함

Contents

RadioGroup
const RadioGroup = ({ className, ...props }: React.ComponentProps<typeof RadioGroupPrimitive.Root>) => { return ( <RadioGroupPrimitive.Root data-slot='radio-group' className={cn('grid gap-3', className)} {...props} /> ); };
TypeScript
볡사
shadcn의 RadioGroup μ»΄ν¬λ„ŒνŠΈλŠ” radix-ui의 RadioGroupPrimitive의 Root μ»΄ν¬λ„ŒνŠΈλ₯Ό κ°μ‹ΈλŠ” Wrapper ν˜•νƒœλ‘œ κ΅¬ν˜„ λœλ‹€. radix-ui의 RadioGroupPrimitive Root μ»΄ν¬λ„ŒνŠΈκ°€ μ‚¬μš©ν•˜λŠ” propsλ₯Ό κ·ΈλŒ€λ‘œ λ„˜κ²¨μ£ΌλŠ” 닀리라고도 λ³Ό 수 있으며 data-slot 속성을 λΆ€μ—¬ν•˜μ—¬ DOM νƒμƒ‰μ΄λ‚˜ ν…ŒμŠ€νŠΈμ‹œμ— μ‹λ³„ν•˜κΈ°μ— μš©μ΄ν•˜κ²Œ ν•˜μ˜€λ‹€.
RadioGroupItem
const RadioGroupItem = ({ className, ...props }: React.ComponentProps<typeof RadioGroupPrimitive.Item>) => { return ( <RadioGroupPrimitive.Item data-slot='radio-group-item' className={cn( 'peer border-input text-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 aspect-square size-4 shrink-0 rounded-full border shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] aria-invalid:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50', className, )} {...props} > <RadioGroupPrimitive.Indicator data-slot='radio-group-indicator' className='relative flex items-center justify-center' > <CircleIcon className='fill-primary absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2' /> </RadioGroupPrimitive.Indicator> </RadioGroupPrimitive.Item> ); };
TypeScript
볡사
RadioGroupItem μ»΄ν¬λ„ŒνŠΈλ„ λ§ˆμ°¬κ°€μ§€λ‘œ radix-ui의 RadioGroupPrimitive Item μ»΄ν¬λ„ŒνŠΈλ₯Ό κ°μ‹ΈλŠ” Wrapper ν˜•νƒœμ˜ μ»΄ν¬λ„ŒνŠΈμ΄λ‹€. Item의 μŠ€νƒ€μΌλ§ λΆ€λΆ„μ—μ„œ νŠΉμ΄ν–ˆλ˜ 뢀뢄은 aspect-square μ†μ„±μ΄μ—ˆλŠ”λ°, 사싀 size μ†μ„±λ§ŒμœΌλ‘œλ„ μΆ©λΆ„νžˆ μ˜μ—­μ„ μ„€μ •ν•  수 μžˆμ§€ μ•Šμ•˜λ‚˜ 생각이 λ“€μ—ˆλ‹€. μ’€ 더 μ°Ύμ•„λ³΄λ‹ˆ, Item이 flexλ‚˜ grid μ•ˆμ— λ“€μ–΄κ°„ 경우, λ˜λŠ” heightμ΄λ‚˜ widthκ°€ μ™ΈλΆ€μ—μ„œ 영ν–₯을 받을 λ•Œ aspect-squareλ₯Ό 톡해 1:1 λΉ„μœ¨μ„ μœ μ§€ν•˜μ—¬ μ°Œκ·ΈλŸ¬μ§€μ§€ μ•Šκ²Œ ν•  수 μžˆλ‹€λŠ” 것을 μ•Œκ²Œ λ˜μ—ˆλ‹€.
RadioGroupPrimitive의 IndicatorλŠ” 선택됨 μƒνƒœμΌ λ•Œλ§Œ λ³΄μ΄λŠ” ν‘œμ‹œ μ˜μ—­μ΄λ‹€. Radio μ•„μ΄ν…œμ΄ 선택 λ˜μ—ˆμ„ λ•Œ κ°€μš΄λ°μ— ν‘œμ‹œ λ˜λŠ” 점(Dot)이닀.