Skip to content

Commit

Permalink
feat: Dioxus 0.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Mar 10, 2024
1 parent 33c3695 commit 5e3fd53
Show file tree
Hide file tree
Showing 40 changed files with 48,000 additions and 81,341 deletions.
14 changes: 7 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[submodule "icon_resources/font-awesome"]
path = icon_resources/font-awesome
url = git@github.com:FortAwesome/Font-Awesome.git
url = https://github.com/FortAwesome/Font-Awesome
[submodule "icon_resources/heroicons"]
path = icon_resources/heroicons
url = git@github.com:tailwindlabs/heroicons.git
url = https://github.com/tailwindlabs/heroicons
[submodule "icon_resources/ionicons"]
path = icon_resources/ionicons
url = git@github.com:ionic-team/ionicons.git
url = https://github.com/ionic-team/ionicons
[submodule "icon_resources/octicons"]
path = icon_resources/octicons
url = git@github.com:primer/octicons.git
url = https://github.com/primer/octicons
[submodule "icon_resources/bootstrap"]
path = icon_resources/bootstrap
url = git@github.com:twbs/icons.git
url = https://github.com/twbs/icons
[submodule "icon_resources/feather"]
path = icon_resources/feather
url = git@github.com:feathericons/feather.git
url = https://github.com/feathericons/feather
[submodule "icon_resources/material-design-icons"]
path = icon_resources/material-design-icons
url = git@github.com:google/material-design-icons.git
url = https://github.com/google/material-design-icons
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# monorepo only work when using virtual manifest
# see: https://github.com/rust-lang/cargo/issues/7467#issuecomment-867632379
[workspace]
resolver = "2"
members = [
"packages/codegen",
"packages/example",
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Daiki Nishikawa
Copyright (c) 2022-Present Daiki Nishikawa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ use dioxus::prelude::*;
use dioxus_free_icons::icons::fa_brands_icons::FaRust;
use dioxus_free_icons::Icon;

fn RustIcon(cx: Scope) -> Element {
cx.render(rsx! {
fn RustIcon() -> Element {
rsx!(
Icon {
width: 30,
height: 30,
fill: "black",
icon: FaRust,
}
})
)
}
```

Expand Down Expand Up @@ -102,7 +102,7 @@ cargo run
```sh
cd packages/exmaple
cargo install dioxus-cli
dioxus serve
dx serve
```

### Update icons
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-fontawesome-examples"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
20 changes: 10 additions & 10 deletions packages/codegen/src/create_icon_file.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::ffi::OsStr;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::{ffi::OsStr, path::Path};

use heck::ToSnakeCase;
use heck::ToUpperCamelCase;
Expand All @@ -12,7 +12,7 @@ use scraper::ElementRef;
use scraper::Html;
use walkdir::WalkDir;

const ICON_TEMPLATE: &str = r#"#[derive(Copy, Clone, Debug)]
const ICON_TEMPLATE: &str = r#"#[derive(Copy, Clone, Debug, PartialEq)]
pub struct {ICON_NAME};
impl IconShape for {ICON_NAME} {
fn view_box(&self) -> String {
Expand All @@ -21,7 +21,7 @@ impl IconShape for {ICON_NAME} {
fn xmlns(&self) -> String {
String::from("{XMLNS}")
}
fn child_elements(&self) -> LazyNodes {
fn child_elements(&self) -> Element {
rsx! {
{CHILD_ELEMENTS}
}
Expand All @@ -44,11 +44,11 @@ pub fn create_icon_file(svg_path: &str, output_path: &str, icon_prefix: &str) {
.filter_map(|node| {
if node.value().is_element() {
let element = ElementRef::wrap(node).unwrap().value();
if element.attrs.len() != 0 {
if !element.attrs.is_empty() {
return Some(element);
}
}
return None;
None
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -91,7 +91,7 @@ fn collect_svg_files(svg_path: &str, icon_prefix: &str) -> Vec<PathBuf> {
.filter(|e| match icon_prefix {
"Go" => {
let re = Regex::new(r".*-16.svg$").unwrap();
return re.is_match(&e.path().to_str().unwrap());
return re.is_match(e.path().to_str().unwrap());
}
"Md" => {
let path_str = e.path().as_os_str().to_str().unwrap();
Expand All @@ -105,7 +105,7 @@ fn collect_svg_files(svg_path: &str, icon_prefix: &str) -> Vec<PathBuf> {
.collect::<Vec<_>>()
}

fn icon_name(path: &PathBuf, icon_prefix: &str) -> String {
fn icon_name(path: &Path, icon_prefix: &str) -> String {
match icon_prefix {
"Go" => {
let filename = path.file_name().unwrap().to_str().unwrap();
Expand All @@ -131,19 +131,19 @@ fn extract_svg_attrs(element: &Element) -> (String, String) {
let xmlns = element
.attr("xmlns")
.unwrap_or("http://www.w3.org/2000/svg");
return (String::from(view_box), String::from(xmlns));
(String::from(view_box), String::from(xmlns))
}

fn extract_svg_child_elements(elements: &[&Element]) -> String {
elements
.into_iter()
.iter()
.map(|element| {
let tag_name = element.name();
let mut element_attrs = element
.attrs()
.filter_map(|(name, value)| {
let re = Regex::new(r"^data-.*$").unwrap();
if !re.is_match(&name) && name != "fill" {
if !re.is_match(name) && name != "fill" {
Some(format!(
" {}: \"{}\",",
name.to_snake_case(),
Expand Down
8 changes: 4 additions & 4 deletions packages/codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ fn main() {
// create ionicons
const IO_SVG_BASE_PATH: &str = "../../icon_resources/ionicons/src/svg";
let output_path = format!("{}/io_icons.rs", OUTPUT_BASE_PATH);
create_icon_file::create_icon_file(&IO_SVG_BASE_PATH, &output_path, "Io");
create_icon_file::create_icon_file(IO_SVG_BASE_PATH, &output_path, "Io");

// create octicons
const GO_SVG_BASE_PATH: &str = "../../icon_resources/octicons/icons";
let go_output_path = format!("{}/go_icons.rs", OUTPUT_BASE_PATH);
create_icon_file::create_icon_file(&GO_SVG_BASE_PATH, &go_output_path, "Go");
create_icon_file::create_icon_file(GO_SVG_BASE_PATH, &go_output_path, "Go");

// create bootstrap icons
const BS_SVG_BASE_PATH: &str = "../../icon_resources/bootstrap/icons";
let bs_output_path = format!("{}/bs_icons.rs", OUTPUT_BASE_PATH);
create_icon_file::create_icon_file(&BS_SVG_BASE_PATH, &bs_output_path, "Bs");
create_icon_file::create_icon_file(BS_SVG_BASE_PATH, &bs_output_path, "Bs");

// create feather icons
const FI_SVG_BASE_PATH: &str = "../../icon_resources/feather/icons";
let fi_output_path = format!("{}/fi_icons.rs", OUTPUT_BASE_PATH);
create_icon_file::create_icon_file(&FI_SVG_BASE_PATH, &fi_output_path, "Fi");
create_icon_file::create_icon_file(FI_SVG_BASE_PATH, &fi_output_path, "Fi");

// create material design icons
const MI_SVG_BASE_PATH: &str = "../../icon_resources/material-design-icons/src";
Expand Down
5 changes: 1 addition & 4 deletions packages/example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ version = "0.1.0"
authors = ["nissy-dev <nd.12021218@gmail.com>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dioxus = { version = "0.4.0" }
dioxus-web = { version = "0.4.0" }
dioxus = { version = "0.5.0-alpha.0", features = ["web"] }
dioxus-free-icons = { path = "../lib", features = ["font-awesome-brands"] }

log = "0.4.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/example/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Dioxus
Copyright (c) 2022-Present Daiki Nishikawa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions packages/example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ fn main() {
wasm_logger::init(wasm_logger::Config::default());
console_error_panic_hook::set_once();

dioxus_web::launch(app);
launch(app);
}

fn app(cx: Scope) -> Element {
cx.render(rsx! (
fn app() -> Element {
rsx! (
div {
style: "text-align: center;",
h1 { "🌗 Dioxus 🚀" }
Expand All @@ -24,5 +24,5 @@ fn app(cx: Scope) -> Element {
icon: FaRust,
}
}
))
)
}
8 changes: 4 additions & 4 deletions packages/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "dioxus-free-icons"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
authors = ["Daiki Nishikawa <nd.12021218@gmail.com>"]
authors = ["Daiki Nishikawa <nd.12021218@gmail.com>", "Marc Espín <mespinsanz@gmail.com>"]
description = "Use free svg icons in your Dioxus projects easily with dioxus-free-icons."
license = "MIT"
repository = "https://github.com/nissy-dev/dioxus-free-icons"
repository = "https://github.com/dioxus-community/dioxus-free-icons"
readme = "../../README.md"

[dependencies]
dioxus = { version = "0.4.0" }
dioxus = { version = "0.5.0-alpha.0" }

[features]
font-awesome-brands = []
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Daiki Nishikawa
Copyright (c) 2022-Present Daiki Nishikawa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
40 changes: 20 additions & 20 deletions packages/lib/src/icon_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use dioxus::prelude::*;
pub trait IconShape {
fn view_box(&self) -> String;
fn xmlns(&self) -> String;
fn child_elements(&self) -> LazyNodes;
fn child_elements(&self) -> Element;
}

/// Icon component Props
#[derive(PartialEq, Props)]
pub struct IconProps<'a, T: IconShape> {
#[derive(PartialEq, Props, Clone)]
pub struct IconProps<T: IconShape + Clone + PartialEq + 'static> {
/// The icon shape to use.
pub icon: T,
/// The height of the `<svg>` element. Defaults to 20.
Expand All @@ -19,33 +19,33 @@ pub struct IconProps<'a, T: IconShape> {
#[props(default = 20)]
pub width: u32,
/// The color to use for filling the icon. Defaults to "currentColor".
#[props(default = "currentColor")]
pub fill: &'a str,
#[props(default = "currentColor".to_string())]
pub fill: String,
/// An class for the `<svg>` element.
#[props(default = "")]
pub class: &'a str,
#[props(default = "".to_string())]
pub class: String,
/// An accessible, short-text description for the icon.
#[props(default = "")]
pub title: &'a str,
#[props(default = "".to_string())]
pub title: String,
}

/// Icon component which generates SVG elements
#[allow(non_snake_case)]
pub fn Icon<'a, T: IconShape>(cx: Scope<'a, IconProps<'a, T>>) -> Element<'a> {
cx.render(rsx! {
pub fn Icon<T: IconShape + Clone + PartialEq + 'static>(props: IconProps<T>) -> Element {
rsx!(
svg {
stroke: "currentColor",
stroke_width: "0",
class: format_args!("{}", cx.props.class),
height: format_args!("{}", cx.props.height),
width: format_args!("{}", cx.props.width),
view_box: format_args!("{}", cx.props.icon.view_box()),
xmlns: format_args!("{}", cx.props.icon.xmlns()),
fill: format_args!("{}", cx.props.fill),
class: "{props.class}",
height: "{props.height}",
width: "{props.width}",
view_box: "{props.icon.view_box()}",
xmlns: "{props.icon.xmlns()}",
fill: "{props.fill}",
title {
"{cx.props.title}"
"{props.title}"
}
cx.props.icon.child_elements()
{props.icon.child_elements()}
}
})
)
}
Loading

0 comments on commit 5e3fd53

Please sign in to comment.