From aca578cb9dfdaed33f91c62ffdf3ef1a456c6a72 Mon Sep 17 00:00:00 2001 From: Haishan Date: Fri, 27 Dec 2019 13:12:49 +0800 Subject: refactor: abstract ButtonWithIcon as a button enhancer --- src/components/Button.js | 18 +----- src/components/Button.module.css | 14 +++-- src/components/Connections.js | 8 +-- src/components/Proxies.js | 6 +- src/components/ProxyProvider.js | 10 +--- src/components/Root.css | 116 +++++++++++++++++++++++++++++++++++++++ src/components/Rules.js | 8 +-- src/components/StyleGuide.js | 19 ++++--- 8 files changed, 149 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/components/Button.js b/src/components/Button.js index d9bcd22..ce83153 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -6,10 +6,11 @@ const noop = () => {}; const { memo, forwardRef } = React; -function Button({ children, label, onClick = noop }, ref) { +function Button({ children, label, text, start, onClick = noop }, ref) { return ( ); } @@ -22,17 +23,4 @@ export function ButtonPlain({ children, label, onClick = noop }) { ); } -function WithIcon({ text, icon, onClick = noop }, ref) { - return ( - - ); -} - -export const ButtonWithIcon = memo(forwardRef(WithIcon)); - export default memo(forwardRef(Button)); diff --git a/src/components/Button.module.css b/src/components/Button.module.css index c232a66..809e133 100644 --- a/src/components/Button.module.css +++ b/src/components/Button.module.css @@ -1,11 +1,14 @@ .btn { -webkit-appearance: none; outline: none; + user-select: none; + display: inline-flex; + align-items: center; + justify-content: center; color: var(--color-btn-fg); background: var(--color-btn-bg); border: 1px solid #555; border-radius: 100px; - user-select: none; &:focus { border-color: var(--color-focus-blue); } @@ -42,10 +45,9 @@ } } -.withIconWrapper { - display: flex; +.btnStart { + margin-right: 5px; + display: inline-flex; align-items: center; - .txt { - margin-left: 5px; - } + justify-content: center; } diff --git a/src/components/Connections.js b/src/components/Connections.js index c07de0a..b2617a6 100644 --- a/src/components/Connections.js +++ b/src/components/Connections.js @@ -6,7 +6,7 @@ import { useStoreState } from '../misc/store'; import { getClashAPIConfig } from '../ducks/app'; import { X as IconClose } from 'react-feather'; import SvgYacd from './SvgYacd'; -import { ButtonWithIcon } from './Button'; +import Button from './Button'; import ModalCloseAllConnections from './ModalCloseAllConnections'; import * as connAPI from '../api/connections'; @@ -89,11 +89,7 @@ function Conn() {
- +
-
diff --git a/src/components/ProxyProvider.js b/src/components/ProxyProvider.js index 3a0b2ef..9561907 100644 --- a/src/components/ProxyProvider.js +++ b/src/components/ProxyProvider.js @@ -10,7 +10,7 @@ import { getClashAPIConfig } from '../ducks/app'; import { connect } from './StateProvider'; import { SectionNameType } from './shared/Basic'; import { ProxyList, ProxyListSummaryView } from './ProxyGroup'; -import { ButtonWithIcon, ButtonPlain } from './Button'; +import Button, { ButtonPlain } from './Button'; import { updateProviderByName, @@ -69,12 +69,8 @@ function ProxyProvider({ item, dispatch }: Props) {
- } - onClick={updateProvider} - /> - } onClick={updateProvider} /> +
- +
); diff --git a/src/components/StyleGuide.js b/src/components/StyleGuide.js index 7b6f53d..63afb54 100644 --- a/src/components/StyleGuide.js +++ b/src/components/StyleGuide.js @@ -1,10 +1,11 @@ import React, { PureComponent } from 'react'; -import PropTypes from 'prop-types'; + +import { Zap } from 'react-feather'; import ToggleSwitch from './ToggleSwitch'; import Input from './Input'; import Switch from './Switch'; -import Button from './Button'; +import Button, { ButtonWithIcon, ButtonPlain } from './Button'; // import Modal from 'c/Modal'; // import APIConfig from 'c/APIConfig'; // import Proxy from 'c/Proxy'; @@ -28,10 +29,9 @@ const optionsRule = [ } ]; -const Pane = ({ children }) =>
{children}
; -Pane.propTypes = { - children: PropTypes.element -}; +const Pane = ({ children, style }) => ( +
{children}
+); class StyleGuide extends PureComponent { render() { @@ -52,7 +52,12 @@ class StyleGuide extends PureComponent { /> -