Documentation overview
Creating documentation is easy with the components provided in this boilerplate. This has been created this way to ensure that the documentation is kept consistent and easy to read.
You can use the following components to create your documentation:
//Import the Documentation component as a wrapper for your documentation pageimport { Documentation } from '@/components/docs/documentation';//Import the DocumentationSection component to create sections in your documentationimport { DocumentationSection } from '@/components/docs/documentation-section';//Import the DocumentationTypography component to create headings and paragraphs in//your documentationimport { DocumentationTypography } from '@/components/docs/documentation-typography';//Import the CodeBlock component to display code blocks in your documentationimport { CodeBlock } from '@/components/code-block';
Advanced details on code blocks can be found here.
Props
The following are the props for the documentation components:
//Documentation componentinterface DocumentationProps {children: React.ReactNode;}//DocumentationSection componentinterface DocumentationSectionProps {id: string; // The id of the section which links to the sidebar # valuechildren: React.ReactNode;}//DocumentationTypography componentinterface DocumentationTypographyProps {variant: 'h1' | 'h2' | 'h3' | 'h4' | 'p'; // The variant of the typography componentchildren: React.ReactNode;}//CodeBlock componentinterface CodeBlockProps {code: string; // The code to display, this is a string of codelanguage: string; // The language of the code, e.g. javascript, typescript, etc.enableLineNumbers?: boolean; // Enable line numbers for the code blocklines?: (number | string)[]; // Highlight specific lines in the code blockcopyToClipboard?: boolean; // Enable copy to clipboard functionality (defaults to true)}
Example usage
Below is an example of how you can use the documentation components to create documentation.
1import { Documentation } from '@/components/docs/documentation';2import { DocumentationSection } from '@/components/docs/documentation-section';3import { DocumentationTypography } from '@/components/docs/documentation-typography';45//Rest of the code6<Documentation>7<DocumentationSection id="overview">8<DocumentationTypography variant="h1">9Documentation overview10</DocumentationTypography>11<DocumentationTypography variant="p">12</DocumentationSection>13</Documentation>
Sidebar
The sidebar is formed within the DocsSidebar component. To add a new section to the sidebar, simply add a group or item to the SIDEBAR_ITEMS array. Link this new item to a corresponding documentation section ID.
To create a new category in the sidebar, add a a new group to SIDEBAR_ITEMS and link it to a newly created page within NextJs router. Below is an example of creating a new section which routes to a new subset page of documentation.
Example
1//Import the DocsSidebar component23const SIDEBAR_ITEMS = [4{5name: 'Getting setup',6items: [7{8text: 'Introduction',9link: '/docs#introduction',10icon: <Lightbulb size={20} />,11visible: true,12},13],14},15{16name: 'New section',17items: [18{19text: 'Overview',20link: '/docs/new-section#overview',21icon: <AppWindowMac size={20} />,22visible: true,23},24],25},26];
Code blocks
Code blocks are used to display code within the documentation. This is achieved using the CodeBlock component. To display code blocks, use the following component:
Props
interface CodeBlockProps {code: string; // The code to display, this is a string of codelanguage: string; // The language of the code, e.g. javascript, typescript, etc.enableLineNumbers?: boolean; // Enable line numbers for the code blocklines?: (number | string)[]; // Highlight specific lines in the code blockcopyToClipboard?: boolean; // Enable copy to clipboard functionality (defaults to true)}
Basic example
1import { CodeBlock } from '@/components/code-block';234//Rest of the code5<CodeBlock code={code} language="javascript" />67const code = `8async function sayHello(name) {9console.log('Hello', name);10}11`;
Expected output
async function sayHello(name) {console.log('Hello', name);}
Advanced use cases
Highlighting code
To highlight specific lines in the code block, pass an array of line numbers to the lines prop. The code block will then highlight the lines specified. To highlight one line, pass type number. To highlight a range of lines, pass type string of format e.g 2:5.
For more advanced use cases you may need to create a custom CodeBlock component, see the following link for more information: https://react-code-block.netlify.app/