Skip to content

Commit

Permalink
Merge pull request #77 from dancespiele/improve-navbar-dropdown
Browse files Browse the repository at this point in the history
set by web_sys the same width for the dropdown than its container
  • Loading branch information
dancespiele authored Nov 11, 2020
2 parents daaa4c9 + 007d2e5 commit 8c26241
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://gitcoin.co/grants/1048/yew-styles', 'https://paypal.me/dancespiele?locale.x=en_US']
custom: ['https://gitcoin.co/grants/1048/yew-styles']
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<a href="https://docs.rs/yew_styles/"><img alt="API Docs" src="https://img.shields.io/badge/yew__styles-docs-informational"/></a>
<a href="https://discord.gg/VQck8X4" target="_blank"><img alt="Discord Chat" src="https://img.shields.io/badge/Discor-Spielrs%20-yellowgreen"/></a>
<a href="https://github.com/spielrs/yew_styles/blob/master/LICENSE-MIT.md" target="_blank"><img alt="License" src="https://img.shields.io/badge/License-MIT%2FApache--2.0-lightgrey"></a>
<a href="https://paypal.me/dancespiele?locale.x=en_US" target="_blank"><img alt="Donate by Paypal" src="https://img.shields.io/badge/Donate-PayPal-green.svg"/></a>
</p>
</div>

