Context Card

Description

A card describing one piece of context attached to a conversation

ContextCard describes a file, a page or a dataset attached to a conversation, and is meant to sit above (or inside) a ChatArea composer. It is an icon tile (a UIcons glyph, an arbitrary component, or an image thumbnail) on a coloured background, followed by a label, an optional second line, and an optional badge pill.

Passing a handler to OnRemove adds a round (x) button hanging just off the card's top-right corner, which fades in while the card is hovered or focused, and on touch devices where there is no hover to speak of. OnContextMenu opens a ContextMenu of actions at the pointer on right-click. Tag carries the document, record or file the card stands for, so a handler can act on it without a lookup.

The label is ellipsized to the width the card is given and carries the full text as its tooltip. KeepExtensionVisible (on by default) holds a trailing file extension out of the ellipsis, so a long name reads "Quarterly repo….pdf" rather than "Quarterly repor…". Compact() turns the card into a one-line pill.

ContextCards

ContextCards groups several cards behind one summary pill ("Added 5 items to context") that expands to list them and collapses back, styled like ToolCall / ToolsUsed so a transcript reads as one family of disclosures.

Expanded, the cards render as rows of a bordered list: full width, one divider between each, the remove button in the row rather than hovering over a corner. Compact() switches the whole group to a wrapping row of pills instead, truncated to MaxVisible with a "+N more" pill that reveals the rest. A card's (x) takes it out of the group, and a handler the caller registered on the card still runs.

Samples

A single card

A group of cards

API reference

class

ContextCard

public sealed class ContextCard : ComponentBase<ContextCard, HTMLElement>

A compact card describing one piece of context attached to a conversation — a file, a page, a dataset — meant to sit above (or inside) a ChatArea composer. It is an icon tile (a UIcons glyph, an arbitrary component, or an image thumbnail) on a colored background, followed by a label, an optional second line, and an optional badge pill. Passing a remove handler to OnRemove adds a round (x) button hanging just off the card's top-right corner that fades in while the card is hovered, focused, or on touch devices where there is no hover to speak of. Compact turns it into a one-line pill, and ContextCards groups several of them behind one expandable summary. Right-clicking a card is handled by OnContextMenu, which opens a ContextMenu of actions at the pointer.

Namespace
Tesserae
Inheritance
ComponentBase<ContextCard, HTMLElement> → ContextCard

Constructors

NameDescription
ContextCardInitializes a new instance of this class showing the given icon.
Constructor
ContextCard
Overload
ContextCard(string, UIcons, UIconsWeight)Initializes a new instance of this class showing the given icon.
ContextCard(string, IComponent)Initializes a new instance of this class showing the given icon or image component - an Icon, an Image, an emoji, or anything else that renders small.
ContextCard(string, UIcons, UIconsWeight)
public ContextCard(string label, UIcons icon = UIcons.File, UIconsWeight weight = UIconsWeight.Regular) : this()

Initializes a new instance of this class showing the given icon.

Parameters

label string
icon UIcons
weight UIconsWeight
ContextCard(string, IComponent)
public ContextCard(string label, IComponent iconOrImage) : this()

Initializes a new instance of this class showing the given icon or image component - an Icon, an Image, an emoji, or anything else that renders small.

Parameters

label string
iconOrImage IComponent

Properties

NameDescription
LabelGets the label shown by the component.
SubLabelGets the secondary line shown below the label, or null when the card has none.
IsRemovableReturns a value indicating whether the component shows a remove button.
TagGets or sets an arbitrary payload associated with this card - the document, record or file it stands for, so a remove or click handler can act on it without a lookup.
Property
ContextCard.Label
public string Label

Gets the label shown by the component.

Property
ContextCard.SubLabel
public string SubLabel

Gets the secondary line shown below the label, or null when the card has none.

Property
ContextCard.IsRemovable
public bool IsRemovable

Returns a value indicating whether the component shows a remove button.

Property
ContextCard.Tag
public object Tag { get; set; }

Gets or sets an arbitrary payload associated with this card - the document, record or file it stands for, so a remove or click handler can act on it without a lookup.

Methods

