From 5f27a6bc94cb52914558a743a7aa923742b8f5c1 Mon Sep 17 00:00:00 2001 From: Steve Heffernan Date: Mon, 9 Feb 2026 13:49:43 -0800 Subject: [PATCH] docs(site): update getting started code examples to match new api (#473) Co-authored-by: Darius Cepulis --- .../installation/HTMLCdnCodeBlock.tsx | 35 +++++++++ .../installation/HTMLInstallTabs.tsx | 65 ++++++++++++++++ .../installation/HTMLUsageCodeBlock.tsx | 74 +++++++++++-------- .../installation/MuxUploaderPanel.tsx | 4 +- .../installation/ReactCreateCodeBlock.tsx | 55 ++++++++++---- .../installation/ReactUsageCodeBlock.tsx | 3 +- .../installation/RendererSelect.tsx | 61 ++++++++++----- .../components/installation/SkinPicker.tsx | 36 ++++++--- .../installation/SkinPickerSection.astro | 12 +++ .../installation/SkinPickerSectionClient.tsx | 19 +++++ site/src/content/docs/how-to/installation.mdx | 51 ++----------- site/src/stores/installation.ts | 15 +++- 12 files changed, 306 insertions(+), 124 deletions(-) create mode 100644 site/src/components/installation/HTMLCdnCodeBlock.tsx create mode 100644 site/src/components/installation/HTMLInstallTabs.tsx create mode 100644 site/src/components/installation/SkinPickerSection.astro create mode 100644 site/src/components/installation/SkinPickerSectionClient.tsx diff --git a/site/src/components/installation/HTMLCdnCodeBlock.tsx b/site/src/components/installation/HTMLCdnCodeBlock.tsx new file mode 100644 index 00000000..4c7a7f49 --- /dev/null +++ b/site/src/components/installation/HTMLCdnCodeBlock.tsx @@ -0,0 +1,35 @@ +import { useStore } from '@nanostores/react'; +import ClientCode from '@/components/Code/ClientCode'; +import type { Skin, UseCase } from '@/stores/installation'; +import { skin, useCase } from '@/stores/installation'; + +function getSkinImportParts(skin: Skin): { group: string; skinFile: string } { + if (skin === 'minimal-video') return { group: 'video', skinFile: 'minimal-skin' }; + if (skin === 'minimal-audio') return { group: 'audio', skinFile: 'minimal-skin' }; + return { group: skin, skinFile: 'skin' }; +} + +function generateCdnCode(useCase: UseCase, skin: Skin): string { + if (useCase === 'background-video') { + return ` +`; + } + + const { group, skinFile } = getSkinImportParts(skin); + + return ` +`; +} + +export default function HTMLCdnCodeBlock() { + const $useCase = useStore(useCase); + const $skin = useStore(skin); + + return ; +} diff --git a/site/src/components/installation/HTMLInstallTabs.tsx b/site/src/components/installation/HTMLInstallTabs.tsx new file mode 100644 index 00000000..be6d9f26 --- /dev/null +++ b/site/src/components/installation/HTMLInstallTabs.tsx @@ -0,0 +1,65 @@ +import { useEffect, useRef } from 'react'; +import ClientCode from '@/components/Code/ClientCode'; +import { Tab, TabsList, TabsPanel, TabsRoot } from '@/components/Tabs'; +import type { InstallMethod } from '@/stores/installation'; +import { installMethod } from '@/stores/installation'; +import HTMLCdnCodeBlock from './HTMLCdnCodeBlock'; + +export default function HTMLInstallTabs() { + const ref = useRef(null); + + // Observe tab changes and sync to installMethod store + useEffect(() => { + const root = ref.current?.querySelector('[data-tabs-root]'); + if (!root) return; + + const observer = new MutationObserver(() => { + const activeTab = root.querySelector('[role="tab"][data-tab-active="true"]'); + if (activeTab) { + const value = activeTab.getAttribute('data-value'); + if (value) { + installMethod.set(value as InstallMethod); + } + } + }); + + // Observe all tab elements for attribute changes + const tabs = root.querySelectorAll('[role="tab"]'); + tabs.forEach((tab) => { + observer.observe(tab, { attributes: true, attributeFilter: ['data-tab-active'] }); + }); + + return () => observer.disconnect(); + }, []); + + return ( +
+ + + + cdn + + npm + pnpm + yarn + bun + + + + + + + + + + + + + + + + + +
+ ); +} diff --git a/site/src/components/installation/HTMLUsageCodeBlock.tsx b/site/src/components/installation/HTMLUsageCodeBlock.tsx index 14d8c5e8..71e7a0ab 100644 --- a/site/src/components/installation/HTMLUsageCodeBlock.tsx +++ b/site/src/components/installation/HTMLUsageCodeBlock.tsx @@ -2,18 +2,21 @@ import { useStore } from '@nanostores/react'; import ClientCode from '@/components/Code/ClientCode'; import { Tab, TabsList, TabsPanel, TabsRoot } from '@/components/Tabs'; import type { Renderer, Skin, UseCase } from '@/stores/installation'; -import { muxPlaybackId, renderer, skin, useCase } from '@/stores/installation'; +import { installMethod, muxPlaybackId, renderer, skin, useCase } from '@/stores/installation'; function getRendererTag(renderer: Renderer): string { const map: Record = { + 'background-video': 'background-video', cloudflare: 'cloudflare-video', dash: 'dash-video', hls: 'hls-video', 'html5-audio': 'audio', 'html5-video': 'video', jwplayer: 'jwplayer-video', - mux: 'mux-video', - shaka: 'shaka-video', + 'mux-audio': 'mux-audio', + 'mux-background-video': 'mux-background-video', + 'mux-video': 'mux-video', + // shaka: 'shaka-video', spotify: 'spotify-audio', vimeo: 'vimeo-video', wistia: 'wistia-video', @@ -31,11 +34,16 @@ function getProviderTag(useCase: UseCase): string { return map[useCase]; } -function getSkinTag(skin: Skin): string { +function getSkinTag(useCase: UseCase, skin: Skin): string { + // Background video has fixed skin + if (useCase === 'background-video') { + return 'background-video-skin'; + } const map: Record = { - 'default-video': 'video-skin', - 'default-audio': 'audio-skin', - minimal: 'minimal-video-skin', + video: 'video-skin', + audio: 'audio-skin', + 'minimal-video': 'minimal-video-skin', + 'minimal-audio': 'minimal-audio-skin', }; return map[skin]; } @@ -43,8 +51,8 @@ function getSkinTag(skin: Skin): string { function getRendererElement(renderer: Renderer, playbackId: string | null): string { const tag = getRendererTag(renderer); - // When renderer is 'mux' and we have a playback ID, use playback-id attribute - if (renderer === 'mux' && playbackId) { + // When renderer is a mux variant and we have a playback ID, use playback-id attribute + if ((renderer === 'mux-video' || renderer === 'mux-audio' || renderer === 'mux-background-video') && playbackId) { return `<${tag} playback-id="${playbackId}">`; } @@ -54,7 +62,7 @@ function getRendererElement(renderer: Renderer, playbackId: string | null): stri function generateHTMLCode(useCase: UseCase, skin: Skin, renderer: Renderer, playbackId: string | null): string { const providerTag = getProviderTag(useCase); - const skinTag = getSkinTag(skin); + const skinTag = getSkinTag(useCase, skin); const rendererElement = getRendererElement(renderer, playbackId); return `