diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 718e4cae..6c64109a 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -1,6 +1,6 @@ # Component Index -> 168 components exported from carbon-components-svelte@0.38.2. +> 169 components exported from carbon-components-svelte@0.38.2. ## Components @@ -107,6 +107,7 @@ - [`RadioButtonGroup`](#radiobuttongroup) - [`RadioButtonSkeleton`](#radiobuttonskeleton) - [`RadioTile`](#radiotile) +- [`RecursiveList`](#recursivelist) - [`Row`](#row) - [`Search`](#search) - [`SearchSkeleton`](#searchskeleton) @@ -3031,6 +3032,33 @@ None. | mouseenter | forwarded | -- | | mouseleave | forwarded | -- | +## `RecursiveList` + +### Types + +```ts +export interface RecursiveListNode { + text?: string; + href?: string; + html?: string; +} +``` + +### Props + +| Prop name | Kind | Reactive | Type | Default value | Description | +| :-------- | :--------------- | :------- | :-------------------------------------------------------------------------- | ------------------------ | ---------------------------------- | +| children | let | No | Array | [] | Specify the children to render | +| type | let | No | "unordered" | "ordered" | "ordered-native" | "unordered" | Specify the type of list to render | + +### Slots + +None. + +### Events + +None. + ## `Row` ### Props diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index 02b86d11..925b35c2 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -1,5 +1,5 @@ { - "total": 168, + "total": 169, "components": [ { "moduleName": "Accordion", @@ -7865,6 +7865,42 @@ "typedefs": [], "rest_props": { "type": "Element", "name": "label" } }, + { + "moduleName": "RecursiveList", + "filePath": "src/RecursiveList/RecursiveList.svelte", + "props": [ + { + "name": "children", + "kind": "let", + "description": "Specify the children to render", + "type": "Array", + "value": "[]", + "isFunction": false, + "constant": false, + "reactive": false + }, + { + "name": "type", + "kind": "let", + "description": "Specify the type of list to render", + "type": "\"unordered\" | \"ordered\" | \"ordered-native\"", + "value": "\"unordered\"", + "isFunction": false, + "constant": false, + "reactive": false + } + ], + "slots": [], + "events": [], + "typedefs": [ + { + "type": "{ text?: string; href?: string; html?: string; }", + "name": "RecursiveListNode", + "ts": "interface RecursiveListNode { text?: string; href?: string; html?: string; }" + } + ], + "rest_props": { "type": "Element", "name": "ul | ol" } + }, { "moduleName": "Row", "filePath": "src/Grid/Row.svelte", diff --git a/docs/src/pages/_layout.svelte b/docs/src/pages/_layout.svelte index ddc4aca6..1fa85bb0 100644 --- a/docs/src/pages/_layout.svelte +++ b/docs/src/pages/_layout.svelte @@ -20,7 +20,7 @@ import Footer from "../components/Footer.svelte"; const deprecated = ["ToggleSmall", "Icon"]; - const new_components = ["ProgressBar"]; + const new_components = ["ProgressBar", "RecursiveList"]; let isOpen = false; let isSideNavOpen = true; diff --git a/docs/src/pages/components/OrderedList.svx b/docs/src/pages/components/OrderedList.svx index 7f53fbce..ef659907 100644 --- a/docs/src/pages/components/OrderedList.svx +++ b/docs/src/pages/components/OrderedList.svx @@ -3,10 +3,16 @@ components: ["OrderedList", "ListItem"] --- + +
+ To render data formatted as a tree structure, use the RecursiveList component. +
+
+ ### Default diff --git a/docs/src/pages/components/RecursiveList.svx b/docs/src/pages/components/RecursiveList.svx new file mode 100644 index 00000000..6212fbe1 --- /dev/null +++ b/docs/src/pages/components/RecursiveList.svx @@ -0,0 +1,34 @@ + + +This component uses the [svelte:self API](https://svelte.dev/docs#svelte_self) to render the [UnorderedList](/components/UnorderedList) and [OrderedList](/components/OrderedList) components with data formatted as a tree structure. This is especially useful when the depth of the tree is unknown. + +A child node can render text (`text`), a link (`href`), HTML content (`html`), and other `children`. + + +
+ HTML content provided via the html prop is not sanitized. +
+
+ +### Unordered + +The `children` prop accepts an array of child nodes. + +By default, the list type is unordered. + + + +### Ordered + +Set `type` to `"ordered"` to use the ordered list variant. + + + +### Ordered (native styles) + +Set `type` to `"ordered-native"` to use the native styles for an ordered list. + + \ No newline at end of file diff --git a/docs/src/pages/components/UnorderedList.svx b/docs/src/pages/components/UnorderedList.svx index 2d8e6f9e..118f37da 100644 --- a/docs/src/pages/components/UnorderedList.svx +++ b/docs/src/pages/components/UnorderedList.svx @@ -3,10 +3,16 @@ components: ["UnorderedList", "ListItem"] --- + +
+ To render data formatted as a tree structure, use the RecursiveList component. +
+
+ ### Default diff --git a/docs/src/pages/framed/RecursiveList/RecursiveList.svelte b/docs/src/pages/framed/RecursiveList/RecursiveList.svelte new file mode 100644 index 00000000..00e8f7b7 --- /dev/null +++ b/docs/src/pages/framed/RecursiveList/RecursiveList.svelte @@ -0,0 +1,32 @@ + + + diff --git a/docs/src/pages/framed/RecursiveList/RecursiveListOrdered.svelte b/docs/src/pages/framed/RecursiveList/RecursiveListOrdered.svelte new file mode 100644 index 00000000..2a20c053 --- /dev/null +++ b/docs/src/pages/framed/RecursiveList/RecursiveListOrdered.svelte @@ -0,0 +1,32 @@ + + + diff --git a/docs/src/pages/framed/RecursiveList/RecursiveListOrderedNative.svelte b/docs/src/pages/framed/RecursiveList/RecursiveListOrderedNative.svelte new file mode 100644 index 00000000..0af16bab --- /dev/null +++ b/docs/src/pages/framed/RecursiveList/RecursiveListOrderedNative.svelte @@ -0,0 +1,32 @@ + + + diff --git a/src/RecursiveList/RecursiveList.svelte b/src/RecursiveList/RecursiveList.svelte new file mode 100644 index 00000000..cd876b72 --- /dev/null +++ b/src/RecursiveList/RecursiveList.svelte @@ -0,0 +1,38 @@ + + + + {#each children as child} + {#if Array.isArray(child.children)} + + + + {:else} + + {/if} + {/each} + diff --git a/src/RecursiveList/RecursiveListItem.svelte b/src/RecursiveList/RecursiveListItem.svelte new file mode 100644 index 00000000..96e92562 --- /dev/null +++ b/src/RecursiveList/RecursiveListItem.svelte @@ -0,0 +1,19 @@ + + + + {#if text && !href}{text}{/if} + {#if href}{text || href}{/if} + {#if !text && html}{@html html}{/if} + + diff --git a/src/RecursiveList/index.js b/src/RecursiveList/index.js new file mode 100644 index 00000000..384129e6 --- /dev/null +++ b/src/RecursiveList/index.js @@ -0,0 +1 @@ +export { default as RecursiveList } from "./RecursiveList.svelte"; diff --git a/src/index.js b/src/index.js index ac9be908..14924283 100644 --- a/src/index.js +++ b/src/index.js @@ -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"; diff --git a/tests/ProgressBar.test.svelte b/tests/ProgressBar.test.svelte index 7c2244a7..c3e0c309 100644 --- a/tests/ProgressBar.test.svelte +++ b/tests/ProgressBar.test.svelte @@ -1,4 +1,4 @@ - diff --git a/tests/RecursiveList.test.svelte b/tests/RecursiveList.test.svelte new file mode 100644 index 00000000..a0f42611 --- /dev/null +++ b/tests/RecursiveList.test.svelte @@ -0,0 +1,32 @@ + + + diff --git a/types/RecursiveList/RecursiveList.d.ts b/types/RecursiveList/RecursiveList.d.ts new file mode 100644 index 00000000..346e0e56 --- /dev/null +++ b/types/RecursiveList/RecursiveList.d.ts @@ -0,0 +1,30 @@ +/// +import { SvelteComponentTyped } from "svelte"; + +export interface RecursiveListNode { + text?: string; + href?: string; + html?: string; +} + +export interface RecursiveListProps + extends svelte.JSX.HTMLAttributes, + svelte.JSX.HTMLAttributes { + /** + * Specify the children to render + * @default [] + */ + children?: Array; + + /** + * Specify the type of list to render + * @default "unordered" + */ + type?: "unordered" | "ordered" | "ordered-native"; +} + +export default class RecursiveList extends SvelteComponentTyped< + RecursiveListProps, + {}, + {} +> {} diff --git a/types/index.d.ts b/types/index.d.ts index a3e3a805..9123950f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -99,6 +99,7 @@ export { default as ProgressStep } from "./ProgressIndicator/ProgressStep"; export { default as RadioButton } from "./RadioButton/RadioButton"; export { default as RadioButtonSkeleton } from "./RadioButton/RadioButtonSkeleton"; export { default as RadioButtonGroup } from "./RadioButtonGroup/RadioButtonGroup"; +export { default as RecursiveList } from "./RecursiveList/RecursiveList"; export { default as Search } from "./Search/Search"; export { default as SearchSkeleton } from "./Search/SearchSkeleton"; export { default as Select } from "./Select/Select";