feat(recursive-list): add RecursiveList

This commit is contained in:
Eric Y Liu 2021-06-30 05:41:37 -07:00
commit 92301b1d46
10 changed files with 254 additions and 3 deletions

View 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>

View 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>

View file

@ -0,0 +1 @@
export { default as RecursiveList } from "./RecursiveList.svelte";

View file

@ -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";