mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
Various features/fixes (#727)
* fix(data-table): export useStaticWidth prop * docs(data-table): add static width example * fix(data-table): do not render table header if title/description not provided * feat(modal): dispatch "click:button--primary" as an alias to "submit" * test: update DataTable types test * test(modal): update modal type tests * docs(data-table): add clear reminder to key headers/rows
This commit is contained in:
parent
921c3e121a
commit
0a69f8ec74
12 changed files with 128 additions and 28 deletions
|
@ -685,17 +685,18 @@ None.
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
| Event name | Type | Detail |
|
| Event name | Type | Detail |
|
||||||
| :------------ | :--------- | :------------------------------ |
|
| :-------------------- | :--------- | :------------------------------ |
|
||||||
| transitionend | dispatched | <code>{ open: boolean; }</code> |
|
| transitionend | dispatched | <code>{ open: boolean; }</code> |
|
||||||
| keydown | forwarded | -- |
|
| keydown | forwarded | -- |
|
||||||
| click | forwarded | -- |
|
| click | forwarded | -- |
|
||||||
| mouseover | forwarded | -- |
|
| mouseover | forwarded | -- |
|
||||||
| mouseenter | forwarded | -- |
|
| mouseenter | forwarded | -- |
|
||||||
| mouseleave | forwarded | -- |
|
| mouseleave | forwarded | -- |
|
||||||
| submit | dispatched | -- |
|
| submit | dispatched | -- |
|
||||||
| close | dispatched | -- |
|
| click:button--primary | dispatched | -- |
|
||||||
| open | dispatched | -- |
|
| close | dispatched | -- |
|
||||||
|
| open | dispatched | -- |
|
||||||
|
|
||||||
## `Content`
|
## `Content`
|
||||||
|
|
||||||
|
@ -958,6 +959,7 @@ export interface DataTableCell {
|
||||||
| radio | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` for the radio selection variant |
|
| radio | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` for the radio selection variant |
|
||||||
| batchSelection | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable batch selection |
|
| batchSelection | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable batch selection |
|
||||||
| stickyHeader | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable a sticky header |
|
| stickyHeader | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable a sticky header |
|
||||||
|
| useStaticWidth | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to use static width |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
@ -2269,6 +2271,7 @@ None.
|
||||||
| mouseenter | forwarded | -- |
|
| mouseenter | forwarded | -- |
|
||||||
| mouseleave | forwarded | -- |
|
| mouseleave | forwarded | -- |
|
||||||
| submit | dispatched | -- |
|
| submit | dispatched | -- |
|
||||||
|
| click:button--primary | dispatched | -- |
|
||||||
| close | dispatched | -- |
|
| close | dispatched | -- |
|
||||||
| open | dispatched | -- |
|
| open | dispatched | -- |
|
||||||
|
|
||||||
|
|
|
@ -1530,6 +1530,7 @@
|
||||||
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
|
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
|
||||||
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
|
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
|
||||||
{ "type": "dispatched", "name": "submit" },
|
{ "type": "dispatched", "name": "submit" },
|
||||||
|
{ "type": "dispatched", "name": "click:button--primary" },
|
||||||
{ "type": "dispatched", "name": "close" },
|
{ "type": "dispatched", "name": "close" },
|
||||||
{ "type": "dispatched", "name": "open" }
|
{ "type": "dispatched", "name": "open" }
|
||||||
],
|
],
|
||||||
|
@ -2095,6 +2096,16 @@
|
||||||
"isFunction": false,
|
"isFunction": false,
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "useStaticWidth",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Set to `true` to use static width",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": "false",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"slots": [
|
"slots": [
|
||||||
|
@ -5500,6 +5511,7 @@
|
||||||
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
|
{ "type": "forwarded", "name": "mouseenter", "element": "div" },
|
||||||
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
|
{ "type": "forwarded", "name": "mouseleave", "element": "div" },
|
||||||
{ "type": "dispatched", "name": "submit" },
|
{ "type": "dispatched", "name": "submit" },
|
||||||
|
{ "type": "dispatched", "name": "click:button--primary" },
|
||||||
{ "type": "dispatched", "name": "close" },
|
{ "type": "dispatched", "name": "close" },
|
||||||
{ "type": "dispatched", "name": "open" }
|
{ "type": "dispatched", "name": "open" }
|
||||||
],
|
],
|
||||||
|
|
|
@ -3,15 +3,23 @@ components: ["DataTable", "Toolbar", "ToolbarContent", "ToolbarSearch", "Toolbar
|
||||||
---
|
---
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { DataTable, DataTableSkeleton, Toolbar, ToolbarContent, ToolbarSearch, ToolbarMenu, ToolbarMenuItem, Button, Link } from "carbon-components-svelte";
|
import { InlineNotification, DataTable, DataTableSkeleton, Toolbar, ToolbarContent, ToolbarSearch, ToolbarMenu, ToolbarMenuItem, Button, Link } from "carbon-components-svelte";
|
||||||
import Launch16 from "carbon-icons-svelte/lib/Launch16";
|
import Launch16 from "carbon-icons-svelte/lib/Launch16";
|
||||||
import Preview from "../../components/Preview.svelte";
|
import Preview from "../../components/Preview.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
`DataTable` is keyed for both rendering and sorting purposes.
|
||||||
|
|
||||||
|
<InlineNotification svx-ignore title="Note:" kind="info" hideCloseButton>
|
||||||
|
<div class="body-short-01">Every <code>headers</code> object must have a unique "key" property.</div>
|
||||||
|
</InlineNotification>
|
||||||
|
|
||||||
|
<InlineNotification svx-ignore title="Note:" kind="info" hideCloseButton>
|
||||||
|
<div class="body-short-01">Every <code>rows</code> object must have a unique "id" property.</div>
|
||||||
|
</InlineNotification>
|
||||||
|
|
||||||
### Default
|
### Default
|
||||||
|
|
||||||
The `DataTable` is keyed for both rendering and sorting. You must define a "key" value per object in the `headers` property and an "id" value in `rows`.
|
|
||||||
|
|
||||||
<DataTable
|
<DataTable
|
||||||
headers="{[
|
headers="{[
|
||||||
{ key: "name", value: "Name" },
|
{ key: "name", value: "Name" },
|
||||||
|
@ -65,6 +73,63 @@ The `DataTable` is keyed for both rendering and sorting. You must define a "key"
|
||||||
]}"
|
]}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
### Static width
|
||||||
|
|
||||||
|
Set `useStaticWidth` to `true` to render the table with a width of "auto" instead of "100%".
|
||||||
|
|
||||||
|
<DataTable useStaticWidth
|
||||||
|
headers="{[
|
||||||
|
{ key: "name", value: "Name" },
|
||||||
|
{ key: "protocol", value: "Protocol" },
|
||||||
|
{ key: "port", value: "Port" },
|
||||||
|
{ key: "rule", value: "Rule" }
|
||||||
|
]}"
|
||||||
|
rows="{[
|
||||||
|
{
|
||||||
|
id: "a",
|
||||||
|
name: "Load Balancer 3",
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 3000,
|
||||||
|
rule: "Round robin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "b",
|
||||||
|
name: "Load Balancer 1",
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 443,
|
||||||
|
rule: "Round robin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "c",
|
||||||
|
name: "Load Balancer 2",
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 80,
|
||||||
|
rule: "DNS delegation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "d",
|
||||||
|
name: "Load Balancer 6",
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 3000,
|
||||||
|
rule: "Round robin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "e",
|
||||||
|
name: "Load Balancer 4",
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 443,
|
||||||
|
rule: "Round robin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "f",
|
||||||
|
name: "Load Balancer 5",
|
||||||
|
protocol: "HTTP",
|
||||||
|
port: 80,
|
||||||
|
rule: "DNS delegation"
|
||||||
|
},
|
||||||
|
]}"
|
||||||
|
/>
|
||||||
|
|
||||||
### Slotted cells
|
### Slotted cells
|
||||||
|
|
||||||
Use the `"cell"` slot to control the display value per table cell. Individual row and cell data are provided through the `let:row` and `let:cell` directives.
|
Use the `"cell"` slot to control the display value per table cell. Individual row and cell data are provided through the `let:row` and `let:cell` directives.
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
},
|
},
|
||||||
submit: () => {
|
submit: () => {
|
||||||
dispatch("submit");
|
dispatch("submit");
|
||||||
|
dispatch("click:button--primary");
|
||||||
},
|
},
|
||||||
declareRef: (ref) => {
|
declareRef: (ref) => {
|
||||||
buttonRef = ref;
|
buttonRef = ref;
|
||||||
|
|
|
@ -91,6 +91,9 @@
|
||||||
/** Set to `true` to enable a sticky header */
|
/** Set to `true` to enable a sticky header */
|
||||||
export let stickyHeader = false;
|
export let stickyHeader = false;
|
||||||
|
|
||||||
|
/** Set to `true` to use static width */
|
||||||
|
export let useStaticWidth = false;
|
||||||
|
|
||||||
import { createEventDispatcher, setContext } from "svelte";
|
import { createEventDispatcher, setContext } from "svelte";
|
||||||
import { writable, derived } from "svelte/store";
|
import { writable, derived } from "svelte/store";
|
||||||
import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16/ChevronRight16.svelte";
|
import ChevronRight16 from "carbon-icons-svelte/lib/ChevronRight16/ChevronRight16.svelte";
|
||||||
|
@ -203,24 +206,27 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<TableContainer {...$$restProps}>
|
<TableContainer {...$$restProps}>
|
||||||
<div class:bx--data-table-header="{true}">
|
{#if title || $$slots.title || description || $$slots.description}
|
||||||
{#if title || $$slots.title}
|
<div class:bx--data-table-header="{true}">
|
||||||
<h4 class:bx--data-table-header__title="{true}">
|
{#if title || $$slots.title}
|
||||||
<slot name="title">{title}</slot>
|
<h4 class:bx--data-table-header__title="{true}">
|
||||||
</h4>
|
<slot name="title">{title}</slot>
|
||||||
{/if}
|
</h4>
|
||||||
{#if description || $$slots.description}
|
{/if}
|
||||||
<p class:bx--data-table-header__description="{true}">
|
{#if description || $$slots.description}
|
||||||
<slot name="description">{description}</slot>
|
<p class:bx--data-table-header__description="{true}">
|
||||||
</p>
|
<slot name="description">{description}</slot>
|
||||||
{/if}
|
</p>
|
||||||
</div>
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<slot />
|
<slot />
|
||||||
<Table
|
<Table
|
||||||
zebra="{zebra}"
|
zebra="{zebra}"
|
||||||
size="{size}"
|
size="{size}"
|
||||||
stickyHeader="{stickyHeader}"
|
stickyHeader="{stickyHeader}"
|
||||||
sortable="{sortable}"
|
sortable="{sortable}"
|
||||||
|
useStaticWidth="{useStaticWidth}"
|
||||||
>
|
>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
|
|
@ -297,6 +297,7 @@
|
||||||
disabled="{primaryButtonDisabled}"
|
disabled="{primaryButtonDisabled}"
|
||||||
on:click="{() => {
|
on:click="{() => {
|
||||||
dispatch('submit');
|
dispatch('submit');
|
||||||
|
dispatch('click:button--primary');
|
||||||
}}"
|
}}"
|
||||||
>
|
>
|
||||||
{primaryButtonText}
|
{primaryButtonText}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
let checked = false;
|
let checked = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ComposedModal open>
|
<ComposedModal open on:close on:click:button--primary>
|
||||||
<ModalHeader title="Confirm changes" />
|
<ModalHeader title="Confirm changes" />
|
||||||
<ModalBody hasForm>
|
<ModalBody hasForm>
|
||||||
<Checkbox labelText="I have reviewed the changes" bind:checked />
|
<Checkbox labelText="I have reviewed the changes" bind:checked />
|
||||||
|
@ -19,6 +19,8 @@
|
||||||
primaryButtonText="Proceed"
|
primaryButtonText="Proceed"
|
||||||
primaryButtonDisabled="{!checked}"
|
primaryButtonDisabled="{!checked}"
|
||||||
secondaryButtons="{[{ text: 'Cancel' }, { text: 'Duplicate' }]}"
|
secondaryButtons="{[{ text: 'Cancel' }, { text: 'Duplicate' }]}"
|
||||||
on:click:button--secondary="{({ detail }) => {}}"
|
on:click:button--secondary="{({ detail }) => {
|
||||||
|
console.log(detail);
|
||||||
|
}}"
|
||||||
/>
|
/>
|
||||||
</ComposedModal>
|
</ComposedModal>
|
||||||
|
|
|
@ -98,6 +98,7 @@
|
||||||
description="Your organization's active load balancers."
|
description="Your organization's active load balancers."
|
||||||
headers="{headers}"
|
headers="{headers}"
|
||||||
rows="{rows}"
|
rows="{rows}"
|
||||||
|
useStaticWidth
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DataTable
|
<DataTable
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
on:open
|
on:open
|
||||||
on:close
|
on:close
|
||||||
on:submit
|
on:submit
|
||||||
|
on:click:button--primary
|
||||||
>
|
>
|
||||||
<p>Create a new Cloudant database in the US South region.</p>
|
<p>Create a new Cloudant database in the US South region.</p>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
1
types/ComposedModal/ComposedModal.d.ts
vendored
1
types/ComposedModal/ComposedModal.d.ts
vendored
|
@ -55,6 +55,7 @@ export default class ComposedModal extends SvelteComponentTyped<
|
||||||
mouseenter: WindowEventMap["mouseenter"];
|
mouseenter: WindowEventMap["mouseenter"];
|
||||||
mouseleave: WindowEventMap["mouseleave"];
|
mouseleave: WindowEventMap["mouseleave"];
|
||||||
submit: CustomEvent<any>;
|
submit: CustomEvent<any>;
|
||||||
|
["click:button--primary"]: CustomEvent<any>;
|
||||||
close: CustomEvent<any>;
|
close: CustomEvent<any>;
|
||||||
open: CustomEvent<any>;
|
open: CustomEvent<any>;
|
||||||
},
|
},
|
||||||
|
|
6
types/DataTable/DataTable.d.ts
vendored
6
types/DataTable/DataTable.d.ts
vendored
|
@ -129,6 +129,12 @@ export interface DataTableProps
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
stickyHeader?: boolean;
|
stickyHeader?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to use static width
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
useStaticWidth?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class DataTable extends SvelteComponentTyped<
|
export default class DataTable extends SvelteComponentTyped<
|
||||||
|
|
1
types/Modal/Modal.d.ts
vendored
1
types/Modal/Modal.d.ts
vendored
|
@ -132,6 +132,7 @@ export default class Modal extends SvelteComponentTyped<
|
||||||
mouseenter: WindowEventMap["mouseenter"];
|
mouseenter: WindowEventMap["mouseenter"];
|
||||||
mouseleave: WindowEventMap["mouseleave"];
|
mouseleave: WindowEventMap["mouseleave"];
|
||||||
submit: CustomEvent<any>;
|
submit: CustomEvent<any>;
|
||||||
|
["click:button--primary"]: CustomEvent<any>;
|
||||||
close: CustomEvent<any>;
|
close: CustomEvent<any>;
|
||||||
open: CustomEvent<any>;
|
open: CustomEvent<any>;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue