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
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
| Name | Description |
|---|---|
| ContextCard | Initializes a new instance of this class showing the given icon. |
| 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. |
Properties
| Name | Description |
|---|---|
| Label | Gets the label shown by the component. |
| SubLabel | Gets the secondary line shown below the label, or null when the card has none. |
| IsRemovable | Returns a value indicating whether the component shows a remove button. |
| Tag | 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. |
public string SubLabelGets the secondary line shown below the label, or null when the card has none.
public bool IsRemovableReturns a value indicating whether the component shows a remove button.
Methods
| Name | Description |
|---|---|
| SetLabel | 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. |
| KeepExtensionVisible | 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. |
| MaxLabelWidth | 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. |
| SetBadge | 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. |
| MonospaceSubLabel | 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. |
| WithChevron | Shows a chevron at the end of the card, the hint that clicking it opens what it stands for. Pair it with OnClick. |
| SetSubLabel | 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. |
| SetIcon | Sets the icon shown on the tile. |
| SetImage | 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. |
| IconBackground | Sets the background color of the icon tile (any CSS color, e.g. "#ef4444" or "var(--tss-danger-background-color)"). |
| IconForeground | Sets the color of the glyph on the icon tile. |
| IconTint | 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. |
| NoIconBackground | Configures the icon tile to have no background, letting the glyph or image sit directly on the card. |
| Background | Sets the background color of the card itself. |
| 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. |
| Removable | 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. |
| NoRemove | Configures the component to show no remove button. |
| Compact | 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. |
| OnClick | Registers a callback invoked when the click event fires. A clickable card also becomes keyboard reachable and is activated with Enter or Space. |
| 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. |
| 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. |
| Selectable | 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. |
| Render | Renders the component's root HTML element. |
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.
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.
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.
| 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
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.
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.
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.
| 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
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.
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)").
public ContextCard IconForeground(string color)Sets the color of the glyph on the icon tile.
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.
public ContextCard NoIconBackground()Configures the icon tile to have no background, letting the glyph or image sit directly on the card.
public ContextCard Background(string color)Sets the background color of the card itself.
| 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>
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.
public ContextCard NoRemove()Configures the component to show no remove button.
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.
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.
| 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[]>
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.
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.
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
| Name | Description |
|---|---|
| ContextCards | Initializes a new instance of this class. |
| Overload | |
|---|---|
| ContextCards(ContextCard[]) | Initializes a new instance of this class. |
| ContextCards(IEnumerable<ContextCard>) | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| Cards | Gets the cards in this group, in the order they were added. |
| Count | Gets the number of cards in this group. |
| IsExpanded | Returns a value indicating whether the group is expanded (in compact mode: whether the cards beyond MaxVisible are shown). |
public IReadOnlyList<ContextCard> CardsGets the cards in this group, in the order they were added.
Methods
| Name | Description |
|---|---|
| Add | 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. |
| AddRange | Adds the given cards to the group. |
| Remove | Removes a card from the group. Does nothing if the card isn't in it. |
| Clear | Removes every card from the group. |
| SetSummary | 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. |
| SetIcon | Sets the icon shown on the header pill (a stack of layers by default). |
| IconBackground | Sets the background color of the header's icon tile (any CSS color). |
| IconForeground | Sets the color of the glyph on the header's icon tile. |
| Compact | 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. |
| MaxVisible | 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. |
| MoreText | 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"). |
| OnShowAll | 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. |
| Expanded | Expands or collapses the group. |
| Expand | Expands the group. |
| Collapse | Collapses the group. |
| Toggle | Toggles the group between expanded and collapsed. |
| OnToggle | Registers a callback invoked whenever the group is expanded or collapsed. |
| Render | Renders the component's root HTML element. |
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.
public ContextCards AddRange(IEnumerable<ContextCard> cards)Adds the given cards to the group.
public ContextCards Remove(ContextCard card)Removes a card from the group. Does nothing if the card isn't in it.
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.
public ContextCards SetIcon(UIcons icon)Sets the icon shown on the header pill (a stack of layers by default).
public ContextCards IconBackground(string color)Sets the background color of the header's icon tile (any CSS color).
public ContextCards IconForeground(string color)Sets the color of the glyph on the header's icon tile.
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.
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.
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").
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.
public ContextCards Expanded(bool value = true)Expands or collapses the group.
public ContextCards Toggle()Toggles the group between expanded and collapsed.
public ContextCards OnToggle(Action<ContextCards> onToggle)Registers a callback invoked whenever the group is expanded or collapsed.
See also
- Omni Box — the composer these cards sit above.
- Chat — the transcript they are attached to.
- Tool Call — the disclosure family
ContextCardsis styled after. - Components overview