GridLayout
A grid container with auto-fit columns and a pointer spotlight.
Usage
Basic
Children with .tx-grid-layout__item get the card style and a spotlight that follows the pointer.
Loading demo...
Card Grid
<template>
<TxGridLayout min-item-width="240px" gap="16px" :max-columns="3">
<article v-for="card in cards" :key="card.id" class="tx-grid-layout__item">
<h3>{{ card.title }}</h3>
<p>{{ card.description }}</p>
</article>
</TxGridLayout>
</template>
Static Grid
<template>
<TxGridLayout :interactive="false" min-item-width="180px" gap="12px">
<div v-for="metric in metrics" :key="metric.name">
{{ metric.name }}
</div>
</TxGridLayout>
</template>
Best Practices
- Use
TxGridLayoutfor repeated peer cards, andTxFlexorTxStackfor one-dimensional alignment. - Add
.tx-grid-layout__itemonly when you want the built-in background, radius, and spotlight. - Turn off
interactivefor large, dense, or virtualized grids to avoid restyling every item on each pointer move. - Set
minItemWidthto the card's real minimum readable width, not as a spacing hack. - Don't nest an interactive grid inside other pointer-heavy surfaces.
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
minItemWidth | string | '300px' | Minimum width of the auto-fit columns. |
gap | string | '1.5rem' | Grid gap. |
maxColumns | number | 4 | Fixed column count at viewport widths ≥ 1400px. |
interactive | boolean | true | Updates spotlight variables on pointer move; when off, children are never restyled. |
Slots
| Slot | Props | Description |
|---|---|---|
default | - | Grid items; add .tx-grid-layout__item for the built-in style and spotlight. |
CSS Variables
| Variable | Source | Description |
|---|---|---|
--tx-grid-gap | gap | Grid gap. |
--tx-grid-min-width | minItemWidth | Minimum column width. |
--tx-grid-max-columns | maxColumns | Wide-screen column count. |
--tx-grid-op | pointer state | Spotlight opacity on each item. |
--tx-grid-x / --tx-grid-y | pointer state | Pointer position relative to each item. |
Overview
- Columns default to
repeat(auto-fit, minmax(minItemWidth, 1fr))and becomerepeat(maxColumns, 1fr)at viewport widths ≥ 1400px. - Spotlight variables are written only to
.tx-grid-layout__itemdescendants; other children are untouched. --tx-grid-opresets to0when the pointer leaves orinteractiveturns off.
Technologies
- On pointer move, each
.tx-grid-layout__itemgets the spotlight variables, which its::beforeradial gradient reads. - Source:
packages/tuffex/packages/components/src/grid-layout/.
查看源码
packages/tuffex/packages/components/src/grid-layout/index.ts