ContextCards

Description

ContextCards holds a set of ContextCards and shows them as one element, to say what a chat, a search or an answer is scoped to. By default it is a summary pill ("Added 3 items to context") that expands into a bordered list of full-width rows and collapses back, with the same pill shape and chevron as ToolsUsed. Compact() drops the header and draws a wrapping row of pills, showing the first MaxVisible (5 by default) and collapsing the rest behind a "+N more" pill.

Adding a card wires its remove button to the group, so the (x) takes it out; a handler registered with ContextCard.OnRemove still runs. An empty group renders nothing and takes no space.

Usage

Pass the cards to ContextCards(...), or add them later with Add. SetSummary replaces the default header text.

In compact form the group is a row of pills. MoreText changes the wording of the "+N more" pill, and OnShowAll hands the pill to the host instead of revealing the hidden cards in place.

API reference

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