Skip to content

Commit

Permalink
Add new edit icon
Browse files Browse the repository at this point in the history
  • Loading branch information
ejoepes committed Oct 17, 2024
1 parent 522e0c3 commit 9c9597b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use web_sys::HtmlElement;
use crate::{
css::TABLE_ROW,
data::Aeat720Record,
utils::{icons::render_svg_delete_square_icon, usize_to_date},
utils::{icons::{render_svg_delete_square_icon, render_svg_edit_icon}, usize_to_date},
};

pub struct Table {
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Table {
.style("vertical-align", "bottom")
.style("font-weight", "bold")
.style("background-color", "#ddd")
.text("Eliminar")
.text("")
})
)
})
Expand Down Expand Up @@ -113,6 +113,7 @@ impl Table {
.text("%")
}),
html!("td" => HtmlElement, {
.child(render_svg_edit_icon("red", "24"))
.child(render_svg_delete_square_icon("red", "24"))
.with_node!(_element => {
.event(clone!(this => move |_: events::Click| {
Expand Down
55 changes: 47 additions & 8 deletions src/utils/icons.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
use dominator::{svg, Dom};
use dominator::{svg, Dom, DomBuilder};
use web_sys::SvgElement;

pub fn render_svg_delete_square_icon(color: &str, size: &str) -> Dom {
// <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-square"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><line x1="9" y1="9" x2="15" y2="15"></line><line x1="15" y1="9" x2="9" y2="15"></line></svg>
svg!("svg", {
.attr("alt", "facebook icon")
.attr("width", size)
.attr("height", size)
fn svg_icon_attrs(icon: DomBuilder<SvgElement>) -> DomBuilder<SvgElement> {
icon
.attr("viewBox", "0 0 24 24")
.attr("fill", "none")
.attr("stroke", color)
.attr("stroke-width", "2")
.attr("stroke-linecap", "round")
.attr("stroke-linejoin", "round")
}

pub fn render_svg_save_icon(color: &str, size: &str) -> Dom {

Check warning on line 13 in src/utils/icons.rs

View workflow job for this annotation

GitHub Actions / Unit Tests on 1.80.1

function `render_svg_save_icon` is never used

Check warning on line 13 in src/utils/icons.rs

View workflow job for this annotation

GitHub Actions / Unit Tests on 1.80.1

function `render_svg_save_icon` is never used

Check warning on line 13 in src/utils/icons.rs

View workflow job for this annotation

GitHub Actions / Format & Clippy (1.80.1)

function `render_svg_save_icon` is never used
svg!("svg", {
.attr("alt", "edit icon")
.attr("width", size)
.attr("height", size)
.attr("stroke", color)
.apply(svg_icon_attrs)
.children(&mut[
svg!("path", {
.attr("d", "M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7")
.attr("d", "M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z")
})
])
})
}

pub fn render_svg_edit_icon(color: &str, size: &str) -> Dom {
svg!("svg", {
.attr("alt", "edit icon")
.attr("width", size)
.attr("height", size)
.attr("stroke", color)
.apply(svg_icon_attrs)
.children(&mut[
svg!("path", {
.attr("d", "M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7")
}),
svg!("path", {
.attr("d", "M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z")
})
])
})
}

pub fn render_svg_delete_square_icon(color: &str, size: &str) -> Dom {
svg!("svg", {
.attr("alt", "delete icon")
.attr("width", size)
.attr("height", size)
.attr("stroke", color)
.apply(svg_icon_attrs)
.children(&mut[
svg!("rect", {
.attr("x", "3")
Expand Down

1 comment on commit 9c9597b

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.