From a603e991442133c546052c66adc0203f02f4d389 Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Mon, 20 Jun 2022 01:34:13 +0100 Subject: [PATCH 1/3] chore: export common settings options --- framework/core/js/src/admin/components/AdminPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/js/src/admin/components/AdminPage.tsx b/framework/core/js/src/admin/components/AdminPage.tsx index 39f8fe2951..acccd0c448 100644 --- a/framework/core/js/src/admin/components/AdminPage.tsx +++ b/framework/core/js/src/admin/components/AdminPage.tsx @@ -57,7 +57,7 @@ export type HTMLInputTypes = | 'url' | 'week'; -interface CommonSettingsItemOptions extends Mithril.Attributes { +export interface CommonSettingsItemOptions extends Mithril.Attributes { setting: string; label: Mithril.Children; help?: Mithril.Children; From 0b00c40708bd4e7f7692285e5dbe7d80b9f6420b Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Mon, 20 Jun 2022 02:59:43 +0100 Subject: [PATCH 2/3] feat: support custom reusable setting components for `buildSettingComponent` --- .../js/src/admin/components/AdminPage.tsx | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/framework/core/js/src/admin/components/AdminPage.tsx b/framework/core/js/src/admin/components/AdminPage.tsx index acccd0c448..f15bc0f22c 100644 --- a/framework/core/js/src/admin/components/AdminPage.tsx +++ b/framework/core/js/src/admin/components/AdminPage.tsx @@ -11,6 +11,7 @@ import saveSettings from '../utils/saveSettings'; import AdminHeader from './AdminHeader'; import generateElementId from '../utils/generateElementId'; import ColorPreviewInput from '../../common/components/ColorPreviewInput'; +import ItemList from '../../common/utils/ItemList'; export interface AdminHeaderOptions { title: Mithril.Children; @@ -120,7 +121,9 @@ export type SettingsComponentOptions = | SwitchSettingComponentOptions | SelectSettingComponentOptions | TextareaSettingComponentOptions - | ColorPreviewSettingComponentOptions; + | ColorPreviewSettingComponentOptions + // For custom settings component options + | string; /** * Valid attrs that can be returned by the `headerInfo` function @@ -185,6 +188,41 @@ export default abstract class AdminPage { + * return ( + *
+ * + * {attrs.help &&

{attrs.help}

} + * + * My setting component! + *
+ * ); + * }) + * }) + * ``` + */ + customSettingComponents(): ItemList<(attributes: CommonSettingsItemOptions) => Mithril.Children> { + const items = new ItemList<(attributes: CommonSettingsItemOptions) => Mithril.Children>(); + + return items; + } + /** * `buildSettingComponent` takes a settings object and turns it into a component. * Depending on the type of input, you can set the type to 'bool', 'select', or @@ -228,6 +266,8 @@ export default abstract class AdminPage ); + } else if (customSettingComponents.has(type)) { + return customSettingComponents.get(type)({ setting, help, label, ...componentAttrs }); } else { - componentAttrs.className = classList(['FormControl', componentAttrs.className]); + componentAttrs.className = classList('FormControl', componentAttrs.className); if ((TextareaSettingTypes as readonly string[]).includes(type)) { settingElement =