Back to Fluentui

@fluentui/react-image

packages/react-components/react-image/library/docs/Spec.md

4.40.2-hotfix26.8 KB
Original Source

@fluentui/react-image

Background

Image is a visual representation of some content, such as a photo, illustration etc.

Concerns

Based on the OpenUI research and the Figma specification, Image seems to be one of those components that is purely styling, thus I would appreciate your answers in any of these questions:

  • Are there any components would need to use Image?

  • Apart from styling, are there any other functionalities for Image?

    Conclusion: Some potential features that Image can have are:

    • fallback image placeholder when image fails to load
    • onLoading callback when image fails to load
    • styling helpers These will be addressed on later iterations when needed
  • Is there any benefit of having Image as a component? (taking into consideration that it is css styling and we will need to maintain it over time.)

    Conclusion: The image component will ensure correct styling and behaviour regardless of the Theme

Prior Art

V8/v0 comparison

Comparison done in: #17608

Purposev7 / v8v0Matching
Additional CSS class name(s) to applyclassNameclassNamematching
Specifies the cover style to be used for this imagecoverStyleN/Av0 missing
Replaces the src in case of errorserrorSrc [DEPRECATED]N/ASee onLoadingStateChanged
Determines how the image is scaled and cropped to fit the frameimageFitfluidpartially matching
Expands image frame to fill its parent containermaximizeFramefluidpartially matching
Optional callback for when the image load state changedonLoadingStateChangedN/Av0 missing
Fades the image in when loadedshouldFadeInN/Av0 missing
The image starts as visible and is hidden on errorshouldStartVisibleN/Av0 missing
Provides customized styling that will layer on top of the variant rulesstylesstylesmatching
Theme provided by HOCthemevariablesmatching
Accessibility behavior overridden by the userN/Aaccessibilityv7/v8 missing
An element type to render as (string or component)N/Aasv7/v8 missing
An image may be formatted to appear inline with text as an avatarN/Aavatarv7/v8 missing
An image can appear circularN/Acircularv7/v8 missing
Component design propN/Adesignv7/v8 missing
Image source URLN/Asrcv7/v8 missing

v8 usage

jsx
import { Image, ImageFit } from '@fluentui/react/lib/Image';

<Image maximizeFrame imageFit={ImageFit.contain} src="..." alt="Example of the image component in v8" />;

v0 usage

jsx
<Image block src="..." alt="Example of the image component in v0" />

Variants

n/a

API proposal

See API at Image.types.ts.

Proposed component props:

NameTypeDefault valueComments
borderedbooleanfalse
fitstring"none"One of: none, center, contain, cover
blockbooleanfalse
shape string "square"One of: square, circular , rounded
shadowbooleanfalse

All native html attributes of the `` will be available to be used as props of the Image component.

Sample Code

Sample code based on the proposed API:

Bordered

jsx
<Image bordered src="..." />

Block

jsx
<Image block src="..." />

Rounded

jsx
<Image shape="rounded" src="..." />

Circular

jsx
<Image shape="circular" src="..." />

Fit

jsx
// None
<Image fit="none" src="..." />

// Center
<Image fit="center" src="..." />

// Contain
<Image fit="contain" src="..." />

// Cover
<Image fit="cover" src="..." />

Structure

Public

tsx
<Image src=".." />

Internal

tsx
<slots.root {...slotProps.root} />

DOM

tsx

Migration

See MIGRATION.md.

Accessibility

Images should include the alt attribute that includes a description of the image's content and function to be accessible to assistive technologies. The alt description should be concise and clearly communicate the meaning and purpose of the image on where it was included. Avoid using "image of", "picture of" etc. as it is redundant.

The images that are only decorative and do not have the structural relevance implied by the semantic element should use the alt="" (null alt text) or role="presentation"/role="none" which will remove the semantic meaning of the element. In case the image is needed to be removed from the accessibility tree then aria-hidden="true" can be used.

Relevant documents