List-Basic
Overview
The List-Basic component provides a clean and accessible way to display lists of content with consistent spacing. It supports both unordered lists (bullet points) and ordered lists (numbers), making it perfect for feature lists, instructions, or any content that needs to be organized in a list format.
Preview
- Preview
- Code
- First item
- Second item
- Third item
import { ListBasic } from './components/ui/list-basic';
function MyComponent() {
return (
<ListBasic
items={['First item', 'Second item', 'Third item']}
type="unordered"
spacing="md"
/>
);
}
Installation
- CLI
- Manual
ignix add component list-basic
import React from "react";
import { cn } from "../../../utils/cn";
export interface ListBasicProps {
items?: React.ReactNode[];
type?: 'unordered' | 'ordered';
spacing?: 'sm' | 'md' | 'lg';
className?: string;
children?: React.ReactNode;
}
const ListBasic: React.FC<ListBasicProps> = ({
items = [],
type = 'unordered',
spacing = 'md',
className,
children
}) => {
const spacingClasses = {
sm: 'space-y-2',
md: 'space-y-3',
lg: 'space-y-4',
};
const unorderedMarkerStyles = {
sm: 'list-disc list-outside ml-5',
md: 'list-disc list-outside ml-5',
lg: 'list-disc list-outside ml-6',
};
const orderedMarkerStyles = {
sm: 'list-decimal list-outside ml-5',
md: 'list-decimal list-outside ml-5',
lg: 'list-decimal list-outside ml-6',
};
const baseClasses = cn(
spacingClasses[spacing],
type === 'unordered' ? unorderedMarkerStyles[spacing] : orderedMarkerStyles[spacing],
'text-foreground',
className
);
const renderItems = () => {
if (!items || items.length === 0) return null;
return items.map((item, index) => (
<li
key={index}
className="leading-relaxed pl-1"
>
{item}
</li>
));
};
if (children) {
const ListTag = type === 'ordered' ? 'ol' : 'ul';
return (
<ListTag className={baseClasses}>
{children}
</ListTag>
);
}
const ListTag = type === 'ordered' ? 'ol' : 'ul';
return (
<ListTag className={baseClasses}>
{renderItems()}
</ListTag>
);
};
ListBasic.displayName = "ListBasic";
export { ListBasic };
Usage
Import the component:
import { ListBasic } from './components/ui/list-basic';
Basic Usage
The simplest way to use ListBasic is with the items prop:
function BasicList() {
return (
<ListBasic
items={['Item 1', 'Item 2', 'Item 3']}
/>
);
}
Ordered List
To create a numbered list, set the type prop to "ordered":
function OrderedList() {
return (
<ListBasic
items={['First step', 'Second step', 'Third step']}
type="ordered"
/>
);
}
Custom Spacing
Control the spacing between items using the spacing prop:
function CustomSpacing() {
return (
<ListBasic
items={['Item 1', 'Item 2', 'Item 3']}
spacing="lg" // Options: 'sm', 'md', 'lg'
/>
);
}
Using Children
For more complex content, you can use the children prop:
function ComplexList() {
return (
<ListBasic type="unordered" spacing="md">
<li>
<strong>Bold item</strong> with additional text
</li>
<li>
Item with <a href="#">a link</a>
</li>
<li>
<em>Italic item</em> for emphasis
</li>
</ListBasic>
);
}
Interactive Demo
- Preview
- Code
<ListBasic
items={undefined}
type="unordered"
spacing="md"
/>
Variants
Spacing Variants
The component supports three spacing options to control the vertical spacing between list items:
Spacing Variants
- Preview
- Code
Small Spacing
- Item one
- Item two
- Item three
Medium Spacing
- Item one
- Item two
- Item three
Large Spacing
- Item one
- Item two
- Item three
<div className="grid grid-cols-1 md:grid-cols-3 gap-8">
<div>
<h3 className="text-sm font-semibold mb-2">Small Spacing</h3>
<ListBasic
items={['Item one', 'Item two', 'Item three']}
type="unordered"
spacing="sm"
/>
</div>
<div>
<h3 className="text-sm font-semibold mb-2">Medium Spacing</h3>
<ListBasic
items={['Item one', 'Item two', 'Item three']}
type="unordered"
spacing="md"
/>
</div>
<div>
<h3 className="text-sm font-semibold mb-2">Large Spacing</h3>
<ListBasic
items={['Item one', 'Item two', 'Item three']}
type="unordered"
spacing="lg"
/>
</div>
</div>
List Types
Choose between unordered (bullet points) and ordered (numbers) lists:
List Types
- Preview
- Code
Unordered List
- Bullet point one
- Bullet point two
- Bullet point three
Ordered List
- Numbered item one
- Numbered item two
- Numbered item three
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
<div>
<h3 className="text-sm font-semibold mb-2">Unordered List</h3>
<ListBasic
items={['Bullet point one', 'Bullet point two', 'Bullet point three']}
type="unordered"
spacing="md"
/>
</div>
<div>
<h3 className="text-sm font-semibold mb-2">Ordered List</h3>
<ListBasic
items={['Numbered item one', 'Numbered item two', 'Numbered item three']}
type="ordered"
spacing="md"
/>
</div>
</div>
Using Children
When you need more control over individual list items, use the children prop:
Using Children
- Preview
- Code
- Bold item with additional text
- Item with a link
- Italic item for emphasis
- Item with
codeinline
<ListBasic type="unordered" spacing="md">
<li>
<strong>Bold item</strong> with additional text
</li>
<li>
Item with <a href="#" className="text-primary underline">a link</a>
</li>
<li>
<em>Italic item</em> for emphasis
</li>
<li>
Item with <code className="bg-muted px-1 py-0.5 rounded">code</code> inline
</li>
</ListBasic>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | React.ReactNode[] | [] | Array of items to display in the list. Can be strings or React nodes. |
type | 'unordered' | 'ordered' | 'unordered' | Type of list marker. 'unordered' for bullet points, 'ordered' for numbers. |
spacing | 'sm' | 'md' | 'lg' | 'md' | Spacing size between list items. 'sm' (8px), 'md' (12px), 'lg' (16px). |
className | string | undefined | Additional CSS classes to apply to the list container. |
children | React.ReactNode | undefined | Alternative way to pass list items as children. If provided, items prop will be ignored. |
Examples
Feature List
A common use case for displaying product features:
<ListBasic
items={[
'Responsive design for all devices',
'Dark mode support',
'Accessible components',
'TypeScript support',
'Customizable themes'
]}
type="unordered"
spacing="md"
/>
Step-by-Step Instructions
Perfect for tutorials or guides:
<ListBasic
items={[
'Open the application',
'Navigate to Settings',
'Select your preferences',
'Click Save to apply changes'
]}
type="ordered"
spacing="md"
/>
Mixed Content List
Using children for complex content:
<ListBasic type="unordered" spacing="lg">
<li className="flex items-start gap-2">
<span className="text-primary">✓</span>
<span>Completed task with checkmark</span>
</li>
<li className="flex items-start gap-2">
<span className="text-warning">⚠</span>
<span>Warning item with icon</span>
</li>
<li className="flex items-start gap-2">
<span className="text-destructive">✗</span>
<span>Error item with icon</span>
</li>
</ListBasic>
Accessibility
The ListBasic component uses semantic HTML (<ul> and <ol>) which provides:
- Screen reader support: Screen readers can identify and navigate lists properly
- Keyboard navigation: Standard list navigation works as expected
- Semantic meaning: The list structure is clear to assistive technologies
Best Practices
- Use unordered lists for items that don't have a specific order (features, options, etc.)
- Use ordered lists for sequential steps, rankings, or numbered instructions
- Choose appropriate spacing based on your design needs:
sm: For compact layouts or when space is limitedmd: For standard content (default)lg: For better readability and visual separation
- Use children prop when you need to customize individual items with links, icons, or formatting
- Keep items concise for better readability and scanning