Skip to Content
Dashflow Logo

Li Component

A comprehensive guide to using the Li component with examples, props, and best practices.


Overview

The Li component provides a styled list item element with consistent spacing and typography. It's designed to be used within ordered or unordered lists for better content organization.

Basic Usage

import { Li } from '@dashflowx/core'
export default function LiExample() {
return (
<ul>
<Li>First item</Li>
<Li>Second item</Li>
<Li>Third item</Li>
</ul>
)
}

Preview: <ul>

  • First item
  • Second item
  • Third item
  • </ul>

    Props

    PropTypeDefaultDescription
    classNamestring''Additional CSS classes for the list item
    childrenReactNode-The list item content

    Examples

    Basic List Item

    import { Li } from '@dashflowx/core'
    export default function BasicLi() {
    return (
    <ul>
    <Li>Basic list item</Li>
    </ul>
    )
    }

    Preview: <ul>

  • Basic list item
  • </ul>

    Styled List Item

    import { Li } from '@dashflowx/core'
    export default function StyledLi() {
    return (
    <ul>
    <Li className="text-blue-600 font-semibold">
    Styled list item
    </Li>
    </ul>
    )
    }

    Preview: <ul>

  • Styled list item
  • </ul>

    Custom Styled List Item

    import { Li } from '@dashflowx/core'
    export default function CustomStyledLi() {
    return (
    <ul>
    <Li className="text-lg font-bold text-purple-600 border-l-4 border-purple-600 pl-4">
    Custom styled item
    </Li>
    </ul>
    )
    }

    Preview: <ul>

  • Custom styled item
  • </ul>

    List Item with Icon

    import { Li } from '@dashflowx/core'
    export default function LiWithIcon() {
    return (
    <ul>
    <Li className="flex items-center space-x-2">
    <span className="text-green-500"></span>
    <span>Item with icon</span>
    </Li>
    </ul>
    )
    }

    Preview: <ul>

  • <span className="text-green-500">✓</span><span>Item with icon</span>
  • </ul>

    Nested List Items

    import { Li } from '@dashflowx/core'
    export default function NestedLi() {
    return (
    <ul>
    <Li>Parent item</Li>
    <ul className="ml-4">
    <Li>Child item 1</Li>
    <Li>Child item 2</Li>
    </ul>
    </ul>
    )
    }

    Preview: <ul>

  • Parent item
  • <ul className="ml-4">
  • Child item 1
  • Child item 2
  • </ul> </ul>

    Common Use Cases

    Feature List

    const featureList = (
    <ul>
    <Li>Feature 1</Li>
    <Li>Feature 2</Li>
    <Li>Feature 3</Li>
    </ul>
    );
    const navigationMenu = (
    <ul>
    <Li>Home</Li>
    <Li>About</Li>
    <Li>Contact</Li>
    </ul>
    );

    Checklist

    const checklist = (
    <ul>
    <Li className="flex items-center space-x-2">
    <span className="text-green-500"></span>
    <span>Completed task</span>
    </Li>
    <Li className="flex items-center space-x-2">
    <span className="text-gray-400"></span>
    <span>Pending task</span>
    </Li>
    </ul>
    );

    Instructions

    const instructions = (
    <ol>
    <Li>Step 1: Prepare the ingredients</Li>
    <Li>Step 2: Mix the ingredients</Li>
    <Li>Step 3: Cook for 30 minutes</Li>
    </ol>
    );

    Benefits List

    const benefitsList = (
    <ul>
    <Li className="text-green-600">✓ Fast delivery</Li>
    <Li className="text-green-600">✓ Quality guarantee</Li>
    <Li className="text-green-600">✓ 24/7 support</Li>
    </ul>
    );

    Best Practices

    1. Semantic Usage

    Use list items within proper list containers.

    // ✅ Good - Proper semantic usage
    <ul>
    <Li>Item 1</Li>
    <Li>Item 2</Li>
    </ul>
    // ❌ Avoid - Missing list container
    <Li>Item 1</Li>
    <Li>Item 2</Li>

    2. Consistent Styling

    Maintain consistent styling across list items.

    // ✅ Good - Consistent styling
    <ul>
    <Li className="standard-li-style">Item 1</Li>
    <Li className="standard-li-style">Item 2</Li>
    </ul>
    // ❌ Avoid - Inconsistent styling
    <ul>
    <Li className="random-style-1">Item 1</Li>
    <Li className="random-style-2">Item 2</Li>
    </ul>

    3. Clear Content

    Use clear and descriptive content for list items.

    // ✅ Good - Clear content
    <Li>Complete the registration form</Li>
    // ❌ Avoid - Unclear content
    <Li>Do stuff</Li>

    4. Appropriate Nesting

    Use appropriate nesting levels for hierarchical content.

    // ✅ Good - Appropriate nesting
    <ul>
    <Li>Main item</Li>
    <ul>
    <Li>Sub item</Li>
    </ul>
    </ul>
    // ❌ Avoid - Too deep nesting
    <ul>
    <Li>Main item</Li>
    <ul>
    <Li>Sub item</Li>
    <ul>
    <Li>Sub-sub item</Li>
    <ul>
    <Li>Sub-sub-sub item</Li>
    </ul>
    </ul>
    </ul>
    </ul>

    5. Accessible Content

    Ensure list items are accessible to all users.

    // ✅ Good - Accessible content
    <Li>Clear and descriptive content</Li>
    // ❌ Avoid - Unclear content
    <Li>Click here</Li>

    Customization

    Custom Styling

    You can customize the list item appearance using CSS classes:

    <Li className="text-lg font-bold text-blue-600">
    Custom styled item
    </Li>

    Different Themes

    Use different themes for different contexts:

    // Light theme
    <Li className="text-gray-900" />
    // Dark theme
    <Li className="text-white" />
    // Brand theme
    <Li className="text-blue-600" />

    Size Variations

    Use different sizes for different emphasis levels:

    // Small list item
    <Li className="text-sm" />
    // Standard list item
    <Li className="text-base" />
    // Large list item
    <Li className="text-lg" />

    Advanced Usage

    Dynamic List Items

    Create dynamic list items based on data:

    const items = ['Item 1', 'Item 2', 'Item 3'];
    <ul>
    {items.map((item, index) => (
    <Li key={index}>{item}</Li>
    ))}
    </ul>

    Conditional Styling

    Apply conditional styling based on state:

    const [isCompleted, setIsCompleted] = useState(false);
    <Li className={isCompleted ? 'text-green-600 line-through' : 'text-gray-600'}>
    Task item
    </Li>

    Interactive List Items

    Make list items interactive:

    const [selectedItem, setSelectedItem] = useState(null);
    <Li
    className={selectedItem === 'item1' ? 'bg-blue-100' : ''}
    onClick={() => setSelectedItem('item1')}
    >
    Interactive item
    </Li>
    • List: For list containers
    • Ul: For unordered lists
    • Ol: For ordered lists
    • Typography: For text styling
    • Button: For interactive list items

    API Reference

    For the complete API reference and advanced usage patterns, see the Li API documentation.

    Edit this page on GitHub