Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

3.2 KB
Raw Blame
## Overview

<%= embed OpPrimer::BorderBoxTableComponentPreview, :default %>

## Anatomy

**Note:** The BorderBoxTable is based on the `Primer::Beta::BorderBox` with a CSS grid applied inside to align the individual rows and make it look like a table. Please note, that it is technically not a table and has therefore none of the benefits a normal HTML table would have (e.g  automatic column width adjustments or accessibility short cuts).

If you want or need that, please use the [TableComponent docs](./tables)

## Best practices

**Do**

- Use a BorderBoxTable if you have a *few* entries of unsorted data
- Use up to two actions using the `:secondary` scheme of `Primer::Beta::Button` and `Primer::Beta::IconButton`.
- OR: Use an action menu with `:invisible` scheme

**Don't**

- Don't use the BorderBoxTable when the table consists of a large number of items that require sorting

## Uses

Some examples of where we already use the Border Box table:

- to display a list of meetings
- to display a list of configured SAML providers
- to display a list of configured OpenID providers
- to display a list of configured SCIM clients

If the content does not need a table structure with column headers and grids, please use the simpler [Border Box](../border_box) component instead.

## Technical notes

Since the `BorderBoxTable` is a sub-class of our normal `TableComponent` it follows the same architecture. For the basic usage please visit the [TableComponent docs](./tables). The following docs are only about the additional specifics of the `BorderBoxTable`.

### Mobile behavior

On mobile, the BorderBoxTable does not scroll, but collapse into two columns (content columns and actions). You can control which columns are shown using the `mobile_columns` method.

As the columns are collapsed, some information might need an additional label, which you can prepend with `mobile_labels`.

```ruby
# On desktop, show these columns
columns :title, :users, :created_at

# On mobile, only two columns are visible
mobile_columns :title, :users

# For users, show the label using the header caption
mobile_labels :users
```

### Mobile headers

On mobile, the usual table headers are replaced with a single `mobile_title` property that you have to set on the table.

### Text wrapping behaviour

By default, text longer than the column width will truncate with ellipsis. Only the main column has text that wraps around to display the full string.

### Main column

Use the `main_column` helper to make a column 2 times as wide as the others and also display the full text:

```ruby
# On desktop, show these columns
columns :title, :users, :created_at

# Make title column wider than the others (factor 2 using grid span)
main_column :title
```
Note: Ideally, only one main column will be present for each table.

### Footer

Set `has_footer?` to true to add a footer to the table, defining the component/content to be rendered with the `footer` method.

```ruby
def has_footer?
  true
end

def footer
  render CustomFooterComponent.new(...)
end
```

### Examples

<%= embed OpPrimer::BorderBoxTableComponentPreview, :default, panels: %i[source] %>

For detailed examples have a look at the other [preview examples](/lookbook/inspect/OpenProject/Primer/border_box_table/default) of the component.