Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Table): Add clickable rows #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ features = [

[patch.crates-io]
# patternfly-yew = { path = "../patternfly-test-minimal/patternfly-yew" }
patternfly-yew = { git = "https://github.com/patternfly-yew/patternfly-yew", rev = "74e20e4429248cbc3b2c8085b9a4f8d9002fe456" } # FIXME: awaiting release
# patternfly-yew = { git = "https://github.com/patternfly-yew/patternfly-yew", rev = "74e20e4429248cbc3b2c8085b9a4f8d9002fe456" } # FIXME: awaiting release
patternfly-yew = { git = "https://github.com/patternfly-yew/patternfly-yew", rev = "c121c5227bb209a5a502e571ae2cb71d7e52d4b6" } # FIXME: awaiting release
#yew-nested-router = { path = "../yew-nested-router" }
#yew-more-hooks = { git = "https://github.com/ctron/yew-more-hooks", rev = "f535bb2e7b227aac7010035215c11d4aeae6cb62" } # FIXME: awaiting release
#yew-more-hooks = { path = "../yew-more-hooks" }
Expand Down
1 change: 1 addition & 0 deletions src/components/pagination/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum Columns {
Hex,
}

#[derive(Clone)]
struct ExampleEntry(usize);

impl TableEntryRenderer<Columns> for ExampleEntry {
Expand Down
2 changes: 2 additions & 0 deletions src/components/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub fn example() -> Html {
let example9 = example!("Table (expandable)" => "table.9.example");
let example10 = example!("Table (expandable, columns)" => "table.10.example");
let example11 = example!("Table (sortable)" => "table.11.example");
let example12 = example!("Table (clickable rows)" => "table.12.example");

html! {
<>
Expand All @@ -124,6 +125,7 @@ pub fn example() -> Html {
{example9}
{example10}
{example11}
{example12}
</ExamplePage>
</>
}
Expand Down
44 changes: 44 additions & 0 deletions src/components/table/table.12.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
#[function_component(Example)]
fn example() -> Html {
let entries = use_memo((), |()| {
vec![
ExampleEntry { foo: "bar".into() },
ExampleEntry {
foo: "Much, much longer foo".into(),
},
]
});

let (entries, _) = use_table_data(MemoizedTableModel::new(entries));

let header = html_nested! {
<TableHeader<Columns>>
<TableColumn<Columns> label="foo" index={Columns::First} />
<TableColumn<Columns> label="bar" index={Columns::Second} />
<TableColumn<Columns> label="baz" index={Columns::Third} />
</TableHeader<Columns>>
};

let selected = use_state(|| None);

let onrowclick = use_callback(selected.clone(), |entry: ExampleEntry, selected| {
selected.set(Some(entry.clone()))
});
let row_selected = use_callback(selected.clone(), |entry: ExampleEntry, selected| {
**selected == Some(entry)
});

html! (
<Table<Columns, UseTableData<Columns, MemoizedTableModel<ExampleEntry>>>
caption="Table caption"
{header}
{entries}
{onrowclick}
{row_selected}
/>
)
}

html!(<Example/>)
}
4 changes: 2 additions & 2 deletions src/components/table/table.6.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{

#[derive(PartialEq)]
#[derive(Clone, PartialEq)]
pub struct Centered(pub ExampleEntry);

impl TableEntryRenderer<Columns> for Centered {
Expand Down Expand Up @@ -44,4 +44,4 @@
}

html!(<Example/>)
}
}
2 changes: 1 addition & 1 deletion src/components/toggle_group/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{example, example::ExamplePage};
use yew::prelude::*;
use patternfly_yew::prelude::*;
use yew::prelude::*;

#[function_component(ToggleGroupExample)]
pub fn toast() -> Html {
Expand Down
Loading