From 282d2b945506cfd8a86414d200f073f233a58742 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Thu, 19 Mar 2020 21:47:50 +0800 Subject: [PATCH] chore: enhance layout --- src/components/SettingsBar.tsx | 2 +- src/components/SimpleToggleField.tsx | 32 ++++---- .../settings/AccessTokenSettings.tsx | 74 +++++++++---------- src/components/settings/Field.tsx | 33 +++++++++ src/components/settings/FileTreeSettings.tsx | 39 +++++----- src/components/settings/SettingsSection.tsx | 4 +- src/components/settings/SidebarSettings.tsx | 36 +++++---- src/content.scss | 24 +++--- 8 files changed, 144 insertions(+), 100 deletions(-) create mode 100644 src/components/settings/Field.tsx diff --git a/src/components/SettingsBar.tsx b/src/components/SettingsBar.tsx index 9b9c712..b1554a8 100644 --- a/src/components/SettingsBar.tsx +++ b/src/components/SettingsBar.tsx @@ -54,7 +54,7 @@ function SettingsBarContent() { return ( <> -

Settings

+

Settings

diff --git a/src/components/SimpleToggleField.tsx b/src/components/SimpleToggleField.tsx index ed0b03f..e45ea2a 100644 --- a/src/components/SimpleToggleField.tsx +++ b/src/components/SimpleToggleField.tsx @@ -1,6 +1,6 @@ import { useConfigs } from 'containers/ConfigsContext' import * as React from 'react' -import { cx } from 'utils/cx' +import { Field } from './settings/Field' import { SimpleField } from './SettingsBar' type Props = { @@ -13,7 +13,23 @@ export function SimpleToggleField({ field, onChange }: Props) { const configContext = useConfigs() const value = configContext.val[field.key] return ( -
+ + {field.label}{' '} + {field.wikiLink ? ( + + (?) + + ) : ( + field.description &&

{field.description}

+ )} + + } + className={'field-checkbox'} + checkbox + > - -
+ ) } diff --git a/src/components/settings/AccessTokenSettings.tsx b/src/components/settings/AccessTokenSettings.tsx index 00b3ba9..c4a3e71 100644 --- a/src/components/settings/AccessTokenSettings.tsx +++ b/src/components/settings/AccessTokenSettings.tsx @@ -62,50 +62,48 @@ export function AccessTokenSettings(props: React.PropsWithChildren) { return ( - Access Token + <> + Access Token{' '} - {' '} (?) - + } > - {!hasAccessToken && ( - { - // use js here to make sure redirect_uri is latest url - const url = `https://github.com/login/oauth/authorize?client_id=${ - oauth.clientId - }&scope=repo&redirect_uri=${encodeURIComponent(window.location.href)}` - window.location.href = url - }} - > - Create with OAuth (recommended) - + {hasAccessToken ? ( + + ) : ( + )} -
- focusInput.set(true)} - onBlur={() => focusInput.set(false)} - onChange={onInputAccessToken} - onKeyPress={onPressAccessToken} - /> - {hasAccessToken && !accessToken ? ( - - ) : ( - - )} -
{accessTokenHint && !focusInput.val && {accessTokenHint}}
) diff --git a/src/components/settings/Field.tsx b/src/components/settings/Field.tsx new file mode 100644 index 0000000..87031fe --- /dev/null +++ b/src/components/settings/Field.tsx @@ -0,0 +1,33 @@ +import * as React from 'react' +import { cx } from 'utils/cx' + +type Props = { + id?: string + className?: string + checkbox?: boolean + title: React.ReactNode +} + +export function Field({ + className, + title, + id, + checkbox, + children, +}: React.PropsWithChildren) { + return ( +
+ {checkbox ? ( + <> + {children} + + + ) : ( + <> + +
{children}
+ + )} +
+ ) +} diff --git a/src/components/settings/FileTreeSettings.tsx b/src/components/settings/FileTreeSettings.tsx index 24e97b2..67365c2 100644 --- a/src/components/settings/FileTreeSettings.tsx +++ b/src/components/settings/FileTreeSettings.tsx @@ -3,6 +3,7 @@ import { SimpleToggleField } from 'components/SimpleToggleField' import { useConfigs } from 'containers/ConfigsContext' import * as React from 'react' import { Config } from 'utils/configHelper' +import { Field } from './Field' import { SettingsSection } from './SettingsSection' const options: { @@ -33,27 +34,23 @@ export function FileTreeSettings(props: React.PropsWithChildren) { const configContext = useConfigs() return ( -
- -
- -
-
+ + + ) { return (
-

{title}

+ {title &&

{title}

} {children}
) diff --git a/src/components/settings/SidebarSettings.tsx b/src/components/settings/SidebarSettings.tsx index 10374f7..6142014 100644 --- a/src/components/settings/SidebarSettings.tsx +++ b/src/components/settings/SidebarSettings.tsx @@ -5,6 +5,7 @@ import * as React from 'react' import { friendlyFormatShortcut } from 'utils/general' import { useStates } from 'utils/hooks/useStates' import * as keyHelper from 'utils/keyHelper' +import { Field } from './Field' import { SettingsSection } from './SettingsSection' type Props = {} @@ -21,8 +22,7 @@ export function SidebarSettings(props: React.PropsWithChildren) { return ( -
- +
) { }, [])} readOnly /> - + {configContext.val.shortcut === toggleShowSideBarShortcut ? ( + + ) : ( + + )}
-
+