Skip to content

Commit

Permalink
feat: list components for ui
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed Aug 9, 2024
1 parent c43effd commit ddfde56
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
11 changes: 10 additions & 1 deletion hac-client/src/components/component_styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub enum ComponentBorder {

#[derive(Debug, Clone, Copy)]
pub enum ComponentFocus {
Focused,
Unfocused,
Focused,
}

pub fn color_from_focus(
Expand All @@ -20,3 +20,12 @@ pub fn color_from_focus(
ComponentFocus::Unfocused => colors.normal.white,
}
}

impl From<bool> for ComponentFocus {
fn from(value: bool) -> Self {
match value {
true => ComponentFocus::Focused,
false => ComponentFocus::Unfocused,
}
}
}
21 changes: 19 additions & 2 deletions hac-client/src/components/list_item.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
use std::borrow::Cow;

use ratatui::{
style::Style,
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
};

use super::component_styles::{color_from_focus, ComponentBorder, ComponentFocus};

pub enum ListItemKind {
_Regular,
Enumerated(usize),
}

pub fn list_item<'a, T>(
text: T,
focus: ComponentFocus,
border_kind: ComponentBorder,
kind: ListItemKind,
colors: &hac_colors::Colors,
) -> Paragraph<'a>
where
Expand All @@ -30,6 +37,16 @@ where

let style = Style::default();
let style = style.fg(color_from_focus(focus, colors));
let style = style.bg(colors.normal.black);

let text = match kind {
ListItemKind::_Regular => Line::from(Span::from(text.into())),
ListItemKind::Enumerated(idx) => Line::from(vec![
Span::from(idx.to_string()).fg(colors.normal.red),
Span::from(" "),
Span::from(text.into()),
]),
};

Paragraph::new(text.into()).block(block).style(style)
Paragraph::new(text).block(block).style(style)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ascii::LOGO_ASCII;
use crate::components::component_styles::{ComponentBorder, ComponentFocus};
use crate::components::list_item::list_item;
use crate::components::list_item::{list_item, ListItemKind};
use crate::pages::collection_viewer::collection_store::CollectionStore;
use crate::pages::{overlay::make_overlay, Eventful, Renderable};

Expand Down Expand Up @@ -50,11 +50,13 @@ impl Renderable for AuthKindPrompt<'_> {
//let mut logo_size = logo.len() as u16;

let auth_kinds = AuthKind::iter()
.map(|v| {
.enumerate()
.map(|(idx, v)| {
list_item(
v.to_string(),
ComponentFocus::Focused,
self.selected_idx.eq(&idx).into(),
ComponentBorder::All,
ListItemKind::Enumerated(idx + 1),
self.colors,
)
})
Expand Down

0 comments on commit ddfde56

Please sign in to comment.