From f34d50da3d93e438649f419359b4f2d0f651ae02 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 20 Nov 2024 15:10:17 -0500 Subject: [PATCH] [Refactor] Extract 'FormItem' and 'SettingItem' (#1619) * Extract SettingItem component * Extract GeneralSettingItem * Rename to FormItem * nit * nit --- .../CustomFormValue.vue} | 0 src/components/common/FormItem.vue | 102 ++++++++++++++++++ .../dialog/content/setting/SettingGroup.vue | 99 +---------------- .../dialog/content/setting/SettingItem.vue | 35 ++++++ src/types/settingTypes.ts | 18 ++-- 5 files changed, 152 insertions(+), 102 deletions(-) rename src/components/{dialog/content/setting/CustomSettingValue.vue => common/CustomFormValue.vue} (100%) create mode 100644 src/components/common/FormItem.vue create mode 100644 src/components/dialog/content/setting/SettingItem.vue diff --git a/src/components/dialog/content/setting/CustomSettingValue.vue b/src/components/common/CustomFormValue.vue similarity index 100% rename from src/components/dialog/content/setting/CustomSettingValue.vue rename to src/components/common/CustomFormValue.vue diff --git a/src/components/common/FormItem.vue b/src/components/common/FormItem.vue new file mode 100644 index 000000000..cca3fe276 --- /dev/null +++ b/src/components/common/FormItem.vue @@ -0,0 +1,102 @@ + + + + + + diff --git a/src/components/dialog/content/setting/SettingGroup.vue b/src/components/dialog/content/setting/SettingGroup.vue index aeca73152..8f822fd96 100644 --- a/src/components/dialog/content/setting/SettingGroup.vue +++ b/src/components/dialog/content/setting/SettingGroup.vue @@ -7,45 +7,15 @@ :key="setting.id" class="setting-item flex items-center mb-4" > -
- - - - {{ setting.name }} - -
-
- -
+ - - diff --git a/src/components/dialog/content/setting/SettingItem.vue b/src/components/dialog/content/setting/SettingItem.vue new file mode 100644 index 000000000..83b4fcc0b --- /dev/null +++ b/src/components/dialog/content/setting/SettingItem.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/types/settingTypes.ts b/src/types/settingTypes.ts index 879da016f..24ebb2ec6 100644 --- a/src/types/settingTypes.ts +++ b/src/types/settingTypes.ts @@ -29,15 +29,10 @@ export interface Setting { render: () => HTMLElement } -export interface SettingParams { +export interface SettingParams extends FormItem { id: keyof Settings - name: string - type: SettingInputType | SettingCustomRenderer defaultValue: any onChange?: (newValue: any, oldValue?: any) => void - attrs?: any - tooltip?: string - options?: Array | ((value: any) => SettingOption[]) // By default category is id.split('.'). However, changing id to assign // new category has poor backward compatibility. Use this field to overwrite // default category from id. @@ -52,3 +47,14 @@ export interface SettingParams { // Version of the setting when it was last modified versionModified?: string } + +/** + * The base form item for rendering in a form. + */ +export interface FormItem { + name: string + type: SettingInputType | SettingCustomRenderer + tooltip?: string + attrs?: Record + options?: Array | ((value: any) => SettingOption[]) +}