-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Table): Add clickable rows (#48)
- Loading branch information
Ari
authored
Feb 10, 2024
1 parent
2be088e
commit a539dcb
Showing
7 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters