-
Notifications
You must be signed in to change notification settings - Fork 333
Add tabs & table #982
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
Merged
Merged
Add tabs & table #982
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -13,4 +13,4 @@ indent_size = 4 | |
|
||
[*.html] | ||
ident_style = space | ||
indent_size = 4 | ||
indent_size = 2 |
This file contains hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
// This file is automatically generated. | ||
// You shouldn't modify it manually. | ||
|
||
// src/components/navigation/tabs | ||
pub mod tabs; |
This file contains hidden or 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,10 @@ | ||
// This file is automatically generated. | ||
// You shouldn't modify it manually. | ||
|
||
// src/components/navigation/tabs/tab | ||
pub mod tab; | ||
pub use tab::Tab; | ||
|
||
// src/components/navigation/tabs/tabs | ||
pub mod tabs; | ||
pub use tabs::Tabs; |
This file contains hidden or 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,70 @@ | ||
#![allow(unused_variables)] | ||
use crate::components::component; | ||
use crate::components::component::Component; | ||
use sailfish::TemplateOnce; | ||
|
||
#[derive(TemplateOnce, Default, Clone)] | ||
#[template(path = "navigation/tabs/tab/template.html")] | ||
pub struct Tab { | ||
content: Component, | ||
active: bool, | ||
name: String, | ||
} | ||
|
||
impl Tab { | ||
pub fn new(name: impl ToString, content: Component) -> Tab { | ||
Tab { | ||
content, | ||
active: false, | ||
name: name.to_string(), | ||
} | ||
} | ||
|
||
pub fn button_classes(&self) -> String { | ||
if self.active { | ||
"nav-link active btn btn-tertiary rounded-0".to_string() | ||
} else { | ||
"nav-link btn btn-tertiary rounded-0".to_string() | ||
} | ||
} | ||
|
||
pub fn content_classes(&self) -> String { | ||
if self.active { | ||
"tab-pane my-4 show active".to_string() | ||
} else { | ||
"tab-pane my-4".to_string() | ||
} | ||
} | ||
|
||
pub fn id(&self) -> String { | ||
format!("tab-{}", self.name.to_lowercase().replace(" ", "-")) | ||
} | ||
|
||
pub fn selected(&self) -> String { | ||
if self.active { | ||
"selected".to_string() | ||
} else { | ||
"".to_string() | ||
} | ||
} | ||
|
||
pub fn name(&self) -> String { | ||
self.name.clone() | ||
} | ||
|
||
pub fn active(mut self) -> Self { | ||
self.active = true; | ||
self | ||
} | ||
|
||
pub fn inactive(mut self) -> Self { | ||
self.active = false; | ||
self | ||
} | ||
|
||
pub fn is_active(&self) -> bool { | ||
self.active | ||
} | ||
} | ||
|
||
component!(Tab); |
Empty file.
3 changes: 3 additions & 0 deletions
3
pgml-dashboard/src/components/navigation/tabs/tab/template.html
This file contains hidden or 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,3 @@ | ||
<div> | ||
<%+ content %> | ||
</div> |
This file contains hidden or 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 @@ | ||
use crate::components::component; | ||
use crate::components::navigation::tabs::Tab; | ||
use sailfish::TemplateOnce; | ||
|
||
#[derive(TemplateOnce, Default)] | ||
#[template(path = "navigation/tabs/tabs/template.html")] | ||
pub struct Tabs { | ||
tabs: Vec<Tab>, | ||
} | ||
|
||
impl Tabs { | ||
pub fn new(tabs: &[Tab]) -> Tabs { | ||
// Set the first tab to active if none are. | ||
let mut tabs = tabs.to_vec(); | ||
if tabs.iter().all(|t| !t.is_active()) { | ||
tabs = tabs | ||
.into_iter() | ||
.enumerate() | ||
.map(|(i, tab)| if i == 0 { tab.active() } else { tab }) | ||
.collect(); | ||
} | ||
|
||
Tabs { tabs } | ||
} | ||
|
||
pub fn active_tab(mut self, name: impl ToString) -> Self { | ||
let tabs = self | ||
.tabs | ||
.into_iter() | ||
.map(|tab| { | ||
if tab.name() == name.to_string() { | ||
tab.active() | ||
} else { | ||
tab.inactive() | ||
} | ||
}) | ||
.collect(); | ||
|
||
self.tabs = tabs; | ||
self | ||
} | ||
} | ||
|
||
component!(Tabs); |
21 changes: 21 additions & 0 deletions
21
pgml-dashboard/src/components/navigation/tabs/tabs/tabs.scss
This file contains hidden or 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,21 @@ | ||
.nav-tabs { | ||
// These tabs are used in docs as well, where they are | ||
// generated using Bootstrap. It wasn't obvious to me | ||
// how to replace those with this component yet, so I'm just | ||
// enforcing the font-family here so they look the same. Docs use Roboto by default. | ||
font-family: 'silka', 'Roboto', 'sans-serif'; | ||
|
||
--bs-nav-tabs-border-width: 4px; | ||
|
||
.nav-link { | ||
border: none; | ||
|
||
&.active, &:focus, &:active { | ||
border-bottom: 4px solid #{$slate-tint-700}; | ||
color: #{$slate-tint-700}; | ||
text-shadow: none; | ||
} | ||
|
||
color: #{$slate-tint-100}; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
pgml-dashboard/src/components/navigation/tabs/tabs/template.html
This file contains hidden or 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,30 @@ | ||
<ul class="nav nav-tabs" role="tablist"> | ||
<% for tab in &tabs { %> | ||
<li class="nav-item" role="presentation"> | ||
<button | ||
class="<%= tab.button_classes() %>" | ||
data-bs-toggle="tab" | ||
data-bs-target="#<%= tab.id() %>" | ||
type="button" | ||
role="tab" | ||
aria-controls="<%= tab.id() %>" | ||
aria-selected="<%= tab.selected() %>" | ||
> | ||
<%= tab.name() %> | ||
</button> | ||
</li> | ||
<% } %> | ||
</ul> | ||
<div class="tab-content"> | ||
<% for (i, tab) in tabs.into_iter().enumerate() { %> | ||
<div | ||
class="<%= tab.content_classes() %>" | ||
id="<%= tab.id() %>" | ||
role="tabpanel" | ||
aria-labelledby="tab-<%= tab.id() %>" | ||
tabindex="<%= i %>" | ||
> | ||
<%+ tab %> | ||
</div> | ||
<% } %> | ||
</div> |
This file contains hidden or 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,10 @@ | ||
// This file is automatically generated. | ||
// You shouldn't modify it manually. | ||
|
||
// src/components/tables/large/row | ||
pub mod row; | ||
pub use row::Row; | ||
|
||
// src/components/tables/large/table | ||
pub mod table; | ||
pub use table::Table; |
This file contains hidden or 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,19 @@ | ||
use crate::components::component; | ||
use crate::components::component::Component; | ||
use sailfish::TemplateOnce; | ||
|
||
#[derive(TemplateOnce, Default, Clone)] | ||
#[template(path = "tables/large/row/template.html")] | ||
pub struct Row { | ||
columns: Vec<Component>, | ||
} | ||
|
||
impl Row { | ||
pub fn new(columns: &[Component]) -> Row { | ||
Row { | ||
columns: columns.to_vec(), | ||
} | ||
} | ||
} | ||
|
||
component!(Row); |
This file contains hidden or 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,37 @@ | ||
table.table.table-lg { | ||
tr { | ||
&:first-of-type { | ||
td { | ||
padding-top: 16px; | ||
} | ||
} | ||
|
||
&:hover { | ||
div.table-cell-content { | ||
background: #{$gray-800}; | ||
} | ||
} | ||
|
||
td { | ||
vertical-align: middle; | ||
padding: 8px 0; | ||
|
||
div.table-cell-content { | ||
background: #{$gray-600}; | ||
padding: 20px 0; | ||
} | ||
|
||
&:first-of-type { | ||
div.table-cell-content { | ||
padding-left: 67px; | ||
} | ||
} | ||
|
||
&:last-of-type { | ||
div.table-cell-content { | ||
padding-right: 67px; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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,9 @@ | ||
<tr> | ||
<% for column in columns { %> | ||
<td> | ||
<div class="table-cell-content"> | ||
<%+ column %> | ||
</div> | ||
</td> | ||
<% } %> | ||
</tr> |
This file contains hidden or 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,21 @@ | ||
use crate::components::component; | ||
use crate::components::tables::large::Row; | ||
use sailfish::TemplateOnce; | ||
|
||
#[derive(TemplateOnce, Default)] | ||
#[template(path = "tables/large/table/template.html")] | ||
pub struct Table { | ||
rows: Vec<Row>, | ||
headers: Vec<String>, | ||
} | ||
|
||
impl Table { | ||
pub fn new(headers: &[impl ToString], rows: &[Row]) -> Table { | ||
Table { | ||
headers: headers.iter().map(|h| h.to_string()).collect(), | ||
rows: rows.to_vec(), | ||
} | ||
} | ||
} | ||
|
||
component!(Table); |
19 changes: 19 additions & 0 deletions
19
pgml-dashboard/src/components/tables/large/table/table.scss
This file contains hidden or 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,19 @@ | ||
table.table.table-lg { | ||
* { | ||
border-width: 0; | ||
} | ||
|
||
thead { | ||
th { | ||
color: #{$slate-shade-100}; | ||
background: #{$gray-800}; | ||
text-transform: uppercase; | ||
font-size: 0.75rem; | ||
padding: 16px 0; | ||
|
||
&:first-of-type { | ||
padding-left: 67px; | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
pgml-dashboard/src/components/tables/large/table/template.html
This file contains hidden or 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,14 @@ | ||
<table class="table table-lg"> | ||
<thead> | ||
<tr> | ||
<% for header in headers { %> | ||
<th><%= header %></th> | ||
<% } %> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% for row in rows { %> | ||
<%+ row %> | ||
<% } %> | ||
</tbody> | ||
</div> |
This file contains hidden or 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,5 @@ | ||
// This file is automatically generated. | ||
// You shouldn't modify it manually. | ||
|
||
// src/components/tables/large | ||
pub mod large; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chillenberger This rebuilt the app every time we changed css which was kinda slow. Instead, I'm running:
in a separate terminal.