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 25eb3c5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 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.

4 changes: 2 additions & 2 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,7 +26,7 @@ const OverrideCard: React.FC = () => {
>
<MdFormatOverline color="default" className="text-[24px]" />
</Button>
<SiderSwitch
<BorderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={setEnable}
Expand Down
6 changes: 3 additions & 3 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,7 +35,7 @@ const SysproxySwitcher: React.FC = () => {
>
<AiOutlineGlobal color="default" className="text-[24px]" />
</Button>
<SiderSwitch
<BorderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={onChange}
Expand Down
5 changes: 3 additions & 2 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 All @@ -15,6 +15,7 @@ const TunSwitcher: React.FC = () => {
const { tun } = controledMihomoConfig || {}
const { enable } = tun || {}

console.log('controledMihomoConfig', controledMihomoConfig)
const onChange = async (enable: boolean): Promise<void> => {
await patchControledMihomoConfig({ tun: { enable } })
await patchMihomoConfig({ tun: { enable } })
Expand All @@ -36,7 +37,7 @@ const TunSwitcher: React.FC = () => {
>
<TbDeviceIpadHorizontalBolt color="default" className="text-[24px] font-bold" />
</Button>
<SiderSwitch
<BorderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={onChange}
Expand Down

0 comments on commit 25eb3c5

Please sign in to comment.