NameDescription
SetLabelSets the label of the component. The label is ellipsized to the width the card is given, and carries the full text as its native tooltip.
KeepExtensionVisibleConfigures whether a trailing file extension is held out of the ellipsis, so a label too long for the card reads "Quarterly repo….pdf" rather than "Quarterly repor…". On by default.
MaxLabelWidthCaps the width the label is ellipsized at, for a dense row where every card should stay short. The extension, when kept visible, sits outside this width.
SetBadgePuts a small pill at the end of the card. The card says nothing about what belongs in it - what the context *is* is already carried by the icon - so it takes whatever the host wants there: a count, a status, a source. A null or empty value hides it.
MonospaceSubLabelRenders the secondary line in the monospace font, for a path, a table name or a size - the same treatment ToolCall gives the command it names.
WithChevronShows a chevron at the end of the card, the hint that clicking it opens what it stands for. Pair it with OnClick.
SetSubLabelSets the secondary line shown below the label ("PDF", "3 pages", a folder). A null or empty value hides the line and leaves the card as a single centered row.
SetIconSets the icon shown on the tile.
SetImageSets a thumbnail that fills the whole tile (cropped to cover it), for context that has a preview of its own - an image, a screenshot, a site favicon. The tile's background color is dropped, as the image covers it.
IconBackgroundSets the background color of the icon tile (any CSS color, e.g. "#ef4444" or "var(--tss-danger-background-color)").
IconForegroundSets the color of the glyph on the icon tile.
IconTintTints the icon tile with the given color: a wash of it behind the glyph, and the glyph itself in full strength. The quieter alternative to a saturated tile, and what a row of many cards usually wants so the colors read as file types rather than as decoration.
NoIconBackgroundConfigures the icon tile to have no background, letting the glyph or image sit directly on the card.
BackgroundSets the background color of the card itself.
OnRemoveRegisters a callback invoked when the user clicks the remove button, and adds that button to the card if it isn't there yet. The card does not remove itself - the handler owns whatever list the card lives in, and can also drop the context it stands for.
RemovableConfigures whether the card shows its remove button. Turning it off keeps any handler registered with OnRemove, so turning it back on restores the same behaviour.
NoRemoveConfigures the component to show no remove button.
CompactConfigures the card as a single tighter row - a pill with a small tile, the label, and the secondary line beside it rather than below. Use it when many cards share a composer, or for one card named inline in a sentence.
OnClickRegisters a callback invoked when the click event fires. A clickable card also becomes keyboard reachable and is activated with Enter or Space.
OnContextMenuRegisters a callback invoked when the user right-clicks the card, suppressing the browser's own menu. The card is handed to the callback, so a shared handler can read its Label or Tag without a closure per card. The (card, event) overload inherited from the base class leaves the browser menu alone, for a handler that would rather decide for itself - call StopEvent(e) from it to suppress it.
ShowMenuOpens the menu registered with OnContextMenu anchored to the card, the way the keyboard menu key does. Does nothing when the card has no menu.
SelectableConfigures whether the text on the card can be selected. It cannot by default: a card is a token standing for one piece of context, not prose, and dragging or right-clicking one should not leave half its label highlighted.
RenderRenders the component's root HTML element.
Method
ContextCard.SetLabel
public ContextCard SetLabel(string label)

Sets the label of the component. The label is ellipsized to the width the card is given, and carries the full text as its native tooltip.

Method
ContextCard.KeepExtensionVisible
public ContextCard KeepExtensionVisible(bool value = true)

Configures whether a trailing file extension is held out of the ellipsis, so a label too long for the card reads "Quarterly repo….pdf" rather than "Quarterly repor…". On by default.

Method
ContextCard.MaxLabelWidth
public ContextCard MaxLabelWidth(UnitSize size)

Caps the width the label is ellipsized at, for a dense row where every card should stay short. The extension, when kept visible, sits outside this width.

Method
ContextCard.SetBadge
Overload
SetBadge(string)Puts a small pill at the end of the card. The card says nothing about what belongs in it - what the context *is* is already carried by the icon - so it takes whatever the host wants there: a count, a status, a source. A null or empty value hides it.
SetBadge(IComponent)Puts the given component at the end of the card, in place of the plain pill - a Badge with a tone of its own, a Spinner while the context loads, a small button. A null value empties the slot.
SetBadge(string)
public ContextCard SetBadge(string text)

Puts a small pill at the end of the card. The card says nothing about what belongs in it - what the context *is* is already carried by the icon - so it takes whatever the host wants there: a count, a status, a source. A null or empty value hides it.

Parameters

text string
SetBadge(IComponent)
public ContextCard SetBadge(IComponent badge)

Puts the given component at the end of the card, in place of the plain pill - a Badge with a tone of its own, a Spinner while the context loads, a small button. A null value empties the slot.

Parameters

