Mobile-focused theme for Dumi documentation generator that provides responsive layouts, touch-optimized navigation, and mobile-specific components for creating documentation websites that work seamlessly on mobile devices.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The Previewer Actions component extends dumi's default previewer actions with QR code functionality, enabling easy mobile testing and sharing of demo URLs.
Enhances the default previewer actions toolbar with mobile-specific features.
import { ReactComponent as IconQrcode } from '@ant-design/icons-svg/inline-svg/outlined/qrcode.svg';
import { useRouteMeta } from 'dumi';
import PreviewerActions from 'dumi/theme-default/slots/PreviewerActions';
import QRCode from 'qrcode.react';
import React, {
useEffect,
useState,
type ComponentProps,
type FC,
} from 'react';
/**
* Enhanced previewer actions with QR code support
* Extends default dumi PreviewerActions with mobile functionality
* Uses inline type definition - no separate interface needed
*/
type IPreviewerActionsProps = ComponentProps<typeof PreviewerActions> & {
/** Optional custom QR code URL (defaults to current demo URL) */
qrCodeUrl?: string;
};
const MobilePreviewerActions: FC<IPreviewerActionsProps>;
// Inherits all props from dumi's PreviewerActions including:
// - demoUrl, demoContainer, iframe, extra, etc.Key Features:
Displays a QR code button that shows a scannable code for easy mobile access.
/**
* QR Code Button Component
* Renders QR code for demo URL when in mobile mode
*/
interface QRCodeButton {
/** QR code value (demo URL) */
value: string;
/** QR code size in pixels */
size: 96;
/** Button title (shows URL on hover) */
title: string;
}QR Code Features:
Uses Ant Design icons for consistent visual design:
/**
* QR Code Icon from Ant Design Icons
* SVG icon component for the QR code button
*/
import { ReactComponent as IconQrcode } from '@ant-design/icons-svg/inline-svg/outlined/qrcode.svg';The component reads mobile mode from route metadata:
const { frontmatter: { mobile = true } } = useRouteMeta();Behavior:
mobile defaults to true when not specified in frontmatterHandles URL generation with SSR compatibility:
/**
* QR Code URL state management
* Handles SSR compatibility and URL updates
*/
interface URLState {
/** Current QR code URL */
qrCodeUrl: string;
/** Setter for URL updates */
setQrCodeUrl: (url: string) => void;
}SSR Handling:
useEffect(() => {
// Adapts for SSR by using location.origin
setQrCodeUrl(props.qrCodeUrl || `${location.origin}${props.demoUrl}`);
}, [props.demoUrl, props.qrCodeUrl]);Provides special handling for mobile iframe containers:
/**
* Demo container resolution for mobile iframes
* When iframe={false}, uses mobile device iframe as demo container
*/
interface DemoContainerProps {
/** Original demo container element */
demoContainer?: HTMLElement;
/** Whether iframe rendering is disabled */
iframe?: boolean | number;
}Logic:
iframe={false}: Finds and uses the mobile device iframe as demo containerBasic Usage: The component is automatically integrated into dumi's previewer system. No manual imports needed.
Custom QR Code URL:
// Custom QR code URL can be passed via props
<MobilePreviewerActions
qrCodeUrl="https://custom-domain.com/demo"
demoUrl="/demo/component"
// ...other props
/>Mobile Demo with QR Code:
---
mobile: true
---
# Mobile Component Demo
This demo will show a QR code button for easy mobile testing.The QR code button structure:
<button
className="dumi-default-previewer-action-btn dumi-mobile-previewer-action-qrcode"
type="button"
title={qrCodeUrl}
>
<IconQrcode />
<QRCode value={qrCodeUrl} size={96} />
</button>CSS Classes:
dumi-default-previewer-action-btn: Standard dumi action button stylingdumi-mobile-previewer-action-qrcode: Mobile-specific QR code button stylingThe component wraps and extends the default PreviewerActions:
<PreviewerActions
{...props}
extra={
<>
{/* QR Code button (when mobile) */}
{extra}
{/* Any additional extra content */}
{props.extra}
</>
}
demoContainer={resolvedDemoContainer}
/>This ensures all standard previewer actions remain available while adding mobile-specific QR code functionality.
Install with Tessl CLI
npx tessl i tessl/npm-dumi-theme-mobile