Related Resources
A reusable React component that displays a styled card containing related documentation links and resources. Perfect for adding contextual navigation at the end of demo pages, documentation sections, or anywhere users might need quick access to related content.
Overviewโ
The Related Resources component provides a clean, consistent way to present related links across your documentation site. It features:
- Consistent Styling using Docusaurus design tokens
- Flexible Button Types (primary, secondary, outline)
- External Link Handling with automatic
target="_blank" - Responsive Design that works on all screen sizes
- Customizable Content with configurable title and description
๐จ Featuresโ
Visual Designโ
- Card Layout: Clean white card with subtle shadow
- Centered Content: Title, description, and buttons centered
- Button Group: Links displayed as styled Docusaurus buttons
- Responsive Spacing: Consistent margins and padding
Link Typesโ
- Primary Buttons: Main call-to-action links
- Secondary Buttons: Supporting or alternative links
- Outline Buttons: Subtle, less prominent links
Smart Link Handlingโ
- Internal Links: Use regular href for Docusaurus routing
- External Links: Automatically add
target="_blank"andrel="noopener noreferrer" - Security: Safe external link handling with proper rel attributes
๐ File Structureโ
src/components/RelatedResources/
โโโ index.tsx # Component implementation and interfaces
๐ง Technical Implementationโ
TypeScript Interfacesโ
export interface RelatedResourceLink {
href: string;
label: string;
type?: 'primary' | 'secondary' | 'outline';
external?: boolean;
}
export interface RelatedResourcesProps {
title?: string;
description?: string;
links: RelatedResourceLink[];
className?: string;
}
Component Structureโ
export default function RelatedResources({
title = '๐ Related Resources',
description,
links,
className = ''
}: RelatedResourcesProps): React.JSX.Element {
return (
<section className={`margin-top--lg ${className}`}>
<div className="card shadow--lw">
<div className="card__body text--center">
<h3 className="margin-bottom--sm">{title}</h3>
{description && (
<p className="margin-bottom--lg text--secondary">{description}</p>
)}
<div className="button-group">
{links.map((link, index) => (
<a
key={index}
href={link.href}
className={`button button--${link.type || 'primary'}`}
{...(link.external && {
target: '_blank',
rel: 'noopener noreferrer'
})}
>
{link.label}
</a>
))}
</div>
</div>
</div>
</section>
);
}
๐ Usage Examplesโ
Basic Usageโ
import RelatedResources from '@site/src/components/RelatedResources';
<RelatedResources
links={[
{
href: '/docs/getting-started',
label: '๐ Getting Started',
type: 'primary'
},
{
href: '/docs/api',
label: '๐ง API Reference',
type: 'secondary'
}
]}
/>;
Custom Title and Descriptionโ
<RelatedResources
title="๐ฏ Next Steps"
description="Continue your journey with these helpful resources:"
links={[
{
href: '/docs/advanced',
label: 'Advanced Guide',
type: 'primary'
},
{
href: '/docs/examples',
label: 'Examples',
type: 'outline'
}
]}
/>
External Linksโ
<RelatedResources
title="๐ External Resources"
links={[
{
href: 'https://docusaurus.io/docs',
label: 'Docusaurus Docs',
type: 'primary',
external: true
},
{
href: 'https://github.com/facebook/docusaurus',
label: 'GitHub Repository',
type: 'secondary',
external: true
}
]}
/>
Complete Exampleโ
<RelatedResources
title="๐ Related Resources"
description="Learn more about GitHub integration and link management:"
className="custom-related-resources"
links={[
{
href: '/docs/core-systems/github-links-system',
label: '๐ GitHub Links Docs',
type: 'primary'
},
{
href: '/demos/github-links',
label: '๐ฎ Interactive Demo',
type: 'secondary'
},
{
href: '/docs/configuration/',
label: 'โ๏ธ Configuration Guide',
type: 'outline'
}
]}
/>
๐จ Stylingโ
Docusaurus Integrationโ
The component uses Docusaurus CSS classes for consistent styling:
margin-top--lg: Top spacingcard: Card container stylingshadow--lw: Light shadow effectcard__body: Card content areatext--center: Center-aligned textmargin-bottom--sm/lg: Spacing utilitiestext--secondary: Secondary text colorbutton-group: Button containerbutton button--*: Button styling variants
Custom Stylingโ
You can add custom styles by:
- className Prop: Pass custom CSS classes
- CSS Override: Target the component with CSS
- CSS Custom Properties: Use Docusaurus design tokens
.custom-related-resources {
/* Custom overrides */
margin-top: 2rem;
}
.custom-related-resources .card {
border: 2px solid var(--ifm-color-primary);
}
๐ง Props Referenceโ
RelatedResourcesPropsโ
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | '๐ Related Resources' | Section heading |
description | string | undefined | Optional description text |
links | RelatedResourceLink[] | Required | Array of links to display |
className | string | '' | Additional CSS classes |
RelatedResourceLinkโ
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | Required | URL or path for the link |
label | string | Required | Display text for the link |
type | 'primary' | 'secondary' | 'outline' | 'primary' | Button style variant |
external | boolean | false | Whether to open in new tab |
๐ Best Practicesโ
Content Guidelinesโ
- Limit Links: 2-4 links work best for readability
- Clear Labels: Use descriptive, action-oriented text
- Logical Order: Place most important links first
- Consistent Icons: Use emoji or icons consistently
Accessibilityโ
- Descriptive Labels: Avoid generic text like "Click here"
- External Link Indication: Mark external links clearly
- Keyboard Navigation: Component supports tab navigation
- Screen Readers: Proper semantic HTML structure
Performanceโ
- Minimal Footprint: Lightweight component with no dependencies
- Static Rendering: Works with Docusaurus static generation
- Fast Loading: Uses optimized Docusaurus CSS classes
๐ Integration Patternsโ
Demo Pagesโ
// At the end of demo pages
<RelatedResources
links={[
{
href: '/docs/component-name',
label: '๐ Documentation',
type: 'primary'
},
{
href: '/demos',
label: '๐ฎ More Demos',
type: 'secondary'
}
]}
/>
Documentation Pagesโ
// At the end of doc sections
<RelatedResources
title="๐ Continue Learning"
description="Explore these related topics:"
links={[
{
href: '/docs/next-topic',
label: 'Next: Advanced Usage',
type: 'primary'
},
{
href: '/docs/related-topic',
label: 'Related: Configuration',
type: 'outline'
}
]}
/>
Tutorial Seriesโ
// Navigation between tutorial steps
<RelatedResources
title="๐ Tutorial Navigation"
links={[
{
href: '/tutorial/previous',
label: 'โ Previous Step',
type: 'secondary'
},
{
href: '/tutorial/next',
label: 'Next Step โ',
type: 'primary'
}
]}
/>
๐ Variations and Extensionsโ
With Iconsโ
Enhance links with consistent emoji or FontAwesome icons:
const links = [
{ href: '/docs', label: '๐ Documentation', type: 'primary' },
{ href: '/examples', label: '๐ก Examples', type: 'secondary' },
{ href: '/api', label: '๐ง API Reference', type: 'outline' }
];
Conditional Renderingโ
Show different links based on context:
const getLinks = (userType: string) => {
const baseLinks = [
{ href: '/docs', label: 'Documentation', type: 'primary' }
];
if (userType === 'developer') {
baseLinks.push({ href: '/api', label: 'API Docs', type: 'secondary' });
}
return baseLinks;
};
<RelatedResources links={getLinks('developer')} />;
This component provides a consistent, professional way to add contextual navigation throughout your Docusaurus site, improving user experience and site engagement.