Skip to content

Commit

Permalink
feat: add SiderSwitch component (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokiki0438 authored Aug 1, 2024
1 parent b43f078 commit ebbd3a2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
out
.DS_Store
*.log*
.idea
1 change: 1 addition & 0 deletions src/renderer/src/components/sider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as SiderSwitch } from './sider-swtich'
10 changes: 4 additions & 6 deletions src/renderer/src/components/sider/override-card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Button, Card, CardBody, CardFooter, Switch } from '@nextui-org/react'
import { Button, Card, CardBody, CardFooter, cn } from '@nextui-org/react'
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 @@ -25,11 +26,8 @@ const OverrideCard: React.FC = () => {
>
<MdFormatOverline color="default" className="text-[24px]" />
</Button>
<Switch
classNames={{
wrapper: `${match && enable ? 'border-2' : ''}`
}}
size="sm"
<SiderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={setEnable}
/>
Expand Down
26 changes: 26 additions & 0 deletions src/renderer/src/components/sider/sider-swtich.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import { cn, Switch, SwitchProps } from '@nextui-org/react'

interface SiderSwitchProps extends SwitchProps {
isShowBorder?: boolean
}

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

return (
<Switch
classNames={{
wrapper: cn('border-2', {
'border-transparent': !isShowBorder
}),
thumb: cn('absolute z-4', { 'transform -translate-x-[2px]': isSelected }),
...classNames
}}
size="sm"
{...switchProps}
/>
)
}

export default SiderSwitch
10 changes: 4 additions & 6 deletions src/renderer/src/components/sider/sysproxy-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Button, Card, CardBody, CardFooter, Switch } from '@nextui-org/react'
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import { useLocation, useNavigate } from 'react-router-dom'
import { useAppConfig } from '@renderer/hooks/use-config'
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 @@ -34,11 +35,8 @@ const SysproxySwitcher: React.FC = () => {
>
<AiOutlineGlobal color="default" className="text-[24px]" />
</Button>
<Switch
classNames={{
wrapper: `${match && enable ? 'border-2' : ''}`
}}
size="sm"
<SiderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={onChange}
/>
Expand Down
10 changes: 4 additions & 6 deletions src/renderer/src/components/sider/tun-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Button, Card, CardBody, CardFooter, Switch } from '@nextui-org/react'
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
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 @@ -35,11 +36,8 @@ const TunSwitcher: React.FC = () => {
>
<TbDeviceIpadHorizontalBolt color="default" className="text-[24px] font-bold" />
</Button>
<Switch
classNames={{
wrapper: `${match && enable ? 'border-2' : ''}`
}}
size="sm"
<SiderSwitch
isShowBorder={match && enable}
isSelected={enable}
onValueChange={onChange}
/>
Expand Down

0 comments on commit ebbd3a2

Please sign in to comment.