Skip to content

Commit

Permalink
feat(table): migrate to core tokens (#3441)
Browse files Browse the repository at this point in the history
* build(table): use beta version of spectrum-css table

Use new 5.0 beta version of spectrum-css/table. Includes updated auto
generated CSS files after yarn install.

* build(table): bump up tokens package version to include table tokens

Table tokens were added in spectrum-css/tokens 10.2.1

* build(table): generated updates after tokens version bump

Auto generated updates after bumping tokens version to 10.2.1

* fix(table): set block-size used for min-height back to auto

Block-size is used for for the min height of elements that are displayed
as table-cell, as min-block-size does not work for that display value.
For SWC elements changing display table-cell to display flex, set this
property back to auto, so there is not a fixed height.

* build(table): bump up spectrum-css beta version to beta.1

* fix(table): border fixes for scrollable display flex

Some fixes to get this looking closer to Spectrum CSS.

SWC changes display to flex, with a scrollable table body, which throws
off the outside border (unset in overrides).

Adjusted some spectrum-config to create the correct selectors.

Still existing: problems with how checkboxCell is handled.

* refactor(table): styles for checkbox cell and head-cell attribute

Previously all styles for Table-cell, Table-headCell, and
Table-checkboxCell were being applied to the sp-table-checkbox-cell,
regardless of where it was located. Resulting in head cell styles
appearing on checkbox body cells, and other incorrect styles.

Adds a 'headCell' property / 'head-cell' attribute to the checkbox
cell component. And modifies the spectrum-config to include the various
styles depending on whether that attribute exists or not.

* build(table): use latest 5.0.0-beta.2

Build with the latest table beta, including generated CSS.

* fix(table): restore flex scrollable and display properties

* fix(table): adjust spectrum config to fix checkbox cell styling

- Target the checkbox element correctly in generated styles.
- Increase specificity on checkboxCell class, so it doesn't get
  overridden by the [head-cell] related classes, using repeated :host
  selector. Using :where to reduce specificity of the [head-cell]
  selectors was an option as well, but its browser support is still
  fairly new.

* fix(table): improve checkbox head-cell attribute with reflect

Set new TableCheckboxCell headCell property to have 'reflect' and
attribute setting.

* feat(table): add support for emphasized and non-emphasized

Table styles now have emphasized and non-emphasized colors used for
selected rows, based on the main table variant class for emphasized is
present.

* fix(table): move sort icon to left side

Sort icon moved to left side and removes whitespace between the icon and
the text that creates 3 pixels of extra space.

Version update to new beta also includes some CSS custom property
refactors that should simplify emphasized and non-emphasized.

* fix(table): adjustment for new inline-size style when using flex

* feat(table): finalize emphasized attribute including docs

Set up emphasized attribute properly, and pass it down to checkbox cell
so it can be applied to the sp-checkbox as well.

Update documentation around emphasized, adding a new section and adding
emphasized to some existing examples.

* feat(table): add density property

Add 'density' property to the component with options for compact and
spacious. Includes documentation examples showing both.

* feat(table): update t-shirt sizing support and docs

- Remove size="m" used on examples, as medium styles are used by default
  and the attribute is not needed when it has that value.
- Add support for large and extra-large t-shirt sizes which are now
  supported in the CSS.
- Add docs section for Sizing.

* docs(table): clarify docs around current use of scroller

Scrolling in previous examples that were not virtualized was a result
of the example wrapper's overflow and not a feature of the table. So
setting a height on these was only triggering scrolling in that wrapper.

There was also a non-virtualized example with 'scroller' set to true
that wasn't doing anything (that feature only appears to work with
virtualized examples).

* feat(table): add quiet property

Add property for the 'quiet' variant, and a documentation example.

* docs(table): organize some examples into tabs

Use tabs for density and emphasized docs examples, in a similar manner
to 'sizing', so the displayed options are more consolidated.

* build(table): use 5.0.0 spectrum css release of table

Set version of Spectrum CSS table to the latest 5.0.0 release, just
merged into main. And run yarn install and yarn build to update
generated files.

* docs(table): non-emphasized default and docs update

Make non-emphasized the default and only have a single emphasized
example. Make sure checkboxes are shown in emphasized story. And minor
text update in the docs for selects=multiple.

* ci: update golden image hash

* test(table): update virtualised tests to update properly

* test(table): abstract testing helpers

---------

