mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
breaking(types): type arrays as read-only (#1335)
Closes #1259 * breaking(types): type arrays as read-only * Run "yarn build:docs" * test: assert read-only arrays
This commit is contained in:
parent
1a904dda36
commit
260bf4e040
34 changed files with 257 additions and 192 deletions
|
@ -1,16 +1,41 @@
|
|||
<script lang="ts">
|
||||
import { Dropdown, DropdownSkeleton } from "../types";
|
||||
import type { DropdownProps } from "../types/Dropdown/Dropdown.svelte";
|
||||
|
||||
let items: DropdownProps["items"] = [
|
||||
{ id: 0, text: "Slack" },
|
||||
{ id: "1", text: "Email" },
|
||||
{ id: "2", text: "Fax" },
|
||||
] as const;
|
||||
|
||||
let itemsWithoutConst = [...items];
|
||||
|
||||
type FieldId = typeof items[number]["id"]; // 'foo' | 'bar' | 'baz'
|
||||
|
||||
export const fieldId: FieldId = "bar";
|
||||
|
||||
// @ts-expect-error
|
||||
$: items[0] = { id: "0", text: "Slack" };
|
||||
$: {
|
||||
// @ts-expect-error
|
||||
items[0] = { id: "0", text: "Slack" };
|
||||
}
|
||||
$: {
|
||||
items = [...items, { id: "3", text: "Email" }];
|
||||
items = items.map((item, index) => {
|
||||
if (index === 0) {
|
||||
return { id: "0", text: "Slack" };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dropdown
|
||||
direction="top"
|
||||
titleText="Contact"
|
||||
selectedId="0"
|
||||
items="{[
|
||||
{ id: 0, text: 'Slack' },
|
||||
{ id: '1', text: 'Email' },
|
||||
{ id: '2', text: 'Fax', disabled: true },
|
||||
]}"
|
||||
items="{items}"
|
||||
on:select="{(e) => {
|
||||
console.log(e.detail.selectedId);
|
||||
}}"
|
||||
|
@ -31,11 +56,7 @@
|
|||
}}"
|
||||
titleText="Contact"
|
||||
selectedId="0"
|
||||
items="{[
|
||||
{ id: '0', text: 'Slack' },
|
||||
{ id: '1', text: 'Email' },
|
||||
{ id: '2', text: 'Fax' },
|
||||
]}"
|
||||
items="{itemsWithoutConst}"
|
||||
/>
|
||||
|
||||
<Dropdown
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue