GithubHelp home page GithubHelp logo

thedodd / ybc Goto Github PK

View Code? Open in Web Editor NEW
253.0 8.0 36.0 236 KB

A Yew component library based on the Bulma CSS framework.

License: Apache License 2.0

Rust 100.00%
bulma yew ybc css sass yew-components wasm web

ybc's Introduction

ybc

Build Status Crates.io docs.rs License Discord Chat Crates.io

A Yew component library based on the Bulma CSS framework.

YBC encapsulates all of the structure, style and functionality of the Bulma CSS framework as a set of Yew components. YBC also ships with support for the Yew Router, adding Bulma-styled components which wrap the Yew Router components for clean integration.

As a guiding principle, YBC does not attempt to encapsulate every single Bulma style as a Rust type, let alone the many valid style combinations. That would be far too complex, and probably limiting to the user in many ways. Instead, YBC handles structure, required classes, functionality, sane defaults and every component can be customized with any additional classes for an exact look and feel.

What does it look like to use YBC? The following is a snippet of a component's view method rendering a navbar, a fluid container, and some tiles.

use ybc::NavbarFixed::Top;
use ybc::TileCtx::{Ancestor, Child, Parent};
use ybc::TileSize::Four;
use yew::prelude::*;

struct App; // An application component.

impl Component for App {
  /* .. snip .. */
  fn view(&self) -> Html {
    html!{
      <>
      <ybc::Navbar fixed=Top /* .. your navbar content here .. *//>
      <ybc::Container fluid=true>
        <ybc::Tile ctx=Ancestor>
          <ybc::Tile ctx=Parent vertical=true size=Four>
            <ybc::Tile ctx=Child classes=classes!("box")>
              <p>{"Lorem ipsum dolor sit amet ..."}</p>
            </ybc::Tile>
            /* .. snip .. more tiles here .. */
          </ybc::Tile>
        </ybc::Tile>
      </ybc::Container>
      </>
    }
  }
}

getting started

add ybc dependency

First, add this library to your Cargo.toml dependencies.

[dependencies]
ybc = "*"

add bulma

add bulma css (no customizations)

This project works perfectly well if you just include the Bulma CSS in your HTML, as described here. The following link in your HTML head should do the trick: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"/>.

add bulma sass (allows customization & themes)

However, if you want to customize Bulma to match your style guidelines, then you will need to have a copy of the Bulma SASS locally, and then import Bulma after you've defined your customizations, as described here.

// index.scss

// Set your brand colors
$purple: #8A4D76;
$pink: #FA7C91;
$brown: #757763;
$beige-light: #D0D1CD;
$beige-lighter: #EFF0EB;

// Import the rest of Bulma
@import "path/to/bulma";

If you are using Trunk to build your application and bundle its assets, then simply point to your index.scss from your index.html file, and Trunk will handle compling your application, your sass, and will make everything available in your dist dir.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="index.sass"/>
  </head>
  <body>
    <!-- ... snip ... -->
  </body>
</html>

Now just execute trunk serve --open, and your application will be built and opened in your browser.

If you are not using Trunk, you will need to use another mechanism for building your Rust WASM application and its assets.

web-sys & stdweb

Currently, this library only supports the web-sys backend. Support for stdweb is not currently planned. If that is problematic, please open an issue describing why. Cheers!

ybc's People

Contributors

follpvosten avatar intgr avatar pscheidl avatar samet195 avatar shenek avatar sionois avatar thedodd 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar

ybc's Issues

Component implementation not being satisfied

Issue: Component implementation not being satisfied.

Working with the master branch of yew gives the following error for many (if not all) components in the library:

error[E0599]: no function or associated item named `new` found for struct `VChild<Navbar>` in the current scope
   --> src/model.rs:149:18
    |
149 |                 <ybc::Navbar classes="is-light">
    |                  ^^^^^^^^^^^ function or associated item not found in `VChild<Navbar>`
    | 
   ::: /home/joseph/.local/share/cargo/git/checkouts/ybc-98c1ec494f717c00/a4a4dd1/src/components/navbar.rs:57:1
    |
