Utilities
Embed
BitEmbed frames embedded content - a YouTube video, a map, a page of another site - in an iframe kept at an aspect ratio that scales with its container, so it shrinks on a phone instead of keeping the fixed size an iframe has of its own. It is lazy by default, and a PlaceholderTemplate turns it into a click-to-load facade that loads no iframe until the user asks for it - what the placeholder shows itself, such as a remote thumbnail, still loads before that.
Notes
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
AspectRatio & MaxWidth
Iframe attributes
Click to load
Style & Class
RTL
CSS variables
The public custom properties this component reads off its root, for what no parameter covers.
Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property:
set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it,
or on the Style of one instance to restyle it - and any instance nested inside it, which inherits the value too; a parameter changes one alone,
as does the real CSS property on the instance's Style / Styles when that property does not inherit (opacity: 1 keeps
one disabled instance undimmed without undimming a disabled one inside it), while an inherited one such as color or
font-family also reaches the nested instances that do not set it themselves. Leave a variable unset and the component
falls back to the theme token beside it.
BitEmbed CSS variables
| Name | Default value | Description |
|---|---|---|
| --bit-Embed-aspect-ratio | 16 / 9 | Shape of the frame. The AspectRatio parameter wins over it. |
| --bit-Embed-max-width | none | Largest width of the frame. The MaxWidth parameter wins over it. |
| --bit-Embed-radius | 0 | Corner radius of the frame, which crops the embedded content. |
| --bit-Embed-background | --bit-clr-bg-sec | Background of the frame, behind the content while it loads. |
| --bit-Embed-focus-color | --bit-clr-pri-focus | Color of the keyboard focus ring of the placeholder. |
API
Every parameter, public member, sub-class and enum this component exposes.
BitEmbed parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Allow | string? | null | The features the embedded content may use, as the value of the allow attribute of the iframe - its permissions policy (e.g. "autoplay; encrypted-media; picture-in-picture"). |
| AllowFullScreen | bool | false | Lets the embedded content go full screen (the allowfullscreen attribute of the iframe), which a video player needs for its full screen button to work. |
| AspectRatio | string? | null | The aspect ratio of the frame, as a CSS aspect-ratio value (e.g. "16 / 9", "4 / 3" or "1"). Default: 16 / 9, the shape of a video. It wins over the --bit-Embed-aspect-ratio variable. |
| Classes | BitEmbedClassStyles? | null | Custom CSS classes for the different parts of the embed. |
| Loading | BitImageLoading | BitImageLoading.Lazy | Allows for browser-level loading of the iframe (lazy or eager). A lazy iframe is only loaded once the browser expects it to be scrolled into view. |
| MaxWidth | string? | null | The largest width of the frame, as a CSS length (e.g. "800px" or "50rem"); below it the frame takes the width of its container. By default it has no limit. It wins over the --bit-Embed-max-width variable. |
| PlaceholderAriaLabel | string? | null | The accessible name of the placeholder button. Defaults to BitStrings.LoadFormat ("Load {0}") filled in with the Title. |
| PlaceholderTemplate | RenderFragment? | null | The content shown in the frame in place of the iframe until the user activates it - a thumbnail and a play icon, most of the time. With it the iframe is not rendered, and so nothing of it is requested, until the placeholder is clicked or activated with the keyboard. It is rendered inside a button, so it should hold no interactive content of its own. |
| ReferrerPolicy | BitImageReferrerPolicy? | null | Specifies how much of the address of the current page is sent to the site serving the embedded content (the referrerpolicy attribute of the iframe). By default the browser's own policy applies. |
| Sandbox | string? | null | Applies extra restrictions to the embedded content, as the value of the sandbox attribute of the iframe: an empty string applies them all, and each token lifts one of them (e.g. "allow-scripts allow-same-origin"). By default the iframe is not sandboxed. |
| Src | string? | null | The address of the content to embed. Only an http or https address, or a relative one, is rendered; any other scheme (javascript:, data:, blob:, ...) is refused and the frame is left empty. |
| Styles | BitEmbedClassStyles? | null | Custom CSS styles for the different parts of the embed. |
| Title | string? | null | The title of the iframe, which is how a screen reader names the embedded content. An iframe needs one to be accessible, so the parameter is EditorRequired: the compiler warns about a BitEmbed written without it. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| Disabled | bool | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitEmbedClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element (the frame) of the BitEmbed. |
| Placeholder | string? | null | Custom CSS classes/styles for the placeholder button of the BitEmbed, which its PlaceholderTemplate is rendered in. |
| Frame | string? | null | Custom CSS classes/styles for the iframe of the BitEmbed. |
BitImageLoading enum
| Name | Value | Description |
|---|---|---|
| Eager | 0 | Tells the browser to load the image or the embedded page as soon as the element is processed, which is what a browser does with an img or an iframe that has no loading attribute. |
| Lazy | 1 | Tells the user agent to hold off on loading the image or the embedded page until the browser estimates that it will be needed imminently. |
BitImageReferrerPolicy enum
| Name | Value | Description |
|---|---|---|
| NoReferrer | 0 | Sends no Referer header at all. |
| NoReferrerWhenDowngrade | 1 | Sends the full URL, except to a less secure destination (HTTPS to HTTP), where nothing is sent. |
| Origin | 2 | Sends only the origin - the scheme, the host and the port - of the current page. |
| OriginWhenCrossOrigin | 3 | Sends the full URL to the same origin, and only the origin to any other one. |
| SameOrigin | 4 | Sends the full URL to the same origin, and nothing at all to any other one. |
| StrictOrigin | 5 | Sends only the origin, and nothing to a less secure destination (HTTPS to HTTP). |
| StrictOriginWhenCrossOrigin | 6 | The default behavior: the full URL to the same origin, the origin alone to another secure one, and nothing to a less secure destination (HTTPS to HTTP). |
| UnsafeUrl | 7 | Sends the full URL to every destination, secure or not. The path and the query string of the current page leave the origin with every request, so this is unsafe wherever either of them can carry anything private. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.