@docpensieve/components 0.1.3 → 0.1.5
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/package.json +2 -2
- package/src/classes.js +20 -0
- package/src/for-theme.js +45 -0
- package/src/index.js +10 -1
- package/src/registry.js +2 -0
- package/types/classes.d.ts +8 -0
- package/types/for-theme.d.ts +24 -0
- package/types/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docpensieve/components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "DocPensieve global MDX components, usable without import: Card, Columns, Tooltip, Tree, Skill, TimeTimer, LogoIcon, ScrollToTop",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"types"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@docpensieve/shared": "0.1.
|
|
23
|
+
"@docpensieve/shared": "0.1.5"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "^19"
|
package/src/classes.js
CHANGED
|
@@ -35,6 +35,26 @@ export function getThemeClasses() {
|
|
|
35
35
|
return themeClasses;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Framework of the active theme, announced alongside the class table. Empty
|
|
40
|
+
* until then.
|
|
41
|
+
*/
|
|
42
|
+
let themeFramework = '';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Declares the framework of the active theme, which `ForTheme` reads.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} [framework]
|
|
48
|
+
*/
|
|
49
|
+
export function setThemeFramework(framework = '') {
|
|
50
|
+
themeFramework = framework;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @returns {string} The active framework, or `''` when none was announced. */
|
|
54
|
+
export function getThemeFramework() {
|
|
55
|
+
return themeFramework;
|
|
56
|
+
}
|
|
57
|
+
|
|
38
58
|
/**
|
|
39
59
|
* Converts a slot name into a fallback class.
|
|
40
60
|
*
|
package/src/for-theme.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content kept for one theme only.
|
|
3
|
+
*
|
|
4
|
+
* A page that shows how to style a component cannot say the same thing to
|
|
5
|
+
* every site: with the utility theme, the look comes from its classes; with
|
|
6
|
+
* the custom theme, from classes the project writes itself. `ForTheme` keeps
|
|
7
|
+
* each variant for the site whose theme matches, at build time — the other
|
|
8
|
+
* one does not even reach the HTML. Changing the theme in the configuration
|
|
9
|
+
* therefore changes what the pages show, without editing them.
|
|
10
|
+
*
|
|
11
|
+
* @module @docpensieve/components/for-theme
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { Fragment, createElement as h } from 'react';
|
|
15
|
+
|
|
16
|
+
import { DocPensieveError, THEME_FRAMEWORKS } from '@docpensieve/shared';
|
|
17
|
+
|
|
18
|
+
import { getThemeFramework } from './classes.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Renders its children only when the site's theme is `framework`.
|
|
22
|
+
*
|
|
23
|
+
* @param {{ framework?: string, children?: any }} props
|
|
24
|
+
* @returns {any}
|
|
25
|
+
* @throws {DocPensieveError} For a framework the configuration does not know,
|
|
26
|
+
* or when no theme was announced.
|
|
27
|
+
*/
|
|
28
|
+
export function ForTheme({ framework, children }) {
|
|
29
|
+
if (!framework || !THEME_FRAMEWORKS.includes(framework)) {
|
|
30
|
+
throw new DocPensieveError(`<ForTheme> does not know the framework "${framework ?? ''}".`, {
|
|
31
|
+
hint: `framework expects one of: ${THEME_FRAMEWORKS.join(', ')}.`,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Rendering nothing here would drop every variant: a page emptied without
|
|
36
|
+
// a word.
|
|
37
|
+
const active = getThemeFramework();
|
|
38
|
+
if (!active) {
|
|
39
|
+
throw new DocPensieveError('<ForTheme> was rendered before any theme was announced.', {
|
|
40
|
+
hint: 'The generator announces the theme with setThemeFramework() before rendering.',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return active === framework ? h(Fragment, null, children) : null;
|
|
45
|
+
}
|
package/src/index.js
CHANGED
|
@@ -9,7 +9,15 @@
|
|
|
9
9
|
* @module @docpensieve/components
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
classNames,
|
|
14
|
+
cls,
|
|
15
|
+
fallbackClass,
|
|
16
|
+
getThemeClasses,
|
|
17
|
+
getThemeFramework,
|
|
18
|
+
setThemeClasses,
|
|
19
|
+
setThemeFramework,
|
|
20
|
+
} from './classes.js';
|
|
13
21
|
export { Card, CardBody, CardFooter, CardHeader, CardImage } from './card.js';
|
|
14
22
|
export { Column, Columns } from './columns.js';
|
|
15
23
|
export { FallbackAfter, FallbackBefore, TimeTimer } from './time-timer.js';
|
|
@@ -18,6 +26,7 @@ export { Tree, TreeItem } from './tree.js';
|
|
|
18
26
|
export { ScrollToTop } from './scroll-to-top.js';
|
|
19
27
|
export { SKILL_SHAPES, Skill } from './skill.js';
|
|
20
28
|
export { LogoIcon } from './logo-icon.js';
|
|
29
|
+
export { ForTheme } from './for-theme.js';
|
|
21
30
|
export { componentsCss } from './styles.js';
|
|
22
31
|
export { getSiteContext, resolveFile, resolveUrl, setSiteContext } from './site.js';
|
|
23
32
|
export { builtinComponents, createRegistry, listComponentNames } from './registry.js';
|
package/src/registry.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { Card, CardBody, CardFooter, CardHeader, CardImage } from './card.js';
|
|
11
11
|
import { Column, Columns } from './columns.js';
|
|
12
|
+
import { ForTheme } from './for-theme.js';
|
|
12
13
|
import { LogoIcon } from './logo-icon.js';
|
|
13
14
|
import { ScrollToTop } from './scroll-to-top.js';
|
|
14
15
|
import { Skill } from './skill.js';
|
|
@@ -37,6 +38,7 @@ export const builtinComponents = {
|
|
|
37
38
|
ScrollToTop,
|
|
38
39
|
Skill,
|
|
39
40
|
LogoIcon,
|
|
41
|
+
ForTheme,
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
/**
|
package/types/classes.d.ts
CHANGED
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
export declare function setThemeClasses(classes?: Record<string, string>): void;
|
|
18
18
|
/** @returns {Record<string, string>} The current table, for inspection. */
|
|
19
19
|
export declare function getThemeClasses(): Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Declares the framework of the active theme, which `ForTheme` reads.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} [framework]
|
|
24
|
+
*/
|
|
25
|
+
export declare function setThemeFramework(framework?: string): void;
|
|
26
|
+
/** @returns {string} The active framework, or `''` when none was announced. */
|
|
27
|
+
export declare function getThemeFramework(): string;
|
|
20
28
|
/**
|
|
21
29
|
* Converts a slot name into a fallback class.
|
|
22
30
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content kept for one theme only.
|
|
3
|
+
*
|
|
4
|
+
* A page that shows how to style a component cannot say the same thing to
|
|
5
|
+
* every site: with the utility theme, the look comes from its classes; with
|
|
6
|
+
* the custom theme, from classes the project writes itself. `ForTheme` keeps
|
|
7
|
+
* each variant for the site whose theme matches, at build time — the other
|
|
8
|
+
* one does not even reach the HTML. Changing the theme in the configuration
|
|
9
|
+
* therefore changes what the pages show, without editing them.
|
|
10
|
+
*
|
|
11
|
+
* @module @docpensieve/components/for-theme
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Renders its children only when the site's theme is `framework`.
|
|
15
|
+
*
|
|
16
|
+
* @param {{ framework?: string, children?: any }} props
|
|
17
|
+
* @returns {any}
|
|
18
|
+
* @throws {DocPensieveError} For a framework the configuration does not know,
|
|
19
|
+
* or when no theme was announced.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ForTheme({ framework, children }: {
|
|
22
|
+
framework?: string;
|
|
23
|
+
children?: any;
|
|
24
|
+
}): any;
|
package/types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module @docpensieve/components
|
|
10
10
|
*/
|
|
11
|
-
export { classNames, cls, fallbackClass, getThemeClasses, setThemeClasses } from './classes.js';
|
|
11
|
+
export { classNames, cls, fallbackClass, getThemeClasses, getThemeFramework, setThemeClasses, setThemeFramework, } from './classes.js';
|
|
12
12
|
export { Card, CardBody, CardFooter, CardHeader, CardImage } from './card.js';
|
|
13
13
|
export { Column, Columns } from './columns.js';
|
|
14
14
|
export { FallbackAfter, FallbackBefore, TimeTimer } from './time-timer.js';
|
|
@@ -17,6 +17,7 @@ export { Tree, TreeItem } from './tree.js';
|
|
|
17
17
|
export { ScrollToTop } from './scroll-to-top.js';
|
|
18
18
|
export { SKILL_SHAPES, Skill } from './skill.js';
|
|
19
19
|
export { LogoIcon } from './logo-icon.js';
|
|
20
|
+
export { ForTheme } from './for-theme.js';
|
|
20
21
|
export { componentsCss } from './styles.js';
|
|
21
22
|
export { getSiteContext, resolveFile, resolveUrl, setSiteContext } from './site.js';
|
|
22
23
|
export { builtinComponents, createRegistry, listComponentNames } from './registry.js';
|