@molecule/app-card-grid-angular
Feature · card-grid · App (browser) · v1.1.3 · Apache-2.0
Responsive Angular card grid and bento-grid layouts
npm install @molecule/app-card-grid-angularHow it works
@molecule/app-card-grid-angular is a ready-made card-grid 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 { BentoGrid, CardGrid } from '@molecule/app-card-grid-angular'
@Component({
selector: 'app-grids',
standalone: true,
imports: [CardGrid, BentoGrid],
template: `
<div mol-card-grid [columns]="3" gap="md">
<app-product-card [product]="products[0]" />
<app-product-card [product]="products[1]" />
<app-product-card [product]="products[2]" />
</div>
<div mol-bento-grid [items]="bentoItems"></div>
`,
})
export class Grids {
readonly products = [
{ id: 'p1', name: 'Mug' },
{ id: 'p2', name: 'Lamp' },
{ id: 'p3', name: 'Chair' },
]
readonly hero = 'Hero card'
readonly stats = 'Stats card'
bentoItems = [
{ id: 'hero', content: this.hero, colSpan: 8, rowSpan: 2 },
{ id: 'stats', content: this.stats, colSpan: 4 },
]
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular card-grid and bento-grid layouts.
Exports:
<CardGrid>— responsive grid with configurable column count.<BentoGrid>— col/row-span or named-areas layout for mixed-size cards.
This is the Angular counterpart of @molecule/app-card-grid-react: the same
exports, the same props (React names), 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 { BentoGrid, CardGrid } from '@molecule/app-card-grid-angular'
@Component({
selector: 'app-grids',
standalone: true,
imports: [CardGrid, BentoGrid],
template: `
<div mol-card-grid [columns]="3" gap="md">
<app-product-card [product]="products[0]" />
<app-product-card [product]="products[1]" />
<app-product-card [product]="products[2]" />
</div>
<div mol-bento-grid [items]="bentoItems"></div>
`,
})
export class Grids {
readonly products = [
{ id: 'p1', name: 'Mug' },
{ id: 'p2', name: 'Lamp' },
{ id: 'p3', name: 'Chair' },
]
readonly hero = 'Hero card'
readonly stats = 'Stats card'
bentoItems = [
{ id: 'hero', content: this.hero, colSpan: 8, rowSpan: 2 },
{ id: 'stats', content: this.stats, colSpan: 4 },
]
}
Type
feature
Installation
npm install @molecule/app-card-grid-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
BentoItem
Data descriptor for a single cell in a BentoGrid layout.
interface BentoItem {
/** Unique item identifier (the `@for` track key). */
id: string
/** Card content (a node template or text). */
content: BentoItemContent
/** CSS grid-column-span (1-12). Defaults to 4. */
colSpan?: number
/** CSS grid-row-span (1-6). Defaults to 1. */
rowSpan?: number
/** Named grid-area when using `areas` layout. */
area?: string
}
BentoGridProps
Props for BentoGrid.
interface BentoGridProps {
/** Items to render. */
items: BentoItem[]
/**
* Optional `grid-template-areas` string (e.g. `'a a b' 'c d d'`). When
* provided, each `BentoItem.area` must match a token in the template.
*/
areas?: string
/** Default column count when `areas` is absent. Defaults to 12. */
columns?: number
/** Gap between items. */
gap?: 'xs' | 'sm' | 'md' | 'lg'
/** Extra classes. */
className?: string
}
CardGridProps
Props for CardGrid. The cards are projected content in Angular (an
input cannot carry a node), so children is typed unknown: pass it in the
host template, not as a value.
interface CardGridProps {
/** Cards, projected as the element's default content. */
children?: unknown
/** Column count at the md+ breakpoint. 1–6. Defaults to 3. */
columns?: 1 | 2 | 3 | 4 | 5 | 6
/** Gap between cards. */
gap?: 'xs' | 'sm' | 'md' | 'lg'
/** Extra classes. */
className?: string
}
Classes
BentoGrid
BentoGrid component.
Items span multiple cells for a magazine / dashboard layout. The host IS the
root <div> (div[mol-bento-grid]), matching React's root exactly. Works in
two modes: (a) col/row-span driven, (b) named-areas driven via the areas
input. Node-valued item content is an ng-template reference rendered
through NgTemplateOutlet; string / number content renders as text.
@Component({
selector: 'div[mol-bento-grid]',
standalone: true,
imports: [NgTemplateOutlet],
inputs: ['items', 'areas', 'columns', 'gap', 'className'],
host: {
'[class]': 'classes()',
'[style.display]': "'grid'",
'[style.grid-template-columns]': 'gridTemplateColumns()',
'[style.grid-template-areas]': 'gridTemplateAreas()',
},
template: `@for (item of items; track item.id) {
<div [attr.style]="itemStyle(item)">
@if (isNode(item.content)) {
<ng-container [ngTemplateOutlet]="item.content" />
} @else {
<ng-container>{{ textOf(item.content) }}</ng-container>
}
</div>
}`,
})
export class BentoGrid {
/** Items to render. */
items: BentoItem[] = []
/** Optional `grid-template-areas` string. */
areas?: string
/** Default column count when `areas` is absent (defaults to `12`). */
columns?: number
/** Gap between items (defaults to `'md'` at read time). */
gap?: 'xs' | 'sm' | 'md' | 'lg'
/** Extra classes. */
className?: string
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Computes the grid class list (React's `cm.grid({ gap })` plus the extra
* `className`).
* @returns The class string.
*/
classes(): string {
return this.cm().cn(this.cm().grid({ gap: this.gap ?? 'md' }), this.className)
}
/**
* The host's `grid-template-columns` in span mode; absent in areas mode
* (React writes one or the other).
* @returns The CSS value, or null for no declaration.
*/
gridTemplateColumns(): string | null {
return this.areas ? null : `repeat(${this.columns ?? 12}, minmax(0, 1fr))`
}
/**
* The host's `grid-template-areas` in areas mode; absent in span mode.
* @returns The CSS value, or null for no declaration.
*/
gridTemplateAreas(): string | null {
return this.areas ?? null
}
/**
* An item's whole style attribute: React's `{ gridColumn, gridRow }` in span mode, its
* `{ gridArea }` in areas mode, and none for an item that sets no area.
*
* One attribute binding rather than `[style.grid-column]`, `[style.grid-row]` and
* `[style.grid-area]`: `grid-area` is the shorthand of the other two, so Angular removing the
* null `grid-area` binding also removed both spans, and a browser laid every item out at span 1.
* A `[style]` map binding has the same fault on a span-to-areas switch, because Angular applies
* map changes in key order (it sets `grid-area`, then removes `grid-column` from it).
* @param item - The item.
* @returns The style text, or null for no style attribute.
*/
itemStyle(item: BentoItem): string | null {
if (!this.areas)
return `grid-column: span ${item.colSpan ?? 4}; grid-row: span ${item.rowSpan ?? 1}`
return item.area ? `grid-area: ${item.area}` : null
}
/**
* Whether item content holds a node (an `ng-template` reference) rather than
* text.
* @param value - The item content.
* @returns True when it renders through a template outlet.
*/
isNode(value: BentoItem['content']): value is TemplateRef<unknown> {
return value instanceof TemplateRef
}
/**
* The text a content field renders (React renders strings and numbers as
* text).
* @param value - The item content.
* @returns The text, or `''` for a node field.
*/
textOf(value: BentoItem['content']): string {
return typeof value === 'string' || typeof value === 'number' ? String(value) : ''
}
}
CardGrid
CardGrid component.
The generic responsive card grid. The host IS the root <div>
(div[mol-card-grid]), matching React's root exactly; the cards are the
element's default projected content, so they land inside that div just as
React's children do. Collapses to one column on narrow viewports and grows
to columns on md+ via the ClassMap grid.
@Component({
selector: 'div[mol-card-grid]',
standalone: true,
inputs: ['columns', 'gap', 'className'],
host: {
'[class]': 'classes()',
},
template: '<ng-content></ng-content>',
})
export class CardGrid {
/** Column count at the md+ breakpoint (defaults to `3` at read time). */
columns?: 1 | 2 | 3 | 4 | 5 | 6
/** Gap between cards (defaults to `'md'` at read time). */
gap?: 'xs' | 'sm' | 'md' | 'lg'
/** Extra classes. */
className?: string
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Computes the grid class list (React's `cm.grid({ cols, gap })` plus the
* extra `className`).
* @returns The class string.
*/
classes(): string {
return this.cm().cn(
this.cm().grid({ cols: this.columns ?? 3, gap: this.gap ?? 'md' }),
this.className,
)
}
}
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.5.0 || ^4.0.0@molecule/app-ui^1.0.1@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
CardGrid collapses to one column on narrow viewports and grows to
columns (1–6) at the md+ breakpoint via the ClassMap grid. In
BentoGrid, span mode uses a columns-wide grid (default 12) with
per-item colSpan/rowSpan; passing areas switches to named
grid-template-areas — then every item must set a matching area
token or it falls out of the template. Node values are projected content:
CardGrid's cards are the element's default content, and a
BentoItem.content is an ng-template reference or text.