mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 12:23:02 +00:00
feat(recursive-list): add RecursiveList
This commit is contained in:
parent
0d3090b123
commit
92301b1d46
10 changed files with 254 additions and 3 deletions
42
src/RecursiveList/RecursiveList.svelte
Normal file
42
src/RecursiveList/RecursiveList.svelte
Normal file
|
@ -0,0 +1,42 @@
|
|||
<script>
|
||||
/**
|
||||
* @typedef {{ text?: string; href?: string; html?: string; }} Item
|
||||
* @type {Array<Item & { items?: Item[]; }>}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specify the items to render
|
||||
* @type {Array<Item & { items?: Item[]; }>}
|
||||
*/
|
||||
export let items = [];
|
||||
|
||||
/**
|
||||
* Specify the type of list to render
|
||||
* @type {"unordered" | "ordered" | "ordered-native"}
|
||||
*/
|
||||
export let type = "unordered";
|
||||
|
||||
/** Set to `true` to use the nested variant */
|
||||
export let nested = false;
|
||||
|
||||
import UnorderedList from "../UnorderedList/UnorderedList.svelte";
|
||||
import OrderedList from "../OrderedList/OrderedList.svelte";
|
||||
import ListItem from "./RecursiveListItem.svelte";
|
||||
</script>
|
||||
|
||||
<svelte:component
|
||||
this="{type === 'unordered' ? UnorderedList : OrderedList}"
|
||||
native="{type === 'ordered-native'}"
|
||||
nested="{nested}"
|
||||
{...$$restProps}
|
||||
>
|
||||
{#each items as item}
|
||||
{#if Array.isArray(item.items)}
|
||||
<ListItem {...item}>
|
||||
<svelte:self {...item} type="{type}" nested />
|
||||
</ListItem>
|
||||
{:else}
|
||||
<ListItem {...item} />
|
||||
{/if}
|
||||
{/each}
|
||||
</svelte:component>
|
19
src/RecursiveList/RecursiveListItem.svelte
Normal file
19
src/RecursiveList/RecursiveListItem.svelte
Normal file
|
@ -0,0 +1,19 @@
|
|||
<script>
|
||||
/** Specify the text to render*/
|
||||
export let text = "";
|
||||
|
||||
/** Specify a link href */
|
||||
export let href = "";
|
||||
|
||||
/** Specify HTML to render using `@html` */
|
||||
export let html = "";
|
||||
|
||||
import ListItem from "../ListItem/ListItem.svelte";
|
||||
</script>
|
||||
|
||||
<ListItem>
|
||||
{#if text && !href}{text}{/if}
|
||||
{#if href}<a class:bx--link="{true}" href="{href}">{text || href}</a>{/if}
|
||||
{#if !text && html}{@html html}{/if}
|
||||
<slot />
|
||||
</ListItem>
|
1
src/RecursiveList/index.js
Normal file
1
src/RecursiveList/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default as RecursiveList } from "./RecursiveList.svelte";
|
|
@ -93,6 +93,7 @@ export {
|
|||
} from "./ProgressIndicator";
|
||||
export { RadioButton, RadioButtonSkeleton } from "./RadioButton";
|
||||
export { RadioButtonGroup } from "./RadioButtonGroup";
|
||||
export { RecursiveList } from "./RecursiveList";
|
||||
export { Search, SearchSkeleton } from "./Search";
|
||||
export { Select, SelectSkeleton, SelectItem, SelectItemGroup } from "./Select";
|
||||
export { SkeletonPlaceholder } from "./SkeletonPlaceholder";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue