-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TreeList Example #107
TreeList Example #107
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,22 @@ | |
import { cls } from '$lib/utils/styles'; | ||
import { getComponentTheme } from './theme'; | ||
|
||
|
||
type Node = { id: number; name: string; level: number; children: Node[] }; | ||
|
||
/** | ||
* An array of nodes containing custom metadata and an array of child nodes | ||
* @param {Array} nodes - An array of Node Objects each containing a children: Node[] attribute. | ||
* Example: type Node = { name: string; children: Node[] } | ||
*/ | ||
export let nodes: Node[]; | ||
|
||
/** | ||
* Allows for conditional classes to be applied to each tag <ul> and <li> | ||
* @param {Object} classes - An object containing optional classes for <ul> and <li> tags. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarily, should this be... /**
* @type {{ul?: string|Function, li?: string|Function}}
**/ It's what I've used for Button, at least as a test to improve how Sveld parses them since it doesn't appear to read the typescript types in this case :(. See also this comment in LayerChart (which applies to Svelte UX) as well with improving how techniq/layerchart#39 (comment) Basically what you're doing here, we need to do everywhere (unless we can find a way to have Sveld handle this, or another "automated" way to parse the typescript defs. I also wrote up a little bit in the discord |
||
* @param {string|Function} classes.ul - A string or function that returns a string of classes to be applied to each <ul> tag. | ||
* @param {string|Function} classes.li - A string or function that returns a string of classes to be applied to each <li> tag. | ||
*/ | ||
export let classes: { | ||
ul?: string | ((nodes: Node[]) => string); | ||
li?: string | ((node: Node) => string); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,77 @@ | |
import TreeList from '$lib/components/TreeList.svelte'; | ||
import Preview from '$lib/components/Preview.svelte'; | ||
import Blockquote from '$docs/Blockquote.svelte'; | ||
</script> | ||
import Icon from '$lib/components/Icon.svelte'; | ||
import { mdiCircleSmall } from '@mdi/js'; | ||
import { cls } from '$lib'; | ||
|
||
type Node = { name: string; level: number; children: Node[] }; | ||
|
||
|
||
let nodes: Node[] = [ | ||
{ | ||
name: 'Node 1', | ||
level: 1, | ||
children: [ | ||
{ | ||
name: 'Node 1.1', | ||
level: 2, | ||
children: [ | ||
{ | ||
name: 'Node 1.1.1', | ||
level: 3, | ||
children: [] | ||
}, | ||
{ | ||
name: 'Node 1.1.2', | ||
level: 3, | ||
children: [] | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'Node 1.2', | ||
level: 2, | ||
children: [] | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'Node 2', | ||
level: 1, | ||
children: [ | ||
{ | ||
name: 'Node 2.1', | ||
level: 2, | ||
children: [] | ||
} | ||
] | ||
} | ||
]; | ||
</script> | ||
<h1>Examples</h1> | ||
|
||
<Blockquote>TODO</Blockquote> | ||
Wer're going to use a TreeList to render the following tree using <ul> and <li>: | ||
<br><br> | ||
|
||
<Preview language="typescript" code="{"type Node = { name: string; level: number; children: Node[] };\n\nconst nodes =" + JSON.stringify(nodes, null, 2)}"> | ||
<pre> | ||
type Node = { name: string; level: number; children: Node[] }; | ||
const nodes = {JSON.stringify(nodes, null, 2).slice(0, 300)}... | ||
</pre> | ||
</Preview> | ||
Comment on lines
+58
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it might be nicer to add CleanShot.2023-11-03.at.10.01.03.mp4I would think we would show it inline instead of via a dialog, but just a nice JSON preview. What do you think? |
||
|
||
<br><br> | ||
|
||
<Preview> | ||
<TreeList nodes="{nodes}" let:node | ||
classes={{ li: (node) => cls(node.level === 1 ? 'mb-2' : node.level > 2 ? 'ml-3' : '') }} | ||
> | ||
<slot {node}> | ||
{#if node.level > 1} | ||
<Icon path={mdiCircleSmall} class="-mx-1 text-black/30" /> | ||
{/if} | ||
{@html node.name} | ||
</slot> | ||
</TreeList> | ||
</Preview> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
@type
instead since it's not a function parameter (I'm not a jsdoc expert though)./** @type {{ name: string; children: Node[] }[]} */
Doing so improves the docs (at least how Sveld parses them). See the orange
unknown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ment to link to the jsdoc
@type
docs - https://jsdoc.app/tags-type.htmlAlso, if we needed to do per-property comments, I think we would need to use this syntax...
but I'm not sure it's worth it over just...
/** @type {{ id: string; name: string; age: number }} */
as I don't think it's handled by Sveld (or at least we have a way to show it in the docs). It could improve VSCode developer experience though (but haven't tested).
Thanks again for tackling this.