Skip to content

Added an accordian and another star #1077

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 1 commit into from
Oct 16, 2023
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
16 changes: 16 additions & 0 deletions pgml-dashboard/src/components/accordian/accordian.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
div[data-controller="accordian"] {
.accordian-header {
cursor: pointer;
}

.accordian-body {
display: none;
height: 0px;
transition: all 0.5s ease-in-out;
}

.accordian-body.selected {
display: block;
height: auto;
}
}
18 changes: 18 additions & 0 deletions pgml-dashboard/src/components/accordian/accordian_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
titleClick(e) {
let target = e.currentTarget.getAttribute("data-value");
let elements = document.getElementsByClassName("accordian-body");
for (let i = 0; i < elements.length; i++) {
elements[i].classList.remove("selected");
}
elements = document.getElementsByClassName("accordian-header");
for (let i = 0; i < elements.length; i++) {
elements[i].classList.remove("selected");
}
let element = document.querySelector(`[data-accordian-target="${target}"]`);
element.classList.add("selected");
e.currentTarget.classList.add("selected");
}
}
36 changes: 36 additions & 0 deletions pgml-dashboard/src/components/accordian/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use sailfish::TemplateOnce;
use pgml_components::component;

// This component will probably not work very well if two are on the same page at once. We can get
// around it if we include some randomness with the data values in the template.html but that
// doesn't feel very clean so I will leave this problem until we have need to fix it or a better
// idea of how to
#[derive(TemplateOnce, Default)]
#[template(path = "accordian/template.html")]
pub struct Accordian {
html_contents: Vec<String>,
Copy link
Contributor

@levkk levkk Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pgml_components::Component so the caller doesn't have to render_once().unwrap() the inputs.

html_titles: Vec<String>,
selected: usize
}

impl Accordian {
pub fn new() -> Accordian {
Accordian {
html_contents: Vec::new(),
html_titles: Vec::new(),
selected: 0,
}
}

pub fn html_contents<S: ToString>(mut self, html_contents: Vec<S>) -> Self {
self.html_contents = html_contents.into_iter().map(|s| s.to_string()).collect();
self
}

pub fn html_titles<S: ToString>(mut self, html_titles: Vec<S>) -> Self {
self.html_titles = html_titles.into_iter().map(|s| s.to_string()).collect();
self
}
}

component!(Accordian);
16 changes: 16 additions & 0 deletions pgml-dashboard/src/components/accordian/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% use std::iter::zip; %>

<div data-controller="accordian">
<div class="accordian">
<% for i in (0..html_contents.len()) { %>
<div class="accordian-item">
<div class="accordian-header <% if i == selected { %> selected <% } %>" data-action="click->accordian#titleClick" data-value="accordian-body<%= i %>">
<%- html_titles[i] %>
</div>
<div class="accordian-body <% if i == selected { %> selected <% } %>" data-accordian-target="accordian-body<%= i %>">
<%- html_contents[i] %>
</div>
</div>
<% } %>
</div>
</div>
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/inputs/select/option.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<li class="menu-item d-flex align-items-center">
<li class="menu-item d-flex align-items-center" data-for="<%= value %>">
<button type="button" class="dropdown-item" data-action="<%- action %>"><%= value %></button>
</li>
4 changes: 4 additions & 0 deletions pgml-dashboard/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// This file is automatically generated.
// You shouldn't modify it manually.

// src/components/accordian
pub mod accordian;
pub use accordian::Accordian;

// src/components/breadcrumbs
pub mod breadcrumbs;
pub use breadcrumbs::Breadcrumbs;
Expand Down
4 changes: 4 additions & 0 deletions pgml-dashboard/src/components/star/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const SVGS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
"party",
include_str!("../../../static/images/icons/stars/party.svg"),
);
map.insert(
"give_it_a_spin",
include_str!("../../../static/images/icons/stars/give_it_a_spin.svg"),
);
map
});

Expand Down
1 change: 1 addition & 0 deletions pgml-dashboard/static/css/modules.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is automatically generated.
// There is no need to edit it manually.

@import "../../src/components/accordian/accordian.scss";
@import "../../src/components/chatbot/chatbot.scss";
@import "../../src/components/dropdown/dropdown.scss";
@import "../../src/components/inputs/range_group/range_group.scss";
Expand Down
31 changes: 31 additions & 0 deletions pgml-dashboard/static/images/icons/stars/give_it_a_spin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy