Struct ImageProps

Source
pub struct ImageProps {
Show 36 fields pub src: &'static str, pub alt: &'static str, pub fallback_src: &'static str, pub width: &'static str, pub height: &'static str, pub style: &'static str, pub class: &'static str, pub sizes: &'static str, pub quality: &'static str, pub loading: Loading, pub placeholder: &'static str, pub on_load: Callback<()>, pub object_fit: ObjectFit, pub object_position: Position, pub on_error: Callback<String>, pub decoding: Decoding, pub blur_data_url: &'static str, pub lazy_boundary: &'static str, pub unoptimized: bool, pub layout: Layout, pub srcset: &'static str, pub crossorigin: CrossOrigin, pub referrerpolicy: ReferrerPolicy, pub usemap: &'static str, pub ismap: bool, pub fetchpriority: FetchPriority, pub elementtiming: &'static str, pub attributionsrc: &'static str, pub aria_current: &'static str, pub aria_describedby: &'static str, pub aria_expanded: &'static str, pub aria_hidden: &'static str, pub aria_live: AriaLive, pub aria_pressed: AriaPressed, pub aria_controls: &'static str, pub aria_labelledby: &'static str,
}
Available on crate feature dio only.
Expand description

Properties for the Image component.

The Image component allows you to display an image with various customization options for layout, styling, and behavior. It supports fallback images, lazy loading, and custom callbacks for error handling and loading completion.

This component is highly flexible, providing support for multiple image layouts, object-fit, object-position, ARIA attributes, and more.

§See Also

Fields§

§src: &'static str

The source URL of the image.

This is the URL of the image to be displayed. This property is required for loading an image. If not provided, the image will not be displayed.

§alt: &'static str

The alternative text for the image.

This is the alt text for the image, which is used for accessibility purposes. If not provided, the alt text will be empty.

§fallback_src: &'static str

Optional fallback image.

This image will be displayed if the main image fails to load. If not provided, the image will attempt to load without a fallback.

§width: &'static str

The width of the image.

Specifies the width of the image in pixels. It is typically used for responsive layouts. Defaults to an empty string if not provided.

§height: &'static str

The height of the image.

Specifies the height of the image in pixels. Like width, it is often used for responsive layouts. Defaults to an empty string if not provided.

§style: &'static str

The style attribute for the image.

Allows you to apply custom inline CSS styles to the image. Defaults to an empty string.

§class: &'static str

The CSS class for the image.

This can be used to apply custom CSS classes to the image for styling purposes. Defaults to an empty string if not provided.

§sizes: &'static str

The sizes attribute for the image.

This is used to define different image sizes for different viewport widths, helping with responsive images. Defaults to an empty string if not provided.

§quality: &'static str

The quality attribute for the image.

Allows you to set the quality of the image (e.g., “low”, “medium”, “high”). Defaults to an empty string if not provided.

§loading: Loading

Indicates if the image should have priority loading.

This controls whether the image should be loaded eagerly (immediately) or lazily

§placeholder: &'static str

The placeholder attribute for the image.

Allows you to specify a placeholder image URL or data URL to show while the main image is loading. Defaults to an empty string.

§on_load: Callback<()>

Callback function for handling loading completion.

This callback is triggered once the image has finished loading. This is useful for actions that should happen after the image has been fully loaded, such as hiding a loading spinner. Defaults to a no-op.

§object_fit: ObjectFit

The object-fit attribute for the image.

Determines how the image should be resized to fit its container. Common values include “contain”, “cover”, “fill”, etc. Defaults to an empty string.

§object_position: Position

The object-position attribute for the image.

Specifies how the image should be positioned within its container when object-fit is set. The available options are:

  • Position::Center: Centers the image within the container.
  • Position::Top: Aligns the image to the top of the container.
  • Position::Bottom: Aligns the image to the bottom of the container.
  • Position::Left: Aligns the image to the left of the container.
  • Position::Right: Aligns the image to the right of the container.
  • Position::TopLeft: Aligns the image to the top-left of the container.
  • Position::TopRight: Aligns the image to the top-right of the container.
  • Position::BottomLeft: Aligns the image to the bottom-left of the container.
  • Position::BottomRight: Aligns the image to the bottom-right of the container.

Defaults to Position::Center.

§on_error: Callback<String>

Callback function for handling errors during image loading.

This callback is triggered if the image fails to load, allowing you to handle error states (e.g., displaying a fallback image or showing an error message).

§decoding: Decoding

The decoding attribute for the image.

Specifies how the image should be decoded. The available options are:

  • Decoding::Auto: The image decoding behavior is automatically decided by the browser.
  • Decoding::Sync: The image is decoded synchronously (blocking other tasks).
  • Decoding::Async: The image is decoded asynchronously (non-blocking).

Defaults to Decoding::Auto.

§blur_data_url: &'static str

The blur data URL for placeholder image.

This is used to display a low-quality blurred version of the image while the full image is loading. Defaults to an empty string.

§lazy_boundary: &'static str

The lazy boundary for lazy loading.

Defines the distance (in pixels) from the viewport at which the image should start loading. Defaults to an empty string.

§unoptimized: bool

Indicates if the image should be unoptimized.

If set to true, the image will be loaded without any optimization applied (e.g., no resizing or compression). Defaults to false.

§layout: Layout

Image layout.

Specifies how the image should be laid out within its container. Possible values include Layout::Fill, Layout::Responsive, Layout::Intrinsic, Layout::Fixed, Layout::Auto, Layout::Stretch, and Layout::ScaleDown. Defaults to Layout::Responsive.

§srcset: &'static str

A list of one or more image sources for responsive loading.

Defines multiple image resources for the browser to choose from, depending on screen size, resolution, and other factors. Each source can include width (w) or pixel density (x) descriptors.

§crossorigin: CrossOrigin

Cross-origin policy to use when fetching the image.

Determines whether the image should be fetched with CORS enabled. Useful when the image needs to be accessed in a <canvas> element. Accepts anonymous or use-credentials.

§referrerpolicy: ReferrerPolicy

Referrer policy to apply when fetching the image.

Controls how much referrer information should be included with requests made for the image resource. Common values include no-referrer, origin, strict-origin-when-cross-origin, etc.

§usemap: &'static str

The fragment identifier of the image map to use.

Associates the image with a <map> element, enabling clickable regions within the image. The value should begin with # and match the name of the corresponding map element.

§ismap: bool

Indicates that the image is part of a server-side image map.

When set, clicking the image will send the click coordinates to the server. Only allowed when the image is inside an <a> element with a valid href.

§fetchpriority: FetchPriority

Hints the browser about the priority of fetching this image.

Helps the browser prioritize network resource loading. Accepts high, low, or auto (default). See HTMLImageElement.fetchPriority for more.

§elementtiming: &'static str

Identifier for tracking image performance timing.

Registers the image with the PerformanceElementTiming API using the given string as its ID. Useful for performance monitoring and analytics.

§attributionsrc: &'static str

URL(s) to send Attribution Reporting requests for the image.

Indicates that the browser should send an Attribution-Reporting-Eligible header with the image request. Can be a boolean or a list of URLs for attribution registration on specified servers. Experimental feature.

§aria_current: &'static str

Indicates the current state of the image in a navigation menu.

Valid values are “page”, “step”, “location”, “date”, “time”, “true”, “false”. This is useful for enhancing accessibility in navigation menus.

§aria_describedby: &'static str

Describes the image using the ID of the element that provides a description.

The ID of the element that describes the image. This is used for accessibility purposes, particularly for screen readers.

§aria_expanded: &'static str

Indicates whether the content associated with the image is currently expanded or collapsed.

This is typically used for ARIA-based accessibility and is represented as “true” or “false”.

§aria_hidden: &'static str

Indicates whether the image is currently hidden from the user.

This attribute is used for accessibility and indicates whether the image is visible to the user or not. Valid values are “true” or “false”.

§aria_live: AriaLive

Indicates whether the content associated with the image is live and dynamic.

The value can be “off”, “assertive”, or “polite”, helping assistive technologies determine how to handle updates to the content.

§aria_pressed: AriaPressed

Indicates whether the image is currently pressed or selected.

This attribute can have values like “true”, “false”, “mixed”, or “undefined”.

§aria_controls: &'static str

ID of the element that the image controls or owns.

Specifies the ID of the element that the image controls or is associated with.

§aria_labelledby: &'static str

ID of the element that labels the image.

Specifies the ID of the element that labels the image for accessibility purposes.

Implementations§

Source§

impl ImageProps

Source

pub fn builder() -> ImagePropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>

Create a builder for building ImageProps. On the builder, call .src(...)(optional), .alt(...)(optional), .fallback_src(...)(optional), .width(...)(optional), .height(...)(optional), .style(...)(optional), .class(...)(optional), .sizes(...)(optional), .quality(...)(optional), .loading(...)(optional), .placeholder(...)(optional), .on_load(...)(optional), .object_fit(...)(optional), .object_position(...)(optional), .on_error(...)(optional), .decoding(...)(optional), .blur_data_url(...)(optional), .lazy_boundary(...)(optional), .unoptimized(...)(optional), .layout(...)(optional), .srcset(...)(optional), .crossorigin(...)(optional), .referrerpolicy(...)(optional), .usemap(...)(optional), .ismap(...)(optional), .fetchpriority(...)(optional), .elementtiming(...)(optional), .attributionsrc(...)(optional), .aria_current(...)(optional), .aria_describedby(...)(optional), .aria_expanded(...)(optional), .aria_hidden(...)(optional), .aria_live(...)(optional), .aria_pressed(...)(optional), .aria_controls(...)(optional), .aria_labelledby(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of ImageProps.

Trait Implementations§

Source§

impl Clone for ImageProps

Source§

fn clone(&self) -> ImageProps

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ImageProps

Source§

fn default() -> Self

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

impl PartialEq for ImageProps

Source§

fn eq(&self, other: &ImageProps) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Properties for ImageProps
where Self: Clone,

Source§

type Builder = ImagePropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>

The type of the builder for this component. Used to create “in-progress” versions of the props.
Source§

fn builder() -> Self::Builder

Create a builder for this component.
Source§

fn memoize(&mut self, new: &Self) -> bool

Make the old props equal to the new props. Return if the props were equal and should be memoized.
Source§

fn into_vcomponent<M>( self, render_fn: impl ComponentFunction<Self, M>, ) -> VComponent
where M: 'static,

Create a component from the props.
Source§

impl StructuralPartialEq for ImageProps

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SerializableKey for T

Source§

fn ser_key(&self) -> String

Serializes the key to a unique string. Read more
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

Source§

impl<T> DependencyElement for T
where T: 'static + PartialEq + Clone,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> HasAllProps<(), T> for T