-
Notifications
You must be signed in to change notification settings - Fork 246
feat(tree): hide children #454
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
Conversation
Signed-off-by: Carlos Alexandro Becker <[email protected]>
Another thing to improve this PR: have an example hiding both ways with comments on why you would use Hide vs SetHidden. It already says in their go doc, but could be handy to show how they differ in usage. |
SetValue for tree does the same thing as Root. Should I mention any difference in the docs? Root can be used during or after creation, SetValue can be used after creation |
After looking at this again and putting an example together, I think we may want a enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("63")).MarginRight(1)
rootStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("35"))
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212"))
t := tree.
Root("⁜ Makeup").
Child(
"Glossier",
"Fenty Beauty",
tree.New().Child(
"Gloss Bomb Universal Lip Luminizer",
"Hot Cheeks Velour Blushlighter",
),
"Nyx",
"Mac",
"Milk",
).
Enumerator(tree.RoundedEnumerator).
EnumeratorStyle(enumeratorStyle).
RootStyle(rootStyle).
ItemStyle(itemStyle)
glossier := t.Children().At(0)
glossier.SetValue(tree.Root(glossier.Value()).Child(tree.Root("Apparel").Child("Pink Hoodie", "Baseball Cap")))
fmt.Println(t.String()) Another thing I noticed here is that when you add a nested tree after the original tree was created, it doesn't inherit the styles. Check out the difference between Glossier and Fenty Beauty above. Will work on that in a separate PR using this as the base branch |
I simplified the usage and it feels much better now. You can update a
and these work with Here's what it looks like: enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("63")).MarginRight(1)
rootStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("35"))
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212"))
t := tree.
Root("⁜ Makeup").
Child(
"Glossier",
"Fenty Beauty",
tree.New().Child(
"Gloss Bomb Universal Lip Luminizer",
"Hot Cheeks Velour Blushlighter",
),
"Nyx",
"Mac",
"Milk",
).
Enumerator(tree.RoundedEnumerator).
EnumeratorStyle(enumeratorStyle).
RootStyle(rootStyle).
ItemStyle(itemStyle)
// Add a Tree as a Child of "Glossier"
t.Replace(0, t.Children().At(0).Child(
tree.Root("Apparel").Child("Pink Hoodie", "Baseball Cap"),
))
// Add a Leaf as a Child of "Glossier"
t.Children().At(0).Child("Makeup")
fmt.Println(ansi.Strip(t.String())) Note: you have to call |
I'll split this PR into two... The other |
I updated the godoc of tree to match capitalization used for leaf while I was at it