@molecule/app-leaderboard-row-angular
Feature · leaderboard-row · App (browser) · v1.1.5 · Apache-2.0
Leaderboard row — rank, avatar, name, score, optional change indicator
npm install @molecule/app-leaderboard-row-angularHow it works
@molecule/app-leaderboard-row-angular is a ready-made leaderboard-row feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { Component } from '@angular/core'
import { LeaderboardRow } from '@molecule/app-leaderboard-row-angular'
@Component({
selector: 'leaderboard-page',
standalone: true,
imports: [LeaderboardRow],
template: `
<div
mol-leaderboard-row
[rank]="1"
name="Alice Chen"
avatarSrc="/avatars/alice.png"
[score]="4820"
[rankDelta]="2"
subtitle="Team Phoenix"
(click)="openProfile('alice')"
></div>
`,
})
export class LeaderboardPage {
readonly openProfile = (id: string): void => {
console.log('open profile', id)
}
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular leaderboard row.
Exports <LeaderboardRow> — rank + avatar + name + score with optional
rank-delta indicator, subtitle, and current-user highlight. Props: rank,
name, score, avatarSrc?, rankDelta?, subtitle?, isMe?,
onClick?, className?. It is the Angular counterpart of
@molecule/app-leaderboard-row-react: same props and the same DOM for the
same input.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { Component } from '@angular/core'
import { LeaderboardRow } from '@molecule/app-leaderboard-row-angular'
@Component({
selector: 'leaderboard-page',
standalone: true,
imports: [LeaderboardRow],
template: `
<div
mol-leaderboard-row
[rank]="1"
name="Alice Chen"
avatarSrc="/avatars/alice.png"
[score]="4820"
[rankDelta]="2"
subtitle="Team Phoenix"
(click)="openProfile('alice')"
></div>
`,
})
export class LeaderboardPage {
readonly openProfile = (id: string): void => {
console.log('open profile', id)
}
}
Type
feature
Installation
npm install @molecule/app-leaderboard-row-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
LeaderboardRowProps
Props accepted by the LeaderboardRow component — the same props
@molecule/app-leaderboard-row-react accepts. Node-valued props render as
text or as projected [slot=<name>] content.
interface LeaderboardRowProps {
/** 1-based rank. */
rank: number
/** Display name: text, or `[slot=name]` content. */
name: unknown
/** Optional avatar URL. */
avatarSrc?: string
/** Score / metric: text, or `[slot=score]` content. */
score: unknown
/** Optional change indicator (positive = climbed). */
rankDelta?: number
/** Optional secondary line (team, level, country): text, or `[slot=subtitle]` content. */
subtitle?: unknown
/** Whether this row represents the current user (highlighted). */
isMe?: boolean
/** Click handler (a native click on the row, with the DOM event; also runs, with no event, on Enter / Space). */
onClick?: (event?: MouseEvent) => void
/** Extra classes. */
className?: string
}
Classes
LeaderboardRow
LeaderboardRow component.
Leaderboard row — rank + avatar + name + score + optional rank-delta
arrow. Top 3 ranks render a medal in place of the numeric rank. The host IS
the row's root <div> (div[mol-leaderboard-row]), matching React's root
exactly. With onClick the row is promoted to a real button in the a11y
tree — role="button", tabindex="0", the pointer cursor — and Enter /
Space activate it (the click handler runs with no event), matching native
button keyboard semantics. When name is not a plain string the Avatar alt
falls back to hardcoded 'Player'. Same props, same DOM as
@molecule/app-leaderboard-row-react's LeaderboardRow. Node-valued
name, score and subtitle content is projected ([slot=<name>]); a
string or number input renders as text. The optional subtitle span stays in
the template, so its <ng-content> always captures, and leaves the page
while it has nothing to render, as React's subtitle && … renders no span.
@Component({
selector: 'div[mol-leaderboard-row]',
standalone: true,
imports: [Avatar],
hostDirectives: [MolPlacement],
inputs: [
'rank',
'name',
'avatarSrc',
'score',
'rankDelta',
'subtitle',
'isMe',
'onClick',
'className',
],
host: {
'[class]': 'classes()',
'[style.borderRadius]': "isMe ? '8px' : ''",
'[attr.role]': 'role()',
'[attr.tabindex]': 'tabindex()',
'(click)': 'rowClick($event)',
'(keydown)': 'handleKeyDown($event)',
},
// prettier-ignore
template: `<span [class]="rankClass()" style="min-width: 32px">{{ rankText() }}</span>
<div mol-avatar [src]="avatarSrc" [alt]="displayName()" [name]="displayName()" [size]="'sm'"></div>
<div [class]="nameColumnClass()"><span [class]="nameClass()">@if (hasName) {<ng-container>{{ name }}</ng-container>}<ng-content select="[slot=name]" /></span><span #subtitleEl [class]="subtitleClass()">@if (hasSubtitle) {<ng-container>{{ subtitle }}</ng-container>}<ng-content select="[slot=subtitle]" /></span></div>
@if (hasDelta) {<span [class]="deltaClass()">{{ deltaArrow() + ' ' + deltaText() }}</span>}
<span [class]="scoreClass()">@if (hasScore) {<ng-container>{{ score }}</ng-container>}<ng-content select="[slot=score]" /></span>`,
})
export class LeaderboardRow {
/** 1-based rank. */
rank?: number
/** Display name: text, or `[slot=name]` content. */
name?: unknown
/** Optional avatar URL. */
avatarSrc?: string
/** Score / metric: text, or `[slot=score]` content. */
score?: unknown
/** Optional change indicator (positive = climbed). */
rankDelta?: number
/** Optional secondary line: text, or `[slot=subtitle]` content. */
subtitle?: unknown
/** Whether this row represents the current user (highlighted). */
isMe?: boolean
/** Click handler, called with the native click event; also runs, with no event, on Enter / Space. */
onClick?: (event?: MouseEvent) => void
/** Extra classes. */
className?: string
/** The optional subtitle span (always in the template; detached while empty). */
@ViewChild('subtitleEl', { static: true }) private subtitleEl?: ElementRef<HTMLSpanElement>
/**
* Keeps the subtitle span on the page only while it renders a text input or
* projected `[slot=subtitle]` content, re-decided whenever either changes (a
* subtitle taken away and given back included).
*/
constructor() {
usePlacement((hasContent) => {
const el = this.subtitleEl?.nativeElement
setElementPresent(el, this.hasSubtitle || (el ? hasContent(el) : false))
})
}
/**
* Whether the row is interactive (`onClick` supplied): React renders the
* button role, tab stop and pointer cursor only then.
* @returns True when clickable.
*/
interactive(): boolean {
return typeof this.onClick === 'function'
}
/**
* The host element's `role` (a button only when clickable).
* @returns `'button'` or null for no attribute.
*/
role(): string | null {
return this.interactive() ? 'button' : null
}
/**
* The host element's tab stop (only when clickable).
* @returns 0 or null for no attribute.
*/
tabindex(): number | null {
return this.interactive() ? 0 : null
}
/**
* Forwards a native click on the row to the `onClick` input (React calls
* the handler with the event).
* @param event - The native click event.
*/
rowClick(event: MouseEvent): void {
this.onClick?.(event)
}
/**
* Activates the row on Enter / Space (React's `handleKeyDown`):
* preventDefault, then the click handler with no event.
* @param event - The keydown.
*/
handleKeyDown(event: KeyboardEvent): void {
const onClick = this.onClick
if (!onClick) return
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
onClick()
}
}
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Computes the row's root class list, with the pointer cursor only when an
* `onClick` handler is set (React's conditional `cm.cursorPointer`).
* @returns The class string.
*/
classes(): string {
return this.cm().cn(
this.cm().flex({ align: 'center', gap: 'sm' }),
this.cm().sp('px', 3),
this.cm().sp('py', 2),
this.onClick ? this.cm().cursorPointer : undefined,
this.isMe ? this.cm().bgTone('info', { subtle: true }) : undefined,
this.className,
)
}
/**
* The rank cell's class.
* @returns The class string.
*/
rankClass(): string {
return this.cm().cn(this.cm().shrink0, this.cm().fontWeight('bold'), this.cm().textCenter)
}
/**
* The rank cell's text: a medal for the top three, `#n` otherwise (React's
* `MEDAL[rank] ?? '#' + rank`).
* @returns The rank display.
*/
rankText(): string {
return MEDAL[this.rank as number] ?? `#${this.rank}`
}
/**
* The Avatar's alt/name (React's `typeof name === 'string' ? name :
* 'Player'`).
* @returns The display name.
*/
displayName(): string {
return typeof this.name === 'string' ? this.name : 'Player'
}
/**
* The name column's class.
* @returns The class string.
*/
nameColumnClass(): string {
return this.cm().cn(this.cm().flex1, this.cm().stack(0 as const))
}
/**
* The name span's class.
* @returns The class string.
*/
nameClass(): string {
return this.cm().cn(this.cm().textSize('sm'), this.cm().fontWeight('semibold'))
}
/**
* The subtitle span's class.
* @returns The class string.
*/
subtitleClass(): string {
return this.cm().textSize('xs')
}
/**
* Whether a text name input is present (a projected name is not).
* @returns True when the name renders as text.
*/
get hasName(): boolean {
return this.name !== undefined && this.name !== null
}
/**
* Whether a text score input is present (a projected score is not).
* @returns True when the score renders as text.
*/
get hasScore(): boolean {
return this.score !== undefined && this.score !== null
}
/**
* Whether the subtitle renders as text: React's `subtitle && …` truthiness.
* @returns True when the subtitle text shows.
*/
get hasSubtitle(): boolean {
return this.subtitle !== undefined && this.subtitle !== null && this.subtitle !== ''
}
/**
* Whether a delta indicator renders: React's `rankDelta !== undefined &&
* rankDelta !== 0` (a zero delta renders nothing).
* @returns True when the ▲/▼ chip shows.
*/
get hasDelta(): boolean {
return this.rankDelta !== undefined && this.rankDelta !== 0
}
/**
* The delta chip's class: the text size and weight, plus the semantic tone
* (React's `cm.textTone(rankDelta > 0 ? 'success' : 'error')`).
* @returns The class string.
*/
deltaClass(): string {
return this.cm().cn(
this.cm().textSize('xs'),
this.cm().fontWeight('semibold'),
this.cm().textTone((this.rankDelta as number) > 0 ? 'success' : 'error'),
)
}
/**
* The delta's arrow (React's `rankDelta > 0 ? '▲' : '▼'`).
* @returns The arrow character.
*/
deltaArrow(): string {
return (this.rankDelta as number) > 0 ? '▲' : '▼'
}
/**
* The delta's magnitude (React's `Math.abs(rankDelta)`).
* @returns The number of ranks climbed or dropped.
*/
deltaText(): number {
return Math.abs(this.rankDelta as number)
}
/**
* The score span's class.
* @returns The class string.
*/
scoreClass(): string {
return this.cm().cn(this.cm().textSize('sm'), this.cm().fontWeight('bold'))
}
}
Injection Notes
Requirements
Peer dependencies:
@angular/common^22.0.0@angular/core^22.0.0@angular/platform-browser^22.0.0@molecule/app-angular^3.13.0 || ^4.0.0@molecule/app-ui^1.4.0@molecule/app-ui-angular^1.1.0
Runtime Dependencies
-
@angular/common -
@angular/core -
@angular/platform-browser -
@molecule/app-angular -
@molecule/app-ui -
@molecule/app-ui-angular -
Ranks 1–3 render medal emoji (gold/silver/bronze) INSTEAD of the rank number; rank 4+ renders
#n. There is no prop to disable the medals. -
rankDeltaarrows use hardcoded green/red hex colors andisMeuses a fixed light-blue translucent background — neither follows the app theme, and theisMetint is tuned for light backgrounds. Override viaclassNamewhere that clashes with a dark theme. -
When
nameis not a plain string the avatar's accessible name falls back to the hardcoded English string 'Player' — pass a stringnamein localized apps. -
With
onClickthe row is promoted to a real button in the a11y tree —role="button",tabindex="0", the pointer cursor — and Enter / Space activate it (the click handler runs with no event), matching native button keyboard semantics; on a click it is called with the native click event. The host IS the row's root<div>, so a click anywhere on the row fires it. -
Requires a wired ClassMap bond;
<Avatar>comes from@molecule/app-ui-angular. Node props are projected content:name,scoreandsubtitleare selected by[slot=<name>], everything else binds as inputs.