tui_dispatch_components/lib.rs
1//! Pre-built UI components for tui-dispatch
2//!
3//! This crate provides reusable TUI components that integrate with tui-dispatch patterns.
4//! Components implement the `Component<A>` trait and emit actions via callback functions
5//! passed through Props.
6//!
7//! # Components
8//!
9//! - [`SelectList`] - Scrollable selection list with keyboard navigation
10//! - [`ScrollView`] - Scrollable view for pre-wrapped lines
11//! - [`StatusBar`] - Left/center/right status bar with hints
12//! - [`TextInput`] - Single-line text input with cursor
13//! - [`TreeView`] - Hierarchical tree view with selection
14//! - [`Modal`] - Overlay with dimmed background
15//!
16//! # Styling
17//!
18//! All components use unified styling objects:
19//! - [`SelectListStyle`] - Styling for SelectList (base, selection, scrollbar)
20//! - [`ScrollViewStyle`] - Styling for ScrollView (base, scrollbar)
21//! - [`StatusBarStyle`] - Styling for StatusBar (base, hints, separators)
22//! - [`TextInputStyle`] - Styling for TextInput (base, placeholder, cursor)
23//! - [`TreeViewStyle`] - Styling for TreeView (base, selection, branches)
24//! - [`ModalStyle`] - Styling for Modal (base, dimming)
25//!
26//! Common types are available in the [`style`] module.
27//!
28//! # Example
29//!
30//! ```ignore
31//! use tui_dispatch_components::{
32//! Line, SelectList, SelectListBehavior, SelectListProps, SelectListStyle,
33//! };
34//!
35//! // In your render function:
36//! let items: Vec<Line> = state.items.iter().map(|s| Line::raw(s)).collect();
37//! let render_item = |item: &Line| item.clone();
38//! let mut list = SelectList::default();
39//! list.render(frame, area, SelectListProps {
40//! items: &items,
41//! count: items.len(),
42//! selected: state.selected,
43//! is_focused: state.focus == Focus::List,
44//! style: SelectListStyle::default(),
45//! behavior: SelectListBehavior::default(),
46//! on_select: |i| Action::Select(i),
47//! render_item: &render_item,
48//! });
49//! ```
50
51mod modal;
52mod scroll_view;
53mod select_list;
54mod status_bar;
55pub mod style;
56mod text_input;
57mod tree_view;
58
59pub use modal::{centered_rect, Modal, ModalBehavior, ModalProps, ModalStyle};
60pub use ratatui::text::Line;
61pub use scroll_view::{
62 LinesScroller, ScrollView, ScrollViewBehavior, ScrollViewProps, ScrollViewStyle, VisibleRange,
63};
64pub use select_list::{SelectList, SelectListBehavior, SelectListProps, SelectListStyle};
65pub use status_bar::{
66 StatusBar, StatusBarHint, StatusBarItem, StatusBarProps, StatusBarSection, StatusBarStyle,
67};
68pub use style::{
69 highlight_substring, BaseStyle, BorderStyle, Color, ComponentStyle, Modifier, Padding,
70 ScrollbarStyle, SelectionStyle, Style,
71};
72pub use text_input::{TextInput, TextInputProps, TextInputStyle};
73pub use tree_view::{
74 TreeBranchMode, TreeBranchStyle, TreeNode, TreeNodeRender, TreeView, TreeViewBehavior,
75 TreeViewProps, TreeViewStyle,
76};
77
78/// Prelude for convenient imports
79pub mod prelude {
80 pub use crate::{
81 centered_rect, BaseStyle, BorderStyle, ComponentStyle, LinesScroller, Modal, ModalBehavior,
82 ModalProps, ModalStyle, Padding, ScrollView, ScrollViewBehavior, ScrollViewProps,
83 ScrollViewStyle, ScrollbarStyle, SelectList, SelectListBehavior, SelectListProps,
84 SelectListStyle, SelectionStyle, StatusBar, StatusBarHint, StatusBarItem, StatusBarProps,
85 StatusBarSection, StatusBarStyle, TextInput, TextInputProps, TextInputStyle,
86 TreeBranchMode, TreeBranchStyle, TreeNode, TreeNodeRender, TreeView, TreeViewBehavior,
87 TreeViewProps, TreeViewStyle, VisibleRange,
88 };
89
90 pub use ratatui::style::{Color, Modifier, Style};
91 pub use ratatui::text::Line;
92}