57  | pub struct Navbar {
    | ----------------- doesn't satisfy `Navbar: yew::Component`
    |
    = note: the method `new` exists but the following trait bounds were not satisfied:
            `Navbar: yew::Component`

error[E0277]: the trait bound `Navbar: yew::Component` is not satisfied
   --> src/model.rs:149:18
    |
149 |                 <ybc::Navbar classes="is-light">
    |                  ^^^^^^^^^^^ the trait `yew::Component` is not implemented for `Navbar`

In trying to debug this issue, I found that it looks like some problem related to https://github.com/yewstack/yew/blob/master/yew/src/virtual_dom/vcomp.rs#L72.

Should `FileProperties::files` be a `Vec<String>`?

Currently the files property of ybc::FileProperties is a Vec<web_sys::File>.
This is slightly inconvenient, because in order to read the file, one need to hand it over eg to a ReaderService, at which point ybc::FileProperties can no longer own it.

Of the whole web_sys::File object, only the name seems in use. If instead of files, ybc::FileProperties contained a file_names: Vec<String>, ownership wouldn't be an issue anymore.

Thus I offer to add a file_names property to ybc::FileProperties. files would stay for compatibility. Its content would appended to the list, after elements from file_names.
Does that sound reasonable? If yes, I'll be happy to send you a pull request.

Onkeydown for input?

Thanks for your work on ybc.

Im looking to implement onkeydown events for an input, as it looks like only oninput callbacks are currently supported, would you be interested in a PR to make onkeydown callbacks optionally available?

migration to yew 0.21.0

Please migrate to yew.0.21.0. I can see only significant problems with Modal and Worker implementation. On Yew's side, the Worker impl got changed.

Impossible to instantiate ybc::Input as `type` is a prohibited identifier

While trying to instantiate an Input component with a custom type, as the struct uses a field name type that conflicts with the Rust reserved type keyword, the macro gets confused and refuses to build. I might be misusing it here, but I can't find a way around it beyond renaming it in the props struct.

Loading prop has no effect

First thanks for working on this lib! I'm a newcomer trying it out.

I believe the loading prop for TextArea has no effect, as the loading spinner animation exists in a html ::after that is present when a is-loading class exists in a control wrapper element.

The following rust:

<ybc::Field
    label={".."}
    help={".."}
><ybc::Control
    tag={"div"}
    classes={classes!("")}
><ybc::TextArea
    name={"example"}
    value={""}
    update={link.callback(Msg::TextAreaUpdated)}
    placeholder={".."}
    loading=true
/></ybc::Control></ybc::Field>

Results in the following html (in which the spinner is not present) :

<div class="field">
  <label class="label">..</label>
  <div class="control">
    <textarea name="example" placeholder=".." rows="0" class="textarea is-loading"></textarea>
  </div>
  <label class="help">..</label>
</div>

Note: the .field.control.is-loading is set.


But the following rust:

<ybc::Field
    label={".."}
    help={".."}
><ybc::Control
    tag={"div"}
    classes={classes!("is-loading")}
><ybc::TextArea
    name={"example"}
    value={""}
    update={link.callback(Msg::TextAreaUpdated)}
    placeholder={".."}
/></ybc::Control></ybc::Field>

Results in the following html (in which the spinner is present) :

<div class="field">
  <label class="label">..</label>
  <div class="control is-loading">
    <textarea name="example" placeholder=".." rows="0" class="textarea"></textarea>
    ::after
  </div>
  <label class="help">..</label>
</div>

Note: The .field.control and the .field.is-loading are set.

Close navbar-dropdown on item click

I'm writing a simple app using ybc and yew-router, triggering routing by using href on navbar items.
Some of these are in a navbar-dropdown, and I've noticed that the dropdown only closes when you click on the overlay, but not when you click on an item in the dropdown; this doesn't really work for my usecase, where the dropdown is used like a menu to navigate the page as described above.
I think this could be fixed by (maybe optionally) internally handling the onclick event on the dropdown itself, which should catch any clicks on its children if they're not getting cancelled (so this approach would still allow overriding this behavior for specific items in any case).
Would you be interested in a PR implementing a feature like that? And if so, should it be an option or the default case? And if it should be optional, what should I call the property on NavbarDropdown?

Allow `onclick` callback property on more things like: `NavbarItem`

Allow setting the onclick property on the NavbarItem. This would allow the creation of Single Page Applications that handle routes using javascript and update the browser history from javascript like this: https://docs.rs/yew-router/latest/yew_router/

Using A or specifically NavbarItem tags instead of buttons has the advantage that the url is actually visible to the user and they can open the link on a new tab if they wish, however if they just click on it the onclick handler runs.

Call for co-maintainers

Hello friends! TL;DR: I'm looking for co-maintainers.

Please see the issue I've opened over in the Trunk project (here is the issue) for more details.

IF YOU ARE INTERESTED, please go over to the Trunk issue and let me know there. Cheers!

Add more examples

Hey!
I find it a bit difficult to get started with ybc because it's not immediately obvious how bulma constructs map to ybc ones. Notably, showing how to make forms would be appreciated as it uses multiple components in intricate ways.

Investigate additional properties to define on Components

As mentioned in #12 (comment):

Looks like this is something we will want to eventually add to ybc::Input. Want to pop a ticket so that we can track this?

This tracking ticket is in reference to wanting to include the onkeypress event to the Input component but extends to other parts of ybc.

Currently, a number of expected/desirable properties are not available on the components in the library, including those expected for global attributes, aria- labels, and per-Component properties (eg: input). A curated list of properties should probably be added to components that would benefit from them.


Input

Attributes

  • autocomplete - Option
  • autofocus - Option
  • class(es) - Option
  • dir - Option
  • disabled - bool
  • hidden - Option
  • id - Option <-- See #10
  • inputmode - Option
  • form - Option
  • list - Option
  • name - String
  • placeholder - String <-- make Option?
  • required - Option
  • spellcheck - Option
  • style - Option
  • tabindex - Option
  • type - InputType
  • value - String

Events

  • onabort ?
  • onblur
  • onerror
  • onfocus
  • oncancel ?
  • onchange <-- currently update?
  • onclick
  • ondblclick
  • oninput
  • oninvalid
  • onkeydown
  • onkeypress
  • onkeyup
  • onsubmit
  • ontouchcancel
  • ontouchend
  • ontouchstart

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.