@ecl/layout-wrapper

中文文档
5.4.1发布于 2026/11/10EUPL-1.2近 30 天下载 2806

ECL layout wrapper

原始使用文档
文档目录3 节
  1. Parameters
  2. Example:
  3. How it works

ECL Layout wrapper

npm package: @ecl/layout-wrapper

npm install --save @ecl/layout-wrapper

Parameters

  • "nb_columns" (int) (default: 3): Number of item columns (2, 3, or 4)
  • "forced_column" (boolean) (default: false): If true, columns on desktop will always be with a fixed number, instead of dynamically adapting to the container; use with caution
  • "info_position" (string) (default: 'top'): Position of the title/description block. Possible options:
    • top: always stacked above the grid
    • side: beside the grid at wider breakpoints; capped to 3 columns
  • "title" (object) (default: {}): Title of the layout wrapper
    • "level" (int) (default: 2): Heading level, up to h4
    • "label" (string) (default: ''): Title content
  • "description" (string) (default: ''): Description of the layout wrapper
  • "items" (array) (default: []): Items to be displayed in the wrapper. Each item can be either:
    • a string (rendered as-is)
    • an object with a defining component key, e.g. { card: { ... } } Supported component keys: card, navigation_list, content_item, file, list_illustration
  • "direction" (string) (default: "horizontal"): Flow of items; can be "horizontal" or "vertical"
  • "divider" (boolean) (default: false): Display dividers between rows
  • "view_all" (object) (default: {}): Link display below the grid; Follows the ECL Link structure
  • "full_height" (boolean) (default: true): Elements inside the layout wrapper would take the full height
  • "extra_classes" (string) (default: '')
  • "extra_attributes" (array) (default: []): format: [ { "name" (string) (default: ''), "value" (optional) (string) }, ... ],

Example:

{% include '@ecl/layout-wrapper/layout-wrapper.html.twig' with { 
  title: {
    level: 2,
    label: 'Heading',
  },
  description: 'Description',
  items: [
    card: {
      // Card content, following the component structure 
      ... 
    },
    navigation_list: { 
      // Navigation list content, following the component structure 
      ... 
    },
  ],
  view_all: {
    link: {
      path: '#',
      label: 'View all',
    },
  },
} %}

How it works

The layout wrapper uses CSS container queries to adapt its column count based on its own available width, not the viewport. This means it responds correctly whether placed full-width or inside a narrower context (e.g. a sidebar layout).

The outer .ecl-layout-wrapper element establishes the container context (container-type: inline-size). An inner .ecl-layout-wrapper__grid element holds the actual CSS grid and is styled by the container queries.

Column breakpoints (col-x variants):

Container widthcol-2col-3col-4
default1 col1 col1 col
> m2 cols2 cols2 cols
> l—3 cols3 cols
> xl——4 cols

Highlight variants (highlight-col-x) place a first item (typically a heading) to the left of a sub-grid of remaining items. At smaller sizes both sections stack vertically.

Container widthhighlight-col-2highlight-col-3
defaultstackedstacked
> mstacked, content 2 colsstacked, content 2 cols
> lhighlight | 2-col contentstacked, content 3 cols
> xl—highlight | 3-col content

Vertical flow (direction="vertical") fills items top-to-bottom within each column before moving to the next, instead of the default left-to-right order:

horizontal (default)     vertical
[ 1 ][ 2 ][ 3 ]          [ 1 ][ 3 ][ 5 ]
[ 4 ][ 5 ][ 6 ]          [ 2 ][ 4 ][ 6 ]

This is implemented with grid-auto-flow: column and an explicit grid-template-rows, which tells the browser how many rows to fill before wrapping to the next column. Below > m (single column), vertical flow has no effect and items stack normally.

Because the column count changes at each breakpoint, the required row count changes too — e.g. 6 items in 2 cols needs 3 rows, but in 3 cols needs 2 rows. CSS cannot compute this dynamically, so the template pre-calculates all needed values and outputs them as separate custom properties (--ecl-layout-rows-2, --ecl-layout-rows-3, --ecl-layout-rows-4). Each container query breakpoint then references the variable that matches its active column count.

版本与发布记录

@ecl/layout-wrapper 共发布 12 个版本,首次发布于 2026/06/03;过去 12 个月发布了 12 个版本。

版本发布日期距今
5.4.1latest2026/11/103 天前
5.4.02026/10/2222 天前
5.3.22026/10/081 个月前
5.3.12026/09/211 个月前
5.3.02026/09/151 个月前
5.2.22026/09/082 个月前

关于 @ecl/layout-wrapper 的常见问题

@ecl/layout-wrapper 是什么?

ECL layout wrapper

如何安装 @ecl/layout-wrapper?

在项目目录运行 npm install @ecl/layout-wrapper,或使用 pnpm add / yarn add / bun add。

@ecl/layout-wrapper 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ecl__layout-wrapper 是否存在。

@ecl/layout-wrapper 可以商用吗?

@ecl/layout-wrapper 使用 EUPL-1.2 许可。声明的许可为 EUPL-1.2,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@ecl/layout-wrapper 的下载量有多少?

根据 npm 官方下载统计,@ecl/layout-wrapper 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,806 次,日均约 94 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ecl/layout-wrapper 还在维护吗?

最新版本 5.4.1 发布于 2026/11/10(3 天前);至今共发布 12 个版本,其中过去 12 个月发布了 12 个;首次发布于 2026/06/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。