badge IComponent
Method
ContextCard.MonospaceSubLabel
public ContextCard MonospaceSubLabel(bool value = true)

Renders the secondary line in the monospace font, for a path, a table name or a size - the same treatment ToolCall gives the command it names.

Method
ContextCard.WithChevron
public ContextCard WithChevron(bool value = true)

Shows a chevron at the end of the card, the hint that clicking it opens what it stands for. Pair it with OnClick.

Method
ContextCard.SetSubLabel
public ContextCard SetSubLabel(string subLabel)

Sets the secondary line shown below the label ("PDF", "3 pages", a folder). A null or empty value hides the line and leaves the card as a single centered row.

Method
ContextCard.SetIcon
Overload
SetIcon(UIcons, UIconsWeight)Sets the icon shown on the tile.
SetIcon(IComponent)Sets the icon of the component to an arbitrary component - an Icon with its own color, an emoji, an Image, a file-type badge. A null value empties the tile, keeping its background as a plain colored square.
SetIcon(UIcons, UIconsWeight)
public ContextCard SetIcon(UIcons icon, UIconsWeight weight = UIconsWeight.Regular)

Sets the icon shown on the tile.

Parameters

icon UIcons
weight UIconsWeight
SetIcon(IComponent)
public ContextCard SetIcon(IComponent iconOrImage)

Sets the icon of the component to an arbitrary component - an Icon with its own color, an emoji, an Image, a file-type badge. A null value empties the tile, keeping its background as a plain colored square.

Parameters

iconOrImage IComponent
Method
ContextCard.SetImage
public ContextCard SetImage(string url)

Sets a thumbnail that fills the whole tile (cropped to cover it), for context that has a preview of its own - an image, a screenshot, a site favicon. The tile's background color is dropped, as the image covers it.

Method
ContextCard.IconBackground
public ContextCard IconBackground(string color)

Sets the background color of the icon tile (any CSS color, e.g. "#ef4444" or "var(--tss-danger-background-color)").

Method
ContextCard.IconForeground
public ContextCard IconForeground(string color)

Sets the color of the glyph on the icon tile.

Method
ContextCard.IconTint
public ContextCard IconTint(string color, int percent = 14)

Tints the icon tile with the given color: a wash of it behind the glyph, and the glyph itself in full strength. The quieter alternative to a saturated tile, and what a row of many cards usually wants so the colors read as file types rather than as decoration.

Method
ContextCard.NoIconBackground
public ContextCard NoIconBackground()

Configures the icon tile to have no background, letting the glyph or image sit directly on the card.

Method
ContextCard.Background
public ContextCard Background(string color)

Sets the background color of the card itself.

Method
ContextCard.OnRemove
Overload
OnRemove(Action<ContextCard>)Registers a callback invoked when the user clicks the remove button, and adds that button to the card if it isn't there yet. The card does not remove itself - the handler owns whatever list the card lives in, and can also drop the context it stands for.
OnRemove(Action)Registers a callback invoked when the user clicks the remove button, and adds that button to the card if it isn't there yet.
OnRemove(Action<ContextCard>)
public ContextCard OnRemove(Action<ContextCard> onRemove)

Registers a callback invoked when the user clicks the remove button, and adds that button to the card if it isn't there yet. The card does not remove itself - the handler owns whatever list the card lives in, and can also drop the context it stands for.

Parameters

onRemove Action<ContextCard>
OnRemove(Action)
public ContextCard OnRemove(Action onRemove)

Registers a callback invoked when the user clicks the remove button, and adds that button to the card if it isn't there yet.

Parameters

onRemove Action
Method
ContextCard.Removable
public ContextCard Removable(bool value = true)

Configures whether the card shows its remove button. Turning it off keeps any handler registered with OnRemove, so turning it back on restores the same behaviour.

Method
ContextCard.NoRemove
public ContextCard NoRemove()

Configures the component to show no remove button.

Method
ContextCard.Compact
public ContextCard Compact(bool value = true)

Configures the card as a single tighter row - a pill with a small tile, the label, and the secondary line beside it rather than below. Use it when many cards share a composer, or for one card named inline in a sentence.

Method
ContextCard.OnClick
public override ContextCard OnClick(ComponentEventHandler<ContextCard, MouseEvent> onClick, bool clearPrevious = true)

Registers a callback invoked when the click event fires. A clickable card also becomes keyboard reachable and is activated with Enter or Space.

