Skip to content

Commit

Permalink
feat: experimental table web components
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed May 21, 2022
1 parent 67abd41 commit d1cb0cc
Show file tree
Hide file tree
Showing 20 changed files with 300 additions and 0 deletions.
8 changes: 8 additions & 0 deletions components/table/css/_mixin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
vertical-align: baseline;
}

/* stylelint-disable-next-line block-no-empty */
@mixin utrecht-table__footer {
}

@mixin utrecht-table__header-cell {
color: var(--utrecht-table-header-cell-color);
font-size: var(--utrecht-table-header-cell-font-size);
Expand Down Expand Up @@ -86,6 +90,10 @@
font-variant-numeric: lining-nums tabular-nums;
}

/* stylelint-disable-next-line block-no-empty */
@mixin utrecht-table__row {
}

@mixin utrecht-table__row--alternate-odd {
background-color: var(--utrecht-table-row-alternate-odd-background-color);
color: var(--utrecht-table-row-alternate-odd-color);
Expand Down
31 changes: 31 additions & 0 deletions components/table/web-component/stories/01-default.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!-- @license CC0-1.0 -->

import { Canvas, Meta, Story } from "@storybook/addon-docs";
import { TableExample } from "../template";

<Meta
id="web-component-table"
title="Web Component/Table"
argTypes={{}}
parameters={{
status: {
type: "WORK IN PROGRESS",
},
}}
/>

# Table

This Table web component is experimental, please share your experiences with our team.

The web component version of the Table component has not yet been tested for accessibility with various assistive tools. Using the CSS component of Table is recommended for now.

Accessibility has been tested in the following manner:

- Accessibility panel in Chrome Developer tools shows the same role structure as the native HTML table equivalent.

For accessibility of `<table-header-cell>` you MUST set the `scope="col"` or `scope="row"` attribute.

<Canvas>
<Story name="Default">{TableExample.bind({})}</Story>
</Canvas>
12 changes: 12 additions & 0 deletions components/table/web-component/table-body.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table__body;

display: table-row-group;
}
16 changes: 16 additions & 0 deletions components/table/web-component/table-body.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, h, Host } from '@stencil/core';

@Component({
tag: 'utrecht-table-body',
styleUrl: 'table-body.scss',
shadow: true,
})
export class TableBody {
render() {
return (
<Host role="rowgroup">
<slot></slot>
</Host>
);
}
}
12 changes: 12 additions & 0 deletions components/table/web-component/table-caption.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table__caption;

display: table-caption;
}
13 changes: 13 additions & 0 deletions components/table/web-component/table-caption.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component, h } from '@stencil/core';

@Component({
tag: 'utrecht-table-caption',
styleUrl: 'table-caption.scss',
shadow: true,
})
export class TableCaption {
render() {
// TODO: Associate with parent <utrecht-table> aria-labelledby attribute
return <slot></slot>;
}
}
12 changes: 12 additions & 0 deletions components/table/web-component/table-cell.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table__cell;

display: table-cell;
}
16 changes: 16 additions & 0 deletions components/table/web-component/table-cell.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, h, Host } from '@stencil/core';

@Component({
tag: 'utrecht-table-cell',
styleUrl: 'table-cell.scss',
shadow: true,
})
export class TableCell {
render() {
return (
<Host role="cell">
<slot></slot>
</Host>
);
}
}
12 changes: 12 additions & 0 deletions components/table/web-component/table-footer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table__footer;

display: table-footer-group;
}
16 changes: 16 additions & 0 deletions components/table/web-component/table-footer.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, h, Host } from '@stencil/core';

@Component({
tag: 'utrecht-table-footer',
styleUrl: 'table-footer.scss',
shadow: true,
})
export class TableFooter {
render() {
return (
<Host role="rowgroup">
<slot></slot>
</Host>
);
}
}
12 changes: 12 additions & 0 deletions components/table/web-component/table-header-cell.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table__header-cell;

display: table-cell;
}
17 changes: 17 additions & 0 deletions components/table/web-component/table-header-cell.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, h, Host, Prop } from '@stencil/core';

