npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trellisjs/plugin-row-expansion

v1.0.0

Published

Trellis 行展開插件 — 支援 accordion 和 multi 展開模式

Downloads

206

Readme

@trellisjs/plugin-row-expansion

Trellis 行展開插件 — 點擊表格行展開額外的自定義內容區域。

安裝

pnpm add @trellisjs/plugin-row-expansion

使用方式

基本用法

import { useTrellis } from '@trellisjs/react';
import { createRowExpansionPlugin } from '@trellisjs/plugin-row-expansion';

function MyTable({ data, columns }) {
  const { api } = useTrellis({
    data,
    columns,
    plugins: [createRowExpansionPlugin()],
  });

  // 註冊展開區域的渲染器
  api.registerSlot('expansion:default', (ctx) => (
    <div>詳細資訊:{ctx.row.name}</div>
  ));

  // ...渲染表格
}

Multi 模式(同時展開多行)

createRowExpansionPlugin({ mode: 'multi' })

Single 模式(Accordion,一次只展開一行)

createRowExpansionPlugin({ mode: 'single' }) // 預設

自訂圖示

createRowExpansionPlugin({
  mode: 'multi',
  expandIcon: <PlusIcon />,
  collapseIcon: <MinusIcon />,
})

事件

| 事件 | Payload | 說明 | |------|---------|------| | expansion:toggle | { rowId: string } | 切換指定行的展開/收合 | | expansion:expand | { rowId: string } | 展開指定行 | | expansion:collapse | { rowId: string } | 收合指定行 | | expansion:expandAll | null | 展開所有行(僅 multi 模式) | | expansion:collapseAll | null | 收合所有行 |

Slot 約定

| Slot 名稱 | 說明 | |-----------|------| | expansion:default | 所有展開行的預設渲染器。接收 { row, rowId } context |

API

createRowExpansionPlugin(options?)

參數:

| 選項 | 類型 | 預設 | 說明 | |------|------|------|------| | mode | 'single' \| 'multi' | 'single' | 展開模式 | | expandIcon | unknown | '▶' | 自訂展開圖示 | | collapseIcon | unknown | '▼' | 自訂收合圖示 |

狀態

插件在 TableState 中管理以下欄位:

  • expandedRows: Set<DataId> — 目前展開的行 ID 集合
  • rowExpansion?: { mode } — 插件設定(由插件安裝時設定)

行為特性

  • 資料變更清理:排序、篩選、分頁變更後,不在 state.data 中的行 ID 會自動從 expandedRows 移除
  • Click 隔離:展開區域的點擊事件使用 stopPropagation 防止冒泡到行選取處理器
  • CSS 過渡:展開/收合時套用 trellis-expansion--expanded class,可搭配 CSS transition 實現動畫

React 元件

  • ExpansionToggle — 展開/收合箭頭按鈕
  • ExpansionRow — 展開區域的 <tr> + <td colSpan>

License

MIT