Skip to content

Commit

Permalink
refactor border switch
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 2, 2024
1 parent ba72269 commit b336026
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ interface SiderSwitchProps extends SwitchProps {
isShowBorder?: boolean
}

const SiderSwitch: React.FC<SiderSwitchProps> = (props) => {
const { isShowBorder = false, isSelected, classNames, ...switchProps } = props
const BorderSwitch: React.FC<SiderSwitchProps> = (props) => {
const { isShowBorder = false, classNames, ...switchProps } = props

return (
<Switch
classNames={{
wrapper: cn('border-2', {
'border-transparent': !isShowBorder
}),
thumb: cn('absolute z-4', { 'transform -translate-x-[2px]': isSelected }),
thumb: cn('absolute z-4', 'transform -translate-x-[2px]'),
...classNames
}}
size="sm"
Expand All @@ -23,4 +23,4 @@ const SiderSwitch: React.FC<SiderSwitchProps> = (props) => {
)
}

export default SiderSwitch
export default BorderSwitch
1 change: 0 additions & 1 deletion src/renderer/src/components/sider/index.ts

This file was deleted.

8 changes: 2 additions & 6 deletions src/renderer/src/components/sider/override-card.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import BorderSwitch from '@renderer/components/base/border-swtich'
import React, { useState } from 'react'
import { MdFormatOverline } from 'react-icons/md'
import { useLocation, useNavigate } from 'react-router-dom'
import { SiderSwitch } from './index'

const OverrideCard: React.FC = () => {
const navigate = useNavigate()
Expand All @@ -26,11 +26,7 @@ const OverrideCard: React.FC = () => {
>
<MdFormatOverline color="default" className="text-[24px]" />
</Button>
<SiderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={setEnable}
/>
<BorderSwitch isShowBorder={match && enable} onValueChange={setEnable} />
</div>
</CardBody>
<CardFooter className="pt-1">
Expand Down
10 changes: 3 additions & 7 deletions src/renderer/src/components/sider/sysproxy-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import BorderSwitch from '@renderer/components/base/border-swtich'
import { useLocation, useNavigate } from 'react-router-dom'
import { useAppConfig } from '@renderer/hooks/use-config'
import { triggerSysProxy } from '@renderer/utils/ipc'
import { AiOutlineGlobal } from 'react-icons/ai'
import React from 'react'
import { triggerSysProxy } from '@renderer/utils/ipc'
import { SiderSwitch } from './index'

const SysproxySwitcher: React.FC = () => {
const navigate = useNavigate()
Expand Down Expand Up @@ -35,11 +35,7 @@ const SysproxySwitcher: React.FC = () => {
>
<AiOutlineGlobal color="default" className="text-[24px]" />
</Button>
<SiderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={onChange}
/>
<BorderSwitch isShowBorder={match && enable} onValueChange={onChange} />
</div>
</CardBody>
<CardFooter className="pt-1">
Expand Down
8 changes: 2 additions & 6 deletions src/renderer/src/components/sider/tun-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
import BorderSwitch from '@renderer/components/base/border-swtich'
import { TbDeviceIpadHorizontalBolt } from 'react-icons/tb'
import { useLocation, useNavigate } from 'react-router-dom'
import { patchMihomoConfig } from '@renderer/utils/ipc'
import React from 'react'
import { SiderSwitch } from './index'

const TunSwitcher: React.FC = () => {
const navigate = useNavigate()
Expand Down Expand Up @@ -36,11 +36,7 @@ const TunSwitcher: React.FC = () => {
>
<TbDeviceIpadHorizontalBolt color="default" className="text-[24px] font-bold" />
</Button>
<SiderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={onChange}
/>
<BorderSwitch isShowBorder={match && enable} onValueChange={onChange} />
</div>
</CardBody>
<CardFooter className="pt-1">
Expand Down

0 comments on commit b336026

Please sign in to comment.