X Post Showcase

Example

Dark Mode

Component Documentation

Component Name

XPost

Builder Function Name

create_x_post_manager

Description

Embeds an X (formerly Twitter) post given its post ID, handling script loading and rendering. Supports internal and external links with optional previews and QR codes.

Use like example

Config

PropertyTypeDefaultDescription
idstring or null

generated unique ID

A unique string ID for this XPost component. If not provided, a unique ID is generated automatically.

post_idstring

The unique identifier of the X (Twitter) post to embed. This is required for rendering the post.

hrefstring or null

The URL associated with the post. If it starts with '/', it's treated as an internal link; otherwise, as an external link.

display_textstring or null

The text to display for the link. If not provided, child content can be used instead.

text_colorCSS color or null

The color of the link text. If not specified, it inherits the default styling.

is_show_previewboolean

!is_internal_link

Determines whether to show a popover preview of the post when clicked. Defaults to true for external links and false for internal links.

is_dark_themeboolean

true

If true, the embedded post uses a dark theme. Otherwise, a light theme is applied.

heightnumber or null

min(40rem, 50vh)

The height of the popover containing the embedded post, specified in rem. Defaults to 'min(40rem, 50vh)' if not set.

widthnumber or null

clamp(60rem, 80vw, 100%)

The width of the popover containing the embedded post, specified in rem. Defaults to 'clamp(60rem, 80vw, 100%)' if not set.

on_goto_external_linkfunction or null

Optional callback function that is invoked when an external link is opened. Receives the `href` as an argument.

Methods

MethodDescriptionParametersReturns
load_script

Dynamically loads the Twitter widgets script necessary for embedding the post. Once loaded, it triggers the rendering of the embedded post.

No Params

render_x_post

Embeds the X (Twitter) post into the designated container using `twttr.widgets.createTweet`. Handles theme settings and error messaging if the post fails to load.

No Params

handle_a_click

Handles click events on the link. Prevents the default behavior and determines whether to navigate internally, show a preview, or open the link externally based on configuration.

No Params

open_link

Opens the link associated with the post. If it's an internal link, it uses SvelteKit's `goto` for navigation. For external links, it opens the URL in a new browser tab and invokes the `on_goto_external_link` callback if provided.

No Params

set_val

Updates the `val` state with a new value and re-initializes the embedded post if necessary.

No Params

Returned Properties

PropertyTypeDescription
post_idstring

The unique identifier of the X (Twitter) post being embedded.

is_dark_themeboolean

Indicates whether the embedded post is using a dark theme.

themestring

The current theme of the embedded post ('dark' or 'light').

popover_managerobject

Popover manager for controlling the display of the post preview. Methods include `open()` and `close()`.

toggle_popover_managerobject

Button manager for toggling the popover. Manages the state and behavior of the toggle button.

heightstring

The height of the popover container, in rem.

widthstring

The width of the popover container, in rem.

icon
Sponsored byContibase