Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#13] 토글 공통 컴포넌트 구현 #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-switch": "^1.0.3",
"@tanstack/react-query": "^5.34.1",
"axios": "^1.6.8",
"dayjs": "^1.11.11",
Expand Down
12 changes: 12 additions & 0 deletions src/components/common/toggle/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ToggleRoot from './ToggleRoot'
import ToggleThumb from './ToggleThumb'

const Toggle = () => {
return (
<ToggleRoot>
Comment on lines +1 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻👍🏻👍🏻👍🏻 경로만 절대로 바꾸면 좋을 것 같아용 !!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하겠습니다 !

<ToggleThumb />
</ToggleRoot>
)
}

export default Toggle
24 changes: 24 additions & 0 deletions src/components/common/toggle/ToggleRoot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client'

import * as Switch from '@radix-ui/react-switch'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 radix 라이브러리를 전체를 가르키는 변수명을 [기능]Primitive 로 이름짓구 있습니다. SwitchPrimitive로 바꾸면 컨벤션을 유지 할 수 있을꺼같아요 !!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 감사합니다 !!

import { theme } from '@/styles/theme'
import styled from 'styled-components'

const StyledRoot = styled(Switch.Root)`
width: 58px;
height: 31px;
background-color: ${theme.color.grey200};
border-radius: 9999px;
position: relative;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);

&[data-state='checked'] {
background-color: ${theme.color.purple700};
}
`

const ToggleRoot = ({ children, ...props }: Switch.PrimitiveButtonProps) => {
return <StyledRoot {...props}>{children}</StyledRoot>
}

export default ToggleRoot
26 changes: 26 additions & 0 deletions src/components/common/toggle/ToggleThumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client'

import * as Switch from '@radix-ui/react-switch'
import { theme } from '@/styles/theme'
import styled from 'styled-components'

const StyledThumb = styled(Switch.SwitchThumb)`
display: block;
width: 25px;
height: 25px;
background-color: ${theme.color.white};
border-radius: 9999px;
transition: transform 300ms;
transform: translateX(2px);
will-change: transform;

&[data-state='checked'] {
transform: translateX(30px);
}
`

const ToggleThumb = ({ ...props }: Switch.SwitchThumbProps) => {
return <StyledThumb {...props} />
}

export default ToggleThumb
Loading