Co-authored-by: Najika Yoo <naj.halsema@gmail.com>
Co-authored-by: Najika Halsema Yoo <44980010+najikahalsema@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 6, 2023
1 parent 95bb964 commit b866bab
Show file tree
Hide file tree
Showing 27 changed files with 2,125 additions and 1,198 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -10,7 +10,7 @@ executors:
parameters:
current_golden_images_hash:
type: string
default: 5c4ad5dc7ea13ffb7aa6652c510c864996053bbe
default: 25d5270ff12f63383aeceefda261f94b6b299bae
wireit_cache_name:
type: string
default: wireit
Expand Down
275 changes: 263 additions & 12 deletions packages/table/README.md
Expand Up @@ -45,10 +45,8 @@ import {

## Example

To ensure that the table scrolls, make sure to add a `style` attribute to `<sp-table>` with your desired height. Otherwise, the table will automatically show all its items.

```html
<sp-table size="m">
<sp-table>
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
Expand Down Expand Up @@ -94,10 +92,8 @@ When `selects="single"`, the `<sp-table>` will manage a _single_ selection in th

```html
<sp-table
size="m"
selects="single"
selected='["row1"]'
style="height: 200px"
onchange="spAlert(this, `Selected: ${JSON.stringify(this.selected)}`)"
>
<sp-table-head>
Expand Down Expand Up @@ -137,12 +133,10 @@ When `selects="single"`, the `<sp-table>` will manage a _single_ selection in th

### `selects="multiple"`

When `selects="multiple"`, the `<sp-table>` will manage a selection in the array value of `selected` in via a presence toggle. Additionally, an `<sp-table-checkbox-cell>` will be made available in the `<sp-table-head>` in order to select/deselect all items in the `<sp-table>`.
When `selects="multiple"`, the `<sp-table>` manages selections via a presence toggle and adds them to the `selected` array. Additionally, an `<sp-table-checkbox-cell>` will be made available in the `<sp-table-head>` in order to select/deselect all items in the `<sp-table>`.

```html
<sp-table
size="m"
style="height: 200px"
selects="multiple"
selected='["row1", "row2"]'
onchange="spAlert(this, `Selected: ${JSON.stringify(this.selected)}`)"
Expand Down Expand Up @@ -182,13 +176,273 @@ When `selects="multiple"`, the `<sp-table>` will manage a selection in the array
</sp-table>
```

## Emphasized

Use the `emphasized` attribute to add priority to the information that is delivered within your `<table>` element. In particular, this affects the appearance of selected rows, and will set the emphasized style for the checkboxes within `sp-table-checkbox-cell`.
Leaving off the `emphasized` attribute will display the non-emphasized colors.

```html
<sp-table emphasized selects="multiple" selected='["row1"]'>
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

## Density

The optional `density` property changes the spacing around table cell content from the "regular" default. It accepts the values of `compact` or `spacious`.

<sp-tabs selected="compact" auto label="Density Attribute Options">
<sp-tab value="compact">Compact</sp-tab>
<sp-tab-panel value="compact">

```html
<sp-table density="compact">
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

</sp-tab-panel>
<sp-tab value="spacious">Spacious</sp-tab>
<sp-tab-panel value="spacious">

```html
<sp-table density="spacious">
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

</sp-tab-panel>
</sp-tabs>

## Sizes

<sp-tabs selected="s" auto label="Size Attribute Options">
<sp-tab value="s">Small</sp-tab>
<sp-tab-panel value="s">

```html
<sp-table size="s">
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

</sp-tab-panel>
<sp-tab value="m">Medium (Default)</sp-tab>
<sp-tab-panel value="m">

```html
<sp-table>
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

</sp-tab-panel>
<sp-tab value="l">Large</sp-tab>
<sp-tab-panel value="l">

```html
<sp-table size="l">
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

</sp-tab-panel>
<sp-tab value="xl">Extra Large</sp-tab>
<sp-tab-panel value="xl">

```html
<sp-table size="xl">
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

</sp-tab-panel>
</sp-tabs>

## Quiet

When using the `quiet` property, the overall look of the table will change. The quiet variant of Table has a transparent background and no borders on the left and right.

```html
<sp-table quiet>
<sp-table-head>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
<sp-table-head-cell>Column Title</sp-table-head-cell>
</sp-table-head>
<sp-table-body>
<sp-table-row value="row1">
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
<sp-table-cell>Row Item Alpha</sp-table-cell>
</sp-table-row>
<sp-table-row value="row2">
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
<sp-table-cell>Row Item Bravo</sp-table-cell>
</sp-table-row>
<sp-table-row value="row3">
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
<sp-table-cell>Row Item Charlie</sp-table-cell>
</sp-table-row>
</sp-table-body>
</sp-table>
```

## Virtualized Table

For large amounts of data, the `<sp-table>` can be virtualised to easily add table rows by using properties.

```html-live
<sp-table
size="m"
id="table-virtualized-demo"
style="height: 200px"
scroller="true"
Expand Down Expand Up @@ -311,7 +565,6 @@ By default the `selected` property will surface an array of item indexes that ar

```html-live
<sp-table
size="m"
id="table-item-value-demo"
style="height: 200px"
scroller="true"
Expand Down Expand Up @@ -414,7 +667,6 @@ All values in the item array are assumed to be homogenous by default. This means

```html-live
<sp-table
size="m"
id="table-row-type-demo"
style="height: 200px"
scroller="true"
Expand Down Expand Up @@ -528,7 +780,6 @@ For each table column you want to sort, use the `sortable` attribute in its resp

```html-live
<sp-table
size="m"
id="sorted-virtualized-table"
style="height: 200px"
scroller="true"
Expand Down
2 changes: 1 addition & 1 deletion packages/table/package.json
Expand Up @@ -123,7 +123,7 @@
"@spectrum-web-components/icons-ui": "^0.38.0"
},
"devDependencies": {
"@spectrum-css/table": "^4.0.66"
"@spectrum-css/table": "^5.0.0"
},
"types": "./src/index.d.ts",
"customElements": "custom-elements.json",
Expand Down

0 comments on commit b866bab

Please sign in to comment.