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

Split tables documentation into TableComponent and BorderBoxComponent

Henriette Darge8a522f577ac5
diff --git a/lookbook/docs/components/borde-box-table.md.erb b/lookbook/docs/components/borde-box-table.md.erb
new file mode 100644
index 00000000000..c633001424e
--- /dev/null
+++ b/lookbook/docs/components/borde-box-table.md.erb
@@ -0,0 +1,81 @@
+## 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 support). If you want or need that, please use the [TableComponent docs](./tables))
+
+## Best practices
+
+**Do**
+
+- Use a BorderBox table if you have a *few* entries of unsorted data, that does not require pagination
+- 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**
+
+- Use the BorderBox table for a lot of items that require sorting or pagination
+
+## 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, one 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.
diff --git a/lookbook/docs/components/tables.md.erb b/lookbook/docs/components/tables.md.erb
index 447a3e0ba4d..bf466391a56 100644
--- a/lookbook/docs/components/tables.md.erb
+++ b/lookbook/docs/components/tables.md.erb
@@ -1,104 +1,46 @@
## Overview
-### Border Box Table
+We currently have two components for implementing a table view:
-<%= embed OpPrimer::BorderBoxTableComponentPreview, :default %>
+* a (sortable) `TableComponent`
+* a (unsortable, primer based) `BorderBoxTableComponent`
-### Sortable table
+**Sortable table**
<%= embed OpenProject::Deprecated::TablePreview, :default %>
-## Usage
-
-To use either table implementation, you need to subclass into your own namespace:
-
-- **Regular table:** `TableComponent` and `RowComponent`
-- **BorderBox table:** `OpPrimer::BorderBoxTableComponent` and `OpPrimer::BorderBoxRowComponent`
-
-**Columns:** Define the columns of the table as class method `columns :a, :b, :c`
-
-**Headers:** Define the headers of the component like so
-
-```ruby
-def headers
- [
- [:a, { caption: 'Column A' }],
- [:b, { caption: 'Column B' }],
- [:c, { caption: 'Column C' }]
- ]
-end
-```
-
-**Actions:** Define the actions in the row component as `button_links`. See the example code
-
-<%= embed OpPrimer::BorderBoxTableComponentPreview, :default, panels: %i[source] %>
-
-### Border Box Table specifics
-
-#### 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.
+**Border Box Table**
-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
+<%= embed OpPrimer::BorderBoxTableComponentPreview, :default %>
-# On mobile, only two columns are visible
-mobile_columns :title, :users
+For the specifics of that component please have a look at the [BorderBoxTableComponent docs](./border_box_table).
-# For users, show the label using the header caption
-mobile_labels :users
-```
+## Anatomy
-#### Mobile headers
+**Sortable table**
-On mobile, the usual table headers are replaced with a single `mobile_title` property that you have to set on the table.
+* The Sortable Table results in a standard HTML table with some classes applied for styling.
+* If `sortable` is set to true, all sortable column headers are clickable to change the sort order. When a sort is applied, that is indicated via an arrow.
-#### Text wrapping behaviour
+**Border Box Table**
-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.
+* 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.
-#### Main column
+## Technical notes
-Use the `main_column` helper to make a column 2 times as wide as the others and also display the full text:
+The `BorderBoxTableComponent` is a subclass of the `TableComponent`, so the following notes apply to both components. There are however some additional things to consider, for that please visit the [BorderBoxTableComponent docs](./border_box_table).
-```ruby
-# On desktop, show these columns
-columns :title, :users, :created_at
+To use either table implementation, you need to subclass the following classes onto your own namespace:
-# Make title column wider than the others (factor 2 using grid span)
-main_column :title
-```
-Note: Ideally, one one main column will be present for each table.
+- **Regular table:** `TableComponent` and `RowComponent`
+- **BorderBox table:** `OpPrimer::BorderBoxTableComponent` and `OpPrimer::BorderBoxRowComponent`
-#### Footer
+**Columns**
-Set `has_footer?` to true to add a footer to the table, defining the component/content to be rendered with the `footer` method.
+Define the columns of the table as class method:
```ruby
-def has_footer?
- true
-end
-
-def footer
- render CustomFooterComponent.new(...)
-end
-```
-
-## Best practices
-
-**Do**
-
-- Use a BorderBox table if you have a *few* entries of unsorted data, that does not require pagination
-- 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**
-
-- Use the BorderBox table for a lot of items that require sorting or pagination
-
-## Examples
-
-For detailed examples have a look at the other [preview examples](/lookbook/inspect/OpenProject/Primer/border_box_table/default) of the component.
+module ModuleA
+ class TableComponent <::TableComponent
+ columns :name
+<%= embed OpenProject::Deprecated::TablePreview, :default, panels: %i[source] %>
diff --git a/lookbook/previews/open_project/deprecated/table_preview/default.html.erb b/lookbook/previews/open_project/deprecated/table_preview/default.html.erb
index 66bd797a8d8..5cd87af4c8c 100644
--- a/lookbook/previews/open_project/deprecated/table_preview/default.html.erb
+++ b/lookbook/previews/open_project/deprecated/table_preview/default.html.erb
@@ -1,100 +1,58 @@
-<div class="generic-table--container">
- <div class="generic-table--results-container" style="max-height: 340px;">
- <table class="generic-table" data-controller="table-highlighting">
- <colgroup>
- <col>
- <col>
- <col>
- <col>
- <col>
- </colgroup>
- <thead>
- <tr>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span class="sort asc">
- First
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span class="sort asc">
- Second
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span class="sort desc">
- Third
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span class="sort desc">
- Fourth
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span class="sort desc">
- Fifth
- </span>
- </div>
- </div>
- </th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
- <td>Nullam a sem et metus congue placerat.</td>
- <td>Mauris ut augue viverra, consequat eros eu, maximus quam.</td>
- <td>Maecenas elementum orci a varius suscipit.</td>
- <td>Nunc molestie neque sit amet eros semper dapibus.</td>
- </tr>
- <tr>
- <td>Nullam a sem et metus congue placerat.</td>
- <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
- <td>Mauris ut augue viverra, consequat eros eu, maximus quam.</td>
- <td>Maecenas elementum orci a varius suscipit.</td>
- <td>Nunc molestie neque sit amet eros semper dapibus.</td>
- </tr>
- <tr>
- <td>Nullam a sem et metus congue placerat.</td>
- <td>Mauris ut augue viverra, consequat eros eu, maximus quam.</td>
- <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
- <td>Maecenas elementum orci a varius suscipit.</td>
- <td>Nunc molestie neque sit amet eros semper dapibus.</td>
- </tr>
- <tr>
- <td>Nullam a sem et metus congue placerat.</td>
- <td>Mauris ut augue viverra, consequat eros eu, maximus quam.</td>
- <td>Maecenas elementum orci a varius suscipit.</td>
- <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
- <td>Nunc molestie neque sit amet eros semper dapibus.</td>
- </tr>
- <tr>
- <td>Nullam a sem et metus congue placerat.</td>
- <td>Mauris ut augue viverra, consequat eros eu, maximus quam.</td>
- <td>Maecenas elementum orci a varius suscipit.</td>
- <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
- <td>Nunc molestie neque sit amet eros semper dapibus.</td>
- </tr>
- </tbody>
- </table>
+<%=
+ table = Class.new(TableComponent) do
+ columns :foo, :bar
- </div>
-</div>
+ def self.name
+ "MyTable"
+ end
+
+ ## This method is just a hack used for the preview
+ ## Create your components under your namespace like so instead
+ ## MyNamespace::TableComponent
+ ## MyNamespace::RowComponent
+ ## and the other class will be autoloaded
+ def row_class
+ @row_class ||= Class.new(RowComponent) do
+ def self.name
+ "Row"
+ end
+
+ def button_links
+ [
+ delete_button
+ ]
+ end
+
+ def delete_button
+ render(Primer::Beta::IconButton.new(icon: :trash, scheme: :danger, tag: :a, href: "#", "aria-label": "Delete"))
+ end
+
+ def foo
+ render(Primer::Beta::Text.new(tag: :p)) { "Hello there" }
+ end
+
+ def bar
+ "bar"
+ end
+ end
+ end
+
+ def has_actions?
+ true
+ end
+
+ def headers
+ [
+ [:foo, { caption: "Foo column" }],
+ [:bar, { caption: "Bar column" }]
+ ]
+ end
+
+ def sortable?
+ # True per default but for this preview disabled
+ false
+ end
+ end
+
+ render(table.new(rows: [1, 2]))
+%>