@Component({
tag: 'utrecht-table-header-cell',
styleUrl: 'table-header-cell.scss',
shadow: true,
})
export class TableHeaderCell {
@Prop() scope: 'col' | 'row';
render() {
return (
<Host role={this.scope === 'col' ? 'columnheader' : this.scope === 'row' ? 'rowheader' : 'cell'}>
<slot></slot>
</Host>
);
}
}
12 changes: 12 additions & 0 deletions components/table/web-component/table-header.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table__header;

display: table-header-group;
}
16 changes: 16 additions & 0 deletions components/table/web-component/table-header.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, h, Host } from '@stencil/core';

@Component({
tag: 'utrecht-table-header',
styleUrl: 'table-header.scss',
shadow: true,
})
export class TableHeader {
render() {
return (
<Host role="rowgroup">
<slot></slot>
</Host>
);
}
}
12 changes: 12 additions & 0 deletions components/table/web-component/table-row.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table__row;

display: table-row;
}
16 changes: 16 additions & 0 deletions components/table/web-component/table-row.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, h, Host } from '@stencil/core';

@Component({
tag: 'utrecht-table-row',
styleUrl: 'table-row.scss',
shadow: true,
})
export class TableRow {
render() {
return (
<Host role="row">
<slot></slot>
</Host>
);
}
}
12 changes: 12 additions & 0 deletions components/table/web-component/table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Robbert Broersma
*/

@import "../css/mixin";

:host {
@include utrecht-table;

display: table;
}
16 changes: 16 additions & 0 deletions components/table/web-component/table.stencil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, h, Host } from '@stencil/core';

@Component({
tag: 'utrecht-table',
styleUrl: 'table.scss',
shadow: true,
})
export class Table {
render() {
return (
<Host role="table">
<slot></slot>
</Host>
);
}
}
23 changes: 23 additions & 0 deletions components/table/web-component/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const TableExample = () => `
<utrecht-table aria-labelledby="53818ecc-f9a6-4a9d-9e63-12a5ebb89e31">
<utrecht-table-caption id="53818ecc-f9a6-4a9d-9e63-12a5ebb89e31">Table</utrecht-table-caption>
<utrecht-table-header>
<utrecht-table-row>
<utrecht-table-header-cell scope="col">Column header cell 1</utrecht-table-header-cell>
<utrecht-table-header-cell scope="col">Column header cell 2</utrecht-table-header-cell>
</utrecht-table-row>
</utrecht-table-header>
<utrecht-table-footer>
<utrecht-table-row>
<utrecht-table-cell>Footer cell 1</utrecht-table-cell>
<utrecht-table-cell>Footer cell 2</utrecht-table-cell>
</utrecht-table-row>
</utrecht-table-footer>
<utrecht-table-body>
<utrecht-table-row>
<utrecht-table-header-cell scope="row">Row header cell</utrecht-table-header-cell>
<utrecht-table-cell>Cell</utrecht-table-cell>
</utrecht-table-row>
</utrecht-table-body>
</utrecht-table>
`;
16 changes: 16 additions & 0 deletions packages/web-component-library-angular/src/index.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ import {
UtrechtParagraph,
UtrechtSeparator,
UtrechtSidenav,
UtrechtTable,
UtrechtTableBody,
UtrechtTableCaption,
UtrechtTableCell,
UtrechtTableFooter,
UtrechtTableHeader,
UtrechtTableHeaderCell,
UtrechtTableRow,
UtrechtTextbox,
} from './directives/proxies';
import { SelectValueAccessor } from './directives/select-value-accessor';
Expand Down Expand Up @@ -132,6 +140,14 @@ const components = [
UtrechtParagraph,
UtrechtSeparator,
UtrechtSidenav,
UtrechtTable,
UtrechtTableBody,
UtrechtTableCaption,
UtrechtTableCell,
UtrechtTableFooter,
UtrechtTableHeader,
UtrechtTableHeaderCell,
UtrechtTableRow,
UtrechtTextbox,
];

Expand Down

0 comments on commit d1cb0cc

Please sign in to comment.