Method
ContextCard.OnContextMenu
Overload
OnContextMenu(Action<ContextCard>)Registers a callback invoked when the user right-clicks the card, suppressing the browser's own menu. The card is handed to the callback, so a shared handler can read its Label or Tag without a closure per card. The (card, event) overload inherited from the base class leaves the browser menu alone, for a handler that would rather decide for itself - call StopEvent(e) from it to suppress it.
OnContextMenu(Action)Registers a callback invoked when the user right-clicks the card, suppressing the browser's own menu.
OnContextMenu(Func<ContextMenu.Item[]>)Attaches a ContextMenu of actions to the card: the generator runs on every right-click, and the items it returns are shown at the pointer - so a menu can reflect the state the card is in when it is opened. The card is also given a tab stop and answers the keyboard menu key (and Shift+F10) with the same menu, anchored to the card itself. Returning null or an empty array opens nothing, which is how a card opts out of the menu without the browser's showing up in its place.
OnContextMenu(Action<ContextCard>)
public ContextCard OnContextMenu(Action<ContextCard> onContextMenu)

Registers a callback invoked when the user right-clicks the card, suppressing the browser's own menu. The card is handed to the callback, so a shared handler can read its Label or Tag without a closure per card. The (card, event) overload inherited from the base class leaves the browser menu alone, for a handler that would rather decide for itself - call StopEvent(e) from it to suppress it.

Parameters

onContextMenu Action<ContextCard>
OnContextMenu(Action)
public ContextCard OnContextMenu(Action onContextMenu)

Registers a callback invoked when the user right-clicks the card, suppressing the browser's own menu.

Parameters

onContextMenu Action
OnContextMenu(Func<ContextMenu.Item[]>)
public ContextCard OnContextMenu(Func<ContextMenu.Item[]> menu)

Attaches a ContextMenu of actions to the card: the generator runs on every right-click, and the items it returns are shown at the pointer - so a menu can reflect the state the card is in when it is opened. The card is also given a tab stop and answers the keyboard menu key (and Shift+F10) with the same menu, anchored to the card itself. Returning null or an empty array opens nothing, which is how a card opts out of the menu without the browser's showing up in its place.

Parameters

menu Func<ContextMenu.Item[]>
Method
ContextCard.ShowMenu
public ContextCard ShowMenu()

Opens the menu registered with OnContextMenu anchored to the card, the way the keyboard menu key does. Does nothing when the card has no menu.

Method
ContextCard.Selectable
public ContextCard Selectable(bool value = true)

Configures whether the text on the card can be selected. It cannot by default: a card is a token standing for one piece of context, not prose, and dragging or right-clicking one should not leave half its label highlighted.

Method
ContextCard.Render
public override HTMLElement Render()

Renders the component's root HTML element.

class

ContextCards

public sealed class ContextCards : ComponentBase<ContextCards, HTMLElement>

A group of ContextCards behind one summary pill ("Added 5 items to context") that expands to list them and collapses back, styled like ToolCall / ToolsUsed so a transcript reads as one family of disclosures. Expanded, the cards render as rows of a bordered list - full width, one divider between each, the remove button in the row rather than hovering over a corner. Compact switches the whole group to a wrapping row of pills instead, truncated to MaxVisible with a "+N more" pill that reveals the rest.

Namespace
Tesserae
Inheritance
ComponentBase<ContextCards, HTMLElement> → ContextCards

Constructors

NameDescription
ContextCardsInitializes a new instance of this class.
Constructor
ContextCards
Overload
ContextCards(ContextCard[])Initializes a new instance of this class.
ContextCards(IEnumerable<ContextCard>)Initializes a new instance of this class.
ContextCards(ContextCard[])
public ContextCards(params ContextCard[] cards)

Initializes a new instance of this class.

Parameters

cards ContextCard[]
ContextCards(IEnumerable<ContextCard>)
public ContextCards(IEnumerable<ContextCard> cards) : this(ToArray(cards))

Initializes a new instance of this class.

Parameters

cards IEnumerable<ContextCard>

Properties

NameDescription
CardsGets the cards in this group, in the order they were added.
CountGets the number of cards in this group.
IsExpandedReturns a value indicating whether the group is expanded (in compact mode: whether the cards beyond MaxVisible are shown).
Property
ContextCards.Cards
public IReadOnlyList<ContextCard> Cards

Gets the cards in this group, in the order they were added.

Property
ContextCards.Count
public int Count

Gets the number of cards in this group.

Property
ContextCards.IsExpanded
public bool IsExpanded

Returns a value indicating whether the group is expanded (in compact mode: whether the cards beyond MaxVisible are shown).

Methods

