-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Visually Hidden to Leptos 0.7 (#403)
- Loading branch information
1 parent
f04a411
commit 188adaf
Showing
11 changed files
with
164 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 34 additions & 20 deletions
54
packages/primitives/leptos/visually-hidden/src/visually_hidden.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
use leptos::{html::AnyElement, *}; | ||
use radix_leptos_primitive::Primitive; | ||
use leptos::prelude::*; | ||
use leptos_style::Style; | ||
|
||
pub struct UseVisuallyHiddenProps { | ||
style: Style, | ||
} | ||
|
||
pub struct UseVisuallyHiddenReturn { | ||
style: Style, | ||
} | ||
|
||
pub fn use_visually_hidden(props: UseVisuallyHiddenProps) -> UseVisuallyHiddenReturn { | ||
UseVisuallyHiddenReturn { | ||
style: props.style.with_defaults([ | ||
// See: https://github.com/twbs/bootstrap/blob/master/scss/mixins/_screen-reader.scss | ||
("position", "absolute"), | ||
("border", "0px"), | ||
("width", "1px"), | ||
("height", "1px"), | ||
("padding", "0px"), | ||
("margin", "-1px"), | ||
("overflow", "hidden"), | ||
("clip", "rect(0, 0, 0, 0)"), | ||
("white-space", "nowrap"), | ||
("word-wrap", "normal"), | ||
]), | ||
} | ||
} | ||
|
||
#[component] | ||
pub fn VisuallyHidden( | ||
#[prop(into, optional)] as_child: MaybeProp<bool>, | ||
#[prop(optional)] node_ref: NodeRef<AnyElement>, | ||
#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>, | ||
children: ChildrenFn, | ||
#[prop(into, optional)] style: Style, | ||
#[prop(optional)] children: Option<Children>, | ||
) -> impl IntoView { | ||
// TODO: replace with style:<name> attributes once they work properly in Leptos (probably in 0.7?) | ||
let mut attrs = attrs.clone(); | ||
attrs.extend([ | ||
// See: https://github.com/twbs/bootstrap/blob/master/scss/mixins/_screen-reader.scss | ||
("style", "position: absolute; border: 0px; width: 1px; height: 1px; padding: 0px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; word-wrap: normal;".into_attribute() | ||
)]); | ||
let UseVisuallyHiddenReturn { style } = use_visually_hidden(UseVisuallyHiddenProps { style }); | ||
|
||
view! { | ||
<Primitive | ||
element=html::span | ||
as_child=as_child | ||
node_ref=node_ref | ||
attrs=attrs | ||
> | ||
{children()} | ||
</Primitive> | ||
<span style=style> | ||
{children.map(|children| children())} | ||
</span> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.