feat(data-table): allow custom column widths (#1265)

* feat(data-table): allow header column `width`, `minWidth` values

* Run "yarn build:docs"

* test(data-table): assert width, minWidth properties

* docs(data-table): add "Custom column widths" example
This commit is contained in:
metonym 2022-05-14 09:24:24 -07:00 committed by GitHub
commit c6f210899b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 14 deletions

View file

@ -328,6 +328,14 @@ title="Load balancers" description="Your organization's active load balancers."
]}"
/>
### Custom column widths
Specify a `width` or `minWidth` property in the `headers` object to customize the width of each column.
A [table-layout: fixed](https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout#values) rule will be applied to the `table` element when using custom widths.
<FileSource src="/framed/DataTable/DataTableHeaderWidth" />
### Sticky header
Set `stickyHeader` to `true` for the header to be fixed in place.

View file

@ -0,0 +1,19 @@
<script>
import { DataTable } from "carbon-components-svelte";
</script>
<DataTable
headers="{[
{ key: 'name', value: 'Name', width: '50%', minWidth: '200px' },
{ key: 'protocol', value: 'Protocol', width: '60px' },
{ key: 'port', value: 'Port', width: '60px' },
{ key: 'rule', value: 'Rule', width: '10rem' },
]}"
rows="{Array.from({ length: 6 }).map((_, i) => ({
id: i,
name: 'Load Balancer ' + (i + 1),
protocol: 'HTTP',
port: i % 3 ? (i % 2 ? 3000 : 80) : 443,
rule: i % 3 ? 'Round robin' : 'DNS delegation',
}))}"
/>