mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-19 20:09:35 +00:00
Merge branch 'master' into patch-1
This commit is contained in:
commit
a2494ad128
20 changed files with 506 additions and 14 deletions
|
@ -3,6 +3,9 @@
|
|||
* @event {boolean} check
|
||||
*/
|
||||
|
||||
/** Specify the value of the checkbox */
|
||||
export let value = "";
|
||||
|
||||
/** Specify whether the checkbox is checked */
|
||||
export let checked = false;
|
||||
|
||||
|
@ -69,6 +72,7 @@
|
|||
<input
|
||||
bind:this="{ref}"
|
||||
type="checkbox"
|
||||
value="{value}"
|
||||
checked="{checked}"
|
||||
disabled="{disabled}"
|
||||
id="{id}"
|
||||
|
|
|
@ -194,6 +194,10 @@
|
|||
if (typeof itemA === "number" && typeof itemB === "number")
|
||||
return itemA - itemB;
|
||||
|
||||
if ([itemA, itemB].every((item) => !item && item !== 0)) return 0;
|
||||
if (!itemA && itemA !== 0) return ascending ? 1 : -1;
|
||||
if (!itemB && itemB !== 0) return ascending ? -1 : 1;
|
||||
|
||||
return itemA
|
||||
.toString()
|
||||
.localeCompare(itemB.toString(), "en", { numeric: true });
|
||||
|
|
|
@ -44,6 +44,44 @@
|
|||
/** Set to `true` to visually hide the label text */
|
||||
export let hideLabel = false;
|
||||
|
||||
/**
|
||||
* Programmatically expand all nodes
|
||||
* @type {() => void}
|
||||
*/
|
||||
export function expandAll() {
|
||||
expandedIds = [...nodeIds];
|
||||
}
|
||||
|
||||
/**
|
||||
* Programmatically collapse all nodes
|
||||
* @type {() => void}
|
||||
*/
|
||||
export function collapseAll() {
|
||||
expandedIds = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Programmatically expand a subset of nodes.
|
||||
* Expands all nodes if no argument is provided
|
||||
* @type {(filterId?: (node: TreeNode) => boolean) => void}
|
||||
*/
|
||||
export function expandNodes(filterNode = (node) => false) {
|
||||
expandedIds = nodes
|
||||
.filter((node) => !filterNode(node))
|
||||
.map((node) => node.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Programmatically collapse a subset of nodes.
|
||||
* Collapses all nodes if no argument is provided
|
||||
* @type {(filterId?: (node: TreeNode) => boolean) => void}
|
||||
*/
|
||||
export function collapseNodes(filterNode = (node) => true) {
|
||||
expandedIds = nodes
|
||||
.filter((node) => !filterNode(node))
|
||||
.map((node) => node.id);
|
||||
}
|
||||
|
||||
import { createEventDispatcher, setContext, onMount } from "svelte";
|
||||
import { writable } from "svelte/store";
|
||||
import TreeViewNodeList from "./TreeViewNodeList.svelte";
|
||||
|
@ -105,6 +143,25 @@
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Array<TreeNode & { children?: TreeNode[] }>} children
|
||||
*/
|
||||
function traverse(children) {
|
||||
let nodes = [];
|
||||
|
||||
children.forEach((node) => {
|
||||
nodes.push(node);
|
||||
|
||||
if (Array.isArray(node.children)) {
|
||||
nodes = [...nodes, ...traverse(node.children)];
|
||||
}
|
||||
});
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
$: nodes = traverse(children);
|
||||
$: nodeIds = nodes.map((node) => node.id);
|
||||
$: activeNodeId.set(activeId);
|
||||
$: selectedNodeIds.set(selectedIds);
|
||||
$: expandedNodeIds.set(expandedIds);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue