Avatar
Represent a person or entity with an image, initials fallback, size, and accessible name.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultAvatar =
fveAvatar {
_ariaLabel "Alex Morgan"
"AM"
}On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add avatar --config src/Acme.Components/fve.jsonAdd to src/Acme.Web/js/app.js once, alongside your other component imports:
import '../../Acme.Components/Components/Assets/avatar.js';The CLI resolves dependencies and preserves consumer-authored files. See Installation for project initialization, Tailwind, the shared runtime, and building/loading your app entry.
Usage
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultAvatar =
fveAvatar {
_ariaLabel "Alex Morgan"
"AM"
}Fallbacks and sizes
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let avatarFallbackExample =
div {
_class "flex flex-wrap items-center gap-4"
fveAvatar {
_ariaLabel "Alex Morgan"
_size Size.Small
"AM"
}
fveAvatar {
_ariaLabel "Jamie Lee"
"JL"
}
fveAvatar {
_ariaLabel "Riley Chen"
_size Size.Large
"RC"
}
}Image
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let avatarImageExample =
fveAvatar {
_ariaLabel "FSharp.ViewEngine"
_src "/android-chrome-512x512.png"
_referrerpolicy "no-referrer"
_size Size.Large
"FV"
}Import Assets/avatar.js to display successfully loaded images. The supplied fallback remains visible while loading, after failure, or when JavaScript is unavailable. _referrerpolicy is forwarded to the image; the caller chooses the policy. The wrapper supplies one accessible name.
Image unavailable
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let failedAvatarImageExample =
fveAvatar {
_ariaLabel "Unavailable profile image"
_src "data:image/png;base64,broken"
"AM"
}Decorative
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let decorativeAvatarExample =
fveAvatar {
_ariaLabel "Decorative profile mark"
_ariaHidden true
"AM"
}API reference
module AvatarDsl =
val fveAvatar : ComponentElementBuilder