mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
feat: add SiderSwitch component (#1)
This commit is contained in:
parent
34ed8898a5
commit
fcef4b18fb
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ dist
|
|||||||
out
|
out
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.log*
|
*.log*
|
||||||
|
.idea
|
||||||
|
|||||||
1
src/renderer/src/components/sider/index.ts
Normal file
1
src/renderer/src/components/sider/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default as SiderSwitch } from './sider-swtich'
|
||||||
@ -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 React, { useState } from 'react'
|
||||||
import { MdFormatOverline } from 'react-icons/md'
|
import { MdFormatOverline } from 'react-icons/md'
|
||||||
import { useLocation, useNavigate } from 'react-router-dom'
|
import { useLocation, useNavigate } from 'react-router-dom'
|
||||||
|
import { SiderSwitch } from './index'
|
||||||
|
|
||||||
const OverrideCard: React.FC = () => {
|
const OverrideCard: React.FC = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@ -25,11 +26,8 @@ const OverrideCard: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<MdFormatOverline color="default" className="text-[24px]" />
|
<MdFormatOverline color="default" className="text-[24px]" />
|
||||||
</Button>
|
</Button>
|
||||||
<Switch
|
<SiderSwitch
|
||||||
classNames={{
|
isShowBorder={match && enable}
|
||||||
wrapper: `${match && enable ? 'border-2' : ''}`
|
|
||||||
}}
|
|
||||||
size="sm"
|
|
||||||
isSelected={enable}
|
isSelected={enable}
|
||||||
onValueChange={setEnable}
|
onValueChange={setEnable}
|
||||||
/>
|
/>
|
||||||
|
|||||||
26
src/renderer/src/components/sider/sider-swtich.tsx
Normal file
26
src/renderer/src/components/sider/sider-swtich.tsx
Normal file
@ -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
|
||||||
@ -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 { useLocation, useNavigate } from 'react-router-dom'
|
||||||
import { useAppConfig } from '@renderer/hooks/use-config'
|
import { useAppConfig } from '@renderer/hooks/use-config'
|
||||||
import { AiOutlineGlobal } from 'react-icons/ai'
|
import { AiOutlineGlobal } from 'react-icons/ai'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { triggerSysProxy } from '@renderer/utils/ipc'
|
import { triggerSysProxy } from '@renderer/utils/ipc'
|
||||||
|
import { SiderSwitch } from './index'
|
||||||
|
|
||||||
const SysproxySwitcher: React.FC = () => {
|
const SysproxySwitcher: React.FC = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@ -34,11 +35,8 @@ const SysproxySwitcher: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<AiOutlineGlobal color="default" className="text-[24px]" />
|
<AiOutlineGlobal color="default" className="text-[24px]" />
|
||||||
</Button>
|
</Button>
|
||||||
<Switch
|
<SiderSwitch
|
||||||
classNames={{
|
isShowBorder={match && enable}
|
||||||
wrapper: `${match && enable ? 'border-2' : ''}`
|
|
||||||
}}
|
|
||||||
size="sm"
|
|
||||||
isSelected={enable}
|
isSelected={enable}
|
||||||
onValueChange={onChange}
|
onValueChange={onChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -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 { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
||||||
import { TbDeviceIpadHorizontalBolt } from 'react-icons/tb'
|
import { TbDeviceIpadHorizontalBolt } from 'react-icons/tb'
|
||||||
import { useLocation, useNavigate } from 'react-router-dom'
|
import { useLocation, useNavigate } from 'react-router-dom'
|
||||||
import { patchMihomoConfig } from '@renderer/utils/ipc'
|
import { patchMihomoConfig } from '@renderer/utils/ipc'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { SiderSwitch } from './index'
|
||||||
|
|
||||||
const TunSwitcher: React.FC = () => {
|
const TunSwitcher: React.FC = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@ -35,11 +36,8 @@ const TunSwitcher: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<TbDeviceIpadHorizontalBolt color="default" className="text-[24px] font-bold" />
|
<TbDeviceIpadHorizontalBolt color="default" className="text-[24px] font-bold" />
|
||||||
</Button>
|
</Button>
|
||||||
<Switch
|
<SiderSwitch
|
||||||
classNames={{
|
isShowBorder={match && enable}
|
||||||
wrapper: `${match && enable ? 'border-2' : ''}`
|
|
||||||
}}
|
|
||||||
size="sm"
|
|
||||||
isSelected={enable}
|
isSelected={enable}
|
||||||
onValueChange={onChange}
|
onValueChange={onChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user