Struct silkenweb::node::Component

source ·
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>

source

pub fn new() -> Self

Constructor

source

pub fn styled(css: &str) -> Self

Constuct a Component with a <style> element in the shadow DOM.

source

pub fn slot(&mut self, child: impl HtmlElement + ChildNode<D>) -> Slot<D>

Add child to the light DOM.

See Component documentation for more details.

source

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.

source

pub fn child(self, child: impl ChildNode<D>) -> Self

Add child to the shadow DOM.

source

pub fn children<N>( self, children: impl IntoIterator<Item = N> + 'static ) -> Self
where N: ChildNode<D>,

Add children to the shadow DOM.

Trait Implementations§

source§

impl<D: InstantiableDom> Default for Component<D>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<D: InstantiableDom> From<Component<D>> for GenericElement<D>

source§

fn from(value: Component<D>) -> Self

Converts to this type from the input type.
source§

impl<D: InstantiableDom> From<Component<D>> for GenericElement<D, Const>

source§

fn from(value: Component<D>) -> Self

Converts to this type from the input type.
source§

impl<D: InstantiableDom> From<Component<D>> for Node<D>

source§

fn from(value: Component<D>) -> Self

Converts to this type from the input type.
source§

impl<D: InstantiableDom> InDom for Component<D>

§

type Dom = D

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<'a, T> RefSignalOrValue<'a> for T
where T: RefValue<'a> + 'a,

§

type Item = T

The underlying type of the value or signal.
§

type Map<'b: 'a, F: FnMut(<T as RefSignalOrValue<'a>>::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b> = R

The return type for Self::map. Read more
§

type Signal = Always<<T as RefSignalOrValue<'a>>::Item>

The signal type. Use Always for value types.
source§

fn map<'b, F, R>( self, callback: F ) -> <T as RefSignalOrValue<'a>>::Map<'b, F, R>
where 'b: 'a, R: RefSignalOrValue<'b, Item = R> + 'b, F: FnMut(<T as RefSignalOrValue<'a>>::Item) -> R + 'b,

Map a function over this signal/value to produce a new signal/value.
source§

fn select<FVal, FSig, Data, Out>( self, fn_val: FVal, _fn_sig: FSig, data: Data ) -> Out
where FVal: FnOnce(Data, <T as RefSignalOrValue<'a>>::Item) -> Out, FSig: FnOnce(Data, <T as RefSignalOrValue<'a>>::Signal) -> Out,

Select a function based on whether this is a signal or value. Read more
source§

fn select_spawn<FVal, FSig, Task, Exec>( self, fn_val: FVal, _fn_sig: FSig, executor: &mut Exec )
where FVal: FnOnce(&mut Exec, <T as RefSignalOrValue<'a>>::Item), FSig: FnOnce(&mut Exec, <T as RefSignalOrValue<'a>>::Signal) -> Task, Task: Future<Output = ()> + 'a, Exec: Executor,

Select a function based on whether this is a signal or value. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<D, T> ChildElement<D> for T
where D: Dom, T: Into<GenericElement<D, Const>> + Into<Node<D>> + Value + 'static,

source§

impl<D, T> ChildNode<D> for T
where D: Dom, T: Into<Node<D>> + Value + 'static,

source§

impl<T> RefValue<'static> for T
where T: Value,

source§

impl<T> SignalOrValue for T
where T: RefSignalOrValue<'static>,