NameDescription
AddAdds a card to the group. Its remove button is wired to the group, so the (x) takes the card out of the list - a handler the caller registered on the card still runs.
AddRangeAdds the given cards to the group.
RemoveRemoves a card from the group. Does nothing if the card isn't in it.
ClearRemoves every card from the group.
SetSummarySets the summary shown on the header pill. Without one, the group summarises itself as "Added N items to context", updated as cards come and go.
SetIconSets the icon shown on the header pill (a stack of layers by default).
IconBackgroundSets the background color of the header's icon tile (any CSS color).
IconForegroundSets the color of the glyph on the header's icon tile.
CompactRenders the group as a wrapping row of pills with no header, showing the first MaxVisible cards and a "+N more" pill for the rest. For a dense line of attachments where the list view would be too much.
MaxVisibleSets how many pills the compact row shows before the "+N more" pill takes over (5 by default). Ignored while the group isn't compact, where the list shows every card.
MoreTextSets the wording of the pill standing in for the cards the compact row is hiding, as a format string whose {0} is how many that is ("+{0} more" by default), and the wording it takes once they are all shown ("Show less").
OnShowAllHands the "+N more" pill over to the given handler instead of revealing the hidden cards in place - for a host that would rather open the full list somewhere else (a panel, a search scoped to the context). Passing null restores the reveal-in-place behaviour.
ExpandedExpands or collapses the group.
ExpandExpands the group.
CollapseCollapses the group.
ToggleToggles the group between expanded and collapsed.
OnToggleRegisters a callback invoked whenever the group is expanded or collapsed.
RenderRenders the component's root HTML element.
Method
ContextCards.Add
public ContextCards Add(ContextCard card)

Adds a card to the group. Its remove button is wired to the group, so the (x) takes the card out of the list - a handler the caller registered on the card still runs.

Method
ContextCards.AddRange
public ContextCards AddRange(IEnumerable<ContextCard> cards)

Adds the given cards to the group.

Method
ContextCards.Remove
public ContextCards Remove(ContextCard card)

Removes a card from the group. Does nothing if the card isn't in it.

Method
ContextCards.Clear
public ContextCards Clear()

Removes every card from the group.

Method
ContextCards.SetSummary
public ContextCards SetSummary(string summary)

Sets the summary shown on the header pill. Without one, the group summarises itself as "Added N items to context", updated as cards come and go.

Method
ContextCards.SetIcon
public ContextCards SetIcon(UIcons icon)

Sets the icon shown on the header pill (a stack of layers by default).

Method
ContextCards.IconBackground
public ContextCards IconBackground(string color)

Sets the background color of the header's icon tile (any CSS color).

Method
ContextCards.IconForeground
public ContextCards IconForeground(string color)

Sets the color of the glyph on the header's icon tile.

Method
ContextCards.Compact
public ContextCards Compact(bool value = true)

Renders the group as a wrapping row of pills with no header, showing the first MaxVisible cards and a "+N more" pill for the rest. For a dense line of attachments where the list view would be too much.

Method
ContextCards.MaxVisible
public ContextCards MaxVisible(int count)

Sets how many pills the compact row shows before the "+N more" pill takes over (5 by default). Ignored while the group isn't compact, where the list shows every card.

Method
ContextCards.MoreText
public ContextCards MoreText(string moreFormat, string lessText = null)

Sets the wording of the pill standing in for the cards the compact row is hiding, as a format string whose {0} is how many that is ("+{0} more" by default), and the wording it takes once they are all shown ("Show less").

Method
ContextCards.OnShowAll
public ContextCards OnShowAll(Action handler)

Hands the "+N more" pill over to the given handler instead of revealing the hidden cards in place - for a host that would rather open the full list somewhere else (a panel, a search scoped to the context). Passing null restores the reveal-in-place behaviour.

Method
ContextCards.Expanded
public ContextCards Expanded(bool value = true)

Expands or collapses the group.

Method
ContextCards.Expand
public ContextCards Expand()

Expands the group.

Method
ContextCards.Collapse
public ContextCards Collapse()

Collapses the group.

Method
ContextCards.Toggle
public ContextCards Toggle()

Toggles the group between expanded and collapsed.

Method
ContextCards.OnToggle
public ContextCards OnToggle(Action<ContextCards> onToggle)

Registers a callback invoked whenever the group is expanded or collapsed.

Method
ContextCards.Render
public override HTMLElement Render()

Renders the component's root HTML element.

See also

© 2026 Curiosity. All rights reserved.