From efa89313fa4152252b477aafd88f7cf4a66747d8 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 5 Feb 2026 10:19:56 +0000 Subject: Initial Strapi plugin project --- admin/custom.d.ts | 2 ++ admin/src/components/Initializer.tsx | 19 ++++++++++++++++ admin/src/components/PluginIcon.tsx | 5 +++++ admin/src/index.ts | 43 ++++++++++++++++++++++++++++++++++++ admin/src/pages/App.tsx | 15 +++++++++++++ admin/src/pages/HomePage.tsx | 16 ++++++++++++++ admin/src/pluginId.ts | 1 + admin/src/translations/en.json | 1 + admin/src/utils/getTranslation.ts | 5 +++++ admin/tsconfig.build.json | 10 +++++++++ admin/tsconfig.json | 8 +++++++ 11 files changed, 125 insertions(+) create mode 100644 admin/custom.d.ts create mode 100644 admin/src/components/Initializer.tsx create mode 100644 admin/src/components/PluginIcon.tsx create mode 100644 admin/src/index.ts create mode 100644 admin/src/pages/App.tsx create mode 100644 admin/src/pages/HomePage.tsx create mode 100644 admin/src/pluginId.ts create mode 100644 admin/src/translations/en.json create mode 100644 admin/src/utils/getTranslation.ts create mode 100644 admin/tsconfig.build.json create mode 100644 admin/tsconfig.json (limited to 'admin') diff --git a/admin/custom.d.ts b/admin/custom.d.ts new file mode 100644 index 0000000..f5d1b28 --- /dev/null +++ b/admin/custom.d.ts @@ -0,0 +1,2 @@ +declare module '@strapi/design-system/*'; +declare module '@strapi/design-system'; diff --git a/admin/src/components/Initializer.tsx b/admin/src/components/Initializer.tsx new file mode 100644 index 0000000..8188291 --- /dev/null +++ b/admin/src/components/Initializer.tsx @@ -0,0 +1,19 @@ +import { useEffect, useRef } from 'react'; + +import { PLUGIN_ID } from '../pluginId'; + +type InitializerProps = { + setPlugin: (id: string) => void; +}; + +const Initializer = ({ setPlugin }: InitializerProps) => { + const ref = useRef(setPlugin); + + useEffect(() => { + ref.current(PLUGIN_ID); + }, []); + + return null; +}; + +export { Initializer }; diff --git a/admin/src/components/PluginIcon.tsx b/admin/src/components/PluginIcon.tsx new file mode 100644 index 0000000..54174ba --- /dev/null +++ b/admin/src/components/PluginIcon.tsx @@ -0,0 +1,5 @@ +import { PuzzlePiece } from '@strapi/icons'; + +const PluginIcon = () => ; + +export { PluginIcon }; diff --git a/admin/src/index.ts b/admin/src/index.ts new file mode 100644 index 0000000..4dff817 --- /dev/null +++ b/admin/src/index.ts @@ -0,0 +1,43 @@ +import { getTranslation } from './utils/getTranslation'; +import { PLUGIN_ID } from './pluginId'; +import { Initializer } from './components/Initializer'; +import { PluginIcon } from './components/PluginIcon'; + +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, + isReady: false, + name: PLUGIN_ID, + }); + }, + + async registerTrads({ locales }: { locales: string[] }) { + return Promise.all( + locales.map(async (locale) => { + try { + const { default: data } = await import(`./translations/${locale}.json`); + + return { data, locale }; + } catch { + return { data: {}, locale }; + } + }) + ); + }, +}; diff --git a/admin/src/pages/App.tsx b/admin/src/pages/App.tsx new file mode 100644 index 0000000..c77159c --- /dev/null +++ b/admin/src/pages/App.tsx @@ -0,0 +1,15 @@ +import { Page } from '@strapi/strapi/admin'; +import { Routes, Route } from 'react-router-dom'; + +import { HomePage } from './HomePage'; + +const App = () => { + return ( + + } /> + } /> + + ); +}; + +export { App }; diff --git a/admin/src/pages/HomePage.tsx b/admin/src/pages/HomePage.tsx new file mode 100644 index 0000000..bff4f4e --- /dev/null +++ b/admin/src/pages/HomePage.tsx @@ -0,0 +1,16 @@ +import { Main } from '@strapi/design-system'; +import { useIntl } from 'react-intl'; + +import { getTranslation } from '../utils/getTranslation'; + +const HomePage = () => { + const { formatMessage } = useIntl(); + + return ( +
+

Welcome to {formatMessage({ id: getTranslation('plugin.name') })}

+
+ ); +}; + +export { HomePage }; diff --git a/admin/src/pluginId.ts b/admin/src/pluginId.ts new file mode 100644 index 0000000..f2d57de --- /dev/null +++ b/admin/src/pluginId.ts @@ -0,0 +1 @@ +export const PLUGIN_ID = 'checkbox-list'; diff --git a/admin/src/translations/en.json b/admin/src/translations/en.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/admin/src/translations/en.json @@ -0,0 +1 @@ +{} diff --git a/admin/src/utils/getTranslation.ts b/admin/src/utils/getTranslation.ts new file mode 100644 index 0000000..e2e57f7 --- /dev/null +++ b/admin/src/utils/getTranslation.ts @@ -0,0 +1,5 @@ +import { PLUGIN_ID } from '../pluginId'; + +const getTranslation = (id: string) => `${PLUGIN_ID}.${id}`; + +export { getTranslation }; diff --git a/admin/tsconfig.build.json b/admin/tsconfig.build.json new file mode 100644 index 0000000..d033e0c --- /dev/null +++ b/admin/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig", + "include": ["./src", "./custom.d.ts"], + "exclude": ["**/*.test.ts", "**/*.test.tsx"], + "compilerOptions": { + "rootDir": "../", + "baseUrl": ".", + "outDir": "./dist" + } +} diff --git a/admin/tsconfig.json b/admin/tsconfig.json new file mode 100644 index 0000000..102f3ca --- /dev/null +++ b/admin/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "@strapi/typescript-utils/tsconfigs/admin", + "include": ["./src", "./custom.d.ts"], + "compilerOptions": { + "rootDir": "../", + "baseUrl": "." + } +} -- cgit v1.2.3