Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Clickable tables#987

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
levkk merged 2 commits intomasterfromlevkk-clickable-tables
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
14 changes: 14 additions & 0 deletionspgml-dashboard/src/components/tables/large/row/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,28 @@ use sailfish::TemplateOnce;
#[template(path = "tables/large/row/template.html")]
pub struct Row {
columns: Vec<Component>,
action: String,
data: Vec<(String, String)>,
}

impl Row {
pub fn new(columns: &[Component]) -> Row {
Row {
columns: columns.to_vec(),
action: "click->tables-large-table#selectRow".to_string(),
data: vec![],
}
}

pub fn action(mut self, action: &str) -> Self {
self.action.push_str(&format!(" {}", action));
self
}

pub fn data(mut self, name: &str, value: &str) -> Self {
self.data.push((name.to_owned(), value.to_owned()));
self
}
}

component!(Row);
10 changes: 9 additions & 1 deletionpgml-dashboard/src/components/tables/large/row/row.scss
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ table.table.table-lg {
}
}

&:hover {
&:hover, &.active {
div.table-cell-content {
background: #{$gray-800};
}
Expand DownExpand Up@@ -34,4 +34,12 @@ table.table.table-lg {
}
}
}

&.selectable {
tbody {
tr:hover {
cursor: pointer;
}
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
<tr>
<tr
data-action="<%= action %>"
data-tables-large-table-target="row"
<% for (name, value) in data { %>
data-<%= name %>="<%= value %>"
<% } %>
>
<% for column in columns { %>
<td>
<div class="table-cell-content">
Expand Down
7 changes: 7 additions & 0 deletionspgml-dashboard/src/components/tables/large/table/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,15 +7,22 @@ use sailfish::TemplateOnce;
pub struct Table {
rows: Vec<Row>,
headers: Vec<String>,
classes: 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(),
classes: "table table-lg".to_string(),
}
}

pub fn selectable(mut self) -> Self {
self.classes.push_str(" selectable");
self
}
}

component!(Table);
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['row']

selectRow(event) {
this.rowTargets.forEach(row => row.classList.remove('active'))
event.currentTarget.classList.add('active')
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
<table class="table table-lg">
<table class="<%= classes %>" data-controller="tables-large-table">
<thead>
<tr>
<% for header in headers { %>
Expand All@@ -11,4 +11,4 @@
<%+ row %>
<% } %>
</tbody>
</div>
</table>
7 changes: 7 additions & 0 deletionspgml-dashboard/static/js/playground.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
selectRow(event) {
console.log('dataset: ', event.currentTarget.dataset)
}
}
71 changes: 50 additions & 21 deletionspgml-dashboard/templates/content/playground.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
<% use crate::components::*; %>
<% use crate::components::*;
use crate::components::tables::large::*;
use crate::components::navigation::tabs::*;
%>

<div class="min-height: 100vh;">
<div class="min-height: 100vh;" data-controller="playground">
<h3 class="h3">Playground</h3>

<div class="mb-3">
Expand DownExpand Up@@ -37,26 +40,52 @@ <h3 class="h3">Playground</h3>
</div>
</div>
<div class="mb-3">
<%+ navigation::tabs::Tabs::new(&vec![
navigation::tabs::Tab::new(
"Test tab",
"Test content".into()
),
navigation::tabs::Tab::new(
"Second tab",
"Second tab content".into()
),
navigation::tabs::Tab::new(
"Third active tab",
"Hello third tab".into(),
),
]).active_tab("Third active tab") %>
<%+ Tabs::new(
&[
Tab::new(
"Test tab",
Table::new(
&["Date", "Time", "Status"],
&[
Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(),
"Ready".into()
])
.action("click->playground#selectRow")
.data("row-id", "1"),

Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()
])
.action("click->playground#selectRow")
.data("row-id", "2"),

Row::new(&[
"01/01/2022".into(),
"20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()
])
.action("click->playground#selectRow")
.data("row-id", "3"),

])
.selectable()
.into()
),
Tab::new(
"Second tab",
"Second tab content".into()
),
Tab::new(
"Third active tab",
"Hello third tab".into(),
),
]
)
.active_tab("Test tab") %>
</div>
<div class="mb-3">
<%+ tables::large::Table::new(&["Date", "Time", "Status"], &vec![
tables::large::Row::new(&["01/01/2022".into(), "20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()]),
tables::large::Row::new(&["01/01/2022".into(), "20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()]),
tables::large::Row::new(&["01/01/2022".into(), "20:00:43.956373 +00:00:00 UTC".into(), "Ready".into()]),
]) %>

</div>
</div>

[8]ページ先頭

©2009-2025 Movatter.jp