Skip to main content

Modal

Struct Modal 

Source
pub struct Modal { /* private fields */ }
Expand description

A dialog over the page: a <dialog> element.

Open it with Press::open_modal on any pressable component, or with the open property to show it right away. Its close button and Escape work without any script; the component script adds opening as a true modal (focus kept inside, the page inert) and closing on a click outside.

let m = Modal![id = "confirm", title = "Delete the class?",
    ModalBody![p!["This cannot be undone."]],
    ModalFooter![Button![on_press = Press::close_modal(), "Cancel"]],
];
let html = render_static(m);
assert!(html.contains(r#"<dialog class="nr-modal nr-modal-md nr-modal-center" id="confirm""#), "{html}");
assert!(html.contains(r#"<form method="dialog""#), "closes without a script");

Implementations§

Source§

impl Modal

Source

pub fn new() -> Self

Source

pub fn class(self, v: impl Into<String>) -> Self

Extra classes for the outer element. They win over the defaults.

Source

pub fn unstyled(self, v: bool) -> Self

Leave out the default classes of the outer element.

Source

pub fn with(self, part: impl Part) -> Self

Add an attribute (class(..), id(..), aria(..), …) or a child.

Source

pub fn id(self, v: impl Into<String>) -> Self

The id Press::open_modal refers to.

Source

pub fn title(self, v: impl Into<String>) -> Self

A heading at the top (also the dialog’s accessible name).

Source

pub fn size(self, v: Width) -> Self

Sm 24rem, Md 32rem, Lg 40rem, Xl 48rem, Xxl 64rem, Full.

Source

pub fn placement(self, v: ModalPlacement) -> Self

Source

pub fn radius(self, v: Radius) -> Self

Source

pub fn open(self, v: bool) -> Self

Shown when the page loads (as a modal once the script runs).

Source

pub fn closable(self, v: bool) -> Self

A close button in the corner (on by default).

Source

pub fn dismissable(self, v: bool) -> Self

A click on the backdrop closes it (on by default). Escape always does.

Source

pub fn scroll_inside(self, v: bool) -> Self

Long content scrolls inside the body, the header and footer stay put.

Trait Implementations§

Source§

impl Default for Modal

Source§

fn default() -> Self

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

impl View for Modal

Auto Trait Implementations§

§

impl !RefUnwindSafe for Modal

§

impl !Sync for Modal

§

impl !UnwindSafe for Modal

§

impl Forget for Modal

§

impl Freeze for Modal

§

impl Move for Modal

§

impl Send for Modal

§

impl Unpin for Modal

§

impl UnsafeUnpin for Modal

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<V, E> IntoViewResult<E> for V
where V: View,

Source§

impl<V> Part for V
where V: View,

Source§

fn apply(self, el: &mut Element)

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.