@m3000/marketv0.0.0

Ranking

Render sorted items as grouped lists.

Installation

pnpm add @m3000/market

Usage

Ranking is a renderer for sorted data. It does not sort items for you, so pass items in the exact order you want them displayed. Group boundaries are created from entry indices.

Use Ranking.Slot to insert items at atIndex before groups render. Slot placement affects the position of subsequent items.

  1. #1 Alice 950
  2. #2 Bob 880
  3. #3 Charlie 820
  1. #4 Dana 790

Examples

Empty

Use Ranking.Empty when there are no ranked items to render.

No items yet.

Custom Group

Use custom group headers when the groups need more than a default divider.

GoldLeading
  1. #1North Star
    112 pts
  2. #2Atlas Club
    108 pts
SilverClose behind
  1. #3Beacon FC
    97 pts
  2. #4Drift Union
    92 pts
BronzeStill in it
  1. #5Ember SC
    88 pts
  2. #6Harbor AC
    84 pts

Static Slot

Insert fixed content at a specific ranked index. Preview rows work especially well here.

  1. #1Alpha
    98
  2. PreviewPreview item96
  3. #3Beacon
    94
  1. #4Cipher
    91
  2. #5Drift
    88

Dynamic Slot

Slots can be moved within the groups dynamically when the inserted content depends on its resolved rank or group.

Move slot to rank
  1. #1Alice
    950
  2. #2Preview bidScore 905
  3. #3Bob
    880
  1. #4Charlie
    820
  2. #5Dana
    790

API Reference

Ranking.Root

Provides ranking context and renders grouped ranked data.

PropTypeDefaultDescription
itemsT[]requiredAlready-sorted items to display
getKey(item: T) => stringrequiredFunction to get a unique key for each item
boundariesnumber[][]Entry indices where groups should split
labelsstring[][]Labels for each rendered group
classNamestringundefinedClass name for the outer container, including the empty state

Ranking.Empty

Renders fallback content when there are no items and no slots.

PropTypeDefaultDescription
childrenReactNoderequiredEmpty-state content
classNamestringundefinedClass name for the empty-state container

Ranking.Slot

Registers content at a specific entry index.

PropTypeDefaultDescription
slotKeystringrequiredStable key for the inserted slot
atIndexnumberrequiredEntry index where the slot should be inserted
childrenReactNode | (ctx: SlotContext) => ReactNoderequiredStatic content or a render function that receives the resolved slot context

Ranking.Group

Renders each group as an ordered list.

PropTypeDefaultDescription
childrenReactNoderequiredGroup content, typically Ranking.GroupDivider and Ranking.GroupItem
classNamestringundefinedClass name for each rendered ordered list

Ranking.GroupDivider

Renders the label/header for each group.

PropTypeDefaultDescription
children({ label, groupIndex }) => ReactNodeundefinedOptional custom divider renderer
classNamestringundefinedClass name for the divider container

Ranking.GroupItem

Renders each ranked entry as a list item.

PropTypeDefaultDescription
childrenReactNoderequiredItem content, typically Ranking.GroupItemValue
classNamestringundefinedClass name for each rendered list item

Ranking.GroupItemValue

Render-prop component that receives the item and item context.

PropTypeDescription
children(item: T, ctx: GroupItemContextValue<T>) => ReactNodeRender function

Ranking.GroupItemIndex

Renders the resolved rank for the current item.

PropTypeDefaultDescription
children({ globalIndex, rank, groupIndex }) => ReactNodeundefinedOptional custom index renderer
classNamestringundefinedClass name for the default index text

SlotContext

The context passed to Ranking.Slot when children is a render function.

PropertyTypeDescription
globalIndexnumberZero-based entry index in the rendered ranking
groupIndexnumberZero-based group index
ranknumberOne-based displayed rank
rankInGroupnumberOne-based position inside the current group
isFirstInGroupbooleanWhether the slot is first in its group
isLastInGroupbooleanWhether the slot is last in its group
isLastItembooleanWhether the slot is the final rendered entry

GroupItemContextValue

PropertyTypeDescription
itemTThe current item
globalIndexnumberZero-based entry index in the rendered ranking
groupIndexnumberZero-based group index
ranknumberOne-based displayed rank
rankInGroupnumberOne-based position inside the current group
isFirstInGroupbooleanWhether the item is first in its group
isLastInGroupbooleanWhether the item is last in its group
isLastItembooleanWhether the item is the final rendered entry

On this page