@elastic/eui-docusaurus-preset 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.txt ADDED
@@ -0,0 +1,6 @@
1
+ Source code in this repository is covered by (i) a dual license under the Server
2
+ Side Public License, v 1 and the Elastic License 2.0 or (ii) an Apache License
3
+ 2.0 compatible license or (iii) solely under the Elastic License 2.0, in each
4
+ case, as noted in the applicable header. The default throughout the repository
5
+ is a dual license under the Server Side Public License, v 1 and the Elastic
6
+ License 2.0, unless the header specifies another license.
package/README.md ADDED
@@ -0,0 +1,216 @@
1
+ # `@elastic/eui-docusaurus-preset`
2
+
3
+ EUI custom [Docusaurus](https://docusaurus.io/) preset made for the EUI [documentation website](https://eui.elastic.co).
4
+
5
+ ## Overview
6
+
7
+ The preset comes with themes and plugins configured.
8
+
9
+ ### Themes
10
+
11
+ | Theme | Description |
12
+ |---------------------------------|----------------------------------------------------|
13
+ | `@docusaurus/theme-classic` | Base Docusaurus theme (required for compatibility) |
14
+ | `@elastic/eui-docusaurus-theme` | EUI custom theme for Docusaurus |
15
+
16
+ ### Plugins
17
+
18
+ | Plugin | Description. | Enabled by default? |
19
+ |----------------------------------------|---------------------------------------------------------------------|---------------------------|
20
+ | `ignore-styles-plugin` | Prevents Infima and some inherited styles from polluting global CSS | Yes |
21
+ | `@docusaurus/plugin-content-docs` | Documentation pages support | Yes (configurable) |
22
+ | `@docusaurus/plugin-content-pages` | Static pages support | Yes (configurable) |
23
+ | `@docusaurus/plugin-svgr` | SVG import support | Yes (configurable) |
24
+ | `@docusaurus/plugin-content-blog` | Blog support | Yes (configurable) |
25
+ | `@docusaurus/plugin-sitemap` | Sitemap generation (for SEO) | Only in production builds |
26
+ | `@docusaurus/plugin-google-analytics` | Google Analytics integration | If configured |
27
+ | `@docusaurus/plugin-google-tag-manager`| Google Tag Manager integration | If configured |
28
+ | `@docusaurus/plugin-google-gtag` | Google Global Site Tag integration | If configured |
29
+
30
+ ## Usage
31
+
32
+ The EUI preset uses the [preset constructor](https://docusaurus.io/docs/using-plugins#creating-presets) to define the theme (`@elastic/eui-docusaurus-theme`) and plugins.
33
+
34
+ To use it in your Docusaurus project, install the package:
35
+
36
+ ```shell
37
+ # npm
38
+ npm install @elastic/eui-docusaurus-preset
39
+
40
+ # pnpm
41
+ pnpm add @elastic/eui-docusaurus-preset
42
+
43
+ # Yarn
44
+ yarn add @elastic/eui-docusaurus-preset
45
+ ```
46
+
47
+ and in your `docusaurus.config.ts` file, add:
48
+
49
+ ```ts
50
+ const config: Config = {
51
+ // ...
52
+ presets: [
53
+ [
54
+ require.resolve("@elastic/eui-docusaurus-preset"),
55
+ {
56
+ docs: {
57
+ sidebarPath: "./sidebars.ts",
58
+ },
59
+ } satisfies Preset.Options,
60
+ ],
61
+ ],
62
+ // ...
63
+ }
64
+ ```
65
+
66
+ ### Theme only
67
+
68
+ Docusaurus uses Infima, its default CSS framework, to style the classic theme (`@docusaurus/theme-classic`). The EUI Docusaurus theme is based on the classic theme, but Infima's global styles often override or conflict with EUI's design system, leading to inconsistent appearance. The `ignore-styles-plugin` disables Infima's styles, ensuring the EUI theme displays correctly. For this reason, we highly recommend using the preset rather than the standalone theme.
69
+
70
+ If you prefer to use only the theme, refer to [Theme only](../docusaurus-theme/README.md#theme-only) section in `@elastic/eui-docusaurus-theme`.
71
+
72
+ ## Local development
73
+
74
+ ### Prerequisites
75
+
76
+ This package requires:
77
+
78
+ - Node.js (check current version in [.nvmrc](../../.nvmrc)),
79
+ - [corepack](https://nodejs.org/api/corepack.html).
80
+
81
+ ### Installing dependencies
82
+
83
+ Please run `yarn` to install dependencies:
84
+
85
+ ```shell
86
+ yarn
87
+ ```
88
+
89
+ ### Building the package
90
+
91
+ ```shell
92
+ yarn build
93
+ ```
94
+
95
+ ### Building in watch mode
96
+
97
+ Run the following command to build this package whenever a file is edited:
98
+
99
+ ```shell
100
+ yarn start
101
+ ```
102
+
103
+ :::warning
104
+ Please note that this package is configured to do incremental builds and sometimes `tsc` may not update the `lib` directory with your latest changes if you rename or delete files.
105
+
106
+ If that's the case please run `yarn build`.
107
+ :::
108
+
109
+ ### Test with EUI documentation website
110
+
111
+ Run the following command from the root of the mono-repository to run the website:
112
+
113
+ ```shell
114
+ yarn workspace @elastic/eui-website start
115
+ ```
116
+
117
+ You can pair it with the watch mode when modifying the Docusaurus theme.
118
+
119
+ ### Test locally with your own Docusaurus project
120
+
121
+ You should have a Docusaurus project running. If you want to test EUI theme with a fresh project, you should create a [Docusaurus scaffolded project website](https://docusaurus.io/docs/installation).
122
+
123
+ Run the following command to create a Docusaurus project:
124
+
125
+ ```shell
126
+ npx create-docusaurus@latest my-website classic --typescript
127
+ ```
128
+
129
+ Install `yalc` globally if you haven't already:
130
+
131
+ ```shell
132
+ npm install -g yalc
133
+ ```
134
+
135
+ In the root of the mono-repository, run the following commands to build and publish the preset locally:
136
+
137
+ ```shell
138
+ yarn workspace @elastic/eui-docusaurus-preset build
139
+
140
+ # Publish the preset locally
141
+ cd packages/docusaurus-preset
142
+ yalc publish
143
+ ```
144
+
145
+ In your project, install EUI dependencies:
146
+
147
+ ```shell
148
+ # npm
149
+ npm install @elastic/eui @elastic/charts @emotion/react @emotion/css moment
150
+
151
+ # pnpm
152
+ pnpm add @elastic/eui @elastic/charts @emotion/react @emotion/css moment
153
+
154
+ # Yarn
155
+ yarn add @elastic/eui @elastic/charts @emotion/react @emotion/css moment
156
+ ```
157
+
158
+ and add the locally published packages:
159
+
160
+ ```shell
161
+ yalc add @elastic/eui-docusaurus-preset
162
+
163
+ # npm
164
+ npm install
165
+
166
+ # pnpm
167
+ pnpm install
168
+
169
+ # Yarn
170
+ yarn
171
+ ```
172
+
173
+ Configure Docusaurus to use the locally built preset as outlined in the [Usage section](#usage).
174
+
175
+ #### Making changes
176
+
177
+ When you make changes to the preset, rebuild and republish the packages:
178
+
179
+ ```shell
180
+ # From the mono-repository root
181
+ yarn workspace @elastic/eui-docusaurus-preset build
182
+
183
+ cd packages/docusaurus-preset
184
+ yalc publish --push
185
+ ```
186
+
187
+ The `--push` flag automatically updates all projects using these packages.
188
+
189
+ Restart your Docusaurus development server:
190
+
191
+ ```shell
192
+ # npm
193
+ npm run start
194
+
195
+ # pnpm
196
+ pnpm start
197
+
198
+ # Yarn
199
+ yarn start
200
+ ```
201
+
202
+ When you're done testing, remove the locally published packages from your project:
203
+
204
+ ```shell
205
+ # In your project
206
+ yalc remove @elastic/eui-docusaurus-preset
207
+
208
+ # npm
209
+ npm install
210
+
211
+ # pnpm
212
+ pnpm install
213
+
214
+ # Yarn
215
+ yarn
216
+ ```
package/lib/index.js ADDED
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+ /**
9
+ * Docusaurus plugin to ignore any unwanted style imports, e.g. like Infima stylesheet imports.
10
+ * This is needed so that Infima doesn't pollute global CSS scope
11
+ * and affect how EUI components are rendered
12
+ */
13
+ const ignoreInheritedStylesPlugin = () => ({
14
+ name: 'ignore-styles-plugin',
15
+ configureWebpack() {
16
+ return {
17
+ module: {
18
+ rules: [
19
+ {
20
+ test: /node_modules\/infima/,
21
+ use: 'null-loader',
22
+ },
23
+ {
24
+ test: /node_modules\/@docusaurus\/theme-common\/lib\/hooks\/styles.css/,
25
+ use: 'null-loader',
26
+ },
27
+ ],
28
+ },
29
+ };
30
+ },
31
+ });
32
+ const makePluginConfig = (source, options) => {
33
+ if (!options) {
34
+ return require.resolve(source);
35
+ }
36
+ return [require.resolve(source), options];
37
+ };
38
+ export default function preset(context, options = {}) {
39
+ const isProd = process.env.NODE_ENV === 'production';
40
+ const themes = [
41
+ // EUI theme is based on the classic docusaurus theme
42
+ require.resolve('@docusaurus/theme-classic'),
43
+ require.resolve('@elastic/eui-docusaurus-theme'),
44
+ ];
45
+ const plugins = [
46
+ ignoreInheritedStylesPlugin,
47
+ makePluginConfig('@docusaurus/plugin-content-docs', options.docs),
48
+ makePluginConfig('@docusaurus/plugin-content-pages', options.pages),
49
+ makePluginConfig('@docusaurus/plugin-svgr', options.svgr),
50
+ ];
51
+ if (options.blog !== false) {
52
+ plugins.push(makePluginConfig('@docusaurus/plugin-content-blog', options.blog));
53
+ }
54
+ if (isProd) {
55
+ plugins.push(makePluginConfig('@docusaurus/plugin-sitemap', options.sitemap));
56
+ }
57
+ if (options.googleAnalytics) {
58
+ plugins.push(makePluginConfig('@docusaurus/plugin-google-analytics', options.googleAnalytics));
59
+ }
60
+ if (options.googleTagManager) {
61
+ plugins.push(makePluginConfig('@docusaurus/plugin-google-tag-manager', options.googleTagManager));
62
+ }
63
+ if (options.gtag) {
64
+ plugins.push(makePluginConfig('@docusaurus/plugin-google-gtag', options.gtag));
65
+ }
66
+ return { themes, plugins };
67
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@elastic/eui-docusaurus-preset",
3
+ "version": "1.0.0",
4
+ "description": "EUI preset for Docusaurus",
5
+ "license": "SEE LICENSE IN LICENSE.txt",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "start": "tsc --watch"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/elastic/eui.git",
15
+ "directory": "packages/docusaurus-preset"
16
+ },
17
+ "dependencies": {
18
+ "@elastic/eui-docusaurus-theme": "^2.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "@docusaurus/types": "^3.7.0",
22
+ "typescript": "~5.5.4"
23
+ },
24
+ "peerDependencies": {
25
+ "react": "^18.0.0 || ^19.0.0",
26
+ "react-dom": "^18.0.0 || ^19.0.0"
27
+ }
28
+ }
package/src/index.ts ADDED
@@ -0,0 +1,113 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import type {
10
+ LoadContext,
11
+ PluginConfig,
12
+ PluginModule,
13
+ PluginOptions,
14
+ Preset,
15
+ } from '@docusaurus/types';
16
+ import { Options } from './options';
17
+
18
+ /**
19
+ * Docusaurus plugin to ignore any unwanted style imports, e.g. like Infima stylesheet imports.
20
+ * This is needed so that Infima doesn't pollute global CSS scope
21
+ * and affect how EUI components are rendered
22
+ */
23
+ const ignoreInheritedStylesPlugin: PluginModule = () => ({
24
+ name: 'ignore-styles-plugin',
25
+ configureWebpack() {
26
+ return {
27
+ module: {
28
+ rules: [
29
+ {
30
+ test: /node_modules\/infima/,
31
+ use: 'null-loader',
32
+ },
33
+ {
34
+ test: /node_modules\/@docusaurus\/theme-common\/lib\/hooks\/styles.css/,
35
+ use: 'null-loader',
36
+ },
37
+ ],
38
+ },
39
+ };
40
+ },
41
+ });
42
+
43
+ const makePluginConfig = (
44
+ source: string,
45
+ options?: PluginOptions
46
+ ): string | [string, PluginOptions] => {
47
+ if (!options) {
48
+ return require.resolve(source);
49
+ }
50
+
51
+ return [require.resolve(source), options];
52
+ };
53
+
54
+ export default function preset(
55
+ context: LoadContext,
56
+ options: Options = {}
57
+ ): Preset {
58
+ const isProd = process.env.NODE_ENV === 'production';
59
+
60
+ const themes: PluginConfig[] = [
61
+ // EUI theme is based on the classic docusaurus theme
62
+ require.resolve('@docusaurus/theme-classic'),
63
+
64
+ require.resolve('@elastic/eui-docusaurus-theme'),
65
+ ];
66
+
67
+ const plugins: PluginConfig[] = [
68
+ ignoreInheritedStylesPlugin,
69
+ makePluginConfig('@docusaurus/plugin-content-docs', options.docs),
70
+ makePluginConfig('@docusaurus/plugin-content-pages', options.pages),
71
+ makePluginConfig('@docusaurus/plugin-svgr', options.svgr),
72
+ ];
73
+
74
+ if (options.blog !== false) {
75
+ plugins.push(
76
+ makePluginConfig('@docusaurus/plugin-content-blog', options.blog)
77
+ );
78
+ }
79
+
80
+ if (isProd) {
81
+ plugins.push(
82
+ makePluginConfig('@docusaurus/plugin-sitemap', options.sitemap)
83
+ );
84
+ }
85
+
86
+ if (options.googleAnalytics) {
87
+ plugins.push(
88
+ makePluginConfig(
89
+ '@docusaurus/plugin-google-analytics',
90
+ options.googleAnalytics
91
+ )
92
+ );
93
+ }
94
+
95
+ if (options.googleTagManager) {
96
+ plugins.push(
97
+ makePluginConfig(
98
+ '@docusaurus/plugin-google-tag-manager',
99
+ options.googleTagManager
100
+ )
101
+ );
102
+ }
103
+
104
+ if (options.gtag) {
105
+ plugins.push(
106
+ makePluginConfig('@docusaurus/plugin-google-gtag', options.gtag)
107
+ );
108
+ }
109
+
110
+ return { themes, plugins };
111
+ }
112
+
113
+ export type { Options };
package/src/options.ts ADDED
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ // Based on https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-preset-classic/src/options.ts
10
+
11
+ import type { ThemeConfig as BaseThemeConfig } from '@docusaurus/types';
12
+ import type { UserThemeConfig as ClassicThemeConfig } from '@docusaurus/theme-common';
13
+
14
+ import type { Options as DocsPluginOptions } from '@docusaurus/plugin-content-docs';
15
+ import type { Options as BlogPluginOptions } from '@docusaurus/plugin-content-blog';
16
+ import type { Options as PagesPluginOptions } from '@docusaurus/plugin-content-pages';
17
+ import type { Options as SitemapPluginOptions } from '@docusaurus/plugin-sitemap';
18
+ import type { Options as SVGRPluginOptions } from '@docusaurus/plugin-svgr';
19
+ import type { Options as ThemeOptions } from '@docusaurus/theme-classic';
20
+ import type { Options as GAPluginOptions } from '@docusaurus/plugin-google-analytics';
21
+ import type { Options as GtagPluginOptions } from '@docusaurus/plugin-google-gtag';
22
+ import type { Options as GTMPluginOptions } from '@docusaurus/plugin-google-tag-manager';
23
+
24
+ export type Options = {
25
+ /**
26
+ * Options for `@docusaurus/plugin-content-docs`.
27
+ */
28
+ docs?: DocsPluginOptions;
29
+
30
+ /**
31
+ * Options for `@docusaurus/plugin-content-pages`.
32
+ */
33
+ pages?: PagesPluginOptions;
34
+
35
+ /**
36
+ * Options for `@docusaurus/plugin-svgr`.
37
+ */
38
+ svgr?: SVGRPluginOptions;
39
+
40
+ /**
41
+ * Options for `@docusaurus/plugin-sitemap`.
42
+ * Enabled in production builds
43
+ */
44
+ sitemap?: SitemapPluginOptions;
45
+
46
+ /**
47
+ * Options for `@docusaurus/theme-classic`.
48
+ */
49
+ theme?: ThemeOptions;
50
+
51
+ /**
52
+ * Options for `@docusaurus/plugin-content-blog`.
53
+ * Use `false` to disable.
54
+ */
55
+ blog?: false | BlogPluginOptions;
56
+
57
+ /**
58
+ * Options for `@docusaurus/plugin-google-analytics`. Only enabled when the
59
+ * key is present.
60
+ */
61
+ googleAnalytics?: GAPluginOptions;
62
+
63
+ /**
64
+ * Options for `@docusaurus/plugin-google-gtag`. Only enabled when the key
65
+ * is present.
66
+ */
67
+ gtag?: GtagPluginOptions;
68
+
69
+ /**
70
+ * Options for `@docusaurus/plugin-google-tag-manager`. Only enabled when
71
+ * the key is present.
72
+ */
73
+ googleTagManager?: GTMPluginOptions;
74
+ };
75
+
76
+ export type ThemeConfig = BaseThemeConfig & ClassicThemeConfig;
package/tsconfig.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "outDir": "lib",
5
+ /* Emit */
6
+ "target": "ES2020",
7
+ "lib": ["ESNext", "DOM"],
8
+ "declaration": true,
9
+ // These two options will be selectively overridden in each project.
10
+ // Utility libraries will have source maps on, but plugins will not.
11
+ "declarationMap": false,
12
+ "sourceMap": false,
13
+ "jsx": "react-jsx",
14
+ "jsxImportSource": "@emotion/react",
15
+ "importHelpers": true,
16
+ "noEmitHelpers": true,
17
+
18
+ /* Strict Type-Checking Options */
19
+ "allowUnreachableCode": false,
20
+ // Too hard to turn on
21
+ "exactOptionalPropertyTypes": false,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "noImplicitOverride": true,
24
+ "noImplicitReturns": true,
25
+ // `process.env` is usually accessed as property
26
+ "noPropertyAccessFromIndexSignature": false,
27
+ "noUncheckedIndexedAccess": true,
28
+ /* strict family */
29
+ "strict": true,
30
+ "alwaysStrict": true,
31
+ "noImplicitAny": true,
32
+ "noImplicitThis": true,
33
+ "strictBindCallApply": true,
34
+ "strictFunctionTypes": true,
35
+ "strictNullChecks": true,
36
+ "strictPropertyInitialization": true,
37
+ "useUnknownInCatchVariables": true,
38
+ /* Handled by ESLint */
39
+ "noUnusedLocals": false,
40
+ "noUnusedParameters": false,
41
+ "importsNotUsedAsValues": "remove",
42
+
43
+ /* Module Resolution */
44
+ "moduleResolution": "Node",
45
+ "resolveJsonModule": true,
46
+ "allowSyntheticDefaultImports": true,
47
+ "esModuleInterop": true,
48
+ "forceConsistentCasingInFileNames": true,
49
+ "isolatedModules": true,
50
+ "allowJs": true,
51
+ "skipLibCheck": true
52
+ },
53
+ "include": ["src"],
54
+ "exclude": [
55
+ "node_modules"
56
+ ]
57
+ }