Toggle

Toggle

Toggle 컴포넌트는 사용자가 두 가지 상태를 전환할 수 있게 합니다.

예제

Default Basic toggle switch. Click to toggle between on and off states. Use value or defaultValue to control the toggle state.

코드 보기
1import { Toggle } from '@devup-ui/components'
2
3export default function Default() {
4    return <Toggle />
5}
6
1import { Toggle } from '@devup-ui/components'
2
3export default function Default() {
4    return <Toggle />
5}
6

Variant Use variant="switch" for an alternative visual style with a smaller track and a floating knob with hover outline effect.

코드 보기
1import { Toggle } from '@devup-ui/components'
2
3export default function Switch() {
4    return <Toggle variant="switch" />
5}
6
1import { Toggle } from '@devup-ui/components'
2
3export default function Switch() {
4    return <Toggle variant="switch" />
5}
6

Disabled Use disabled prop to prevent user interaction. The toggle will have a muted appearance and cannot be toggled.

코드 보기
1import { Toggle } from '@devup-ui/components'
2import { Flex } from '@devup-ui/react'
3
4export default function Disabled() {
5    return (
6        <Flex gap="16px">
7            <Toggle disabled />
8            <Toggle defaultValue disabled />
9        </Flex>
10    )
11}
12
1import { Toggle } from '@devup-ui/components'
2import { Flex } from '@devup-ui/react'
3
4export default function Disabled() {
5    return (
6        <Flex gap="16px">
7            <Toggle disabled />
8            <Toggle defaultValue disabled />
9        </Flex>
10    )
11}
12

Colors Pass in an object containing color tokens into colors prop. Customize the toggle appearance using primary, bg, hoverBg, primaryHoverBg, disabledBg, and more.

코드 보기
1import { Toggle } from '@devup-ui/components'
2import { Flex } from '@devup-ui/react'
3
4export default function Colors() {
5    return (
6        <Flex gap="16px">
7            <Toggle colors={{ primary: '#10B981' }} defaultValue />
8            <Toggle colors={{ primary: 'orange' }} defaultValue />
9            <Toggle colors={{ primary: 'steelblue' }} defaultValue />
10        </Flex>
11    )
12}
13
1import { Toggle } from '@devup-ui/components'
2import { Flex } from '@devup-ui/react'
3
4export default function Colors() {
5    return (
6        <Flex gap="16px">
7            <Toggle colors={{ primary: '#10B981' }} defaultValue />
8            <Toggle colors={{ primary: 'orange' }} defaultValue />
9            <Toggle colors={{ primary: 'steelblue' }} defaultValue />
10        </Flex>
11    )
12}
13
API

Toggle 컴포넌트의 props입니다.

속성설명타입기본값
value

토글의 제어 값

boolean | null

null

defaultValue

토글의 기본값(비제어)

boolean | null

null

onChange

토글 값이 바뀔 때 호출되는 콜백

(value: boolean) => void

undefined

disabled

토글의 비활성화 여부

boolean

false

variant

토글의 시각적 variant

'default' | 'switch'

'default'

className

토글 컨테이너에 추가할 클래스 이름

string

undefined

style

토글 컨테이너의 인라인 스타일

React.CSSProperties

undefined

classNames

내부 요소에 적용할 사용자 정의 클래스 이름

{
toggle?: string

}

undefined

styles

내부 요소에 적용할 사용자 정의 인라인 스타일

{
toggle?: React.CSSProperties

}

undefined

colors

토글의 사용자 정의 색상 변수

{
primary?: string

bg?: string

hoverBg?: string

primaryHoverBg?: string

disabledBg?: string

switchHoverOutline?: string

switchShadow?: string

}

undefined