Skip to main content

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
51#[cfg(target_arch = "wasm32")]
52extern crate tinycrossterm as crossterm;
53
54mod modal;
55mod scroll_view;
56mod select_list;
57mod status_bar;
58pub mod style;
59mod text_input;
60mod tree_view;
61
62pub use modal::{centered_rect, Modal, ModalBehavior, ModalProps, ModalStyle};
63pub use ratatui::text::Line;
64pub use scroll_view::{
65    LinesScroller, ScrollView, ScrollViewBehavior, ScrollViewProps, ScrollViewStyle, VisibleRange,
66};
67pub use select_list::{SelectList, SelectListBehavior, SelectListProps, SelectListStyle};
68pub use status_bar::{
69    StatusBar, StatusBarHint, StatusBarItem, StatusBarProps, StatusBarSection, StatusBarStyle,
70};
71pub use style::{
72    highlight_substring, BaseStyle, BorderStyle, Color, ComponentStyle, Modifier, Padding,
73    ScrollbarStyle, SelectionStyle, Style,
74};
75pub use text_input::{TextInput, TextInputProps, TextInputStyle};
76pub use tree_view::{
77    TreeBranchMode, TreeBranchStyle, TreeNode, TreeNodeRender, TreeView, TreeViewBehavior,
78    TreeViewProps, TreeViewStyle,
79};
80
81/// Prelude for convenient imports
82pub mod prelude {
83    pub use crate::{
84        centered_rect, BaseStyle, BorderStyle, ComponentStyle, LinesScroller, Modal, ModalBehavior,
85        ModalProps, ModalStyle, Padding, ScrollView, ScrollViewBehavior, ScrollViewProps,
86        ScrollViewStyle, ScrollbarStyle, SelectList, SelectListBehavior, SelectListProps,
87        SelectListStyle, SelectionStyle, StatusBar, StatusBarHint, StatusBarItem, StatusBarProps,
88        StatusBarSection, StatusBarStyle, TextInput, TextInputProps, TextInputStyle,
89        TreeBranchMode, TreeBranchStyle, TreeNode, TreeNodeRender, TreeView, TreeViewBehavior,
90        TreeViewProps, TreeViewStyle, VisibleRange,
91    };
92
93    pub use ratatui::style::{Color, Modifier, Style};
94    pub use ratatui::text::Line;
95}