From a86f78554c6865edd37ed81a691ebdba08a04bd4 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 29 May 2022 23:27:05 +0800 Subject: [PATCH] feat: use primer select --- src/components/SelectInput.tsx | 46 ++++++++++++++------ src/components/settings/FileTreeSettings.tsx | 46 +++++++++----------- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/components/SelectInput.tsx b/src/components/SelectInput.tsx index ff3a130..9ba17af 100644 --- a/src/components/SelectInput.tsx +++ b/src/components/SelectInput.tsx @@ -1,18 +1,44 @@ +import { FormControl, Select, SelectProps } from '@primer/react' import * as React from 'react' + +export type Option = { + key: string + label: string + value: T +} + export function SelectInput({ value, onChange, + label, options, ...selectProps }: Override< - React.DetailedHTMLProps, HTMLSelectElement>, + SelectProps, IO & { + label: string options: Option[] } >) { return ( -
- { const key = e.target.value const option = options.find(option => option.key === key) @@ -22,17 +48,11 @@ export function SelectInput({ {...selectProps} > {options.map(option => ( - + ))} - - -
+ + ) } -export type Option = { - key: string - label: string - value: T -} diff --git a/src/components/settings/FileTreeSettings.tsx b/src/components/settings/FileTreeSettings.tsx index 96ab893..756571a 100644 --- a/src/components/settings/FileTreeSettings.tsx +++ b/src/components/settings/FileTreeSettings.tsx @@ -4,7 +4,6 @@ import { useConfigs } from 'containers/ConfigsContext' import * as React from 'react' import { Config } from 'utils/config/helper' import { Option, SelectInput } from '../SelectInput' -import { Field } from './Field' import { SettingsSection } from './SettingsSection' const iconOptions: Option[] = [ @@ -42,30 +41,27 @@ export function FileTreeSettings() { const configContext = useConfigs() return ( - - { - configContext.onChange({ - recursiveToggleFolder: v, - }) - }} - value={configContext.value.recursiveToggleFolder} - /> - - - - id="file-tree-icons" - options={iconOptions} - onChange={v => { - configContext.onChange({ - icons: v, - }) - }} - value={configContext.value.icons} - /> - + { + configContext.onChange({ + recursiveToggleFolder: v, + }) + }} + value={configContext.value.recursiveToggleFolder} + /> + + + label="Icons" + options={iconOptions} + onChange={v => { + configContext.onChange({ + icons: v, + }) + }} + value={configContext.value.icons} + />