pub struct Component<D: InstantiableDom = DefaultDom> { /* private fields */ }
Expand description
A lightweight type to encapsulate HTML and CSS using shadow DOM.
See Using Shadow DOM for some background on shadow DOM.
The slot
and multi_slot
methods
generate a slot name and assign it to their arguments. They return a
slot, which should be added to the shadow DOM with the
child
or children
methods.
§Example
This creates a <div>
with an open shadow root attached. The light DOM
will contain the name
and description
spans, assigned to a slot each.
The shadow DOM will contain the <dl>
, <dt>
, and <dd>
elements and
slots for the light DOM elements. HTML id
attributes and CSS are
encapsulated by the shadow DOM.
let name = span().text("HTML");
let description = span().text("HyperText Markup Language");
css!(content = "span {border: 3px solid red}");
let mut term = Component::<Dry>::styled(stylesheet::text());
let name_slot = term.slot(name);
let description_slot = term.slot(description);
term.child(
div().child(span().text("Term Definition")).child(
dl().child(dt().child(name_slot))
.child(dd().child(description_slot)),
),
);
Implementations§
source§impl<D: InstantiableDom> Component<D>
impl<D: InstantiableDom> Component<D>
sourcepub fn styled(css: &str) -> Self
pub fn styled(css: &str) -> Self
Constuct a Component
with a <style>
element in the shadow DOM.
sourcepub fn slot(&mut self, child: impl HtmlElement + ChildNode<D>) -> Slot<D>
pub fn slot(&mut self, child: impl HtmlElement + ChildNode<D>) -> Slot<D>
Add child
to the light DOM.
See Component
documentation for more details.
sourcepub fn multi_slot<E>(
&mut self,
children: impl IntoIterator<Item = E>
) -> Slot<D>where
E: HtmlElement + ChildNode<D>,
pub fn multi_slot<E>(
&mut self,
children: impl IntoIterator<Item = E>
) -> Slot<D>where
E: HtmlElement + ChildNode<D>,
Add children
to the light DOM.
See Component
documentation for more details.
sourcepub fn children<N>(
self,
children: impl IntoIterator<Item = N> + 'static
) -> Selfwhere
N: ChildNode<D>,
pub fn children<N>(
self,
children: impl IntoIterator<Item = N> + 'static
) -> Selfwhere
N: ChildNode<D>,
Add children
to the shadow DOM.
Trait Implementations§
source§impl<D: InstantiableDom> Default for Component<D>
impl<D: InstantiableDom> Default for Component<D>
source§impl<D: InstantiableDom> From<Component<D>> for GenericElement<D>
impl<D: InstantiableDom> From<Component<D>> for GenericElement<D>
source§impl<D: InstantiableDom> From<Component<D>> for GenericElement<D, Const>
impl<D: InstantiableDom> From<Component<D>> for GenericElement<D, Const>
impl<D: InstantiableDom> Value for Component<D>
Auto Trait Implementations§
impl<D> Freeze for Component<D>where
<D as InstantiableDom>::InstantiableElement: Freeze,
impl<D = Dry> !RefUnwindSafe for Component<D>
impl<D = Dry> !Send for Component<D>
impl<D = Dry> !Sync for Component<D>
impl<D> Unpin for Component<D>where
<D as InstantiableDom>::InstantiableElement: Unpin,
impl<D = Dry> !UnwindSafe for Component<D>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<'a, T> RefSignalOrValue<'a> for Twhere
T: RefValue<'a> + 'a,
impl<'a, T> RefSignalOrValue<'a> for Twhere
T: RefValue<'a> + 'a,
§type Map<'b: 'a, F: FnMut(<T as RefSignalOrValue<'a>>::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b> = R
type Map<'b: 'a, F: FnMut(<T as RefSignalOrValue<'a>>::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b> = R
§type Signal = Always<<T as RefSignalOrValue<'a>>::Item>
type Signal = Always<<T as RefSignalOrValue<'a>>::Item>
Always
for value types.