mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
cancelable event
This commit is contained in:
parent
5e630d2873
commit
0e34a0631f
4 changed files with 21 additions and 19 deletions
|
@ -4435,7 +4435,9 @@ None.
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
None.
|
| Event name | Type | Detail |
|
||||||
|
| :--------- | :--------- | :---------------- |
|
||||||
|
| cancel | dispatched | <code>null</code> |
|
||||||
|
|
||||||
## `ToolbarContent`
|
## `ToolbarContent`
|
||||||
|
|
||||||
|
|
|
@ -13684,7 +13684,7 @@
|
||||||
"slot_props": "{}"
|
"slot_props": "{}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"events": [],
|
"events": [{ "type": "dispatched", "name": "cancel", "detail": "null" }],
|
||||||
"typedefs": [],
|
"typedefs": [],
|
||||||
"rest_props": { "type": "Element", "name": "div" }
|
"rest_props": { "type": "Element", "name": "div" }
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<script>
|
<script>
|
||||||
|
/**
|
||||||
|
* @event {null} cancel
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the total items selected text
|
* Override the total items selected text
|
||||||
* @type {(totalSelected: number) => string}
|
* @type {(totalSelected: number) => string}
|
||||||
|
@ -6,28 +10,24 @@
|
||||||
export let formatTotalSelected = (totalSelected) =>
|
export let formatTotalSelected = (totalSelected) =>
|
||||||
`${totalSelected} item${totalSelected === 1 ? "" : "s"} selected`;
|
`${totalSelected} item${totalSelected === 1 ? "" : "s"} selected`;
|
||||||
|
|
||||||
/**
|
import { onMount, getContext, createEventDispatcher } from "svelte";
|
||||||
* Override the default behavior of the cancel button
|
|
||||||
* @type {function}
|
|
||||||
*/
|
|
||||||
export let cancel ;
|
|
||||||
|
|
||||||
import { onMount, getContext } from "svelte";
|
|
||||||
import Button from "../Button/Button.svelte";
|
import Button from "../Button/Button.svelte";
|
||||||
|
|
||||||
let batchSelectedIds = [];
|
let batchSelectedIds = [];
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
$: showActions = batchSelectedIds.length > 0;
|
$: showActions = batchSelectedIds.length > 0;
|
||||||
|
|
||||||
const ctx = getContext("DataTable");
|
const ctx = getContext("DataTable");
|
||||||
|
|
||||||
$: cancelClick = () => {
|
function cancel() {
|
||||||
if (typeof cancel === "function") {
|
const shouldContinue = dispatch("cancel", null, { cancelable: true });
|
||||||
cancel();
|
|
||||||
} else {
|
if (shouldContinue) {
|
||||||
ctx.resetSelectedRowIds()
|
ctx.resetSelectedRowIds();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const unsubscribe = ctx.batchSelectedIds.subscribe((value) => {
|
const unsubscribe = ctx.batchSelectedIds.subscribe((value) => {
|
||||||
batchSelectedIds = value;
|
batchSelectedIds = value;
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
<Button
|
<Button
|
||||||
class="bx--batch-summary__cancel"
|
class="bx--batch-summary__cancel"
|
||||||
tabindex="{showActions ? '0' : '-1'}"
|
tabindex="{showActions ? '0' : '-1'}"
|
||||||
on:click="{cancelClick}"
|
on:click="{cancel}"
|
||||||
>
|
>
|
||||||
<slot name="cancel">Cancel</slot>
|
<slot name="cancel">Cancel</slot>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -12,6 +12,6 @@ export interface ToolbarBatchActionsProps
|
||||||
|
|
||||||
export default class ToolbarBatchActions extends SvelteComponentTyped<
|
export default class ToolbarBatchActions extends SvelteComponentTyped<
|
||||||
ToolbarBatchActionsProps,
|
ToolbarBatchActionsProps,
|
||||||
{},
|
{ cancel: CustomEvent<null> },
|
||||||
{ default: {}; cancel: {} }
|
{ default: {}; cancel: {} }
|
||||||
> {}
|
> {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue