diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 372038f..97bb141 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -10,7 +10,7 @@ type ButtonInternalProps = { children?: React.ReactNode; label?: string; text?: string; - start?: React.ReactElement | (() => React.ReactElement); + start?: React.ReactNode | (() => React.ReactNode); }; type ButtonProps = { diff --git a/src/components/Config.module.css b/src/components/Config.module.css deleted file mode 100644 index 1f71765..0000000 --- a/src/components/Config.module.css +++ /dev/null @@ -1,34 +0,0 @@ -.root { - > div { - min-width: 345px; - @media (--breakpoint-not-small) { - width: 360px; - } - } -} - -.root, -.section { - padding: 6px 15px 15px; - @media (--breakpoint-not-small) { - padding: 0 40px 40px; - } -} - -.sep { - padding: 0 15px; - @media (--breakpoint-not-small) { - padding: 0 40px; - } - > div { - border-top: 1px dashed #373737; - } -} - -.label { - padding: 16px 0; -} - -.narrow { - width: 360px; -} diff --git a/src/components/Config.module.scss b/src/components/Config.module.scss new file mode 100644 index 0000000..49e2a4a --- /dev/null +++ b/src/components/Config.module.scss @@ -0,0 +1,39 @@ +.root, +.section { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(345px, 1fr)); + max-width: 900px; + gap: 5px; + @media (--breakpoint-not-small) { + gap: 15px; + } +} + +.root, +.section { + padding: 6px 15px 10px; + @media (--breakpoint-not-small) { + padding: 10px 40px 15px; + } +} + +.wrapSwitch { + height: 40px; + display: flex; + align-items: center; +} + +.sep { + max-width: 900px; + padding: 0 15px; + @media (--breakpoint-not-small) { + padding: 0 40px; + } + > div { + border-top: 1px dashed #373737; + } +} + +.label { + padding: 11px 0; +} diff --git a/src/components/Config.tsx b/src/components/Config.tsx index 4659e16..8c0678c 100644 --- a/src/components/Config.tsx +++ b/src/components/Config.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import { LogOut } from 'react-feather'; import { useTranslation } from 'react-i18next'; import Select from 'src/components/shared/Select'; import { ClashGeneralConfig, DispatchFn, State } from 'src/store/types'; @@ -12,55 +13,25 @@ import { import { fetchConfigs, getConfigs, updateConfigs } from '../store/configs'; import { openModal } from '../store/modals'; import Button from './Button'; -import s0 from './Config.module.css'; +import s0 from './Config.module.scss'; import ContentHeader from './ContentHeader'; import Input, { SelfControlledInput } from './Input'; import { Selection2 } from './Selection'; import { connect, useStoreActions } from './StateProvider'; import Switch from './SwitchThemed'; -import ToggleSwitch from './ToggleSwitch'; import TrafficChartSample from './TrafficChartSample'; +// import ToggleSwitch from './ToggleSwitch'; const { useEffect, useState, useCallback, useRef, useMemo } = React; const propsList = [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]; -const optionsRule = [ - { - label: 'Global', - value: 'Global', - }, - { - label: 'Rule', - value: 'Rule', - }, - { - label: 'Direct', - value: 'Direct', - }, -]; - -const optionsLogLevel = [ - { - label: 'Debug', - value: 'debug', - }, - { - label: 'Warning', - value: 'warning', - }, - { - label: 'Info', - value: 'info', - }, - { - label: 'Error', - value: 'error', - }, - { - label: 'Silent', - value: 'silent', - }, +const logLeveOptions = [ + ['debug', 'Debug'], + ['warning', 'Warning'], + ['info', 'Info'], + ['error', 'Error'], + ['silent', 'Silent'], ]; const portFields = [ @@ -75,6 +46,12 @@ const langOptions = [ ['en', 'English'], ]; +const modeOptions = [ + ['Global', 'Global'], + ['Rule', 'Rule'], + ['Direct', 'Direct'], +]; + const mapState = (s: State) => ({ configs: getConfigs(s), apiConfig: getClashAPIConfig(s), @@ -144,12 +121,9 @@ function ConfigImpl({ [apiConfig, dispatch, setConfigState] ); - const handleInputOnChange = useCallback( - (e) => { - const target = e.target; - const { name } = target; - const { value } = target; - switch (target.name) { + const handleChangeValue = useCallback( + ({ name, value }) => { + switch (name) { case 'mode': case 'log-level': setConfigState(name, value); @@ -159,8 +133,8 @@ function ConfigImpl({ case 'socks-port': case 'mixed-port': case 'port': - if (target.value !== '') { - const num = parseInt(target.value, 10); + if (value !== '') { + const num = parseInt(value, 10); if (num < 0 || num > 65535) return; } setConfigState(name, value); @@ -172,6 +146,11 @@ function ConfigImpl({ [apiConfig, dispatch, setConfigState] ); + const handleInputOnChange = useCallback( + (e) => handleChangeValue(e.target), + [handleChangeValue] + ); + const { selectChartStyleIndex, updateAppConfig } = useStoreActions(); const handleInputOnBlur = useCallback( @@ -224,34 +203,39 @@ function ConfigImpl({ ) : null )} -