Expand Down Expand Up @@ -78,11 +77,16 @@ its logic works, in the same file where it is implemented (test events is not ne
* Documentation in the component showing an example of using it and small description of each prop
* Create a component page in `/crate/src/page` with the same structure than the rest of the components



## Do you like Yew Styles?
If you like Yew Styles, help us supporting the project:
If you like Yew Styles, help me supporting the project:
- [Gitcoin](https://gitcoin.co/grants/1048/yew-styles)
- BAT rewards in case that you use [Brave Browser](https://brave.com/)
- [Github Sponsors](https://github.com/sponsors/dancespiele)
- [Paypal](https://paypal.me/dancespiele?locale.x=en_US)
- Burst coins to the address BURST-DPN6-2AT3-FCRL-9BBKG

If you need a feature that is not cover yet, as soon as possible, you can also fund the issue [here](https://issuehunt.io/r/spielrs/yew_styles)

## Code of Conduct
Please check our [code of conduct](CODE_OF_CONDUCT.md)
Expand Down
5 changes: 0 additions & 5 deletions app/page-styles/_navbar.sass
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
.navbar-dropdown
svg
vertical-align: bottom

@media all and (min-width: 769px)
.navbar-dropdown
ul
width: 80px
8 changes: 7 additions & 1 deletion app/yew-styles/_navbar.sass
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@

ul
padding: 0
margin-top: 3px
margin-top: 2px
position: absolute
left: 0
top: 40px

z-index: 1

&.active
display: inherit

&.inactive
display: none

li
display: block
padding: 10px
Expand Down
8 changes: 7 additions & 1 deletion app/yew-styles/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/yew-styles/main.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/yew-styles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yew-styles",
"version": "0.8.0",
"version": "0.8.1",
"description": "css for yew_styles",
"repository": {
"url": "https://github.com/spielrs/yew-styles-page/tree/master/app/yew-styles"
Expand Down
4 changes: 2 additions & 2 deletions crate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT/Apache-2.0"
name = "yew_style_page"
readme = "./README.md"
repository = "https://github.com/spielrs/yew-styles-page.git"
version = "0.8.0"
version = "0.8.1"

[lib]
crate-type = ["cdylib"]
Expand Down
6 changes: 4 additions & 2 deletions crate/src/page/home_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ impl Component for HomePage {
</Item>
<Item layouts=vec!(ItemLayout::ItXl(8), ItemLayout::ItM(10), ItemLayout::ItXs(12))>
<h2>{"Do you like Yew Styles?"}</h2>
<p>{"If you like Yew Styles, help us supporting the project:"}</p>
<p>{"If you like Yew Styles, help me supporting the project:"}</p>
<ul>
<li><a href="https://gitcoin.co/grants/1048/yew-styles" target="_blank">{"Gitcoin"}</a></li>
<li>{"BAT rewards in case that you use "}<a href="https://brave.com">{"Brave Browser"}</a></li>
<li><a href="https://github.com/sponsors/dancespiele" target="_blank">{"Github Sponsors"}</a></li>
<li><a href="https://paypal.me/dancespiele?locale.x=en_US" target="_blank">{"Paypal"}</a></li>
<li>{"Burst coins to the address BURST-DPN6-2AT3-FCRL-9BBKG"}</li>
</ul>
<p>{"If you need a feature that is not cover yet, as soon as possible, you can also fund the issue "}<a href="https://issuehunt.io/r/spielrs/yew_styles">{"here"}</a></p>
</Item>
<Item layouts=vec!(ItemLayout::ItXl(8), ItemLayout::ItM(10), ItemLayout::ItXs(12))>
<h2>{"Code of Conduct"}</h2>
Expand Down
2 changes: 1 addition & 1 deletion crate/yew_styles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crate/yew_styles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yew_styles"
version = "0.8.0"
version = "0.8.1"
description = "Framework styles for yew"
documentation = "https://docs.rs/crate/yew_styles"
authors = ["Francisco Jesus Navarro Cortes <[email protected]>"]
Expand Down
7 changes: 5 additions & 2 deletions crate/yew_styles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ its logic works, in the same file where it is implemented (test events is not ne
* Create a component page in `/crate/src/page` with the same structure than the rest of the components

## Do you like Yew Styles?
If you like Yew Styles, help us supporting the project:
If you like Yew Styles, help me supporting the project:
- [Gitcoin](https://gitcoin.co/grants/1048/yew-styles)
- BAT rewards in case that you use [Brave Browser](https://brave.com/)
- [Github Sponsors](https://github.com/sponsors/dancespiele)
- [Paypal](https://paypal.me/dancespiele?locale.x=en_US)
- Burst coins to the address BURST-DPN6-2AT3-FCRL-9BBKG

If you need a feature that is not cover yet, as soon as possible, you can also fund the issue [here](https://issuehunt.io/r/spielrs/yew_styles).

## Code Contributors

Expand Down
14 changes: 5 additions & 9 deletions crate/yew_styles/src/components/modal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::styles::{get_palette, get_size, get_style, Palette, Size, Style};
use crate::utils::get_html_element_by_class;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
use web_sys::{Element, HtmlElement};
use web_sys::Element;
use yew::prelude::*;
use yew::{utils, App};

Expand Down Expand Up @@ -214,14 +215,9 @@ impl Component for Modal {

fn rendered(&mut self, _first_render: bool) {
if self.props.is_open && self.props.auto_focus {
utils::document()
.get_elements_by_class_name("modal")
.get_with_index(0)
.unwrap()
.dyn_into::<HtmlElement>()
.unwrap()
.focus()
.unwrap();
let modal_form = get_html_element_by_class("modal", 0);

modal_form.focus().unwrap();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils::{get_html_element_by_class, get_random_string};
use wasm_bindgen_test::*;
use yew::prelude::*;
use yew::{utils, App};
Expand Down Expand Up @@ -108,6 +109,7 @@ use yew::{utils, App};
pub struct NavbarDropdown {
props: Props,
show: bool,
key: String,
link: ComponentLink<Self>,
}

Expand Down Expand Up @@ -140,9 +142,12 @@ impl Component for NavbarDropdown {
type Properties = Props;

fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
let key = get_random_string(10);

Self {
props,
link,
key,
show: false,
}
}
Expand All @@ -167,10 +172,26 @@ impl Component for NavbarDropdown {
false
}

fn rendered(&mut self, first_render: bool) {
if first_render {
let navbar_dropdown =
get_html_element_by_class(&format!("navbar-dropdown-{}", self.key), 0);
let navbar_dropdown_width = navbar_dropdown.offset_width();

let navbar_dropdown_container =
get_html_element_by_class(&format!("navbar-dropdown-container-{}", self.key), 0);

navbar_dropdown_container
.style()
.set_property("width", &format!("{}px", navbar_dropdown_width))
.unwrap()
}
}

fn view(&self) -> Html {
html! {
<div
class=("navbar-dropdown", if self.props.active {
class=("navbar-dropdown", format!("navbar-dropdown-{}", self.key), if self.props.active {
"active"
} else {
""
Expand All @@ -182,21 +203,17 @@ impl Component for NavbarDropdown {
onclick=self.link.callback(|_| Msg::HideDropdown)
>
<div class="main-content">{self.props.main_content.clone()}</div>
{get_items(self.show, self.props.children.clone())}
{get_items(self.show, self.key.clone(), self.props.children.clone())}
</div>
}
}
}

fn get_items(show: bool, children: Children) -> Html {
if show {
html! {
<ul>
{children.clone()}
</ul>
}
} else {
html! {}
fn get_items(show: bool, key: String, children: Children) -> Html {
html! {
<ul class=(format!("navbar-dropdown-container-{}", key), if show { "active"} else {"inactive"})>
{children.clone()}
</ul>
}
}

Expand Down
18 changes: 11 additions & 7 deletions crate/yew_styles/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
use web_sys::{window, HtmlElement};
use yew::utils;

pub fn create_style(style: String, value: String, wrap: String) {
let document = window().unwrap().document().unwrap();
let element = document
.get_elements_by_class_name(&wrap)
.get_with_index(0)
.unwrap()
.dyn_into::<HtmlElement>()
.unwrap();
let element = get_html_element_by_class(&wrap, 0);

element.style().set_property(&style, &value).unwrap();
}
Expand All @@ -25,6 +20,15 @@ pub fn get_random_string(len: usize) -> String {
.collect::<String>()
}

pub fn get_html_element_by_class(class_name: &str, index: u32) -> HtmlElement {
utils::document()
.get_elements_by_class_name(class_name)
.get_with_index(index)
.unwrap()
.dyn_into::<HtmlElement>()
.unwrap()
}

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
Expand Down
10 changes: 2 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c26241

Please sign in to comment.