Content-Length: 563994 | pFad | http://github.com/postgresml/postgresml/commit/a5472c9945b9649df6dc3060b22869ee696ee11c

F9 accordian that uses bootstrap, so no custom js (#1546) · postgresml/postgresml@a5472c9 · GitHub
Skip to content

Commit a5472c9

Browse files
accordian that uses bootstrap, so no custom js (#1546)
1 parent 08d643e commit a5472c9

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
div[data-controller="accordion"] {
2+
.accordion-header {
3+
cursor: pointer;
4+
}
5+
6+
.accordion-body {
7+
overflow: hidden;
8+
transition: all 0.3s ease-in-out;
9+
}
10+
11+
.accordion-item {
12+
padding-top: 1rem;
13+
padding-bottom: 1rem;
14+
border-top: solid #{$gray-600} 1px;
15+
}
16+
17+
.accordion-item:last-child {
18+
border-bottom: solid #{$gray-600} 1px;
19+
}
20+
21+
.accordion-header {
22+
div[aria-expanded="true"] {
23+
.title {
24+
color: #{$gray-100};
25+
}
26+
.add {
27+
display: none;
28+
}
29+
.remove {
30+
display: block;
31+
}
32+
}
33+
div[aria-expanded="false"] {
34+
.title {
35+
color: #{$gray-300};
36+
}
37+
.add {
38+
display: block;
39+
}
40+
.remove {
41+
display: none;
42+
}
43+
}
44+
}
45+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use pgml_components::{component, Component};
2+
use sailfish::TemplateOnce;
3+
4+
#[derive(TemplateOnce, Default)]
5+
#[template(path = "accordion/template.html")]
6+
pub struct Accordion {
7+
html_contents: Vec<Component>,
8+
html_titles: Vec<Component>,
9+
selected: usize,
10+
title_size: String,
11+
}
12+
13+
impl Accordion {
14+
pub fn new() -> Accordion {
15+
Accordion {
16+
html_contents: Vec::new(),
17+
html_titles: Vec::new(),
18+
selected: 0,
19+
title_size: "h5".to_string(),
20+
}
21+
}
22+
23+
pub fn html_contents(mut self, html_contents: Vec<Component>) -> Self {
24+
self.html_contents = html_contents;
25+
self
26+
}
27+
28+
pub fn html_titles(mut self, html_titles: Vec<Component>) -> Self {
29+
self.html_titles = html_titles;
30+
self
31+
}
32+
33+
pub fn set_title_size_body(mut self) -> Self {
34+
self.title_size = "body-regular-text".to_string();
35+
self
36+
}
37+
38+
pub fn set_title_size_header(mut self, title_size: i32) -> Self {
39+
match title_size {
40+
1 => self.title_size = "h1".to_string(),
41+
2 => self.title_size = "h2".to_string(),
42+
3 => self.title_size = "h3".to_string(),
43+
4 => self.title_size = "h4".to_string(),
44+
5 => self.title_size = "h5".to_string(),
45+
6 => self.title_size = "h6".to_string(),
46+
_ => self.title_size = "h5".to_string(),
47+
}
48+
self
49+
}
50+
}
51+
52+
component!(Accordion);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<%
2+
let items = html_contents.iter().zip(html_titles.iter());
3+
%>
4+
5+
<div data-controller="accordion">
6+
<div class="accordion" id="accordionExample">
7+
<% for (i, (content, title)) in items.enumerate() {%>
8+
9+
<%
10+
let expanded = i == selected;
11+
let target = format!("collapse{}a", i);
12+
%>
13+
14+
<div class="accordion-item">
15+
<div class="accordion-header">
16+
<div class="d-flex justify-content-between align-items-center w-100" type="button" data-bs-toggle="collapse" data-bs-target="#<%- target %>" aria-expanded=<%- expanded %> aria-controls="<%- target %>">
17+
<h6 class="mb-0 title <%- title_size %>"><%+ title.clone() %></h6>
18+
<span class="add material-symbols-outlined">add</span>
19+
<span class="remove material-symbols-outlined">remove</span>
20+
</div>
21+
</div>
22+
<div id="<%- target %>" class="accordion-collapse collapse <% if expanded {%>show<% } %>" data-bs-parent="#accordionExample">
23+
<div class="accordion-body pt-3">
24+
<%+ content.clone() %>
25+
</div>
26+
</div>
27+
</div>
28+
<% } %>
29+
30+
</div>
31+
</div>

pgml-dashboard/src/components/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
pub mod accordian;
66
pub use accordian::Accordian;
77

8+
// src/components/accordion
9+
pub mod accordion;
10+
pub use accordion::Accordion;
11+
812
// src/components/badges
913
pub mod badges;
1014

pgml-dashboard/static/css/modules.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// There is no need to edit it manually.
33

44
@import "../../src/components/accordian/accordian.scss";
5+
@import "../../src/components/accordion/accordion.scss";
56
@import "../../src/components/badges/large/label/label.scss";
67
@import "../../src/components/badges/small/label/label.scss";
78
@import "../../src/components/breadcrumbs/breadcrumbs.scss";

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgresml/postgresml/commit/a5472c9945b9649df6dc3060b22869ee696ee11c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy