Skip to content

Commit 3864995

Browse files
committed
feat(site): list required css imports per skin in preset reference
Closes #1519
1 parent 0cfd3bb commit 3864995

9 files changed

Lines changed: 34 additions & 20 deletions

File tree

site/scripts/api-docs-builder/src/pipeline.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ export { generateFeatureReferences } from './feature-handler.js';
549549
export interface PresetSkinDef {
550550
name: string;
551551
tagName?: string;
552+
cssImport?: string;
552553
}
553554

554555
export interface PresetReference {

site/scripts/api-docs-builder/src/preset-handler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function scanHtmlDirectory(scanDir: string): { skins: PresetSkinDef[]; mediaElem
384384
return { skins, mediaElement };
385385
}
386386

387-
function scanReactDirectory(scanDir: string, barrelPath: string): PresetSkinDef[] {
387+
function scanReactDirectory(scanDir: string, barrelPath: string, presetName: string): PresetSkinDef[] {
388388
const skins: PresetSkinDef[] = [];
389389

390390
if (!fs.existsSync(scanDir)) return skins;
@@ -397,11 +397,16 @@ function scanReactDirectory(scanDir: string, barrelPath: string): PresetSkinDef[
397397
for (const file of files) {
398398
const filePath = path.join(scanDir, file);
399399
const exports = extractValueExports(filePath);
400+
const basename = path.basename(file, path.extname(file));
401+
const cssFile = path.join(scanDir, `${basename}.css`);
402+
const cssImport = fs.existsSync(cssFile) ? `@videojs/react/${presetName}/${basename}.css` : undefined;
400403

401404
for (const name of exports) {
402405
if (isFeatureBundle(name)) continue;
403406
if (isReactSkin(name)) {
404-
skins.push({ name });
407+
const skin: PresetSkinDef = { name };
408+
if (cssImport) skin.cssImport = cssImport;
409+
skins.push(skin);
405410
}
406411
}
407412
}
@@ -426,7 +431,7 @@ function buildPresetReference(preset: PresetInfo, featureBundleMap: Map<string,
426431

427432
// Scan React directory for skins, read barrel for media element
428433
const reactSkins = preset.react
429-
? scanReactDirectory(preset.react.scanDir, preset.react.barrelPath)
434+
? scanReactDirectory(preset.react.scanDir, preset.react.barrelPath, preset.name)
430435
: ([] as PresetSkinDef[]);
431436
const reactMediaElement = preset.react ? findReactMediaElement(preset.react.barrelPath) : undefined;
432437

site/scripts/api-docs-builder/src/tests/e2e.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,14 @@ describe('Preset pipeline (end-to-end)', () => {
930930
expect(ref.html.mediaElement).toBeUndefined();
931931
});
932932

933-
it('detects React skins', () => {
933+
it('detects React skins with CSS imports', () => {
934934
const skins = findPreset('video')!.reference.react.skins;
935-
expect(skins).toEqual(expect.arrayContaining([{ name: 'VideoSkin' }, { name: 'MinimalVideoSkin' }]));
935+
expect(skins).toEqual(
936+
expect.arrayContaining([
937+
{ name: 'VideoSkin', cssImport: '@videojs/react/video/skin.css' },
938+
{ name: 'MinimalVideoSkin', cssImport: '@videojs/react/video/minimal-skin.css' },
939+
])
940+
);
936941
});
937942

938943
it('excludes React tailwind skins', () => {
@@ -971,9 +976,9 @@ describe('Preset pipeline (end-to-end)', () => {
971976
expect(ref.html.mediaElement).toBeUndefined();
972977
});
973978

974-
it('detects single React skin', () => {
979+
it('detects single React skin with CSS import', () => {
975980
const skins = findPreset('audio')!.reference.react.skins;
976-
expect(skins).toEqual([{ name: 'AudioSkin' }]);
981+
expect(skins).toEqual([{ name: 'AudioSkin', cssImport: '@videojs/react/audio/skin.css' }]);
977982
});
978983

979984
it('detects React media element', () => {
@@ -1012,7 +1017,7 @@ describe('Preset pipeline (end-to-end)', () => {
10121017
expect(skinNames).not.toContain('BackgroundVideoPlayerElement');
10131018
});
10141019

1015-
it('detects React skin', () => {
1020+
it('detects React skin without CSS import when no CSS file exists', () => {
10161021
const skins = findPreset('background')!.reference.react.skins;
10171022
expect(skins).toEqual([{ name: 'BackgroundVideoSkin' }]);
10181023
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* fixture */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* fixture */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* fixture */

site/src/components/docs/api-reference/PresetReference.astro

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,16 @@ const listFormat = new Intl.ListFormat('en', { style: 'long', type: 'unit' });
142142
<dd>
143143
<FrameworkCase frameworks={["react"]}>
144144
{preset.react.skins.length > 0
145-
? listFormat
146-
.formatToParts(
147-
preset.react.skins.map((s) => s.name),
148-
)
149-
.map((part) =>
150-
part.type === "element" ? (
151-
<MarkdownCode class="inline-block whitespace-nowrap">{`<${part.value}>`}</MarkdownCode>
152-
) : (
153-
<span>{part.value}</span>
154-
),
155-
)
145+
? preset.react.skins.map((skin) => (
146+
<div class="mb-2 last:mb-0">
147+
<MarkdownCode class="inline-block whitespace-nowrap">{`<${skin.name}>`}</MarkdownCode>
148+
{skin.cssImport && (
149+
<div class="mt-0.5">
150+
<MarkdownCode class="text-sm inline-block whitespace-nowrap">{`import '${skin.cssImport}';`}</MarkdownCode>
151+
</div>
152+
)}
153+
</div>
154+
))
156155
: ""}
157156
</FrameworkCase>
158157
<FrameworkCase frameworks={["html"]}>

site/src/content/docs/concepts/skins.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ There are currently two options for styling:
105105

106106
<FrameworkCase frameworks={["react"]}>
107107

108-
- Vanilla CSS where you import the stylesheet in your app. This is the default.
108+
- Vanilla CSS import the stylesheet listed for each skin in the [preset table](#skins-features-and-presets). This is the default.
109109
- Tailwind where you [eject](../how-to/customize-skins#ejecting) the skin and use Tailwind classnames in your app.
110110

111111
</FrameworkCase>

site/src/types/preset-reference.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { z } from 'astro/zod';
66
export const PresetSkinDefSchema = z.object({
77
name: z.string(),
88
tagName: z.string().optional(),
9+
cssImport: z.string().optional(),
910
});
1011

1112
export const PresetReferenceSchema = z.object({

0 commit comments

Comments
 (0)