@djangocfg/ui-nextjs 1.4.45
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 +21 -0
- package/README.md +152 -0
- package/package.json +110 -0
- package/src/animations/AnimatedBackground.tsx +645 -0
- package/src/animations/index.ts +2 -0
- package/src/blocks/ArticleCard.tsx +94 -0
- package/src/blocks/ArticleList.tsx +95 -0
- package/src/blocks/CTASection.tsx +136 -0
- package/src/blocks/FeatureSection.tsx +104 -0
- package/src/blocks/Hero.tsx +102 -0
- package/src/blocks/NewsletterSection.tsx +119 -0
- package/src/blocks/StatsSection.tsx +103 -0
- package/src/blocks/SuperHero.tsx +328 -0
- package/src/blocks/TestimonialSection.tsx +122 -0
- package/src/blocks/index.ts +9 -0
- package/src/components/README.md +2018 -0
- package/src/components/breadcrumb-navigation.tsx +127 -0
- package/src/components/breadcrumb.tsx +132 -0
- package/src/components/button-download.tsx +275 -0
- package/src/components/dropdown-menu.tsx +219 -0
- package/src/components/index.ts +86 -0
- package/src/components/markdown/MarkdownMessage.tsx +338 -0
- package/src/components/markdown/index.ts +5 -0
- package/src/components/menubar.tsx +274 -0
- package/src/components/multi-select-pro/async.tsx +608 -0
- package/src/components/multi-select-pro/helpers.tsx +84 -0
- package/src/components/multi-select-pro/index.tsx +622 -0
- package/src/components/navigation-menu.tsx +153 -0
- package/src/components/pagination-static.tsx +348 -0
- package/src/components/pagination.tsx +138 -0
- package/src/components/phone-input.tsx +276 -0
- package/src/components/sidebar.tsx +866 -0
- package/src/components/sonner.tsx +31 -0
- package/src/components/ssr-pagination.tsx +237 -0
- package/src/hooks/index.ts +19 -0
- package/src/hooks/useCfgRouter.ts +153 -0
- package/src/hooks/useLocalStorage.ts +221 -0
- package/src/hooks/useQueryParams.ts +73 -0
- package/src/hooks/useSessionStorage.ts +188 -0
- package/src/hooks/useTheme.ts +57 -0
- package/src/index.ts +24 -0
- package/src/lib/index.ts +2 -0
- package/src/styles/index.css +2 -0
- package/src/theme/ForceTheme.tsx +115 -0
- package/src/theme/ThemeProvider.tsx +82 -0
- package/src/theme/ThemeToggle.tsx +52 -0
- package/src/theme/index.ts +3 -0
- package/src/tools/JsonForm/JsonSchemaForm.tsx +199 -0
- package/src/tools/JsonForm/examples/BotConfigExample.tsx +245 -0
- package/src/tools/JsonForm/examples/RealBotConfigExample.tsx +157 -0
- package/src/tools/JsonForm/index.ts +46 -0
- package/src/tools/JsonForm/templates/ArrayFieldItemTemplate.tsx +46 -0
- package/src/tools/JsonForm/templates/ArrayFieldTemplate.tsx +73 -0
- package/src/tools/JsonForm/templates/BaseInputTemplate.tsx +106 -0
- package/src/tools/JsonForm/templates/ErrorListTemplate.tsx +34 -0
- package/src/tools/JsonForm/templates/FieldTemplate.tsx +61 -0
- package/src/tools/JsonForm/templates/ObjectFieldTemplate.tsx +43 -0
- package/src/tools/JsonForm/templates/index.ts +12 -0
- package/src/tools/JsonForm/types.ts +83 -0
- package/src/tools/JsonForm/utils.ts +212 -0
- package/src/tools/JsonForm/widgets/CheckboxWidget.tsx +36 -0
- package/src/tools/JsonForm/widgets/NumberWidget.tsx +88 -0
- package/src/tools/JsonForm/widgets/SelectWidget.tsx +100 -0
- package/src/tools/JsonForm/widgets/SwitchWidget.tsx +34 -0
- package/src/tools/JsonForm/widgets/TextWidget.tsx +95 -0
- package/src/tools/JsonForm/widgets/index.ts +12 -0
- package/src/tools/JsonTree/index.tsx +252 -0
- package/src/tools/LottiePlayer/LottiePlayer.client.tsx +212 -0
- package/src/tools/LottiePlayer/index.tsx +54 -0
- package/src/tools/LottiePlayer/types.ts +108 -0
- package/src/tools/LottiePlayer/useLottie.ts +163 -0
- package/src/tools/Mermaid/Mermaid.client.tsx +341 -0
- package/src/tools/Mermaid/index.tsx +40 -0
- package/src/tools/OpenapiViewer/components/EndpointInfo.tsx +144 -0
- package/src/tools/OpenapiViewer/components/EndpointsLibrary.tsx +255 -0
- package/src/tools/OpenapiViewer/components/PlaygroundLayout.tsx +123 -0
- package/src/tools/OpenapiViewer/components/PlaygroundStepper.tsx +98 -0
- package/src/tools/OpenapiViewer/components/RequestBuilder.tsx +164 -0
- package/src/tools/OpenapiViewer/components/RequestParametersForm.tsx +253 -0
- package/src/tools/OpenapiViewer/components/ResponseViewer.tsx +169 -0
- package/src/tools/OpenapiViewer/components/VersionSelector.tsx +64 -0
- package/src/tools/OpenapiViewer/components/index.ts +14 -0
- package/src/tools/OpenapiViewer/constants.ts +39 -0
- package/src/tools/OpenapiViewer/context/PlaygroundContext.tsx +338 -0
- package/src/tools/OpenapiViewer/hooks/index.ts +8 -0
- package/src/tools/OpenapiViewer/hooks/useMobile.ts +10 -0
- package/src/tools/OpenapiViewer/hooks/useOpenApiSchema.ts +203 -0
- package/src/tools/OpenapiViewer/index.tsx +36 -0
- package/src/tools/OpenapiViewer/types.ts +152 -0
- package/src/tools/OpenapiViewer/utils/apiKeyManager.ts +149 -0
- package/src/tools/OpenapiViewer/utils/formatters.ts +71 -0
- package/src/tools/OpenapiViewer/utils/index.ts +9 -0
- package/src/tools/OpenapiViewer/utils/versionManager.ts +161 -0
- package/src/tools/PrettyCode/PrettyCode.client.tsx +217 -0
- package/src/tools/PrettyCode/index.tsx +43 -0
- package/src/tools/VideoPlayer/README.md +239 -0
- package/src/tools/VideoPlayer/VideoControls.tsx +138 -0
- package/src/tools/VideoPlayer/VideoPlayer.tsx +230 -0
- package/src/tools/VideoPlayer/index.ts +9 -0
- package/src/tools/VideoPlayer/types.ts +62 -0
- package/src/tools/index.ts +43 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Highlight, Language, themes } from 'prism-react-renderer';
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import { Copy, Check } from 'lucide-react';
|
|
6
|
+
import { useCopy } from '@djangocfg/ui-core/hooks';
|
|
7
|
+
import { useTheme } from '../../hooks/useTheme';
|
|
8
|
+
|
|
9
|
+
interface PrettyCodeProps {
|
|
10
|
+
data: string | object;
|
|
11
|
+
language: Language;
|
|
12
|
+
className?: string;
|
|
13
|
+
mode?: 'dark' | 'light';
|
|
14
|
+
inline?: boolean;
|
|
15
|
+
customBg?: string; // Custom background class
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const PrettyCode = ({ data, language, className, mode, inline = false, customBg }: PrettyCodeProps) => {
|
|
19
|
+
const detectedTheme = useTheme();
|
|
20
|
+
const [copied, setCopied] = useState(false);
|
|
21
|
+
const { copyToClipboard } = useCopy({
|
|
22
|
+
successMessage: "Code copied to clipboard",
|
|
23
|
+
errorMessage: "Failed to copy code"
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Use provided mode or fall back to detected theme
|
|
27
|
+
const currentTheme = mode || detectedTheme;
|
|
28
|
+
const isDarkMode = currentTheme === 'dark';
|
|
29
|
+
|
|
30
|
+
// Select the Prism theme based on the current theme
|
|
31
|
+
const prismTheme = isDarkMode ? themes.vsDark : themes.vsLight;
|
|
32
|
+
|
|
33
|
+
// Convert form object to JSON string with proper formatting
|
|
34
|
+
const contentJson = typeof data === 'string' ? data : JSON.stringify(data || {}, null, 2);
|
|
35
|
+
|
|
36
|
+
// Handle copy
|
|
37
|
+
const handleCopy = async () => {
|
|
38
|
+
const success = await copyToClipboard(contentJson);
|
|
39
|
+
if (success) {
|
|
40
|
+
setCopied(true);
|
|
41
|
+
setTimeout(() => setCopied(false), 2000);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Handle empty content
|
|
46
|
+
if (!contentJson || contentJson.trim() === '') {
|
|
47
|
+
const bgClass = customBg || 'bg-muted dark:bg-zinc-900';
|
|
48
|
+
return (
|
|
49
|
+
<div className={`relative h-full ${bgClass} rounded-sm border border-border dark:border-zinc-700 ${className || ''}`}>
|
|
50
|
+
<div className="h-full overflow-auto p-4">
|
|
51
|
+
<p className="text-muted-foreground text-sm italic">No content available</p>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Get display name for language badge
|
|
58
|
+
const getLanguageDisplayName = (lang: string): string => {
|
|
59
|
+
switch (lang.toLowerCase()) {
|
|
60
|
+
case 'bash':
|
|
61
|
+
case 'shell':
|
|
62
|
+
return 'Bash';
|
|
63
|
+
case 'python':
|
|
64
|
+
case 'py':
|
|
65
|
+
return 'Python';
|
|
66
|
+
case 'javascript':
|
|
67
|
+
case 'js':
|
|
68
|
+
return 'JavaScript';
|
|
69
|
+
case 'typescript':
|
|
70
|
+
case 'ts':
|
|
71
|
+
return 'TypeScript';
|
|
72
|
+
case 'json':
|
|
73
|
+
return 'JSON';
|
|
74
|
+
case 'yaml':
|
|
75
|
+
case 'yml':
|
|
76
|
+
return 'YAML';
|
|
77
|
+
case 'html':
|
|
78
|
+
return 'HTML';
|
|
79
|
+
case 'css':
|
|
80
|
+
return 'CSS';
|
|
81
|
+
case 'sql':
|
|
82
|
+
return 'SQL';
|
|
83
|
+
case 'xml':
|
|
84
|
+
return 'XML';
|
|
85
|
+
case 'markdown':
|
|
86
|
+
case 'md':
|
|
87
|
+
return 'Markdown';
|
|
88
|
+
case 'plaintext':
|
|
89
|
+
case 'text':
|
|
90
|
+
return 'Text';
|
|
91
|
+
case 'mermaid':
|
|
92
|
+
return 'Mermaid';
|
|
93
|
+
default:
|
|
94
|
+
return lang.charAt(0).toUpperCase() + lang.slice(1);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Normalize language for Prism - use only basic supported languages
|
|
99
|
+
const normalizedLanguage = (() => {
|
|
100
|
+
const lang = language.toLowerCase();
|
|
101
|
+
|
|
102
|
+
// Try basic languages that are definitely supported
|
|
103
|
+
switch (lang) {
|
|
104
|
+
case 'javascript':
|
|
105
|
+
case 'js':
|
|
106
|
+
return 'javascript';
|
|
107
|
+
case 'typescript':
|
|
108
|
+
case 'ts':
|
|
109
|
+
return 'typescript'; // Try TypeScript first
|
|
110
|
+
case 'python':
|
|
111
|
+
case 'py':
|
|
112
|
+
return 'python';
|
|
113
|
+
case 'json':
|
|
114
|
+
return 'json';
|
|
115
|
+
case 'css':
|
|
116
|
+
return 'css';
|
|
117
|
+
case 'html':
|
|
118
|
+
return 'markup';
|
|
119
|
+
case 'xml':
|
|
120
|
+
return 'markup';
|
|
121
|
+
case 'bash':
|
|
122
|
+
case 'shell':
|
|
123
|
+
return 'bash';
|
|
124
|
+
case 'sql':
|
|
125
|
+
return 'sql';
|
|
126
|
+
case 'yaml':
|
|
127
|
+
case 'yml':
|
|
128
|
+
return 'yaml';
|
|
129
|
+
case 'markdown':
|
|
130
|
+
case 'md':
|
|
131
|
+
return 'markdown';
|
|
132
|
+
case 'mermaid':
|
|
133
|
+
return 'text'; // Mermaid is handled separately in MarkdownMessage
|
|
134
|
+
default:
|
|
135
|
+
// For unknown languages, try to use the original name first
|
|
136
|
+
// If it doesn't work, Prism will fallback to plain text
|
|
137
|
+
return lang || 'text';
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
|
|
141
|
+
const displayLanguage = getLanguageDisplayName(language);
|
|
142
|
+
|
|
143
|
+
if (inline) {
|
|
144
|
+
const inlineBgClass = customBg || 'bg-muted dark:bg-[#1e1e1e]';
|
|
145
|
+
return (
|
|
146
|
+
<Highlight theme={prismTheme} code={contentJson} language={normalizedLanguage as Language}>
|
|
147
|
+
{({ className, style, tokens, getTokenProps }) => (
|
|
148
|
+
<code
|
|
149
|
+
className={`${className} ${inlineBgClass} px-2 py-1 rounded text-sm font-mono inline-block`}
|
|
150
|
+
style={{
|
|
151
|
+
...style,
|
|
152
|
+
fontSize: '0.875rem',
|
|
153
|
+
fontFamily: 'monospace',
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
{tokens.map((line) => (
|
|
157
|
+
line.map((token, key) => (
|
|
158
|
+
<span key={key} {...getTokenProps({ token })} />
|
|
159
|
+
))
|
|
160
|
+
))}
|
|
161
|
+
</code>
|
|
162
|
+
)}
|
|
163
|
+
</Highlight>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const bgClass = customBg || 'bg-muted dark:bg-[#1e1e1e]';
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<div className={`relative h-full ${bgClass} rounded-sm border border-border dark:border-zinc-800 dark:shadow-sm ${className || ''}`}>
|
|
171
|
+
{/* Header with language badge and copy button */}
|
|
172
|
+
<div className="absolute top-2 left-3 right-3 z-10 flex items-center justify-between">
|
|
173
|
+
<span className="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-background/80 text-muted-foreground border border-border/50 backdrop-blur-sm">
|
|
174
|
+
{displayLanguage}
|
|
175
|
+
</span>
|
|
176
|
+
<button
|
|
177
|
+
onClick={handleCopy}
|
|
178
|
+
className="inline-flex items-center justify-center p-1.5 rounded text-muted-foreground hover:text-foreground bg-background/80 border border-border/50 backdrop-blur-sm transition-colors"
|
|
179
|
+
title="Copy code"
|
|
180
|
+
>
|
|
181
|
+
{copied ? <Check className="h-3.5 w-3.5 text-green-500" /> : <Copy className="h-3.5 w-3.5" />}
|
|
182
|
+
</button>
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<div className="h-full overflow-auto">
|
|
186
|
+
<Highlight theme={prismTheme} code={contentJson} language={normalizedLanguage as Language}>
|
|
187
|
+
{({ className, style, tokens, getLineProps, getTokenProps }) => (
|
|
188
|
+
<pre
|
|
189
|
+
className={`${className}`}
|
|
190
|
+
style={{
|
|
191
|
+
...style,
|
|
192
|
+
margin: 0,
|
|
193
|
+
padding: '2.5rem 1rem 1rem 1rem', // Extra top padding for language badge
|
|
194
|
+
fontSize: '0.875rem',
|
|
195
|
+
lineHeight: 1.5,
|
|
196
|
+
fontFamily: 'monospace',
|
|
197
|
+
whiteSpace: 'pre-wrap',
|
|
198
|
+
wordBreak: 'break-word',
|
|
199
|
+
overflowWrap: 'break-word',
|
|
200
|
+
}}
|
|
201
|
+
>
|
|
202
|
+
{tokens.map((line, i) => (
|
|
203
|
+
<div key={i} {...getLineProps({ line })}>
|
|
204
|
+
{line.map((token, key) => (
|
|
205
|
+
<span key={key} {...getTokenProps({ token })} />
|
|
206
|
+
))}
|
|
207
|
+
</div>
|
|
208
|
+
))}
|
|
209
|
+
</pre>
|
|
210
|
+
)}
|
|
211
|
+
</Highlight>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export default PrettyCode;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PrettyCode Component - Dynamic Import Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Lazy loads the heavy Prism library (~500KB) only when needed.
|
|
5
|
+
* This significantly reduces the initial bundle size.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use client';
|
|
9
|
+
|
|
10
|
+
import dynamic from 'next/dynamic';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import type { Language } from 'prism-react-renderer';
|
|
13
|
+
|
|
14
|
+
// Dynamic import with loading state
|
|
15
|
+
const PrettyCodeClient = dynamic(() => import('./PrettyCode.client'), {
|
|
16
|
+
ssr: false,
|
|
17
|
+
loading: () => (
|
|
18
|
+
<div className="relative rounded-sm border border-border overflow-hidden bg-muted dark:bg-zinc-900">
|
|
19
|
+
<div className="p-4">
|
|
20
|
+
<div className="flex items-center gap-2">
|
|
21
|
+
<div className="animate-pulse h-4 w-4 rounded-full bg-muted-foreground/20"></div>
|
|
22
|
+
<span className="text-xs text-muted-foreground">Loading code...</span>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
interface PrettyCodeProps {
|
|
30
|
+
data: string | object;
|
|
31
|
+
language: Language;
|
|
32
|
+
className?: string;
|
|
33
|
+
mode?: 'dark' | 'light';
|
|
34
|
+
inline?: boolean;
|
|
35
|
+
customBg?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const PrettyCode: React.FC<PrettyCodeProps> = (props) => {
|
|
39
|
+
return <PrettyCodeClient {...props} />;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default PrettyCode;
|
|
43
|
+
export type { Language };
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# VideoPlayer - Professional Vidstack Implementation
|
|
2
|
+
|
|
3
|
+
A professional, accessible video player built with Vidstack React that supports YouTube, Vimeo, MP4, HLS, and more.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Multi-platform support**: YouTube, Vimeo, MP4, HLS, DASH
|
|
8
|
+
- ✅ **Custom controls**: Professional UI with hover effects
|
|
9
|
+
- ✅ **Accessibility**: Full keyboard navigation and screen reader support
|
|
10
|
+
- ✅ **Responsive**: Works on all screen sizes
|
|
11
|
+
- ✅ **TypeScript**: Full type safety
|
|
12
|
+
- ✅ **Themes**: Default, minimal, and modern themes
|
|
13
|
+
- ✅ **No recommendations**: Clean playback without YouTube distractions
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
The VideoPlayer is already included in the UI package with all dependencies:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @vidstack/react@next media-icons@next
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Basic Usage
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { VideoPlayer } from '@djangocfg/ui-nextjs/tools';
|
|
27
|
+
|
|
28
|
+
function MyComponent() {
|
|
29
|
+
return (
|
|
30
|
+
<VideoPlayer
|
|
31
|
+
source={{
|
|
32
|
+
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
33
|
+
title: 'Never Gonna Give You Up',
|
|
34
|
+
description: 'Rick Astley - Never Gonna Give You Up (Official Video)'
|
|
35
|
+
}}
|
|
36
|
+
autoplay={false}
|
|
37
|
+
controls={true}
|
|
38
|
+
className="max-w-4xl mx-auto"
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Advanced Usage
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { VideoPlayer, VideoPlayerRef } from '@djangocfg/ui-nextjs/tools';
|
|
48
|
+
import { useRef } from 'react';
|
|
49
|
+
|
|
50
|
+
function AdvancedPlayer() {
|
|
51
|
+
const playerRef = useRef<VideoPlayerRef>(null);
|
|
52
|
+
|
|
53
|
+
const handleCustomPlay = () => {
|
|
54
|
+
playerRef.current?.play();
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<VideoPlayer
|
|
59
|
+
ref={playerRef}
|
|
60
|
+
source={{
|
|
61
|
+
url: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
|
|
62
|
+
title: 'Big Buck Bunny',
|
|
63
|
+
poster: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg',
|
|
64
|
+
duration: 596
|
|
65
|
+
}}
|
|
66
|
+
theme="modern"
|
|
67
|
+
autoplay={false}
|
|
68
|
+
muted={false}
|
|
69
|
+
playsInline={true}
|
|
70
|
+
showInfo={true}
|
|
71
|
+
onPlay={() => console.log('Video started')}
|
|
72
|
+
onPause={() => console.log('Video paused')}
|
|
73
|
+
onEnded={() => console.log('Video ended')}
|
|
74
|
+
onError={(error) => console.error('Video error:', error)}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Supported Video Sources
|
|
81
|
+
|
|
82
|
+
### YouTube
|
|
83
|
+
- **URL Format**: `https://www.youtube.com/watch?v=VIDEO_ID` or `youtube/VIDEO_ID`
|
|
84
|
+
- **Auto-conversion**: Full YouTube URLs are automatically converted to `youtube/ID` format
|
|
85
|
+
- **Poster**: ⚠️ YouTube iframe ignores custom poster images and always shows YouTube's thumbnail
|
|
86
|
+
- **Examples**:
|
|
87
|
+
```tsx
|
|
88
|
+
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
|
|
89
|
+
url: 'https://youtu.be/dQw4w9WgXcQ'
|
|
90
|
+
url: 'youtube/dQw4w9WgXcQ'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Vimeo
|
|
94
|
+
- **URL Format**: `https://vimeo.com/VIDEO_ID` or `vimeo/VIDEO_ID`
|
|
95
|
+
- **Auto-conversion**: Full Vimeo URLs are automatically converted to `vimeo/ID` format
|
|
96
|
+
- **Poster**: ⚠️ Vimeo may ignore custom poster and use their own thumbnail
|
|
97
|
+
- **Example**: `url: 'vimeo/76979871'`
|
|
98
|
+
|
|
99
|
+
### Direct Video Files (MP4, WebM, OGG)
|
|
100
|
+
- **Poster**: ✅ **Works perfectly!** Custom poster images are fully supported
|
|
101
|
+
- **Examples**:
|
|
102
|
+
```tsx
|
|
103
|
+
url: 'https://example.com/video.mp4',
|
|
104
|
+
poster: '/images/video-poster.jpg' // This works!
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### HLS Streams
|
|
108
|
+
- **Poster**: ✅ Custom poster supported
|
|
109
|
+
- **Example**: `url: 'https://example.com/stream.m3u8'`
|
|
110
|
+
|
|
111
|
+
### DASH Streams
|
|
112
|
+
- **Poster**: ✅ Custom poster supported
|
|
113
|
+
- **Example**: `url: 'https://example.com/stream.mpd'`
|
|
114
|
+
|
|
115
|
+
> **Note**: The `poster` prop works for direct video files, HLS, and DASH streams. For YouTube and Vimeo, the platform's own thumbnail is displayed regardless of the `poster` prop due to iframe limitations.
|
|
116
|
+
|
|
117
|
+
### YouTube
|
|
118
|
+
```tsx
|
|
119
|
+
<VideoPlayer
|
|
120
|
+
source={{
|
|
121
|
+
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
122
|
+
title: 'YouTube Video'
|
|
123
|
+
}}
|
|
124
|
+
/>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Vimeo
|
|
128
|
+
```tsx
|
|
129
|
+
<VideoPlayer
|
|
130
|
+
source={{
|
|
131
|
+
url: 'https://vimeo.com/76979871',
|
|
132
|
+
title: 'Vimeo Video'
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Direct MP4
|
|
138
|
+
```tsx
|
|
139
|
+
<VideoPlayer
|
|
140
|
+
source={{
|
|
141
|
+
url: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
|
|
142
|
+
title: 'Direct MP4',
|
|
143
|
+
poster: 'https://example.com/poster.jpg'
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### HLS Stream
|
|
149
|
+
```tsx
|
|
150
|
+
<VideoPlayer
|
|
151
|
+
source={{
|
|
152
|
+
url: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',
|
|
153
|
+
title: 'HLS Stream'
|
|
154
|
+
}}
|
|
155
|
+
/>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## API Reference
|
|
159
|
+
|
|
160
|
+
### VideoPlayerProps
|
|
161
|
+
|
|
162
|
+
| Prop | Type | Default | Description |
|
|
163
|
+
|------|------|---------|-------------|
|
|
164
|
+
| `source` | `VideoSource` | - | Video source configuration |
|
|
165
|
+
| `aspectRatio` | `number` | `16/9` | Video aspect ratio |
|
|
166
|
+
| `autoplay` | `boolean` | `false` | Auto-play video |
|
|
167
|
+
| `muted` | `boolean` | `false` | Mute video by default |
|
|
168
|
+
| `playsInline` | `boolean` | `true` | Play inline on mobile |
|
|
169
|
+
| `controls` | `boolean` | `true` | Show custom controls |
|
|
170
|
+
| `showInfo` | `boolean` | `false` | Show video info below player |
|
|
171
|
+
| `theme` | `'default' \| 'minimal' \| 'modern'` | `'default'` | Player theme |
|
|
172
|
+
| `className` | `string` | - | Custom CSS class |
|
|
173
|
+
| `onPlay` | `() => void` | - | Play event callback |
|
|
174
|
+
| `onPause` | `() => void` | - | Pause event callback |
|
|
175
|
+
| `onEnded` | `() => void` | - | End event callback |
|
|
176
|
+
| `onError` | `(error: string) => void` | - | Error event callback |
|
|
177
|
+
|
|
178
|
+
### VideoSource
|
|
179
|
+
|
|
180
|
+
| Property | Type | Description |
|
|
181
|
+
|----------|------|-------------|
|
|
182
|
+
| `url` | `string` | Video URL (YouTube, Vimeo, MP4, HLS, etc.) |
|
|
183
|
+
| `title` | `string?` | Video title |
|
|
184
|
+
| `description` | `string?` | Video description |
|
|
185
|
+
| `poster` | `string?` | Custom poster/thumbnail URL |
|
|
186
|
+
| `duration` | `number?` | Video duration in seconds |
|
|
187
|
+
|
|
188
|
+
### VideoPlayerRef Methods
|
|
189
|
+
|
|
190
|
+
| Method | Description |
|
|
191
|
+
|--------|-------------|
|
|
192
|
+
| `play()` | Play the video |
|
|
193
|
+
| `pause()` | Pause the video |
|
|
194
|
+
| `togglePlay()` | Toggle play/pause |
|
|
195
|
+
| `seekTo(time: number)` | Seek to specific time |
|
|
196
|
+
| `setVolume(volume: number)` | Set volume (0-1) |
|
|
197
|
+
| `toggleMute()` | Toggle mute |
|
|
198
|
+
| `enterFullscreen()` | Enter fullscreen |
|
|
199
|
+
| `exitFullscreen()` | Exit fullscreen |
|
|
200
|
+
|
|
201
|
+
## Themes
|
|
202
|
+
|
|
203
|
+
### Default Theme
|
|
204
|
+
Clean, professional look with rounded corners and subtle shadows.
|
|
205
|
+
|
|
206
|
+
### Minimal Theme
|
|
207
|
+
No rounded corners, minimal styling for embedding in tight spaces.
|
|
208
|
+
|
|
209
|
+
### Modern Theme
|
|
210
|
+
Enhanced shadows and larger border radius for a contemporary look.
|
|
211
|
+
|
|
212
|
+
## Accessibility
|
|
213
|
+
|
|
214
|
+
The VideoPlayer includes full accessibility support:
|
|
215
|
+
|
|
216
|
+
- ✅ Keyboard navigation (Space, Arrow keys, F for fullscreen)
|
|
217
|
+
- ✅ Screen reader announcements
|
|
218
|
+
- ✅ Focus indicators
|
|
219
|
+
- ✅ ARIA labels and roles
|
|
220
|
+
- ✅ High contrast support
|
|
221
|
+
|
|
222
|
+
## Performance
|
|
223
|
+
|
|
224
|
+
- ✅ Lazy loading of video content
|
|
225
|
+
- ✅ Efficient re-renders with Vidstack's optimized state management
|
|
226
|
+
- ✅ Minimal bundle size impact
|
|
227
|
+
- ✅ Hardware-accelerated playback when available
|
|
228
|
+
|
|
229
|
+
## Browser Support
|
|
230
|
+
|
|
231
|
+
Supports all modern browsers through Vidstack's comprehensive compatibility layer:
|
|
232
|
+
|
|
233
|
+
- ✅ Chrome 63+
|
|
234
|
+
- ✅ Firefox 67+
|
|
235
|
+
- ✅ Safari 12+
|
|
236
|
+
- ✅ Edge 79+
|
|
237
|
+
- ✅ iOS Safari 12+
|
|
238
|
+
- ✅ Chrome Android 63+
|
|
239
|
+
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Video Controls for Vidstack Player
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
'use client';
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { useMediaStore, useMediaRemote } from '@vidstack/react';
|
|
9
|
+
import type { MediaPlayerInstance } from '@vidstack/react';
|
|
10
|
+
import { Play, Pause, Volume2, VolumeX, Maximize, Minimize } from 'lucide-react';
|
|
11
|
+
import { cn } from '@djangocfg/ui-core/lib';
|
|
12
|
+
|
|
13
|
+
interface VideoControlsProps {
|
|
14
|
+
player: React.RefObject<MediaPlayerInstance | null>;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function VideoControls({ player, className }: VideoControlsProps) {
|
|
19
|
+
const store = useMediaStore(player);
|
|
20
|
+
const remote = useMediaRemote();
|
|
21
|
+
|
|
22
|
+
const isPaused = store.paused;
|
|
23
|
+
const isMuted = store.muted;
|
|
24
|
+
const isFullscreen = store.fullscreen;
|
|
25
|
+
const currentTime = store.currentTime;
|
|
26
|
+
const duration = store.duration;
|
|
27
|
+
const volume = store.volume;
|
|
28
|
+
|
|
29
|
+
const formatTime = (seconds: number): string => {
|
|
30
|
+
if (!seconds || seconds < 0) return '0:00';
|
|
31
|
+
const minutes = Math.floor(seconds / 60);
|
|
32
|
+
const secs = Math.floor(seconds % 60);
|
|
33
|
+
return `${minutes}:${secs.toString().padStart(2, '0')}`;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const handleProgressClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
37
|
+
if (!duration) return;
|
|
38
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
39
|
+
const clickX = e.clientX - rect.left;
|
|
40
|
+
const percentage = clickX / rect.width;
|
|
41
|
+
const newTime = percentage * duration;
|
|
42
|
+
remote.seek(newTime);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const handleVolumeChange = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
46
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
47
|
+
const clickX = e.clientX - rect.left;
|
|
48
|
+
const percentage = Math.max(0, Math.min(1, clickX / rect.width));
|
|
49
|
+
remote.changeVolume(percentage);
|
|
50
|
+
if (percentage > 0 && isMuted) {
|
|
51
|
+
remote.toggleMuted();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const progress = duration > 0 ? (currentTime / duration) * 100 : 0;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className={cn(
|
|
60
|
+
"absolute inset-0 flex flex-col justify-end transition-opacity duration-300",
|
|
61
|
+
"bg-gradient-to-t from-black/80 via-black/20 to-transparent",
|
|
62
|
+
"opacity-0 group-hover:opacity-100 focus-within:opacity-100",
|
|
63
|
+
"pointer-events-none group-hover:pointer-events-auto",
|
|
64
|
+
className
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
{/* Progress Bar */}
|
|
68
|
+
<div className="px-4 pb-2 pointer-events-auto">
|
|
69
|
+
<div
|
|
70
|
+
className="h-1.5 bg-white/20 rounded-full cursor-pointer hover:h-2 transition-all group"
|
|
71
|
+
onClick={handleProgressClick}
|
|
72
|
+
>
|
|
73
|
+
<div
|
|
74
|
+
className="h-full bg-primary rounded-full transition-all relative group-hover:bg-primary/90"
|
|
75
|
+
style={{ width: `${progress}%` }}
|
|
76
|
+
>
|
|
77
|
+
<div className="absolute right-0 top-1/2 -translate-y-1/2 w-3 h-3 bg-white rounded-full opacity-0 group-hover:opacity-100 transition-opacity" />
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
{/* Control Bar */}
|
|
83
|
+
<div className="flex items-center gap-4 px-4 pb-4 pointer-events-auto">
|
|
84
|
+
{/* Play/Pause */}
|
|
85
|
+
<button
|
|
86
|
+
onClick={() => remote.togglePaused()}
|
|
87
|
+
className="text-white hover:text-primary transition-colors p-1.5 hover:bg-white/10 rounded-full"
|
|
88
|
+
>
|
|
89
|
+
{isPaused ? <Play className="h-6 w-6" /> : <Pause className="h-6 w-6" />}
|
|
90
|
+
</button>
|
|
91
|
+
|
|
92
|
+
{/* Time */}
|
|
93
|
+
<div className="text-white text-sm font-medium">
|
|
94
|
+
{formatTime(currentTime)} / {formatTime(duration)}
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div className="flex-1" />
|
|
98
|
+
|
|
99
|
+
{/* Volume Control */}
|
|
100
|
+
<div className="flex items-center gap-2 group/volume">
|
|
101
|
+
<button
|
|
102
|
+
onClick={() => remote.toggleMuted()}
|
|
103
|
+
className="text-white hover:text-primary transition-colors p-1.5 hover:bg-white/10 rounded-full"
|
|
104
|
+
>
|
|
105
|
+
{isMuted || volume === 0 ? (
|
|
106
|
+
<VolumeX className="h-5 w-5" />
|
|
107
|
+
) : (
|
|
108
|
+
<Volume2 className="h-5 w-5" />
|
|
109
|
+
)}
|
|
110
|
+
</button>
|
|
111
|
+
|
|
112
|
+
<div
|
|
113
|
+
className="w-0 group-hover/volume:w-20 transition-all overflow-hidden"
|
|
114
|
+
>
|
|
115
|
+
<div
|
|
116
|
+
className="h-1.5 bg-white/20 rounded-full cursor-pointer hover:h-2 transition-all"
|
|
117
|
+
onClick={handleVolumeChange}
|
|
118
|
+
>
|
|
119
|
+
<div
|
|
120
|
+
className="h-full bg-white rounded-full transition-all"
|
|
121
|
+
style={{ width: `${volume * 100}%` }}
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
{/* Fullscreen */}
|
|
128
|
+
<button
|
|
129
|
+
onClick={() => isFullscreen ? remote.exitFullscreen() : remote.enterFullscreen()}
|
|
130
|
+
className="text-white hover:text-primary transition-colors p-1.5 hover:bg-white/10 rounded-full"
|
|
131
|
+
>
|
|
132
|
+
{isFullscreen ? <Minimize className="h-5 w-5" /> : <Maximize className="h-5 w-5" />}
|
|
133
|
+
</button>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|