|
| 1 | +The Border Box List component displays compact, structured list items with |
| 2 | +optional section headers, item actions, empty states, and a footer. |
| 3 | + |
| 4 | +## Overview |
| 5 | + |
| 6 | +<%= embed OpenProject::Common::BorderBoxListComponentPreview, :default %> |
| 7 | + |
| 8 | +## Anatomy |
| 9 | + |
| 10 | +The list is structured in up to four parts: |
| 11 | + |
| 12 | +**Header** *(optional)* |
| 13 | +Names the list section. It can show a count, description, action buttons, an |
| 14 | +action menu, and an optional collapse toggle. |
| 15 | + |
| 16 | +**Items** |
| 17 | +The list rows. Items can render generic row content or a work package card. |
| 18 | + |
| 19 | +**Empty state** *(optional)* |
| 20 | +Shown when the list has no items. |
| 21 | + |
| 22 | +**Footer** *(optional)* |
| 23 | +Shown below the items. Use it for summary or follow-up content. |
| 24 | + |
| 25 | +If a page shows multiple Border Box Lists and one list has a header, all |
| 26 | +comparable lists should use headers. |
| 27 | + |
| 28 | +## Parameters |
| 29 | + |
| 30 | +| Parameter | Type | Default | Description | |
| 31 | +|---|---|---|---| |
| 32 | +| `container` | `String`, `Symbol`, `Class`, `Object` | required | Seed used to derive stable DOM ids for the list, header, and footer | |
| 33 | +| `interactive` | `Boolean` | `false` | Announces counter and configured empty-state updates politely to assistive technologies | |
| 34 | +| `collapsible` | `Boolean` | `false` | Renders the header as a collapsible toggle when a header is present | |
| 35 | +| `current_user` | `User` | `User.current` | User context forwarded to work package item rows | |
| 36 | +| `system_arguments` | `Hash` | `{}` | Forwarded to the underlying `Primer::Beta::BorderBox` | |
| 37 | + |
| 38 | +## Slots |
| 39 | + |
| 40 | +| Slot | Description | |
| 41 | +|---|---| |
| 42 | +| `with_header` | Optional section header with title, count, description, action buttons, and menu | |
| 43 | +| `with_item` | Generic list row that renders the provided block content | |
| 44 | +| `with_work_package_item` | Work package row that renders a work package card | |
| 45 | +| `with_empty_state` | Empty-state content rendered when no items are present | |
| 46 | +| `with_footer` | Optional footer row below the list items | |
| 47 | + |
| 48 | +## Header |
| 49 | + |
| 50 | +Collapsible headers add: |
| 51 | + |
| 52 | +- an **arrow indicator** next to the title to show whether the section is |
| 53 | + collapsed or expanded. |
| 54 | +- an optional **header description** that gives more context to the section. |
| 55 | + The description is hidden when the list is collapsed. |
| 56 | +- an optional **counter** that displays the number of items in the section. |
| 57 | + |
| 58 | +When collapsed, the bottom border is slightly thicker to indicate that content |
| 59 | +is hidden. |
| 60 | + |
| 61 | +Both static and collapsible headers can include additional actions. For example, |
| 62 | +a menu button can offer contextual actions such as edit, delete, move up, or |
| 63 | +move down. |
| 64 | + |
| 65 | +<%= embed OpenProject::Common::BorderBoxListComponentPreview, :default, params: { collapsible: true } %> |
| 66 | + |
| 67 | +## Variants |
| 68 | + |
| 69 | +<%= embed OpenProject::Common::BorderBoxListComponentPreview, :playground, panels: %i[params source] %> |
| 70 | + |
| 71 | +### Work package items |
| 72 | + |
| 73 | +Use `with_work_package_item` for rows that should render a work package card. |
| 74 | + |
| 75 | +<%= embed OpenProject::Common::BorderBoxListComponentPreview, :with_work_package_items, panels: %i[source] %> |
| 76 | + |
| 77 | +### Empty state |
| 78 | + |
| 79 | +Use `with_empty_state` when the list can be rendered without items. |
| 80 | + |
| 81 | +<%= embed OpenProject::Common::BorderBoxListComponentPreview, :empty_state, panels: %i[source] %> |
| 82 | + |
| 83 | +## Uses |
| 84 | + |
| 85 | +Use the Border Box List for compact item collections such as: |
| 86 | + |
| 87 | +- meeting agenda items. |
| 88 | +- project attributes in project settings. |
| 89 | +- configured OAuth applications. |
| 90 | +- work package lists with card-style rows. |
| 91 | + |
| 92 | +If the content needs table structure with columns and column headers, use the |
| 93 | +[Border Box Table](./tables/border_box_table) component instead. |
| 94 | + |
| 95 | +## Best practices |
| 96 | + |
| 97 | +**Do** |
| 98 | + |
| 99 | +- Use section headers when the items have logical categories, such as open and |
| 100 | + planned meetings. |
| 101 | +- Use the built-in header actions and item menus instead of composing raw |
| 102 | + BorderBox rows by hand. |
| 103 | +- Make headers and items draggable when users need to reorder sections or move |
| 104 | + items between sections. |
| 105 | + |
| 106 | +**Don't** |
| 107 | + |
| 108 | +- Don't mix sections with and without headers. If one section has a header, they must all have headers. |
| 109 | +- Don't make sections collapsible when users benefit from seeing all content at |
| 110 | + once. |
| 111 | +- Don't use the Border Box List for data that needs column alignment, sorting, |
| 112 | + or column headers. |
| 113 | + |
| 114 | +## Technical notes |
| 115 | + |
| 116 | +Use `OpenProject::Common::BorderBoxListComponent` instead of composing |
| 117 | +`Primer::Beta::BorderBox` directly when rendering OpenProject lists. |
| 118 | + |
| 119 | +## Code structure |
| 120 | + |
| 121 | +```ruby |
| 122 | +render OpenProject::Common::BorderBoxListComponent.new( |
| 123 | + container: "project-attributes", |
| 124 | + collapsible: true |
| 125 | +) do |list| |
| 126 | + list.with_header(title: "Project attributes", count: true) do |header| |
| 127 | + header.with_description { "Visible in the project overview" } |
| 128 | + header.with_menu(button_aria_label: "Project attribute actions") do |menu| |
| 129 | + menu.with_item(label: "Edit", href: edit_project_path(@project)) |
| 130 | + end |
| 131 | + end |
| 132 | + |
| 133 | + @project_attributes.each do |attribute| |
| 134 | + list.with_item { attribute.name } |
| 135 | + end |
| 136 | + |
| 137 | + list.with_empty_state( |
| 138 | + title: "No attributes yet", |
| 139 | + description: "Add attributes to describe this project." |
| 140 | + ) |
| 141 | + |
| 142 | + list.with_footer { "Last updated: #{helpers.format_date(@project.updated_at)}" } |
| 143 | +end |
| 144 | +``` |
| 145 | + |
| 146 | +For lower-level details, see the [Primer BorderBox preview examples](/lookbook/inspect/primer/beta/border_box/playground) |
| 147 | +or the [collapsible header preview examples](/lookbook/inspect/primer/open_project/border_box/collapsible_header/playground). |
0 commit comments