Stack
Description
A Stack is a container component that abstracts the implementation of a flexbox to layout its children components. It is useful for grouping other components, arranging them either vertically or horizontally (with optional reverse orders), and providing various alignment, wrapping, and spacing options. Use it when you need to arrange components in a flexible, responsive layout in your UI.
Usage
Instantiate a Stack using the Tesserae fluent interface via the static helper method. For example, call Stack() and chain configuration methods to set orientation, alignment, and wrapping as needed.
API reference
public class Stack : IContainer<Stack, IComponent>, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStyling, ICanWrap, IRoundedStyleA Stack is a container-type component that abstracts the implementation of a flexbox in order to define the layout of its children components.
Constructors
Properties
public Orientation StackOrientation { get ; set ; }Gets or sets the stack orientation.
public bool CanWrap { get ; set ; }Gets or sets whether the stack can wrap its children.
public bool IsInline { get ; set ; }Gets or sets whether the stack is displayed as an inline-flex.
public HTMLElement InnerElement { get; private set; }Gets the inner element.
Methods
public static void SetAlign(IComponent component, ItemAlign align)Sets the alignment for a component within a stack.
Parameters
- component
- The component.
- align
- The alignment.
public static void SetJustify(IComponent component, ItemJustify align)Sets the justification for a component within a stack.
Parameters
- component
- The component.
- align
- The justification.
public Stack AlignItems(ItemAlign align)Sets the align-items CSS property for this stack.
Parameters
- align
- The alignment.
Returns
The current instance.
public Stack AlignItemsCenter()Sets the align-items CSS property for this stack to 'center'.
Returns
The current instance.
public Stack Relative()Make this stack relative (i.e. position:relative).
Returns
The current instance.
public Stack Gap(UnitSize gapSize)Sets the gap between both rows and columns for the stack layout.
Parameters
- gapSize
- The size of the gap to apply between items.
public Stack RowGap(UnitSize gapSize)Sets the vertical spacing (row gap) between items in the stack layout.
Parameters
- gapSize
- The size of the gap to apply between rows.
public Stack ColumnGap(UnitSize gapSize)Sets the horizontal spacing (column gap) between items in the stack layout.
Parameters
- gapSize
- The size of the gap to apply between columns.
public Stack AlignContent(ItemAlign align)Sets the align-content CSS property for this stack.
Parameters
- align
- The alignment.
Returns
The current instance.
public Stack JustifyContent(ItemJustify justify)Sets the justify-content CSS property for this stack.
Parameters
- justify
- The justification.
Returns
The current instance.
public Stack JustifyItems(ItemJustify justify)Sets the justify-items CSS property for this stack.
Parameters
- justify
- The justification.
Returns
The current instance.
public Stack RemovePropagation()Disables propagation of styling to the stack item parent.
Returns
The current instance.
public static void SetWidth(IComponent component, UnitSize unitSize)Sets the width of a component within a stack.
public static void SetMinWidth(IComponent component, UnitSize unitSize)Sets the minimum width of a component within a stack.
public static void SetMaxWidth(IComponent component, UnitSize unitSize)Sets the maximum width of a component within a stack.
public static void SetHeight(IComponent component, UnitSize unitSize)Sets the height of a component within a stack.
public static void SetMinHeight(IComponent component, UnitSize unitSize)Sets the minimum height of a component within a stack.
public static void SetMaxHeight(IComponent component, UnitSize unitSize)Sets the maximum height of a component within a stack.
public static void SetMarginLeft(IComponent component, UnitSize unitSize)Sets the left margin of a component within a stack.
public static void SetMarginRight(IComponent component, UnitSize unitSize)Sets the right margin of a component within a stack.
public static void SetMarginTop(IComponent component, UnitSize unitSize)Sets the top margin of a component within a stack.
public static void SetMarginBottom(IComponent component, UnitSize unitSize)Sets the bottom margin of a component within a stack.
public static void SetPaddingLeft(IComponent component, UnitSize unitSize)Sets the left padding of a component within a stack.
public static void SetPaddingRight(IComponent component, UnitSize unitSize)Sets the right padding of a component within a stack.
public static void SetPaddingTop(IComponent component, UnitSize unitSize)Sets the top padding of a component within a stack.
public static void SetPaddingBottom(IComponent component, UnitSize unitSize)Sets the bottom padding of a component within a stack.
public static void SetGrow(IComponent component, int grow)Sets the flex-grow of a component within a stack.
public static void SetShrink(IComponent component, bool shrink)Sets the flex-shrink of a component within a stack.
public Stack OnMouseOver(ComponentEventHandler<Stack, Event> onMouseOver)Attaches a handler to the mouse over event.
Parameters
- onMouseOver
- The handler.
Returns
The current instance.
public Stack OnMouseOut(ComponentEventHandler<Stack, Event> onMouseOut)Attaches a handler to the mouse out event.
Parameters
- onMouseOut
- The handler.
Returns
The current instance.
public void Add(IComponent component)Adds a component to the stack.
Parameters
- component
- The component.
public void Prepend(IComponent component)Adds a component to the beginning of the stack.
Parameters
- component
- The component.
public void InsertBefore(IComponent component, IComponent componentToInsertBefore)Inserts a component before another component in the stack.
Parameters
- component
- The component to insert.
- componentToInsertBefore
- The reference component.
public void InsertAfter(IComponent component, IComponent componentToInsertBefore)Inserts a component after another component in the stack.
Parameters
- component
- The component to insert.
- componentToInsertBefore
- The reference component.
public void Replace(IComponent newComponent, IComponent oldComponent)Replaces a component in the stack.
Parameters
- newComponent
- The new component.
- oldComponent
- The old component.
public void Remove(IComponent component)Removes a component from the stack.
Parameters
- component
- The component.
public virtual HTMLElement Render()Renders the component.
Returns
The rendered HTML element.
public Stack HorizontalReverse()Sets the stack orientation to horizontal reverse.
public Stack VerticalReverse()Sets the stack orientation to vertical reverse.
public enum ItemAlignRepresents the alignment of an item.
public enum ItemJustifyRepresents the justification of an item.
Samples
Basic Vertical Stack Sample
The following sample demonstrates creating a vertical stack with two buttons. The Stack is configured to center its items and disallow wrapping.
Interactive Orientation Change Sample
This sample shows how to dynamically change the orientation of a Stack via user interaction.
See also
This documentation provides an overview of the Stack component’s functionality, methods, and properties, along with code samples to help you integrate it into your Tesserae UI application.