From b9bd07c53d8c624f14f9b7da71ff1e4de099a029 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 5 Feb 2026 12:39:14 +0000 Subject: Refactor checkbox-list custom field implementation - Replaced the PluginIcon with EnumerationField in the custom field registration. - Introduced CheckboxListDefaultInput component for handling checkbox list inputs. - Updated the admin interface to include new settings for the checkbox-list custom field. - Enhanced server-side registration to support resizable input size for the checkbox-list. --- admin/src/index.ts | 93 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 18 deletions(-) (limited to 'admin/src/index.ts') diff --git a/admin/src/index.ts b/admin/src/index.ts index f3e7a28..a1c0473 100644 --- a/admin/src/index.ts +++ b/admin/src/index.ts @@ -1,25 +1,10 @@ -import { Check } from '@strapi/icons'; +import { EnumerationField } from '@strapi/icons/symbols'; import { Initializer } from './components/Initializer'; -import { PluginIcon } from './components/PluginIcon'; +import { CheckboxListDefaultInput } from './components/CheckboxListDefaultInput'; import { PLUGIN_ID } from './pluginId'; -import { getTranslation } from './utils/getTranslation'; export default { register(app: any) { - app.addMenuLink({ - to: `plugins/${PLUGIN_ID}`, - icon: PluginIcon, - intlLabel: { - id: `${PLUGIN_ID}.plugin.name`, - defaultMessage: PLUGIN_ID, - }, - Component: async () => { - const { App } = await import('./pages/App'); - - return App; - }, - }); - app.registerPlugin({ id: PLUGIN_ID, initializer: Initializer, @@ -27,11 +12,20 @@ export default { name: PLUGIN_ID, }); + const ctbPlugin = app.getPlugin?.('content-type-builder'); + + if (ctbPlugin?.apis?.forms?.components?.add) { + ctbPlugin.apis.forms.components.add({ + id: 'checkbox-list-default', + component: CheckboxListDefaultInput, + }); + } + app.customFields.register({ name: 'checkbox-list', pluginId: PLUGIN_ID, type: 'json', - icon: Check, + icon: EnumerationField, intlLabel: { id: `${PLUGIN_ID}.customField.label`, defaultMessage: 'Checkbox list', @@ -71,6 +65,69 @@ export default { ], }, ], + advanced: [ + { + sectionTitle: null, + items: [ + { + name: 'default', + type: 'checkbox-list-default', + size: 6, + intlLabel: { + id: 'form.attribute.settings.default', + defaultMessage: 'Default value', + }, + validations: {}, + }, + { + name: 'options.enumName', + type: 'text', + size: 6, + intlLabel: { + id: 'form.attribute.item.enumeration.graphql', + defaultMessage: 'Name override for GraphQL', + }, + description: { + id: 'form.attribute.item.enumeration.graphql.description', + defaultMessage: 'Allows you to override the default generated name for GraphQL', + }, + validations: {}, + }, + ], + }, + { + sectionTitle: { + id: 'global.settings', + defaultMessage: 'Settings', + }, + items: [ + { + name: 'required', + type: 'checkbox', + intlLabel: { + id: 'form.attribute.item.requiredField', + defaultMessage: 'Required field', + }, + description: { + id: 'form.attribute.item.requiredField.description', + defaultMessage: "You won't be able to create an entry if this field is empty", + }, + }, + { + name: 'private', + type: 'checkbox', + intlLabel: { + id: 'form.attribute.item.privateField', + defaultMessage: 'Private field', + }, + description: { + id: 'form.attribute.item.privateField.description', + defaultMessage: 'This field will not show up in the API response', + }, + }, + ], + }, + ], }, }); }, -- cgit v1.2.3