Code Monkey home page Code Monkey logo

yew_icons's Introduction

yew_icons

Icons Gallery Latest Version

This crate makes it easy to use SVG icons from the following collections (more may be added in the future):

Icon Set License Variants
Bootstrap MIT License -
Feather MIT License Deprecated (use Lucide)
Font Awesome CC BY 4.0 License Regular, Solid
Heroicons MIT License Solid, Outline, Mini Solid
Lipis Flag Icons MIT License -
Lucide ISC License -
Octicons MIT License -
Simple Icons CC0 License -
Extra Case-by-case -

Gallery

Gallery

*not all icons included in gallery.

Usage

Use the gallery to find icons you like, and add them as feature flags.

# If still using yew 0.19, use yew_icons 0.6.1
# If still using yew 0.20, use yew_icons 0.7.3

[dependencies]
yew_icons = {version = "0.8", features = ["LucideArrowLeftCircle", "LucideArrowRightCircle", "LucideArrowUpCircle"]}

Then, add an <Icon> component with the corresponding icon id, optionally specifying a width, height, and/or onclick callback.

use yew::prelude::*;
use yew_icons::{Icon, IconId};

html!{
    <>
        <Icon icon_id={IconId::LucideArrowLeftCircle}/>
        <Icon icon_id={IconId::LucideArrowUpCircle} width={"2em".to_owned()} height={"2em".to_owned()}/>
        <Icon icon_id={IconId::LucideArrowRightCircle} onclick={Callback::from(|_: MouseEvent| {})}/>
    </>
}

example image

Note: The icons will inherit their parent's CSS color.

Feature Flags

Each icon collection must be included with the corresponding feature flag, such as lucide or font_awesome_solid.

To save binary size, individual icons can also be included by feature flag, such as LucideZoomIn or FontAwesomeSolidAtom.

By default, no collections or icons are included. Be warned that including too many icons may result in a .wasm binary that some WebAssembly engines refuse to load, especially in debug mode (see rustwasm/wasm-pack#981).

License

Code is licensed under either of

at your option.

Icons are licensed by their respective creators (see above). An license summary is emitted to the DOM for each icon:

<svg data-license="...original license..."></svg>

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Updating an Icon Collection

# 1. on first checkout, init submodules:
git submodule update --init --recursive

# 2. update a submodule to latest commit in remote branch:
git submodule update --remote bootstrap

# 3. generate the icons, writing the feature flags to a file:
cargo run --features="generator" > generated_feature_flags.txt

# 4. reformat the feature flags onto separate lines (choose your own adventure, e.g. vim macros)

# 5. copy the feature flags from generated_feature_flags.txt to the Cargo.toml

PR's ideally shouldn't include non-trivial amounts of generated file diffs. Merging and then generating is much easier to review than thousands of generated files.

Running tests

# 1. uncomment the "testing" feature flag in Cargo.toml

# 2. for each icon set to test, run:
cargo test test --features "enum-iterator testing [icon collection to test]"
# (the test name is "test", which we specify to skip the doc tests)
# icon collection options are: bootstrap feather font_awesome_regular font_awesome_solid heroicons_mini_solid heroicons_outline heroicons_solid lipis_flag_icons_1_x_1 lipis_flag_icons_4_x_3 lucide octicons simple_icons
# if testing all icon sets at once, the prokio-runtime-worker may overflow its stack

yew_icons's People

Contributors

finnbear avatar github-actions[bot] avatar mjpauly avatar neo-ciber94 avatar palkerecsenyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yew_icons's Issues

Add Simple Icons

Hi, maintainer of Simple Icons here ๐Ÿ‘๐Ÿผ

Have you considered to add simple-icons as part of the package? You can see all icons that the library provides at https://simpleicons.org

All icons are in a 24x24 px format using viewBox="0 0 24 24" (see example here), including the brand color as part of the npm package. You may find useful NodeJS usage section of the docs and metadata explanation.

If you need help with the implementation I would be happy to help. Cheers!

Cannot use any icons

No icons work, and fail to compile. This is reproducible by copying the example. This is most likely because of the latest version of Yew.

The compiler gives this error message:

error[E0277]: the trait bound `Icon: yew::Component` is not satisfied
   |
21 |                     <Icon icon_id={IconId::LucideArrowUpCircle}/>
   |                      ^^^^ the trait `yew::Component` is not implemented for `Icon`
   |
   = help: the trait `yew::Component` is implemented for `ContextProvider<T>`
   = note: required for `Icon` to implement `yew::BaseComponent`
   = note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

Change from Feather Icons to Lucide

It seems that the Feather repository is not actively maintained anymore, but there is Lucide which is a fork, with an actively maintained code base. Please consider switching to Lucide.

failed to read `/.../Cargo.toml` error when cargo build

cargo --version
cargo 1.59.0 (49d8809dc 2022-02-10)

Cargo.toml

[package]
name = "my-website"
version = "0.1.0"
edition = "2021"

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

[dependencies]
yew = "0.19.3"
yew-router = "0.16.0"
yew_icons = {path = "..", features = ["FeatherArrowLeftCircle", "FeatherArrowRightCircle", "FeatherArrowUpCircle"]}

Error:

โžœ  my-website git:(main) โœ— cargo build
error: failed to get `yew_icons` as a dependency of package `my-website v0.1.0 (/home/s1n7ax/Workspace/my-website)`

Caused by:
  failed to load source for dependency `yew_icons`

Caused by:
  Unable to update /home/s1n7ax/Workspace

Caused by:
  failed to read `/home/s1n7ax/Workspace/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

In gallery, copy icon id to clipboard upon click

Just a suggestion:
Currently the workflow in the gallery is very cumbersome, as one has to open dev tools to inspect the icon element before being able to copy the icon id.
It would be much easier if the icon id was copied into the clipboard upon click on an icon :)

Cannot use with yew-next

building results in the following error

error[E0277]: the trait bound `yew::functional::FunctionComponent<icon>: yew::Component` is not satisfied
  --> src/client/components/navbar.rs:59:26
   |
59 |                         <Icon icon_id={IconId::FontAwesomeSolidBars} />
   |                          ^^^^ the trait `yew::Component` is not implemented for `yew::functional::FunctionComponent<icon>`
   |
   = help: the trait `yew::Component` is implemented for `ContextProvider<T>`
   = note: required for `yew::functional::FunctionComponent<icon>` to implement `yew::BaseComponent`
   = note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `new` exists for struct `VChild<yew::functional::FunctionComponent<icon>>`, but its trait bounds were not satisfied
  --> src/client/components/navbar.rs:59:26
   |
59 |                         <Icon icon_id={IconId::FontAwesomeSolidBars} />
   |                          ^^^^ function or associated item cannot be called on `VChild<yew::functional::FunctionComponent<icon>>` due to unsatisfied trait bounds
   |
  ::: /Users/maxgiga/.cargo/registry/src/github.com-1ecc6299db9ec823/yew-0.19.3/src/functional/mod.rs:80:1
   |
80 | pub struct FunctionComponent<T: FunctionProvider + 'static> {
   | ----------------------------------------------------------- doesn't satisfy `_: yew::BaseComponent`
   |
   = note: the following trait bounds were not satisfied:
           `yew::functional::FunctionComponent<icon>: yew::BaseComponent`
   = note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.