import UI from "#components/ui";
import React from "react";
import type { ListProps, ListItemProps } from "./list.types";
// Re-export types for external use
export type { ListProps, ListItemProps };
/**
* ListItem - A flexible list item component for ul, ol, and dl lists.
*
* This component renders different HTML elements (li, dt, dd) based on the parent
* list type, maintaining semantic HTML and accessibility best practices.
*
* ## Key Features:
* - **Semantic HTML**: Renders appropriate element type (li, dt, dd)
* - **Type-Safe**: Full TypeScript support with comprehensive props
* - **Ref Forwarding**: Enables direct DOM access for focus management
* - **Customizable**: Supports custom styles and CSS classes
*
* ## Accessibility:
* - ✅ Uses semantic HTML elements
* - ✅ Works with screen readers out of the box
* - ✅ Supports all native HTML attributes
* - ✅ Ref forwarding for programmatic focus
*
* @example
* ```tsx
* // Standard list item
* Item content
* ```
*
* @example
* ```tsx
* // Definition term
* Term to define
* ```
*
* @example
* ```tsx
* // Definition description
* The definition text
* ```
*
* @param {ListItemProps} props - Component props
* @param {React.Ref} ref - Forwarded ref for DOM access
* @returns {React.ReactElement} A list item element
*/
export const ListItem = React.forwardRef<
HTMLLIElement | HTMLElement,
ListItemProps
>(({ type = "li", id, styles, children, classes, ...props }, ref) => {
return (
{children}
);
});
ListItem.displayName = "ListItem";
/**
* List - A flexible, accessible list component for creating ul, ol, and dl lists.
*
* This component provides a type-safe, accessible way to create different types of lists
* with built-in support for custom styling, variants, and WCAG 2.1 AA compliance.
*
* ## Key Features:
* - **Multiple List Types**: Supports ul (unordered), ol (ordered), and dl (definition) lists
* - **Semantic HTML**: Uses native HTML list elements for proper accessibility
* - **Customizable Styling**: CSS custom properties and variant support
* - **Type-Safe**: Comprehensive TypeScript types with JSDoc
* - **Ref Forwarding**: Direct DOM access for scroll positioning and focus management
* - **WCAG 2.1 AA**: Meets accessibility standards with proper semantic structure
*
* ## Accessibility:
* - ✅ WCAG 2.1 AA compliant using semantic HTML
* - ✅ Screen reader compatible (announced as "list" with item count)
* - ✅ Supports role="list" override for styled lists (Safari/VoiceOver compatibility)
* - ✅ Keyboard navigation works naturally with focusable children
* - ✅ Ref forwarding for programmatic focus management
*
* ## Common Use Cases:
* - **Navigation menus** - Use ul with variant="inline" or "none"
* - **Sequential steps** - Use ol for numbered instructions
* - **Glossaries** - Use dl for term-definition pairs
* - **Feature lists** - Use ul for product features
*
* @example
* ```tsx
* // Basic unordered list
*
* First item
* Second item
*
* ```
*
* @example
* ```tsx
* // Ordered list with custom styling
*
* Step one
* Step two
*
* ```
*
* @example
* ```tsx
* // Unstyled list with role restoration for accessibility
* // IMPORTANT: Use role="list" when removing list styling
*
* Navigation link
* Another link
*
* ```
*
* @example
* ```tsx
* // Definition list
*
* React
* A JavaScript library for building UIs
* TypeScript
* JavaScript with syntax for types
*
* ```
*
* @param {ListProps} props - Component props
* @param {React.Ref} ref - Forwarded ref for DOM access
* @returns {React.ReactElement} A list element (ul, ol, or dl)
*/
export const List = React.forwardRef<
HTMLUListElement | HTMLOListElement | HTMLDListElement,
ListProps
>(({ children, classes, type = "ul", variant, styles, role, ...props }, ref) => {
return (
{children}
);
});
List.displayName = "List";
// Compound component pattern - attach ListItem to List with proper typing
export interface ListComponent
extends React.ForwardRefExoticComponent<
ListProps & React.RefAttributes
> {
ListItem: typeof ListItem;
}
// Attach ListItem to List using Object.assign for better type inference
const ListWithItem = Object.assign(List, {
ListItem,
});
export default ListWithItem as ListComponent;